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 */
15module core.sys.posix.pwd;
16
17import core.sys.posix.config;
18public import core.sys.posix.sys.types; // for gid_t, uid_t
19
20version (OSX)
21    version = Darwin;
22else version (iOS)
23    version = Darwin;
24else version (TVOS)
25    version = Darwin;
26else version (WatchOS)
27    version = Darwin;
28
29version (Posix):
30extern (C):
31nothrow:
32@nogc:
33@system:
34
35//
36// Required
37//
38/*
39struct 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
48passwd* getpwnam(const scope char*);
49passwd* getpwuid(uid_t);
50*/
51
52version (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}
65else 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}
81else 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}
98else 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}
114else 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}
130else 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}
147else 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}
162else 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}
174else 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}
187else 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}
200else
201{
202    static assert(false, "Unsupported platform");
203}
204
205passwd* getpwnam(const scope char*);
206passwd* getpwuid(uid_t);
207
208//
209// Thread-Safe Functions (TSF)
210//
211/*
212int getpwnam_r(const scope char*, passwd*, char*, size_t, passwd**);
213int getpwuid_r(uid_t, passwd*, char*, size_t, passwd**);
214*/
215
216version (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}
221else 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}
226else 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}
231else 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}
238else 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}
243else 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}
248else 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}
257else version (CRuntime_Bionic)
258{
259}
260else 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}
265else 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}
270else
271{
272    static assert(false, "Unsupported platform");
273}
274
275//
276// XOpen (XSI)
277//
278/*
279void    endpwent();
280passwd* getpwent();
281void    setpwent();
282*/
283
284version (CRuntime_Glibc)
285{
286    void    endpwent();
287    passwd* getpwent();
288    void    setpwent();
289}
290else version (Darwin)
291{
292    void    endpwent();
293    passwd* getpwent();
294    void    setpwent();
295}
296else version (FreeBSD)
297{
298    void    endpwent();
299    passwd* getpwent();
300    void    setpwent();
301}
302else version (NetBSD)
303{
304    void    endpwent();
305    passwd* getpwent();
306    void    setpwent();
307}
308else version (OpenBSD)
309{
310    void    endpwent();
311    passwd* getpwent();
312    void    setpwent();
313}
314else version (DragonFlyBSD)
315{
316    void    endpwent();
317    passwd* getpwent();
318    void    setpwent();
319}
320else version (Solaris)
321{
322    void endpwent();
323    passwd* getpwent();
324    void setpwent();
325}
326else version (CRuntime_Bionic)
327{
328    void    endpwent();
329}
330else version (CRuntime_Musl)
331{
332    void    endpwent();
333    passwd* getpwent();
334    void    setpwent();
335}
336else version (CRuntime_UClibc)
337{
338    void    endpwent();
339    passwd* getpwent();
340    void    setpwent();
341}
342else
343{
344    static assert(false, "Unsupported platform");
345}
346