Mercurial > cpython-lru_cache-weakref
annotate Modules/spwdmodule.c @ 70817:dd775b1561ba
Fix markup.
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Tue, 14 Jun 2011 21:09:55 +0200 |
| parents | 3c9232a684ae |
| children | fc718c177ee6 |
| rev | line source |
|---|---|
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
1 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
2 /* UNIX shadow password file access module */ |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
3 /* A lot of code has been taken from pwdmodule.c */ |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
4 /* For info also see http://www.unixpapa.com/incnote/passwd.html */ |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
5 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
6 #include "Python.h" |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
7 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
8 #include <sys/types.h> |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
9 #ifdef HAVE_SHADOW_H |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
10 #include <shadow.h> |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
11 #endif |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
12 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
13 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
14 PyDoc_STRVAR(spwd__doc__, |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
15 "This module provides access to the Unix shadow password database.\n\ |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
16 It is available on various Unix versions.\n\ |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
17 \n\ |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
18 Shadow password database entries are reported as 9-tuples of type struct_spwd,\n\ |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
19 containing the following items from the password database (see `<shadow.h>'):\n\ |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
20 sp_namp, sp_pwdp, sp_lstchg, sp_min, sp_max, sp_warn, sp_inact, sp_expire, sp_flag.\n\ |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
21 The sp_namp and sp_pwdp are strings, the rest are integers.\n\ |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
22 An exception is raised if the entry asked for cannot be found.\n\ |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
23 You have to be root to be able to use this module."); |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
24 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
25 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
26 #if defined(HAVE_GETSPNAM) || defined(HAVE_GETSPENT) |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
27 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
28 static PyStructSequence_Field struct_spwd_type_fields[] = { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
29 {"sp_nam", "login name"}, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
30 {"sp_pwd", "encrypted password"}, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
31 {"sp_lstchg", "date of last change"}, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
32 {"sp_min", "min #days between changes"}, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
33 {"sp_max", "max #days between changes"}, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
34 {"sp_warn", "#days before pw expires to warn user about it"}, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
35 {"sp_inact", "#days after pw expires until account is blocked"}, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
36 {"sp_expire", "#days since 1970-01-01 until account is disabled"}, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
37 {"sp_flag", "reserved"}, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
38 {0} |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
39 }; |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
40 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
41 PyDoc_STRVAR(struct_spwd__doc__, |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
42 "spwd.struct_spwd: Results from getsp*() routines.\n\n\ |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
43 This object may be accessed either as a 9-tuple of\n\ |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
44 (sp_nam,sp_pwd,sp_lstchg,sp_min,sp_max,sp_warn,sp_inact,sp_expire,sp_flag)\n\ |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
45 or via the object attributes as named in the above tuple."); |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
46 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
47 static PyStructSequence_Desc struct_spwd_type_desc = { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
48 "spwd.struct_spwd", |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
49 struct_spwd__doc__, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
50 struct_spwd_type_fields, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
51 9, |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
52 }; |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
53 |
|
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
|
54 static int initialized; |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
55 static PyTypeObject StructSpwdType; |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
56 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
57 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
58 static void |
|
42804
69b8e2976556
Use unicode for password modules
Neal Norwitz <nnorwitz@gmail.com>
parents:
39442
diff
changeset
|
59 sets(PyObject *v, int i, const char* val) |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
60 { |
|
54422
28d64192ab5a
Issue #4859: Implement PEP 383 for pwd, spwd, and grp.
Martin v. Löwis <martin@v.loewis.de>
parents:
47580
diff
changeset
|
61 if (val) { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61365
diff
changeset
|
62 PyObject *o = PyUnicode_DecodeFSDefault(val); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
63 PyStructSequence_SET_ITEM(v, i, o); |
|
54422
28d64192ab5a
Issue #4859: Implement PEP 383 for pwd, spwd, and grp.
Martin v. Löwis <martin@v.loewis.de>
parents:
47580
diff
changeset
|
64 } else { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
65 PyStructSequence_SET_ITEM(v, i, Py_None); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
66 Py_INCREF(Py_None); |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
67 } |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
68 } |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
69 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
70 static PyObject *mkspent(struct spwd *p) |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
71 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
72 int setIndex = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
73 PyObject *v = PyStructSequence_New(&StructSpwdType); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
74 if (v == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
75 return NULL; |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
76 |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
42804
diff
changeset
|
77 #define SETI(i,val) PyStructSequence_SET_ITEM(v, i, PyLong_FromLong((long) val)) |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
78 #define SETS(i,val) sets(v, i, val) |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
79 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
80 SETS(setIndex++, p->sp_namp); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
81 SETS(setIndex++, p->sp_pwdp); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
82 SETI(setIndex++, p->sp_lstchg); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
83 SETI(setIndex++, p->sp_min); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
84 SETI(setIndex++, p->sp_max); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
85 SETI(setIndex++, p->sp_warn); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
86 SETI(setIndex++, p->sp_inact); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
87 SETI(setIndex++, p->sp_expire); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
88 SETI(setIndex++, p->sp_flag); |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
89 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
90 #undef SETS |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
91 #undef SETI |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
92 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
93 if (PyErr_Occurred()) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
94 Py_DECREF(v); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
95 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
96 } |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
97 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
98 return v; |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
99 } |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
100 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
101 #endif /* HAVE_GETSPNAM || HAVE_GETSPENT */ |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
102 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
103 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
104 #ifdef HAVE_GETSPNAM |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
105 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
106 PyDoc_STRVAR(spwd_getspnam__doc__, |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
107 "getspnam(name) -> (sp_namp, sp_pwdp, sp_lstchg, sp_min, sp_max,\n\ |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
108 sp_warn, sp_inact, sp_expire, sp_flag)\n\ |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
109 Return the shadow password database entry for the given user name.\n\ |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
110 See spwd.__doc__ for more on shadow password database entries."); |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
111 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
112 static PyObject* spwd_getspnam(PyObject *self, PyObject *args) |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
113 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
114 char *name; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
115 struct spwd *p; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
116 PyObject *arg, *bytes, *retval = NULL; |
|
54422
28d64192ab5a
Issue #4859: Implement PEP 383 for pwd, spwd, and grp.
Martin v. Löwis <martin@v.loewis.de>
parents:
47580
diff
changeset
|
117 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
118 if (!PyArg_ParseTuple(args, "U:getspnam", &arg)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
119 return NULL; |
|
61597
b5ba7ea4246b
Issue #8715: Create PyUnicode_EncodeFSDefault() function: Encode a Unicode
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61466
diff
changeset
|
120 if ((bytes = PyUnicode_EncodeFSDefault(arg)) == NULL) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
121 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
122 if (PyBytes_AsStringAndSize(bytes, &name, NULL) == -1) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
123 goto out; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
124 if ((p = getspnam(name)) == NULL) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
125 PyErr_SetString(PyExc_KeyError, "getspnam(): name not found"); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
126 goto out; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
127 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
128 retval = mkspent(p); |
|
54422
28d64192ab5a
Issue #4859: Implement PEP 383 for pwd, spwd, and grp.
Martin v. Löwis <martin@v.loewis.de>
parents:
47580
diff
changeset
|
129 out: |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
130 Py_DECREF(bytes); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
131 return retval; |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
132 } |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
133 |
|
34488
4209ec1706ab
Put docstring for getspall into same #ifdef block as function definition
Neal Norwitz <nnorwitz@gmail.com>
parents:
34481
diff
changeset
|
134 #endif /* HAVE_GETSPNAM */ |
|
4209ec1706ab
Put docstring for getspall into same #ifdef block as function definition
Neal Norwitz <nnorwitz@gmail.com>
parents:
34481
diff
changeset
|
135 |
|
4209ec1706ab
Put docstring for getspall into same #ifdef block as function definition
Neal Norwitz <nnorwitz@gmail.com>
parents:
34481
diff
changeset
|
136 #ifdef HAVE_GETSPENT |
|
4209ec1706ab
Put docstring for getspall into same #ifdef block as function definition
Neal Norwitz <nnorwitz@gmail.com>
parents:
34481
diff
changeset
|
137 |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
138 PyDoc_STRVAR(spwd_getspall__doc__, |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
139 "getspall() -> list_of_entries\n\ |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
140 Return a list of all available shadow password database entries, \ |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
141 in arbitrary order.\n\ |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
142 See spwd.__doc__ for more on shadow password database entries."); |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
143 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
144 static PyObject * |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
145 spwd_getspall(PyObject *self, PyObject *args) |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
146 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
147 PyObject *d; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
148 struct spwd *p; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
149 if ((d = PyList_New(0)) == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
150 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
151 setspent(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
152 while ((p = getspent()) != NULL) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
153 PyObject *v = mkspent(p); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
154 if (v == NULL || PyList_Append(d, v) != 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
155 Py_XDECREF(v); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
156 Py_DECREF(d); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
157 endspent(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
158 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
159 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
160 Py_DECREF(v); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
161 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
162 endspent(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
163 return d; |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
164 } |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
165 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
166 #endif /* HAVE_GETSPENT */ |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
167 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
168 static PyMethodDef spwd_methods[] = { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
169 #ifdef HAVE_GETSPNAM |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
170 {"getspnam", spwd_getspnam, METH_VARARGS, spwd_getspnam__doc__}, |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
171 #endif |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
172 #ifdef HAVE_GETSPENT |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
173 {"getspall", spwd_getspall, METH_NOARGS, spwd_getspall__doc__}, |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
174 #endif |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
175 {NULL, NULL} /* sentinel */ |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
176 }; |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
177 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
178 |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
179 |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
180 static struct PyModuleDef spwdmodule = { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
181 PyModuleDef_HEAD_INIT, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
182 "spwd", |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
183 spwd__doc__, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
184 -1, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
185 spwd_methods, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
186 NULL, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
187 NULL, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
188 NULL, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
189 NULL |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
190 }; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
191 |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
192 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
|
193 PyInit_spwd(void) |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
194 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
195 PyObject *m; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
196 m=PyModule_Create(&spwdmodule); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
197 if (m == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
198 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
199 if (!initialized) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
200 PyStructSequence_InitType(&StructSpwdType, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
201 &struct_spwd_type_desc); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
202 Py_INCREF((PyObject *) &StructSpwdType); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
203 PyModule_AddObject(m, "struct_spwd", (PyObject *) &StructSpwdType); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
204 initialized = 1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
205 return m; |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
206 } |
