The OpenD Programming Language

1 /**
2  * D header file for POSIX.
3  *
4  * Copyright: Copyright Sean Kelly 2005 - 2009.
5  * License:   $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
6  * Authors:   Sean Kelly, Alex Rønne Petersen
7  * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
8  */
9 
10 /*          Copyright Sean Kelly 2005 - 2009.
11  * Distributed under the Boost Software License, Version 1.0.
12  *    (See accompanying file LICENSE or copy at
13  *          http://www.boost.org/LICENSE_1_0.txt)
14  */
15 module core.sys.posix.pwd;
16 
17 import core.sys.posix.config;
18 public import core.sys.posix.sys.types; // for gid_t, uid_t
19 
20 version (OSX)
21     version = Darwin;
22 else version (iOS)
23     version = Darwin;
24 else version (TVOS)
25     version = Darwin;
26 else version (WatchOS)
27     version = Darwin;
28 
29 version (Posix):
30 extern (C):
31 nothrow:
32 @nogc:
33 
34 //
35 // Required
36 //
37 /*
38 struct passwd
39 {
40     char*   pw_name;
41     uid_t   pw_uid;
42     gid_t   pw_gid;
43     char*   pw_dir;
44     char*   pw_shell;
45 }
46 
47 passwd* getpwnam(const scope char*);
48 passwd* getpwuid(uid_t);
49 */
50 
51 version (CRuntime_Glibc)
52 {
53     struct passwd
54     {
55         char*   pw_name;
56         char*   pw_passwd;
57         uid_t   pw_uid;
58         gid_t   pw_gid;
59         char*   pw_gecos;
60         char*   pw_dir;
61         char*   pw_shell;
62     }
63 }
64 else version (Darwin)
65 {
66     struct passwd
67     {
68         char*   pw_name;
69         char*   pw_passwd;
70         uid_t   pw_uid;
71         gid_t   pw_gid;
72         time_t  pw_change;
73         char*   pw_class;
74         char*   pw_gecos;
75         char*   pw_dir;
76         char*   pw_shell;
77         time_t  pw_expire;
78     }
79 }
80 else version (FreeBSD)
81 {
82     struct passwd
83     {
84         char*   pw_name;        /* user name */
85         char*   pw_passwd;      /* encrypted password */
86         uid_t   pw_uid;         /* user uid */
87         gid_t   pw_gid;         /* user gid */
88         time_t  pw_change;      /* password change time */
89         char*   pw_class;       /* user access class */
90         char*   pw_gecos;       /* Honeywell login info */
91         char*   pw_dir;     /* home directory */
92         char*   pw_shell;       /* default shell */
93         time_t  pw_expire;      /* account expiration */
94         int pw_fields;      /* internal: fields filled in */
95     }
96 }
97 else version (NetBSD)
98 {
99     struct passwd
100     {
101         char*   pw_name;        /* user name */
102         char*   pw_passwd;      /* encrypted password */
103         uid_t   pw_uid;         /* user uid */
104         gid_t   pw_gid;         /* user gid */
105         time_t  pw_change;      /* password change time */
106         char*   pw_class;       /* user access class */
107         char*   pw_gecos;       /* Honeywell login info */
108         char*   pw_dir;     /* home directory */
109         char*   pw_shell;       /* default shell */
110         time_t  pw_expire;      /* account expiration */
111     }
112 }
113 else version (OpenBSD)
114 {
115     struct passwd
116     {
117         char*   pw_name;        /* user name */
118         char*   pw_passwd;      /* encrypted password */
119         uid_t   pw_uid;         /* user uid */
120         gid_t   pw_gid;         /* user gid */
121         time_t  pw_change;      /* password change time */
122         char*   pw_class;       /* user access class */
123         char*   pw_gecos;       /* Honeywell login info */
124         char*   pw_dir;     /* home directory */
125         char*   pw_shell;       /* default shell */
126         time_t  pw_expire;      /* account expiration */
127     }
128 }
129 else version (DragonFlyBSD)
130 {
131     struct passwd
132     {
133         char*   pw_name;        /* user name */
134         char*   pw_passwd;      /* encrypted password */
135         uid_t   pw_uid;         /* user uid */
136         gid_t   pw_gid;         /* user gid */
137         time_t  pw_change;      /* password change time */
138         char*   pw_class;       /* user access class */
139         char*   pw_gecos;       /* Honeywell login info */
140         char*   pw_dir;         /* home directory */
141         char*   pw_shell;       /* default shell */
142         time_t  pw_expire;      /* account expiration */
143         int pw_fields;          /* internal: fields filled in */
144     }
145 }
146 else version (Solaris)
147 {
148     struct passwd
149     {
150         char* pw_name;
151         char* pw_passwd;
152         uid_t pw_uid;
153         gid_t pw_gid;
154         char* pw_age;
155         char* pw_comment;
156         char* pw_gecos;
157         char* pw_dir;
158         char* pw_shell;
159     }
160 }
161 else version (CRuntime_Bionic)
162 {
163     struct passwd
164     {
165         char*   pw_name;
166         char*   pw_passwd;
167         uid_t   pw_uid;
168         gid_t   pw_gid;
169         char*   pw_dir;
170         char*   pw_shell;
171     }
172 }
173 else version (CRuntime_Musl)
174 {
175     struct passwd
176     {
177         char *pw_name;
178         char *pw_passwd;
179         uid_t pw_uid;
180         gid_t pw_gid;
181         char *pw_gecos;
182         char *pw_dir;
183         char *pw_shell;
184     }
185 }
186 else version (CRuntime_UClibc)
187 {
188     struct passwd
189     {
190         char*   pw_name;
191         char*   pw_passwd;
192         uid_t   pw_uid;
193         gid_t   pw_gid;
194         char*   pw_gecos;
195         char*   pw_dir;
196         char*   pw_shell;
197     }
198 }
199 else
200 {
201     static assert(false, "Unsupported platform");
202 }
203 
204 passwd* getpwnam(const scope char*);
205 passwd* getpwuid(uid_t);
206 
207 //
208 // Thread-Safe Functions (TSF)
209 //
210 /*
211 int getpwnam_r(const scope char*, passwd*, char*, size_t, passwd**);
212 int getpwuid_r(uid_t, passwd*, char*, size_t, passwd**);
213 */
214 
215 version (CRuntime_Glibc)
216 {
217     int getpwnam_r(const scope char*, passwd*, char*, size_t, passwd**);
218     int getpwuid_r(uid_t, passwd*, char*, size_t, passwd**);
219 }
220 else version (Darwin)
221 {
222     int getpwnam_r(const scope char*, passwd*, char*, size_t, passwd**);
223     int getpwuid_r(uid_t, passwd*, char*, size_t, passwd**);
224 }
225 else version (FreeBSD)
226 {
227     int getpwnam_r(const scope char*, passwd*, char*, size_t, passwd**);
228     int getpwuid_r(uid_t, passwd*, char*, size_t, passwd**);
229 }
230 else version (NetBSD)
231 {
232     int __getpwnam_r50(const scope char*, passwd*, char*, size_t, passwd**);
233     alias __getpwnam_r50 getpwnam_r;
234     int __getpwuid_r50(uid_t, passwd*, char*, size_t, passwd**);
235     alias __getpwuid_r50 getpwuid_r;
236 }
237 else version (OpenBSD)
238 {
239     int getpwnam_r(const scope char*, passwd*, char*, size_t, passwd**);
240     int getpwuid_r(uid_t, passwd*, char*, size_t, passwd**);
241 }
242 else version (DragonFlyBSD)
243 {
244     int getpwnam_r(const scope char*, passwd*, char*, size_t, passwd**);
245     int getpwuid_r(uid_t, passwd*, char*, size_t, passwd**);
246 }
247 else version (Solaris)
248 {
249     alias getpwnam_r = __posix_getpwnam_r;
250     alias getpwuid_r = __posix_getpwuid_r;
251 
252     // POSIX.1c standard version of the functions
253     int __posix_getpwnam_r(const scope char*, passwd*, char*, size_t, passwd**);
254     int __posix_getpwuid_r(uid_t, passwd*, char*, size_t, passwd**);
255 }
256 else version (CRuntime_Bionic)
257 {
258 }
259 else version (CRuntime_Musl)
260 {
261     int getpwnam_r(const scope char*, passwd*, char*, size_t, passwd**);
262     int getpwuid_r(uid_t, passwd*, char*, size_t, passwd**);
263 }
264 else version (CRuntime_UClibc)
265 {
266     int getpwnam_r(const scope char*, passwd*, char*, size_t, passwd**);
267     int getpwuid_r(uid_t, passwd*, char*, size_t, passwd**);
268 }
269 else
270 {
271     static assert(false, "Unsupported platform");
272 }
273 
274 //
275 // XOpen (XSI)
276 //
277 /*
278 void    endpwent();
279 passwd* getpwent();
280 void    setpwent();
281 */
282 
283 version (CRuntime_Glibc)
284 {
285     void    endpwent();
286     passwd* getpwent();
287     void    setpwent();
288 }
289 else version (Darwin)
290 {
291     void    endpwent();
292     passwd* getpwent();
293     void    setpwent();
294 }
295 else version (FreeBSD)
296 {
297     void    endpwent();
298     passwd* getpwent();
299     void    setpwent();
300 }
301 else version (NetBSD)
302 {
303     void    endpwent();
304     passwd* getpwent();
305     void    setpwent();
306 }
307 else version (OpenBSD)
308 {
309     void    endpwent();
310     passwd* getpwent();
311     void    setpwent();
312 }
313 else version (DragonFlyBSD)
314 {
315     void    endpwent();
316     passwd* getpwent();
317     void    setpwent();
318 }
319 else version (Solaris)
320 {
321     void endpwent();
322     passwd* getpwent();
323     void setpwent();
324 }
325 else version (CRuntime_Bionic)
326 {
327     void    endpwent();
328 }
329 else version (CRuntime_Musl)
330 {
331     void    endpwent();
332     passwd* getpwent();
333     void    setpwent();
334 }
335 else version (CRuntime_UClibc)
336 {
337     void    endpwent();
338     passwd* getpwent();
339     void    setpwent();
340 }
341 else
342 {
343     static assert(false, "Unsupported platform");
344 }