1 /***********************************************************
2 Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
3 Amsterdam, The Netherlands.
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the names of Stichting Mathematisch
12 Centrum or CWI not be used in advertising or publicity pertaining to
13 distribution of the software without specific, written prior permission.
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 ******************************************************************/
25 /* Passwd/group file access module */
27 #include "allobjects.h"
28 #include "modsupport.h"
30 #include <sys/types.h>
38 static object
*mkpwent(p
)
41 return mkvalue("(ssllsss)",
51 static object
*pwd_getpwuid(self
, args
)
56 if (!getintarg(args
, &uid
))
58 if ((p
= getpwuid(uid
)) == NULL
) {
59 err_setstr(KeyError
, "getpwuid(): uid not found");
65 static object
*pwd_getpwnam(self
, args
)
70 if (!getstrarg(args
, &name
))
72 if ((p
= getpwnam(name
)) == NULL
) {
73 err_setstr(KeyError
, "getpwnam(): name not found");
79 static object
*pwd_getpwall(self
, args
)
86 if ((d
= newlistobject(0)) == NULL
)
89 while ((p
= getpwent()) != NULL
) {
90 object
*v
= mkpwent(p
);
91 if (v
== NULL
|| addlistitem(d
, v
) != 0) {
100 static struct methodlist pwd_methods
[] = {
101 {"getpwuid", pwd_getpwuid
},
102 {"getpwnam", pwd_getpwnam
},
103 {"getpwall", pwd_getpwall
},
104 {NULL
, NULL
} /* sentinel */
110 initmodule("pwd", pwd_methods
);
117 static object
*mkgrent(p
)
122 if ((w
= newlistobject(0)) == NULL
) {
125 for (member
= p
->gr_mem
; *member
!= NULL
; member
++) {
126 object
*x
= newstringobject(*member
);
127 if (x
== NULL
|| addlistitem(w
, x
) != 0) {
133 v
= mkvalue("(sslO)",
142 static object
*grp_getgrgid(self
, args
)
147 if (!getintarg(args
, &gid
))
149 if ((p
= getgrgid(gid
)) == NULL
) {
150 err_setstr(KeyError
, "getgrgid(): gid not found");
156 static object
*grp_getgrnam(self
, args
)
161 if (!getstrarg(args
, &name
))
163 if ((p
= getgrnam(name
)) == NULL
) {
164 err_setstr(KeyError
, "getgrnam(): name not found");
170 static object
*grp_getgrall(self
, args
)
177 if ((d
= newlistobject(0)) == NULL
)
180 while ((p
= getgrent()) != NULL
) {
181 object
*v
= mkgrent(p
);
182 if (v
== NULL
|| addlistitem(d
, v
) != 0) {
191 static struct methodlist grp_methods
[] = {
192 {"getgrgid", grp_getgrgid
},
193 {"getgrnam", grp_getgrnam
},
194 {"getgrall", grp_getgrall
},
195 {NULL
, NULL
} /* sentinel */
201 initmodule("grp", grp_methods
);