Mercurial > cpython-lru_cache-weakref
annotate Modules/spwdmodule.c @ 87690:66c1c9f32567 default tip
Add use_weakref option to functools.lru_cache
The use_weakref option makes lru_cache create weak references to the function
arguments when creating the cache key, which prevents them from staying in the
memory forever even after all other references to them are gone.
This is a proof of concept for http://bugs.python.org/issue19859
| author | Radomir Dopieralski <devel@sheep.art.pl> |
|---|---|
| date | Tue, 03 Dec 2013 16:02:48 +0100 |
| parents | 1b0ca1a7a3ca |
| children |
| 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[] = { |
|
86900
1b0ca1a7a3ca
#18678: Correct names of spwd struct members.
R David Murray <rdmurray@bitdance.com>
parents:
84793
diff
changeset
|
29 {"sp_namp", "login name"}, |
|
1b0ca1a7a3ca
#18678: Correct names of spwd struct members.
R David Murray <rdmurray@bitdance.com>
parents:
84793
diff
changeset
|
30 {"sp_pwdp", "encrypted password"}, |
|
61467
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"}, |
|
86900
1b0ca1a7a3ca
#18678: Correct names of spwd struct members.
R David Murray <rdmurray@bitdance.com>
parents:
84793
diff
changeset
|
35 {"sp_inact", "#days after pw expires until account is disabled"}, |
|
1b0ca1a7a3ca
#18678: Correct names of spwd struct members.
R David Murray <rdmurray@bitdance.com>
parents:
84793
diff
changeset
|
36 {"sp_expire", "#days since 1970-01-01 when account expires"}, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
37 {"sp_flag", "reserved"}, |
|
86900
1b0ca1a7a3ca
#18678: Correct names of spwd struct members.
R David Murray <rdmurray@bitdance.com>
parents:
84793
diff
changeset
|
38 {"sp_nam", "login name; deprecated"}, /* Backward compatibility */ |
|
1b0ca1a7a3ca
#18678: Correct names of spwd struct members.
R David Murray <rdmurray@bitdance.com>
parents:
84793
diff
changeset
|
39 {"sp_pwd", "encrypted password; deprecated"}, /* Backward compatibility */ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
40 {0} |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
41 }; |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
42 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
43 PyDoc_STRVAR(struct_spwd__doc__, |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
44 "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
|
45 This object may be accessed either as a 9-tuple of\n\ |
|
86900
1b0ca1a7a3ca
#18678: Correct names of spwd struct members.
R David Murray <rdmurray@bitdance.com>
parents:
84793
diff
changeset
|
46 (sp_namp,sp_pwdp,sp_lstchg,sp_min,sp_max,sp_warn,sp_inact,sp_expire,sp_flag)\n\ |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
47 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
|
48 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
49 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
|
50 "spwd.struct_spwd", |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
51 struct_spwd__doc__, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
52 struct_spwd_type_fields, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
53 9, |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
54 }; |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
55 |
|
37772
b90a7c6021bc
Initialize structseq types only once.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
56 static int initialized; |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
57 static PyTypeObject StructSpwdType; |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
58 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
59 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
60 static void |
|
42804
69b8e2976556
Use unicode for password modules
Neal Norwitz <nnorwitz@gmail.com>
parents:
39352
diff
changeset
|
61 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
|
62 { |
|
54422
28d64192ab5a
Issue #4859: Implement PEP 383 for pwd, spwd, and grp.
Martin v. Löwis <martin@v.loewis.de>
parents:
47580
diff
changeset
|
63 if (val) { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61365
diff
changeset
|
64 PyObject *o = PyUnicode_DecodeFSDefault(val); |
|
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, 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
|
66 } else { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
67 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
|
68 Py_INCREF(Py_None); |
|
34481
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 } |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
71 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
72 static PyObject *mkspent(struct spwd *p) |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
73 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
74 int setIndex = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
75 PyObject *v = PyStructSequence_New(&StructSpwdType); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
76 if (v == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
77 return NULL; |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
78 |
|
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
|
79 #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
|
80 #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
|
81 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
82 SETS(setIndex++, p->sp_namp); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
83 SETS(setIndex++, p->sp_pwdp); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
84 SETI(setIndex++, p->sp_lstchg); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
85 SETI(setIndex++, p->sp_min); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
86 SETI(setIndex++, p->sp_max); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
87 SETI(setIndex++, p->sp_warn); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
88 SETI(setIndex++, p->sp_inact); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
89 SETI(setIndex++, p->sp_expire); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
90 SETI(setIndex++, p->sp_flag); |
|
86900
1b0ca1a7a3ca
#18678: Correct names of spwd struct members.
R David Murray <rdmurray@bitdance.com>
parents:
84793
diff
changeset
|
91 SETS(setIndex++, p->sp_namp); /* Backward compatibility for sp_nam */ |
|
1b0ca1a7a3ca
#18678: Correct names of spwd struct members.
R David Murray <rdmurray@bitdance.com>
parents:
84793
diff
changeset
|
92 SETS(setIndex++, p->sp_pwdp); /* Backward compatibility for sp_pwd */ |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
93 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
94 #undef SETS |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
95 #undef SETI |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
96 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
97 if (PyErr_Occurred()) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
98 Py_DECREF(v); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
99 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
100 } |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
101 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
102 return v; |
|
34481
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 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
105 #endif /* HAVE_GETSPNAM || HAVE_GETSPENT */ |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
106 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
107 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
108 #ifdef HAVE_GETSPNAM |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
109 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
110 PyDoc_STRVAR(spwd_getspnam__doc__, |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
111 "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
|
112 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
|
113 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
|
114 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
|
115 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
116 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
|
117 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
118 char *name; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
119 struct spwd *p; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
120 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
|
121 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
122 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
|
123 return NULL; |
|
61597
b5ba7ea4246b
Issue #8715: Create PyUnicode_EncodeFSDefault() function: Encode a Unicode
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61466
diff
changeset
|
124 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
|
125 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
126 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
|
127 goto out; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
128 if ((p = getspnam(name)) == NULL) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
129 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
|
130 goto out; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
131 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
132 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
|
133 out: |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
134 Py_DECREF(bytes); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
135 return retval; |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
136 } |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
137 |
|
34488
4209ec1706ab
Put docstring for getspall into same #ifdef block as function definition
Neal Norwitz <nnorwitz@gmail.com>
parents:
34481
diff
changeset
|
138 #endif /* HAVE_GETSPNAM */ |
|
4209ec1706ab
Put docstring for getspall into same #ifdef block as function definition
Neal Norwitz <nnorwitz@gmail.com>
parents:
34481
diff
changeset
|
139 |
|
4209ec1706ab
Put docstring for getspall into same #ifdef block as function definition
Neal Norwitz <nnorwitz@gmail.com>
parents:
34481
diff
changeset
|
140 #ifdef HAVE_GETSPENT |
|
4209ec1706ab
Put docstring for getspall into same #ifdef block as function definition
Neal Norwitz <nnorwitz@gmail.com>
parents:
34481
diff
changeset
|
141 |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
142 PyDoc_STRVAR(spwd_getspall__doc__, |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
143 "getspall() -> list_of_entries\n\ |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
144 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
|
145 in arbitrary order.\n\ |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
146 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
|
147 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
148 static PyObject * |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
149 spwd_getspall(PyObject *self, PyObject *args) |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
150 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
151 PyObject *d; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
152 struct spwd *p; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
153 if ((d = PyList_New(0)) == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
154 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
155 setspent(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
156 while ((p = getspent()) != NULL) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
157 PyObject *v = mkspent(p); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
158 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
|
159 Py_XDECREF(v); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
160 Py_DECREF(d); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
161 endspent(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
162 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
163 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
164 Py_DECREF(v); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
165 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
166 endspent(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
167 return d; |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
168 } |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
169 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
170 #endif /* HAVE_GETSPENT */ |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
171 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
172 static PyMethodDef spwd_methods[] = { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
173 #ifdef HAVE_GETSPNAM |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
174 {"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
|
175 #endif |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
176 #ifdef HAVE_GETSPENT |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
177 {"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
|
178 #endif |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
179 {NULL, NULL} /* sentinel */ |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
180 }; |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
181 |
|
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
182 |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
183 |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
184 static struct PyModuleDef spwdmodule = { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
185 PyModuleDef_HEAD_INIT, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
186 "spwd", |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
187 spwd__doc__, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
188 -1, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
189 spwd_methods, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
190 NULL, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
191 NULL, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
192 NULL, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
193 NULL |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
194 }; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
195 |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
196 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
|
197 PyInit_spwd(void) |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
198 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
199 PyObject *m; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
200 m=PyModule_Create(&spwdmodule); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
201 if (m == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
202 return NULL; |
|
84793
fc718c177ee6
Issue #18520: Add a new PyStructSequence_InitType2() function, same than
Victor Stinner <victor.stinner@gmail.com>
parents:
68257
diff
changeset
|
203 if (!initialized) { |
|
fc718c177ee6
Issue #18520: Add a new PyStructSequence_InitType2() function, same than
Victor Stinner <victor.stinner@gmail.com>
parents:
68257
diff
changeset
|
204 if (PyStructSequence_InitType2(&StructSpwdType, |
|
fc718c177ee6
Issue #18520: Add a new PyStructSequence_InitType2() function, same than
Victor Stinner <victor.stinner@gmail.com>
parents:
68257
diff
changeset
|
205 &struct_spwd_type_desc) < 0) |
|
fc718c177ee6
Issue #18520: Add a new PyStructSequence_InitType2() function, same than
Victor Stinner <victor.stinner@gmail.com>
parents:
68257
diff
changeset
|
206 return NULL; |
|
fc718c177ee6
Issue #18520: Add a new PyStructSequence_InitType2() function, same than
Victor Stinner <victor.stinner@gmail.com>
parents:
68257
diff
changeset
|
207 } |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
208 Py_INCREF((PyObject *) &StructSpwdType); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
209 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
|
210 initialized = 1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54422
diff
changeset
|
211 return m; |
|
34481
9c62e7d690a5
Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
212 } |
