annotate Modules/grpmodule.c @ 4566:6403c94de50d legacy-trunk

Added safeguard against failure in __del__.
author Guido van Rossum <guido@python.org>
date Wed, 27 Nov 1996 19:39:58 +0000
parents 65d2d8e67da3
children 9e48abbee6c5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1677
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 /***********************************************************
2061
172ba04a5191 Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 1677
diff changeset
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
172ba04a5191 Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 1677
diff changeset
3 The Netherlands.
1677
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 All Rights Reserved
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2297
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2297
diff changeset
8 documentation for any purpose and without fee is hereby granted,
1677
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 provided that the above copyright notice appear in all copies and that
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2297
diff changeset
10 both that copyright notice and this permission notice appear in
1677
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2297
diff changeset
12 Centrum or CWI or Corporation for National Research Initiatives or
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2297
diff changeset
13 CNRI not be used in advertising or publicity pertaining to
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2297
diff changeset
14 distribution of the software without specific, written prior
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2297
diff changeset
15 permission.
1677
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
16
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2297
diff changeset
17 While CWI is the initial source for this software, a modified version
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2297
diff changeset
18 is made available by the Corporation for National Research Initiatives
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2297
diff changeset
19 (CNRI) at the Internet address ftp://ftp.python.org.
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2297
diff changeset
20
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2297
diff changeset
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2297
diff changeset
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2297
diff changeset
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2297
diff changeset
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2297
diff changeset
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2297
diff changeset
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2297
diff changeset
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2297
diff changeset
28 PERFORMANCE OF THIS SOFTWARE.
1677
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
29
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 ******************************************************************/
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
31
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 /* UNIX group file access module */
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 #include "allobjects.h"
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 #include "modsupport.h"
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
36
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 #include <sys/types.h>
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 #include <grp.h>
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
39
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 static object *mkgrent(p)
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 struct group *p;
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 {
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 object *v, *w;
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 char **member;
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 if ((w = newlistobject(0)) == NULL) {
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 return NULL;
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 }
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 for (member = p->gr_mem; *member != NULL; member++) {
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 object *x = newstringobject(*member);
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 if (x == NULL || addlistitem(w, x) != 0) {
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 XDECREF(x);
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 DECREF(w);
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 return NULL;
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 }
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 }
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 v = mkvalue("(sslO)",
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 p->gr_name,
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 p->gr_passwd,
2297
9717f6a8f5fa patches for NeXT weirdness
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
59 #if defined(NeXT) && defined(_POSIX_SOURCE) && defined(__LITTLE_ENDIAN__)
9717f6a8f5fa patches for NeXT weirdness
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
60 /* Correct a bug present on Intel machines in NextStep 3.2 and 3.3;
9717f6a8f5fa patches for NeXT weirdness
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
61 for later versions you may have to remove this */
9717f6a8f5fa patches for NeXT weirdness
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
62 (long)p->gr_short_pad, /* ugh-NeXT broke the padding */
9717f6a8f5fa patches for NeXT weirdness
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
63 #else
1677
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 (long)p->gr_gid,
2297
9717f6a8f5fa patches for NeXT weirdness
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
65 #endif
1677
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 w);
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 DECREF(w);
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 return v;
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 }
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
70
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 static object *grp_getgrgid(self, args)
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 object *self, *args;
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 {
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 int gid;
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 struct group *p;
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 if (!getintarg(args, &gid))
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 return NULL;
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 if ((p = getgrgid(gid)) == NULL) {
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 err_setstr(KeyError, "getgrgid(): gid not found");
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 return NULL;
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 }
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 return mkgrent(p);
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 }
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
84
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 static object *grp_getgrnam(self, args)
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 object *self, *args;
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 {
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 char *name;
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 struct group *p;
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 if (!getstrarg(args, &name))
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 return NULL;
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 if ((p = getgrnam(name)) == NULL) {
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 err_setstr(KeyError, "getgrnam(): name not found");
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 return NULL;
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 }
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 return mkgrent(p);
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 }
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
98
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 static object *grp_getgrall(self, args)
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 object *self, *args;
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 {
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 object *d;
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 struct group *p;
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 if (!getnoarg(args))
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 return NULL;
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 if ((d = newlistobject(0)) == NULL)
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 return NULL;
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 setgrent();
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 while ((p = getgrent()) != NULL) {
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 object *v = mkgrent(p);
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 if (v == NULL || addlistitem(d, v) != 0) {
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 XDECREF(v);
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 DECREF(d);
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 return NULL;
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 }
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 }
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 return d;
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 }
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
119
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 static struct methodlist grp_methods[] = {
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 {"getgrgid", grp_getgrgid},
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 {"getgrnam", grp_getgrnam},
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 {"getgrall", grp_getgrall},
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 {NULL, NULL} /* sentinel */
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 };
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
126
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 void
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 initgrp()
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 {
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 initmodule("grp", grp_methods);
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 }