annotate Modules/grpmodule.c @ 5817:48b94de85bf3 legacy-trunk

Extensive changes by AMK.
author Guido van Rossum <guido@python.org>
date Thu, 17 Jul 1997 16:29:42 +0000
parents 1bcd4972da7e
children 38023a425e48
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
4774
9e48abbee6c5 Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4503
diff changeset
34 #include "Python.h"
1677
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
35
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 #include <sys/types.h>
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 #include <grp.h>
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
38
4774
9e48abbee6c5 Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4503
diff changeset
39 static PyObject *mkgrent(p)
1677
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 struct group *p;
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 {
4774
9e48abbee6c5 Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4503
diff changeset
42 PyObject *v, *w;
1677
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 char **member;
4774
9e48abbee6c5 Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4503
diff changeset
44 if ((w = PyList_New(0)) == NULL) {
1677
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 return NULL;
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 }
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 for (member = p->gr_mem; *member != NULL; member++) {
4774
9e48abbee6c5 Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4503
diff changeset
48 PyObject *x = PyString_FromString(*member);
9e48abbee6c5 Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4503
diff changeset
49 if (x == NULL || PyList_Append(w, x) != 0) {
9e48abbee6c5 Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4503
diff changeset
50 Py_XDECREF(x);
9e48abbee6c5 Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4503
diff changeset
51 Py_DECREF(w);
1677
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 return NULL;
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 }
4917
1bcd4972da7e Nailed a couple of memory leaks, caught by Purify.
Barry Warsaw <barry@python.org>
parents: 4779
diff changeset
54 Py_DECREF(x);
1677
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 }
4774
9e48abbee6c5 Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4503
diff changeset
56 v = Py_BuildValue("(sslO)",
1677
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);
4774
9e48abbee6c5 Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4503
diff changeset
67 Py_DECREF(w);
1677
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
4774
9e48abbee6c5 Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4503
diff changeset
71 static PyObject *grp_getgrgid(self, args)
9e48abbee6c5 Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4503
diff changeset
72 PyObject *self, *args;
1677
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;
4779
a571c7f08991 Eradicated all references to getintarg and getstrarg and substituded the
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4778
diff changeset
76 if (!PyArg_Parse((args),"i",(&gid)))
1677
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) {
4774
9e48abbee6c5 Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4503
diff changeset
79 PyErr_SetString(PyExc_KeyError, "getgrgid(): gid not found");
1677
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
4774
9e48abbee6c5 Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4503
diff changeset
85 static PyObject *grp_getgrnam(self, args)
9e48abbee6c5 Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4503
diff changeset
86 PyObject *self, *args;
1677
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;
4779
a571c7f08991 Eradicated all references to getintarg and getstrarg and substituded the
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4778
diff changeset
90 if (!PyArg_Parse((args),"s",(&name)))
1677
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) {
4774
9e48abbee6c5 Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4503
diff changeset
93 PyErr_SetString(PyExc_KeyError, "getgrnam(): name not found");
1677
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
4774
9e48abbee6c5 Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4503
diff changeset
99 static PyObject *grp_getgrall(self, args)
9e48abbee6c5 Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4503
diff changeset
100 PyObject *self, *args;
1677
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 {
4774
9e48abbee6c5 Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4503
diff changeset
102 PyObject *d;
1677
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 struct group *p;
4774
9e48abbee6c5 Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4503
diff changeset
104 if (!PyArg_NoArgs(args))
1677
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 return NULL;
4774
9e48abbee6c5 Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4503
diff changeset
106 if ((d = PyList_New(0)) == NULL)
1677
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) {
4774
9e48abbee6c5 Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4503
diff changeset
110 PyObject *v = mkgrent(p);
9e48abbee6c5 Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4503
diff changeset
111 if (v == NULL || PyList_Append(d, v) != 0) {
9e48abbee6c5 Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4503
diff changeset
112 Py_XDECREF(v);
9e48abbee6c5 Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4503
diff changeset
113 Py_DECREF(d);
1677
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 }
4917
1bcd4972da7e Nailed a couple of memory leaks, caught by Purify.
Barry Warsaw <barry@python.org>
parents: 4779
diff changeset
116 Py_DECREF(v);
1677
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 }
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 return d;
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
4774
9e48abbee6c5 Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4503
diff changeset
121 static PyMethodDef grp_methods[] = {
1677
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 {"getgrgid", grp_getgrgid},
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 {"getgrnam", grp_getgrnam},
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 {"getgrall", grp_getgrall},
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 {NULL, NULL} /* sentinel */
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
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 void
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 initgrp()
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 {
4774
9e48abbee6c5 Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4503
diff changeset
131 Py_InitModule("grp", grp_methods);
1677
76371805d9f3 Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 }