Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2)

Side by Side Diff: Modules/spwdmodule.c

Issue 20152: Derby: Convert the _imp module to use Argument Clinic
Patch Set: Created 6 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* UNIX shadow password file access module */ 2 /* UNIX shadow password file access module */
3 /* A lot of code has been taken from pwdmodule.c */ 3 /* A lot of code has been taken from pwdmodule.c */
4 /* For info also see http://www.unixpapa.com/incnote/passwd.html */ 4 /* For info also see http://www.unixpapa.com/incnote/passwd.html */
5 5
6 #include "Python.h" 6 #include "Python.h"
7 7
8 #include <sys/types.h> 8 #include <sys/types.h>
9 #ifdef HAVE_SHADOW_H 9 #ifdef HAVE_SHADOW_H
10 #include <shadow.h> 10 #include <shadow.h>
11 #endif 11 #endif
12 12
13 /*[clinic input]
14 module spwd
15 [clinic start generated code]*/
16 /*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709] */
13 17
14 PyDoc_STRVAR(spwd__doc__, 18 PyDoc_STRVAR(spwd__doc__,
15 "This module provides access to the Unix shadow password database.\n\ 19 "This module provides access to the Unix shadow password database.\n\
16 It is available on various Unix versions.\n\ 20 It is available on various Unix versions.\n\
17 \n\ 21 \n\
18 Shadow password database entries are reported as 9-tuples of type struct_spwd,\n \ 22 Shadow password database entries are reported as 9-tuples of type struct_spwd,\n \
19 containing the following items from the password database (see `<shadow.h>'):\n\ 23 containing the following items from the password database (see `<shadow.h>'):\n\
20 sp_namp, sp_pwdp, sp_lstchg, sp_min, sp_max, sp_warn, sp_inact, sp_expire, sp_fl ag.\n\ 24 sp_namp, sp_pwdp, sp_lstchg, sp_min, sp_max, sp_warn, sp_inact, sp_expire, sp_fl ag.\n\
21 The sp_namp and sp_pwdp are strings, the rest are integers.\n\ 25 The sp_namp and sp_pwdp are strings, the rest are integers.\n\
22 An exception is raised if the entry asked for cannot be found.\n\ 26 An exception is raised if the entry asked for cannot be found.\n\
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 } 104 }
101 105
102 return v; 106 return v;
103 } 107 }
104 108
105 #endif /* HAVE_GETSPNAM || HAVE_GETSPENT */ 109 #endif /* HAVE_GETSPNAM || HAVE_GETSPENT */
106 110
107 111
108 #ifdef HAVE_GETSPNAM 112 #ifdef HAVE_GETSPNAM
109 113
114 /*[clinic input]
115 spwd.getspnam
116
117 arg: unicode
118 /
119
120 Return the shadow password database entry for the given user name.
121
122 See spwd.__doc__ for more on shadow password database entries.
123 [clinic start generated code]*/
124
110 PyDoc_STRVAR(spwd_getspnam__doc__, 125 PyDoc_STRVAR(spwd_getspnam__doc__,
111 "getspnam(name) -> (sp_namp, sp_pwdp, sp_lstchg, sp_min, sp_max,\n\ 126 "getspnam(arg)\n"
112 sp_warn, sp_inact, sp_expire, sp_flag)\n\ 127 "Return the shadow password database entry for the given user name.\n"
113 Return the shadow password database entry for the given user name.\n\ 128 "\n"
114 See spwd.__doc__ for more on shadow password database entries."); 129 "See spwd.__doc__ for more on shadow password database entries.");
115 130
116 static PyObject* spwd_getspnam(PyObject *self, PyObject *args) 131 #define SPWD_GETSPNAM_METHODDEF \
132 {"getspnam", (PyCFunction)spwd_getspnam, METH_VARARGS, spwd_getspnam__doc__} ,
133
134 static PyObject *
135 spwd_getspnam_impl(PyModuleDef *module, PyObject *arg);
136
137 static PyObject *
138 spwd_getspnam(PyModuleDef *module, PyObject *args)
139 {
140 PyObject *return_value = NULL;
141 PyObject *arg;
142
143 if (!PyArg_ParseTuple(args,
144 "U:getspnam",
145 &arg))
146 goto exit;
147 return_value = spwd_getspnam_impl(module, arg);
148
149 exit:
150 return return_value;
151 }
152
153 static PyObject *
154 spwd_getspnam_impl(PyModuleDef *module, PyObject *arg)
155 /*[clinic end generated code: checksum=27dea695607d1afd3caf7979ec673a3ed73d652c] */
117 { 156 {
118 char *name; 157 char *name;
119 struct spwd *p; 158 struct spwd *p;
120 PyObject *arg, *bytes, *retval = NULL; 159 PyObject *bytes, *retval = NULL;
121 160
122 if (!PyArg_ParseTuple(args, "U:getspnam", &arg))
123 return NULL;
124 if ((bytes = PyUnicode_EncodeFSDefault(arg)) == NULL) 161 if ((bytes = PyUnicode_EncodeFSDefault(arg)) == NULL)
125 return NULL; 162 return NULL;
126 if (PyBytes_AsStringAndSize(bytes, &name, NULL) == -1) 163 if (PyBytes_AsStringAndSize(bytes, &name, NULL) == -1)
127 goto out; 164 goto out;
128 if ((p = getspnam(name)) == NULL) { 165 if ((p = getspnam(name)) == NULL) {
129 PyErr_SetString(PyExc_KeyError, "getspnam(): name not found"); 166 PyErr_SetString(PyExc_KeyError, "getspnam(): name not found");
130 goto out; 167 goto out;
131 } 168 }
132 retval = mkspent(p); 169 retval = mkspent(p);
133 out: 170 out:
134 Py_DECREF(bytes); 171 Py_DECREF(bytes);
135 return retval; 172 return retval;
136 } 173 }
137 174
138 #endif /* HAVE_GETSPNAM */ 175 #endif /* HAVE_GETSPNAM */
139 176
140 #ifdef HAVE_GETSPENT 177 #ifdef HAVE_GETSPENT
141 178
179 /*[clinic input]
180 spwd.getspall
181
182 Return a list of all available shadow password database entries, in arbitrary or der.
183
184 See spwd.__doc__ for more on shadow password database entries.
185 [clinic start generated code]*/
186
142 PyDoc_STRVAR(spwd_getspall__doc__, 187 PyDoc_STRVAR(spwd_getspall__doc__,
143 "getspall() -> list_of_entries\n\ 188 "getspall()\n"
144 Return a list of all available shadow password database entries, \ 189 "Return a list of all available shadow password database entries, in arbitrary o rder.\n"
145 in arbitrary order.\n\ 190 "\n"
146 See spwd.__doc__ for more on shadow password database entries."); 191 "See spwd.__doc__ for more on shadow password database entries.");
192
193 #define SPWD_GETSPALL_METHODDEF \
194 {"getspall", (PyCFunction)spwd_getspall, METH_NOARGS, spwd_getspall__doc__},
147 195
148 static PyObject * 196 static PyObject *
149 spwd_getspall(PyObject *self, PyObject *args) 197 spwd_getspall_impl(PyModuleDef *module);
198
199 static PyObject *
200 spwd_getspall(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
201 {
202 PyObject *return_value = NULL;
203
204 return_value = spwd_getspall_impl(module);
205
206 return return_value;
207 }
208
209 static PyObject *
210 spwd_getspall_impl(PyModuleDef *module)
211 /*[clinic end generated code: checksum=7f633b75eeaa2f15311042fec7a553c95f5cf5d5] */
150 { 212 {
151 PyObject *d; 213 PyObject *d;
152 struct spwd *p; 214 struct spwd *p;
153 if ((d = PyList_New(0)) == NULL) 215 if ((d = PyList_New(0)) == NULL)
154 return NULL; 216 return NULL;
155 setspent(); 217 setspent();
156 while ((p = getspent()) != NULL) { 218 while ((p = getspent()) != NULL) {
157 PyObject *v = mkspent(p); 219 PyObject *v = mkspent(p);
158 if (v == NULL || PyList_Append(d, v) != 0) { 220 if (v == NULL || PyList_Append(d, v) != 0) {
159 Py_XDECREF(v); 221 Py_XDECREF(v);
160 Py_DECREF(d); 222 Py_DECREF(d);
161 endspent(); 223 endspent();
162 return NULL; 224 return NULL;
163 } 225 }
164 Py_DECREF(v); 226 Py_DECREF(v);
165 } 227 }
166 endspent(); 228 endspent();
167 return d; 229 return d;
168 } 230 }
169 231
170 #endif /* HAVE_GETSPENT */ 232 #endif /* HAVE_GETSPENT */
171 233
loewis 2014/07/27 17:53:41 This needs /*[clinic input] dump buffer [clinic s
172 static PyMethodDef spwd_methods[] = { 234 static PyMethodDef spwd_methods[] = {
173 #ifdef HAVE_GETSPNAM 235 #ifdef HAVE_GETSPNAM
174 {"getspnam", spwd_getspnam, METH_VARARGS, spwd_getspnam__doc__}, 236 SPWD_GETSPNAM_METHODDEF
175 #endif 237 #endif
176 #ifdef HAVE_GETSPENT 238 #ifdef HAVE_GETSPENT
177 {"getspall", spwd_getspall, METH_NOARGS, spwd_getspall__doc__}, 239 SPWD_GETSPALL_METHODDEF
178 #endif 240 #endif
179 {NULL, NULL} /* sentinel */ 241 {NULL, NULL} /* sentinel */
180 }; 242 };
181 243
182 244
183 245
184 static struct PyModuleDef spwdmodule = { 246 static struct PyModuleDef spwdmodule = {
185 PyModuleDef_HEAD_INIT, 247 PyModuleDef_HEAD_INIT,
186 "spwd", 248 "spwd",
187 spwd__doc__, 249 spwd__doc__,
(...skipping 15 matching lines...) Expand all
203 if (!initialized) { 265 if (!initialized) {
204 if (PyStructSequence_InitType2(&StructSpwdType, 266 if (PyStructSequence_InitType2(&StructSpwdType,
205 &struct_spwd_type_desc) < 0) 267 &struct_spwd_type_desc) < 0)
206 return NULL; 268 return NULL;
207 } 269 }
208 Py_INCREF((PyObject *) &StructSpwdType); 270 Py_INCREF((PyObject *) &StructSpwdType);
209 PyModule_AddObject(m, "struct_spwd", (PyObject *) &StructSpwdType); 271 PyModule_AddObject(m, "struct_spwd", (PyObject *) &StructSpwdType);
210 initialized = 1; 272 initialized = 1;
211 return m; 273 return m;
212 } 274 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+