Mercurial > cpython-lru_cache-weakref
annotate Modules/pwdmodule.c @ 58765:2ba7677bfa95 legacy-trunk
testCopysign was defined twice in test_math; combine the definitions
| author | Mark Dickinson <dickinsm@gmail.com> |
|---|---|
| date | Sat, 06 Feb 2010 23:11:25 +0000 |
| parents | 5dec8a12e455 |
| children | fd25030223b0 |
| rev | line source |
|---|---|
| 201 | 1 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1351
diff
changeset
|
2 /* UNIX password file access module */ |
| 201 | 3 |
| 4684 | 4 #include "Python.h" |
|
22099
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
5 #include "structseq.h" |
| 201 | 6 |
| 7 #include <sys/types.h> | |
| 8 #include <pwd.h> | |
| 9 | |
|
22099
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
10 static PyStructSequence_Field struct_pwd_type_fields[] = { |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
11 {"pw_name", "user name"}, |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
12 {"pw_passwd", "password"}, |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
13 {"pw_uid", "user id"}, |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
14 {"pw_gid", "group id"}, |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
15 {"pw_gecos", "real name"}, |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
16 {"pw_dir", "home directory"}, |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
17 {"pw_shell", "shell program"}, |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
18 {0} |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
19 }; |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
20 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23048
diff
changeset
|
21 PyDoc_STRVAR(struct_passwd__doc__, |
|
22099
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
22 "pwd.struct_passwd: Results from getpw*() routines.\n\n\ |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
23 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
|
24 (pw_name,pw_passwd,pw_uid,pw_gid,pw_gecos,pw_dir,pw_shell)\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23048
diff
changeset
|
25 or via the object attributes as named in the above tuple."); |
|
22099
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
26 |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
27 static PyStructSequence_Desc struct_pwd_type_desc = { |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
28 "pwd.struct_passwd", |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
29 struct_passwd__doc__, |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
30 struct_pwd_type_fields, |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
31 7, |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
32 }; |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
33 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23048
diff
changeset
|
34 PyDoc_STRVAR(pwd__doc__, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23048
diff
changeset
|
35 "This module provides access to the Unix password database.\n\ |
|
7530
891105dac9b4
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6142
diff
changeset
|
36 It is available on all Unix versions.\n\ |
|
891105dac9b4
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6142
diff
changeset
|
37 \n\ |
|
891105dac9b4
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6142
diff
changeset
|
38 Password database entries are reported as 7-tuples containing the following\n\ |
|
891105dac9b4
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6142
diff
changeset
|
39 items from the password database (see `<pwd.h>'), in order:\n\ |
|
891105dac9b4
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6142
diff
changeset
|
40 pw_name, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell.\n\ |
|
891105dac9b4
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6142
diff
changeset
|
41 The uid and gid items are integers, all others are strings. An\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23048
diff
changeset
|
42 exception is raised if the entry asked for cannot be found."); |
|
7530
891105dac9b4
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6142
diff
changeset
|
43 |
|
891105dac9b4
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6142
diff
changeset
|
44 |
|
37772
b90a7c6021bc
Initialize structseq types only once.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
45 static int initialized; |
|
22099
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
46 static PyTypeObject StructPwdType; |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
47 |
|
25303
df03fcc66104
Deal with NULL fields in mkpwent.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
48 static void |
|
df03fcc66104
Deal with NULL fields in mkpwent.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
49 sets(PyObject *v, int i, char* val) |
|
df03fcc66104
Deal with NULL fields in mkpwent.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
50 { |
|
df03fcc66104
Deal with NULL fields in mkpwent.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
51 if (val) |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
52 PyStructSequence_SET_ITEM(v, i, PyString_FromString(val)); |
|
25303
df03fcc66104
Deal with NULL fields in mkpwent.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
53 else { |
|
df03fcc66104
Deal with NULL fields in mkpwent.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
54 PyStructSequence_SET_ITEM(v, i, Py_None); |
|
df03fcc66104
Deal with NULL fields in mkpwent.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
55 Py_INCREF(Py_None); |
|
df03fcc66104
Deal with NULL fields in mkpwent.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
56 } |
|
df03fcc66104
Deal with NULL fields in mkpwent.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
57 } |
|
df03fcc66104
Deal with NULL fields in mkpwent.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
58 |
| 4684 | 59 static PyObject * |
|
13505
0edeb4efe6db
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
60 mkpwent(struct passwd *p) |
| 201 | 61 { |
|
22099
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
62 int setIndex = 0; |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
63 PyObject *v = PyStructSequence_New(&StructPwdType); |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
64 if (v == NULL) |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
65 return NULL; |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
66 |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
67 #define SETI(i,val) PyStructSequence_SET_ITEM(v, i, PyInt_FromLong((long) val)) |
|
25303
df03fcc66104
Deal with NULL fields in mkpwent.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
68 #define SETS(i,val) sets(v, i, val) |
|
22099
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
69 |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
70 SETS(setIndex++, p->pw_name); |
|
26550
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25303
diff
changeset
|
71 #ifdef __VMS |
|
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25303
diff
changeset
|
72 SETS(setIndex++, ""); |
|
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25303
diff
changeset
|
73 #else |
|
22099
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
74 SETS(setIndex++, p->pw_passwd); |
|
26550
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25303
diff
changeset
|
75 #endif |
|
22099
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
76 SETI(setIndex++, p->pw_uid); |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
77 SETI(setIndex++, p->pw_gid); |
|
26550
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25303
diff
changeset
|
78 #ifdef __VMS |
|
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25303
diff
changeset
|
79 SETS(setIndex++, ""); |
|
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25303
diff
changeset
|
80 #else |
|
22099
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
81 SETS(setIndex++, p->pw_gecos); |
|
26550
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25303
diff
changeset
|
82 #endif |
|
22099
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
83 SETS(setIndex++, p->pw_dir); |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
84 SETS(setIndex++, p->pw_shell); |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
85 |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
86 #undef SETS |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
87 #undef SETI |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
88 |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
89 if (PyErr_Occurred()) { |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
90 Py_XDECREF(v); |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
91 return NULL; |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
92 } |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
93 |
|
d0acb3cb011d
Patch #523268, #522027: return enhanced tuples.
Martin v. Löwis <martin@v.loewis.de>
parents:
21859
diff
changeset
|
94 return v; |
| 201 | 95 } |
| 96 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23048
diff
changeset
|
97 PyDoc_STRVAR(pwd_getpwuid__doc__, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23048
diff
changeset
|
98 "getpwuid(uid) -> (pw_name,pw_passwd,pw_uid,\n\ |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23048
diff
changeset
|
99 pw_gid,pw_gecos,pw_dir,pw_shell)\n\ |
|
7530
891105dac9b4
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6142
diff
changeset
|
100 Return the password database entry for the given numeric user ID.\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23048
diff
changeset
|
101 See pwd.__doc__ for more on password database entries."); |
|
7530
891105dac9b4
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6142
diff
changeset
|
102 |
| 4684 | 103 static PyObject * |
|
13505
0edeb4efe6db
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
104 pwd_getpwuid(PyObject *self, PyObject *args) |
| 201 | 105 { |
|
35551
57f630a9de26
- Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents:
31403
diff
changeset
|
106 unsigned int uid; |
| 201 | 107 struct passwd *p; |
|
35551
57f630a9de26
- Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents:
31403
diff
changeset
|
108 if (!PyArg_ParseTuple(args, "I:getpwuid", &uid)) |
| 201 | 109 return NULL; |
| 110 if ((p = getpwuid(uid)) == NULL) { | |
|
31403
9005f2662a70
pwd_getpwuid(), pwd_getpwnam(): Patch # 868499, improvement to the error
Barry Warsaw <barry@python.org>
parents:
30763
diff
changeset
|
111 PyErr_Format(PyExc_KeyError, |
|
9005f2662a70
pwd_getpwuid(), pwd_getpwnam(): Patch # 868499, improvement to the error
Barry Warsaw <barry@python.org>
parents:
30763
diff
changeset
|
112 "getpwuid(): uid not found: %d", uid); |
| 201 | 113 return NULL; |
| 114 } | |
| 115 return mkpwent(p); | |
| 116 } | |
| 117 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23048
diff
changeset
|
118 PyDoc_STRVAR(pwd_getpwnam__doc__, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23048
diff
changeset
|
119 "getpwnam(name) -> (pw_name,pw_passwd,pw_uid,\n\ |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23048
diff
changeset
|
120 pw_gid,pw_gecos,pw_dir,pw_shell)\n\ |
|
7530
891105dac9b4
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6142
diff
changeset
|
121 Return the password database entry for the given user name.\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23048
diff
changeset
|
122 See pwd.__doc__ for more on password database entries."); |
|
7530
891105dac9b4
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6142
diff
changeset
|
123 |
| 4684 | 124 static PyObject * |
|
13505
0edeb4efe6db
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
125 pwd_getpwnam(PyObject *self, PyObject *args) |
| 201 | 126 { |
|
643
02d3f161b7f5
Use getargs() function.
Guido van Rossum <guido@python.org>
parents:
513
diff
changeset
|
127 char *name; |
| 201 | 128 struct passwd *p; |
| 22709 | 129 if (!PyArg_ParseTuple(args, "s:getpwnam", &name)) |
| 201 | 130 return NULL; |
|
643
02d3f161b7f5
Use getargs() function.
Guido van Rossum <guido@python.org>
parents:
513
diff
changeset
|
131 if ((p = getpwnam(name)) == NULL) { |
|
31403
9005f2662a70
pwd_getpwuid(), pwd_getpwnam(): Patch # 868499, improvement to the error
Barry Warsaw <barry@python.org>
parents:
30763
diff
changeset
|
132 PyErr_Format(PyExc_KeyError, |
|
9005f2662a70
pwd_getpwuid(), pwd_getpwnam(): Patch # 868499, improvement to the error
Barry Warsaw <barry@python.org>
parents:
30763
diff
changeset
|
133 "getpwnam(): name not found: %s", name); |
| 201 | 134 return NULL; |
| 135 } | |
| 136 return mkpwent(p); | |
| 137 } | |
| 138 | |
|
6142
144db635b49d
Added configuration tests for presence of alarm(), pause(), and getpwent()
Guido van Rossum <guido@python.org>
parents:
4917
diff
changeset
|
139 #ifdef HAVE_GETPWENT |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23048
diff
changeset
|
140 PyDoc_STRVAR(pwd_getpwall__doc__, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23048
diff
changeset
|
141 "getpwall() -> list_of_entries\n\ |
|
7530
891105dac9b4
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6142
diff
changeset
|
142 Return a list of all available password database entries, \ |
|
891105dac9b4
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6142
diff
changeset
|
143 in arbitrary order.\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23048
diff
changeset
|
144 See pwd.__doc__ for more on password database entries."); |
|
7530
891105dac9b4
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6142
diff
changeset
|
145 |
| 4684 | 146 static PyObject * |
|
22561
043ad7adc896
Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
22114
diff
changeset
|
147 pwd_getpwall(PyObject *self) |
| 201 | 148 { |
| 4684 | 149 PyObject *d; |
| 201 | 150 struct passwd *p; |
| 4684 | 151 if ((d = PyList_New(0)) == NULL) |
| 201 | 152 return NULL; |
|
22114
c454b76d51e7
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
22099
diff
changeset
|
153 #if defined(PYOS_OS2) && defined(PYCC_GCC) |
|
c454b76d51e7
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
22099
diff
changeset
|
154 if ((p = getpwuid(0)) != NULL) { |
|
c454b76d51e7
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
22099
diff
changeset
|
155 #else |
| 201 | 156 setpwent(); |
| 157 while ((p = getpwent()) != NULL) { | |
|
22114
c454b76d51e7
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
22099
diff
changeset
|
158 #endif |
| 4684 | 159 PyObject *v = mkpwent(p); |
| 160 if (v == NULL || PyList_Append(d, v) != 0) { | |
| 161 Py_XDECREF(v); | |
| 162 Py_DECREF(d); | |
|
54424
76f1be9d2818
Merged revisions 73016 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47527
diff
changeset
|
163 endpwent(); |
| 201 | 164 return NULL; |
| 165 } | |
|
4917
1bcd4972da7e
Nailed a couple of memory leaks, caught by Purify.
Barry Warsaw <barry@python.org>
parents:
4786
diff
changeset
|
166 Py_DECREF(v); |
| 201 | 167 } |
|
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
|
168 endpwent(); |
| 201 | 169 return d; |
| 170 } | |
|
6142
144db635b49d
Added configuration tests for presence of alarm(), pause(), and getpwent()
Guido van Rossum <guido@python.org>
parents:
4917
diff
changeset
|
171 #endif |
| 201 | 172 |
| 4684 | 173 static PyMethodDef pwd_methods[] = { |
| 22709 | 174 {"getpwuid", pwd_getpwuid, METH_VARARGS, pwd_getpwuid__doc__}, |
| 175 {"getpwnam", pwd_getpwnam, METH_VARARGS, pwd_getpwnam__doc__}, | |
|
6142
144db635b49d
Added configuration tests for presence of alarm(), pause(), and getpwent()
Guido van Rossum <guido@python.org>
parents:
4917
diff
changeset
|
176 #ifdef HAVE_GETPWENT |
|
22664
f63f2bc8bdba
Add missing typecast.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22561
diff
changeset
|
177 {"getpwall", (PyCFunction)pwd_getpwall, |
|
f63f2bc8bdba
Add missing typecast.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22561
diff
changeset
|
178 METH_NOARGS, pwd_getpwall__doc__}, |
|
6142
144db635b49d
Added configuration tests for presence of alarm(), pause(), and getpwent()
Guido van Rossum <guido@python.org>
parents:
4917
diff
changeset
|
179 #endif |
| 201 | 180 {NULL, NULL} /* sentinel */ |
| 181 }; | |
| 182 | |
|
24471
f66b3a3509c7
Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents:
23832
diff
changeset
|
183 PyMODINIT_FUNC |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13505
diff
changeset
|
184 initpwd(void) |
| 201 | 185 { |
|
23048
c1668a819242
Remove unused variable reported by Walter Dörwald
Neal Norwitz <nnorwitz@gmail.com>
parents:
23024
diff
changeset
|
186 PyObject *m; |
|
23024
4e58a38e3c06
initpwd(): Clean up initialization, avoid PyModule_GetDict().
Fred Drake <fdrake@acm.org>
parents:
22709
diff
changeset
|
187 m = Py_InitModule3("pwd", pwd_methods, pwd__doc__); |
|
36324
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35551
diff
changeset
|
188 if (m == NULL) |
|
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35551
diff
changeset
|
189 return; |
|
23024
4e58a38e3c06
initpwd(): Clean up initialization, avoid PyModule_GetDict().
Fred Drake <fdrake@acm.org>
parents:
22709
diff
changeset
|
190 |
|
37772
b90a7c6021bc
Initialize structseq types only once.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
191 if (!initialized) |
|
b90a7c6021bc
Initialize structseq types only once.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
192 PyStructSequence_InitType(&StructPwdType, |
|
b90a7c6021bc
Initialize structseq types only once.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
193 &struct_pwd_type_desc); |
|
23024
4e58a38e3c06
initpwd(): Clean up initialization, avoid PyModule_GetDict().
Fred Drake <fdrake@acm.org>
parents:
22709
diff
changeset
|
194 Py_INCREF((PyObject *) &StructPwdType); |
|
30763
48b9cc51742b
- The pwd module incorrectly advertised its struct type as
Guido van Rossum <guido@python.org>
parents:
26550
diff
changeset
|
195 PyModule_AddObject(m, "struct_passwd", (PyObject *) &StructPwdType); |
|
48b9cc51742b
- The pwd module incorrectly advertised its struct type as
Guido van Rossum <guido@python.org>
parents:
26550
diff
changeset
|
196 /* And for b/w compatibility (this was defined by mistake): */ |
| 55900 | 197 Py_INCREF((PyObject *) &StructPwdType); |
|
23024
4e58a38e3c06
initpwd(): Clean up initialization, avoid PyModule_GetDict().
Fred Drake <fdrake@acm.org>
parents:
22709
diff
changeset
|
198 PyModule_AddObject(m, "struct_pwent", (PyObject *) &StructPwdType); |
|
37772
b90a7c6021bc
Initialize structseq types only once.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
199 initialized = 1; |
| 201 | 200 } |
