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