Mercurial > cpython-lru_cache-weakref
annotate Modules/grpmodule.c @ 78069:a8aa77458e12 3.2
Add c_size_t and c_ssize_t to the ctypes summary table.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Thu, 12 Jul 2012 20:31:50 +0200 |
| parents | 3c9232a684ae |
| children | b322655a4a88 |
| 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 |
|
76371805d9f3
Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 /* 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
|
3 |
|
4774
9e48abbee6c5
Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4503
diff
changeset
|
4 #include "Python.h" |
|
1677
76371805d9f3
Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 |
|
76371805d9f3
Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
|
76371805d9f3
Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 #include <grp.h> |
|
76371805d9f3
Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 |
|
22099
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
9 static PyStructSequence_Field struct_group_type_fields[] = { |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
10 {"gr_name", "group name"}, |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
11 {"gr_passwd", "password"}, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54425
diff
changeset
|
12 {"gr_gid", "group id"}, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54425
diff
changeset
|
13 {"gr_mem", "group memebers"}, |
|
22099
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
14 {0} |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
15 }; |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
16 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22099
diff
changeset
|
17 PyDoc_STRVAR(struct_group__doc__, |
|
22099
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
18 "grp.struct_group: Results from getgr*() routines.\n\n\ |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
19 This object may be accessed either as a tuple of\n\ |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
20 (gr_name,gr_passwd,gr_gid,gr_mem)\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22099
diff
changeset
|
21 or via the object attributes as named in the above tuple.\n"); |
|
22099
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
22 |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
23 static PyStructSequence_Desc struct_group_type_desc = { |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
24 "grp.struct_group", |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
25 struct_group__doc__, |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
26 struct_group_type_fields, |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
27 4, |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
28 }; |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
29 |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
30 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36324
diff
changeset
|
31 static int initialized; |
|
22099
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
32 static PyTypeObject StructGrpType; |
|
13433
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
33 |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
34 static PyObject * |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
35 mkgrent(struct group *p) |
|
1677
76371805d9f3
Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 { |
|
22099
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
37 int setIndex = 0; |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
38 PyObject *v = PyStructSequence_New(&StructGrpType), *w; |
|
13433
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
39 char **member; |
|
22099
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
40 |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
41 if (v == NULL) |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
42 return NULL; |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
43 |
|
13433
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
44 if ((w = PyList_New(0)) == NULL) { |
|
22099
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
45 Py_DECREF(v); |
|
13433
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
46 return NULL; |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
47 } |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
48 for (member = p->gr_mem; *member != NULL; member++) { |
|
61365
f737d6cbb045
Replace PyUnicode_Decode(buf, strlen(buf), Py_FileSystemDefaultEncoding,
Victor Stinner <victor.stinner@haypocalc.com>
parents:
54425
diff
changeset
|
49 PyObject *x = PyUnicode_DecodeFSDefault(*member); |
|
13433
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
50 if (x == NULL || PyList_Append(w, x) != 0) { |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
51 Py_XDECREF(x); |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
52 Py_DECREF(w); |
|
22099
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
53 Py_DECREF(v); |
|
13433
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
54 return NULL; |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
55 } |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
56 Py_DECREF(x); |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
57 } |
|
22099
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
58 |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
59 #define SET(i,val) PyStructSequence_SET_ITEM(v, i, val) |
|
61365
f737d6cbb045
Replace PyUnicode_Decode(buf, strlen(buf), Py_FileSystemDefaultEncoding,
Victor Stinner <victor.stinner@haypocalc.com>
parents:
54425
diff
changeset
|
60 SET(setIndex++, PyUnicode_DecodeFSDefault(p->gr_name)); |
|
28949
ac487a7f7f2c
Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25302
diff
changeset
|
61 #ifdef __VMS |
|
ac487a7f7f2c
Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25302
diff
changeset
|
62 SET(setIndex++, Py_None); |
|
ac487a7f7f2c
Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25302
diff
changeset
|
63 Py_INCREF(Py_None); |
|
ac487a7f7f2c
Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25302
diff
changeset
|
64 #else |
|
25302
eb28dcddd34d
Deal with a NULL gr_passwd. Reported by Anders Qvist.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
65 if (p->gr_passwd) |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61365
diff
changeset
|
66 SET(setIndex++, PyUnicode_DecodeFSDefault(p->gr_passwd)); |
|
25302
eb28dcddd34d
Deal with a NULL gr_passwd. Reported by Anders Qvist.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
67 else { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54425
diff
changeset
|
68 SET(setIndex++, Py_None); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54425
diff
changeset
|
69 Py_INCREF(Py_None); |
|
25302
eb28dcddd34d
Deal with a NULL gr_passwd. Reported by Anders Qvist.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
70 } |
|
28949
ac487a7f7f2c
Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25302
diff
changeset
|
71 #endif |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43866
diff
changeset
|
72 SET(setIndex++, PyLong_FromLong((long) p->gr_gid)); |
|
22099
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
73 SET(setIndex++, w); |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
74 #undef SET |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
75 |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
76 if (PyErr_Occurred()) { |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
77 Py_DECREF(v); |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
78 return NULL; |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
79 } |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
80 |
|
13433
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
81 return v; |
|
1677
76371805d9f3
Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
82 } |
|
76371805d9f3
Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
83 |
|
13433
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
84 static PyObject * |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
85 grp_getgrgid(PyObject *self, PyObject *pyo_id) |
|
1677
76371805d9f3
Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
86 { |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
87 PyObject *py_int_id; |
|
35551
57f630a9de26
- Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents:
31404
diff
changeset
|
88 unsigned int gid; |
|
13433
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
89 struct group *p; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
90 |
|
50866
8325eb041921
Merged revisions 68675 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48660
diff
changeset
|
91 py_int_id = PyNumber_Long(pyo_id); |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
92 if (!py_int_id) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54425
diff
changeset
|
93 return NULL; |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43866
diff
changeset
|
94 gid = PyLong_AS_LONG(py_int_id); |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
95 Py_DECREF(py_int_id); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
96 |
|
13433
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
97 if ((p = getgrgid(gid)) == NULL) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54425
diff
changeset
|
98 PyErr_Format(PyExc_KeyError, "getgrgid(): gid not found: %d", gid); |
|
13433
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
99 return NULL; |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
100 } |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
101 return mkgrent(p); |
|
1677
76371805d9f3
Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
102 } |
|
76371805d9f3
Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
103 |
|
13433
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
104 static PyObject * |
|
54422
28d64192ab5a
Issue #4859: Implement PEP 383 for pwd, spwd, and grp.
Martin v. Löwis <martin@v.loewis.de>
parents:
50866
diff
changeset
|
105 grp_getgrnam(PyObject *self, PyObject *args) |
|
1677
76371805d9f3
Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
106 { |
|
13433
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
107 char *name; |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
108 struct group *p; |
|
54422
28d64192ab5a
Issue #4859: Implement PEP 383 for pwd, spwd, and grp.
Martin v. Löwis <martin@v.loewis.de>
parents:
50866
diff
changeset
|
109 PyObject *arg, *bytes, *retval = NULL; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
110 |
|
54422
28d64192ab5a
Issue #4859: Implement PEP 383 for pwd, spwd, and grp.
Martin v. Löwis <martin@v.loewis.de>
parents:
50866
diff
changeset
|
111 if (!PyArg_ParseTuple(args, "U:getgrnam", &arg)) |
|
28d64192ab5a
Issue #4859: Implement PEP 383 for pwd, spwd, and grp.
Martin v. Löwis <martin@v.loewis.de>
parents:
50866
diff
changeset
|
112 return NULL; |
|
61597
b5ba7ea4246b
Issue #8715: Create PyUnicode_EncodeFSDefault() function: Encode a Unicode
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61466
diff
changeset
|
113 if ((bytes = PyUnicode_EncodeFSDefault(arg)) == NULL) |
|
54422
28d64192ab5a
Issue #4859: Implement PEP 383 for pwd, spwd, and grp.
Martin v. Löwis <martin@v.loewis.de>
parents:
50866
diff
changeset
|
114 return NULL; |
|
28d64192ab5a
Issue #4859: Implement PEP 383 for pwd, spwd, and grp.
Martin v. Löwis <martin@v.loewis.de>
parents:
50866
diff
changeset
|
115 if (PyBytes_AsStringAndSize(bytes, &name, NULL) == -1) |
|
28d64192ab5a
Issue #4859: Implement PEP 383 for pwd, spwd, and grp.
Martin v. Löwis <martin@v.loewis.de>
parents:
50866
diff
changeset
|
116 goto out; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54425
diff
changeset
|
117 |
|
13433
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
118 if ((p = getgrnam(name)) == NULL) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54425
diff
changeset
|
119 PyErr_Format(PyExc_KeyError, "getgrnam(): name not found: %s", name); |
|
54422
28d64192ab5a
Issue #4859: Implement PEP 383 for pwd, spwd, and grp.
Martin v. Löwis <martin@v.loewis.de>
parents:
50866
diff
changeset
|
120 goto out; |
|
13433
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
121 } |
|
54422
28d64192ab5a
Issue #4859: Implement PEP 383 for pwd, spwd, and grp.
Martin v. Löwis <martin@v.loewis.de>
parents:
50866
diff
changeset
|
122 retval = mkgrent(p); |
|
28d64192ab5a
Issue #4859: Implement PEP 383 for pwd, spwd, and grp.
Martin v. Löwis <martin@v.loewis.de>
parents:
50866
diff
changeset
|
123 out: |
|
28d64192ab5a
Issue #4859: Implement PEP 383 for pwd, spwd, and grp.
Martin v. Löwis <martin@v.loewis.de>
parents:
50866
diff
changeset
|
124 Py_DECREF(bytes); |
|
28d64192ab5a
Issue #4859: Implement PEP 383 for pwd, spwd, and grp.
Martin v. Löwis <martin@v.loewis.de>
parents:
50866
diff
changeset
|
125 return retval; |
|
1677
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 |
|
13433
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
128 static PyObject * |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
129 grp_getgrall(PyObject *self, PyObject *ignore) |
|
1677
76371805d9f3
Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
130 { |
|
13433
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
131 PyObject *d; |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
132 struct group *p; |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
133 |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
134 if ((d = PyList_New(0)) == NULL) |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
135 return NULL; |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
136 setgrent(); |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
137 while ((p = getgrent()) != NULL) { |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
138 PyObject *v = mkgrent(p); |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
139 if (v == NULL || PyList_Append(d, v) != 0) { |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
140 Py_XDECREF(v); |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
141 Py_DECREF(d); |
|
54425
134d12c2e745
Merged revisions 73016 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
54422
diff
changeset
|
142 endgrent(); |
|
13433
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
143 return NULL; |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
144 } |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
145 Py_DECREF(v); |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
146 } |
|
17025
971ff6b58edb
Make sure we close the group and password databases when we are done with
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
147 endgrent(); |
|
13433
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
148 return d; |
|
1677
76371805d9f3
Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
149 } |
|
76371805d9f3
Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
150 |
|
4774
9e48abbee6c5
Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4503
diff
changeset
|
151 static PyMethodDef grp_methods[] = { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54425
diff
changeset
|
152 {"getgrgid", grp_getgrgid, METH_O, |
|
13433
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
153 "getgrgid(id) -> tuple\n\ |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
154 Return the group database entry for the given numeric group ID. If\n\ |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
155 id is not valid, raise KeyError."}, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54425
diff
changeset
|
156 {"getgrnam", grp_getgrnam, METH_VARARGS, |
|
13433
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
157 "getgrnam(name) -> tuple\n\ |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
158 Return the group database entry for the given group name. If\n\ |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
159 name is not valid, raise KeyError."}, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54425
diff
changeset
|
160 {"getgrall", grp_getgrall, METH_NOARGS, |
|
13433
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
161 "getgrall() -> list of tuples\n\ |
|
66899
6afbe4612d49
Merged revisions 87238 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
61467
diff
changeset
|
162 Return a list of all available group entries, in arbitrary order.\n\ |
|
6afbe4612d49
Merged revisions 87238 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
61467
diff
changeset
|
163 An entry whose name starts with '+' or '-' represents an instruction\n\ |
|
6afbe4612d49
Merged revisions 87238 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
61467
diff
changeset
|
164 to use YP/NIS and may not be accessible via getgrnam or getgrgid."}, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54425
diff
changeset
|
165 {NULL, NULL} /* sentinel */ |
|
1677
76371805d9f3
Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
166 }; |
|
76371805d9f3
Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
167 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22099
diff
changeset
|
168 PyDoc_STRVAR(grp__doc__, |
|
13433
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
169 "Access to the Unix group database.\n\ |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
170 \n\ |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
171 Group entries are reported as 4-tuples containing the following fields\n\ |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
172 from the group database, in order:\n\ |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
173 \n\ |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
174 name - name of the group\n\ |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
175 passwd - group password (encrypted); often empty\n\ |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
176 gid - numeric ID of the group\n\ |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
177 mem - list of members\n\ |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
178 \n\ |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
179 The gid is an integer, name and password are strings. (Note that most\n\ |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
180 users are not explicitly listed as members of the groups they are in\n\ |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
181 according to the password database. Check both databases to get\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22099
diff
changeset
|
182 complete membership information.)"); |
|
13433
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
183 |
|
fc78e5a7812a
ANSI-fication of the sources, convert to 4-space indents.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
184 |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
185 |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
186 static struct PyModuleDef grpmodule = { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54425
diff
changeset
|
187 PyModuleDef_HEAD_INIT, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54425
diff
changeset
|
188 "grp", |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54425
diff
changeset
|
189 grp__doc__, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54425
diff
changeset
|
190 -1, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54425
diff
changeset
|
191 grp_methods, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54425
diff
changeset
|
192 NULL, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54425
diff
changeset
|
193 NULL, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54425
diff
changeset
|
194 NULL, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54425
diff
changeset
|
195 NULL |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
196 }; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
197 |
|
24471
f66b3a3509c7
Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents:
23832
diff
changeset
|
198 PyMODINIT_FUNC |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
199 PyInit_grp(void) |
|
1677
76371805d9f3
Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
200 { |
|
22099
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
201 PyObject *m, *d; |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
202 m = PyModule_Create(&grpmodule); |
|
36324
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35551
diff
changeset
|
203 if (m == NULL) |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
204 return NULL; |
|
22099
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
205 d = PyModule_GetDict(m); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36324
diff
changeset
|
206 if (!initialized) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54425
diff
changeset
|
207 PyStructSequence_InitType(&StructGrpType, &struct_group_type_desc); |
|
22099
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
208 PyDict_SetItemString(d, "struct_group", (PyObject *) &StructGrpType); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36324
diff
changeset
|
209 initialized = 1; |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
210 return m; |
|
1677
76371805d9f3
Split pwd in pwd and grp; added imgformat (by Jack)
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
211 } |
