annotate Modules/spwdmodule.c @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents fd25030223b0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 #include "structseq.h"
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
8
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
9 #include <sys/types.h>
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
10 #ifdef HAVE_SHADOW_H
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
11 #include <shadow.h>
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
12 #endif
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
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
15 PyDoc_STRVAR(spwd__doc__,
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
16 "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
17 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
18 \n\
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
19 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
20 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
21 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
22 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
23 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
24 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
25
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
26
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
27 #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
28
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
29 static PyStructSequence_Field struct_spwd_type_fields[] = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
30 {"sp_nam", "login name"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
31 {"sp_pwd", "encrypted password"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
32 {"sp_lstchg", "date of last change"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
33 {"sp_min", "min #days between changes"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
34 {"sp_max", "max #days between changes"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
35 {"sp_warn", "#days before pw expires to warn user about it"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
36 {"sp_inact", "#days after pw expires until account is blocked"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
37 {"sp_expire", "#days since 1970-01-01 until account is disabled"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
38 {"sp_flag", "reserved"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
39 {0}
34481
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
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
42 PyDoc_STRVAR(struct_spwd__doc__,
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
43 "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
44 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
45 (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
46 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
47
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
48 static PyStructSequence_Desc struct_spwd_type_desc = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
49 "spwd.struct_spwd",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
50 struct_spwd__doc__,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
51 struct_spwd_type_fields,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
52 9,
34481
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
53 };
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
54
37772
b90a7c6021bc Initialize structseq types only once.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
55 static int initialized;
34481
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
56 static PyTypeObject StructSpwdType;
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
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
59 static void
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
60 sets(PyObject *v, int i, char* val)
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
61 {
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
62 if (val)
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
63 PyStructSequence_SET_ITEM(v, i, PyString_FromString(val));
34481
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
64 else {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
65 PyStructSequence_SET_ITEM(v, i, Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
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 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
72 int setIndex = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
73 PyObject *v = PyStructSequence_New(&StructSpwdType);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
74 if (v == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
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
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
77 #define SETI(i,val) PyStructSequence_SET_ITEM(v, i, PyInt_FromLong((long) val))
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
80 SETS(setIndex++, p->sp_namp);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
81 SETS(setIndex++, p->sp_pwdp);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
82 SETI(setIndex++, p->sp_lstchg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
83 SETI(setIndex++, p->sp_min);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
84 SETI(setIndex++, p->sp_max);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
85 SETI(setIndex++, p->sp_warn);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
86 SETI(setIndex++, p->sp_inact);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
87 SETI(setIndex++, p->sp_expire);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
93 if (PyErr_Occurred()) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
94 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
95 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
96 }
34481
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
97
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
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 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
114 char *name;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
115 struct spwd *p;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
116 if (!PyArg_ParseTuple(args, "s:getspnam", &name))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
117 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
118 if ((p = getspnam(name)) == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
119 PyErr_SetString(PyExc_KeyError, "getspnam(): name not found");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
120 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
121 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
122 return mkspent(p);
34481
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
123 }
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
124
34488
4209ec1706ab Put docstring for getspall into same #ifdef block as function definition
Neal Norwitz <nnorwitz@gmail.com>
parents: 34481
diff changeset
125 #endif /* HAVE_GETSPNAM */
4209ec1706ab Put docstring for getspall into same #ifdef block as function definition
Neal Norwitz <nnorwitz@gmail.com>
parents: 34481
diff changeset
126
4209ec1706ab Put docstring for getspall into same #ifdef block as function definition
Neal Norwitz <nnorwitz@gmail.com>
parents: 34481
diff changeset
127 #ifdef HAVE_GETSPENT
4209ec1706ab Put docstring for getspall into same #ifdef block as function definition
Neal Norwitz <nnorwitz@gmail.com>
parents: 34481
diff changeset
128
34481
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
129 PyDoc_STRVAR(spwd_getspall__doc__,
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
130 "getspall() -> list_of_entries\n\
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
131 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
132 in arbitrary order.\n\
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
133 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
134
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
135 static PyObject *
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
136 spwd_getspall(PyObject *self, PyObject *args)
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
137 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
138 PyObject *d;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
139 struct spwd *p;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
140 if ((d = PyList_New(0)) == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
141 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
142 setspent();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
143 while ((p = getspent()) != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
144 PyObject *v = mkspent(p);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
145 if (v == NULL || PyList_Append(d, v) != 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
146 Py_XDECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
147 Py_DECREF(d);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
148 endspent();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
149 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
150 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
151 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
152 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
153 endspent();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
154 return d;
34481
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
155 }
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
156
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
157 #endif /* HAVE_GETSPENT */
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
158
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
159 static PyMethodDef spwd_methods[] = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
160 #ifdef HAVE_GETSPNAM
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
161 {"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
162 #endif
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
163 #ifdef HAVE_GETSPENT
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
164 {"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
165 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
166 {NULL, NULL} /* sentinel */
34481
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
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 PyMODINIT_FUNC
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
171 initspwd(void)
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
172 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
173 PyObject *m;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
174 m=Py_InitModule3("spwd", spwd_methods, spwd__doc__);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
175 if (m == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
176 return;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
177 if (!initialized)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
178 PyStructSequence_InitType(&StructSpwdType,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
179 &struct_spwd_type_desc);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
180 Py_INCREF((PyObject *) &StructSpwdType);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
181 PyModule_AddObject(m, "struct_spwd", (PyObject *) &StructSpwdType);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
182 initialized = 1;
34481
9c62e7d690a5 Patch #579435: Shadow Password Support Module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
183 }