1 /***********************************************************
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
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 /* UNIX group file access module */
27 #include "allobjects.h"
28 #include "modsupport.h"
30 #include <sys/types.h>
33 static object
*mkgrent(p
)
38 if ((w
= newlistobject(0)) == NULL
) {
41 for (member
= p
->gr_mem
; *member
!= NULL
; member
++) {
42 object
*x
= newstringobject(*member
);
43 if (x
== NULL
|| addlistitem(w
, x
) != 0) {
52 #if defined(NeXT) && defined(_POSIX_SOURCE) && defined(__LITTLE_ENDIAN__)
53 /* Correct a bug present on Intel machines in NextStep 3.2 and 3.3;
54 for later versions you may have to remove this */
55 (long)p
->gr_short_pad
, /* ugh-NeXT broke the padding */
64 static object
*grp_getgrgid(self
, args
)
69 if (!getintarg(args
, &gid
))
71 if ((p
= getgrgid(gid
)) == NULL
) {
72 err_setstr(KeyError
, "getgrgid(): gid not found");
78 static object
*grp_getgrnam(self
, args
)
83 if (!getstrarg(args
, &name
))
85 if ((p
= getgrnam(name
)) == NULL
) {
86 err_setstr(KeyError
, "getgrnam(): name not found");
92 static object
*grp_getgrall(self
, args
)
99 if ((d
= newlistobject(0)) == NULL
)
102 while ((p
= getgrent()) != NULL
) {
103 object
*v
= mkgrent(p
);
104 if (v
== NULL
|| addlistitem(d
, v
) != 0) {
113 static struct methodlist grp_methods
[] = {
114 {"getgrgid", grp_getgrgid
},
115 {"getgrnam", grp_getgrnam
},
116 {"getgrall", grp_getgrall
},
117 {NULL
, NULL
} /* sentinel */
123 initmodule("grp", grp_methods
);