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

Side by Side Diff: Modules/pwdmodule.c

Issue 20152: Derby: Convert the _imp module to use Argument Clinic
Patch Set: Created 6 years, 2 months 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 password file access module */ 2 /* UNIX password file access module */
3 3
4 #include "Python.h" 4 #include "Python.h"
5 #include "posixmodule.h" 5 #include "posixmodule.h"
6 6
7 #include <pwd.h> 7 #include <pwd.h>
8
9 /*[clinic input]
10 module pwd
11 [clinic start generated code]*/
12 /*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709] */
8 13
9 static PyStructSequence_Field struct_pwd_type_fields[] = { 14 static PyStructSequence_Field struct_pwd_type_fields[] = {
10 {"pw_name", "user name"}, 15 {"pw_name", "user name"},
11 {"pw_passwd", "password"}, 16 {"pw_passwd", "password"},
12 {"pw_uid", "user id"}, 17 {"pw_uid", "user id"},
13 {"pw_gid", "group id"}, 18 {"pw_gid", "group id"},
14 {"pw_gecos", "real name"}, 19 {"pw_gecos", "real name"},
15 {"pw_dir", "home directory"}, 20 {"pw_dir", "home directory"},
16 {"pw_shell", "shell program"}, 21 {"pw_shell", "shell program"},
17 {0} 22 {0}
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 #undef SETI 85 #undef SETI
81 86
82 if (PyErr_Occurred()) { 87 if (PyErr_Occurred()) {
83 Py_XDECREF(v); 88 Py_XDECREF(v);
84 return NULL; 89 return NULL;
85 } 90 }
86 91
87 return v; 92 return v;
88 } 93 }
89 94
95 /*[clinic input]
96 pwd.getpwuid
97
98 uidobj: object
loewis 2014/07/27 17:58:48 It would be better if the parameter name remains "
99 /
100
101 Return the password database entry for the given numeric user ID.
102
103 See help(pwd) for more on password database entries.
104 [clinic start generated code]*/
105
90 PyDoc_STRVAR(pwd_getpwuid__doc__, 106 PyDoc_STRVAR(pwd_getpwuid__doc__,
91 "getpwuid(uid) -> (pw_name,pw_passwd,pw_uid,\n\ 107 "getpwuid(uidobj)\n"
92 pw_gid,pw_gecos,pw_dir,pw_shell)\n\ 108 "Return the password database entry for the given numeric user ID.\n"
93 Return the password database entry for the given numeric user ID.\n\ 109 "\n"
94 See help(pwd) for more on password database entries."); 110 "See help(pwd) for more on password database entries.");
111
112 #define PWD_GETPWUID_METHODDEF \
113 {"getpwuid", (PyCFunction)pwd_getpwuid, METH_O, pwd_getpwuid__doc__},
95 114
96 static PyObject * 115 static PyObject *
97 pwd_getpwuid(PyObject *self, PyObject *args) 116 pwd_getpwuid(PyModuleDef *module, PyObject *uidobj)
117 /*[clinic end generated code: checksum=b54b400bd87c1fdb90d2b6ae5d1c799ec2314bff] */
98 { 118 {
99 uid_t uid; 119 uid_t uid;
100 struct passwd *p; 120 struct passwd *p;
101 if (!PyArg_ParseTuple(args, "O&:getpwuid", _Py_Uid_Converter, &uid)) { 121
122 if (!_Py_Uid_Converter(uidobj, &uid)) {
102 if (PyErr_ExceptionMatches(PyExc_OverflowError)) 123 if (PyErr_ExceptionMatches(PyExc_OverflowError))
103 PyErr_Format(PyExc_KeyError, 124 PyErr_Format(PyExc_KeyError,
104 "getpwuid(): uid not found"); 125 "getpwuid(): uid not found");
105 return NULL; 126 return NULL;
106 } 127 }
107 if ((p = getpwuid(uid)) == NULL) { 128 if ((p = getpwuid(uid)) == NULL) {
108 PyObject *uid_obj = _PyLong_FromUid(uid); 129 PyObject *uid_obj = _PyLong_FromUid(uid);
109 if (uid_obj == NULL) 130 if (uid_obj == NULL)
110 return NULL; 131 return NULL;
111 PyErr_Format(PyExc_KeyError, 132 PyErr_Format(PyExc_KeyError,
112 "getpwuid(): uid not found: %S", uid_obj); 133 "getpwuid(): uid not found: %S", uid_obj);
113 Py_DECREF(uid_obj); 134 Py_DECREF(uid_obj);
114 return NULL; 135 return NULL;
115 } 136 }
116 return mkpwent(p); 137 return mkpwent(p);
117 } 138 }
118 139
140 /*[clinic input]
141 pwd.getpwnam
142
143 arg: unicode
loewis 2014/07/27 17:58:48 Likewise, the name should remain "name".
144 /
145
146 Return the password database entry for the given user name.
147
148 See help(pwd) for more on password database entries.
149 [clinic start generated code]*/
150
119 PyDoc_STRVAR(pwd_getpwnam__doc__, 151 PyDoc_STRVAR(pwd_getpwnam__doc__,
120 "getpwnam(name) -> (pw_name,pw_passwd,pw_uid,\n\ 152 "getpwnam(arg)\n"
121 pw_gid,pw_gecos,pw_dir,pw_shell)\n\ 153 "Return the password database entry for the given user name.\n"
122 Return the password database entry for the given user name.\n\ 154 "\n"
123 See help(pwd) for more on password database entries."); 155 "See help(pwd) for more on password database entries.");
156
157 #define PWD_GETPWNAM_METHODDEF \
158 {"getpwnam", (PyCFunction)pwd_getpwnam, METH_VARARGS, pwd_getpwnam__doc__},
124 159
125 static PyObject * 160 static PyObject *
126 pwd_getpwnam(PyObject *self, PyObject *args) 161 pwd_getpwnam_impl(PyModuleDef *module, PyObject *arg);
162
163 static PyObject *
164 pwd_getpwnam(PyModuleDef *module, PyObject *args)
165 {
166 PyObject *return_value = NULL;
167 PyObject *arg;
168
169 if (!PyArg_ParseTuple(args,
170 "U:getpwnam",
171 &arg))
172 goto exit;
173 return_value = pwd_getpwnam_impl(module, arg);
174
175 exit:
176 return return_value;
177 }
178
179 static PyObject *
180 pwd_getpwnam_impl(PyModuleDef *module, PyObject *arg)
181 /*[clinic end generated code: checksum=f4530b6a4564930e0f821eeb26bcc1ab3f4a002d] */
127 { 182 {
128 char *name; 183 char *name;
129 struct passwd *p; 184 struct passwd *p;
130 PyObject *arg, *bytes, *retval = NULL; 185 PyObject *bytes, *retval = NULL;
131 186
132 if (!PyArg_ParseTuple(args, "U:getpwnam", &arg))
133 return NULL;
134 if ((bytes = PyUnicode_EncodeFSDefault(arg)) == NULL) 187 if ((bytes = PyUnicode_EncodeFSDefault(arg)) == NULL)
135 return NULL; 188 return NULL;
136 if (PyBytes_AsStringAndSize(bytes, &name, NULL) == -1) 189 if (PyBytes_AsStringAndSize(bytes, &name, NULL) == -1)
137 goto out; 190 goto out;
138 if ((p = getpwnam(name)) == NULL) { 191 if ((p = getpwnam(name)) == NULL) {
139 PyErr_Format(PyExc_KeyError, 192 PyErr_Format(PyExc_KeyError,
140 "getpwnam(): name not found: %s", name); 193 "getpwnam(): name not found: %s", name);
141 goto out; 194 goto out;
142 } 195 }
143 retval = mkpwent(p); 196 retval = mkpwent(p);
144 out: 197 out:
145 Py_DECREF(bytes); 198 Py_DECREF(bytes);
146 return retval; 199 return retval;
147 } 200 }
148 201
149 #ifdef HAVE_GETPWENT 202 #ifdef HAVE_GETPWENT
203 /*[clinic input]
204 pwd.getpwall
205
206 Return a list of all available password database entries, in arbitrary order.
207
208 See help(pwd) for more on password database entries.
209 [clinic start generated code]*/
210
150 PyDoc_STRVAR(pwd_getpwall__doc__, 211 PyDoc_STRVAR(pwd_getpwall__doc__,
151 "getpwall() -> list_of_entries\n\ 212 "getpwall()\n"
152 Return a list of all available password database entries, \ 213 "Return a list of all available password database entries, in arbitrary order.\n "
153 in arbitrary order.\n\ 214 "\n"
154 See help(pwd) for more on password database entries."); 215 "See help(pwd) for more on password database entries.");
216
217 #define PWD_GETPWALL_METHODDEF \
218 {"getpwall", (PyCFunction)pwd_getpwall, METH_NOARGS, pwd_getpwall__doc__},
155 219
156 static PyObject * 220 static PyObject *
157 pwd_getpwall(PyObject *self) 221 pwd_getpwall_impl(PyModuleDef *module);
222
223 static PyObject *
224 pwd_getpwall(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
225 {
226 PyObject *return_value = NULL;
227
228 return_value = pwd_getpwall_impl(module);
229
230 return return_value;
231 }
232
233 static PyObject *
234 pwd_getpwall_impl(PyModuleDef *module)
235 /*[clinic end generated code: checksum=8656f6cad166fb0711d54f0c5285fde473d90e38] */
158 { 236 {
159 PyObject *d; 237 PyObject *d;
160 struct passwd *p; 238 struct passwd *p;
161 if ((d = PyList_New(0)) == NULL) 239 if ((d = PyList_New(0)) == NULL)
162 return NULL; 240 return NULL;
163 setpwent(); 241 setpwent();
164 while ((p = getpwent()) != NULL) { 242 while ((p = getpwent()) != NULL) {
165 PyObject *v = mkpwent(p); 243 PyObject *v = mkpwent(p);
166 if (v == NULL || PyList_Append(d, v) != 0) { 244 if (v == NULL || PyList_Append(d, v) != 0) {
167 Py_XDECREF(v); 245 Py_XDECREF(v);
168 Py_DECREF(d); 246 Py_DECREF(d);
169 endpwent(); 247 endpwent();
170 return NULL; 248 return NULL;
171 } 249 }
172 Py_DECREF(v); 250 Py_DECREF(v);
173 } 251 }
174 endpwent(); 252 endpwent();
175 return d; 253 return d;
176 } 254 }
177 #endif 255 #endif
178 256
loewis 2014/07/27 17:58:48 This needs a "dump buffer" here.
179 static PyMethodDef pwd_methods[] = { 257 static PyMethodDef pwd_methods[] = {
180 {"getpwuid", pwd_getpwuid, METH_VARARGS, pwd_getpwuid__doc__}, 258 PWD_GETPWUID_METHODDEF
181 {"getpwnam", pwd_getpwnam, METH_VARARGS, pwd_getpwnam__doc__}, 259 PWD_GETPWNAM_METHODDEF
182 #ifdef HAVE_GETPWENT 260 #ifdef HAVE_GETPWENT
183 {"getpwall", (PyCFunction)pwd_getpwall, 261 PWD_GETPWALL_METHODDEF
184 METH_NOARGS, pwd_getpwall__doc__},
185 #endif 262 #endif
186 {NULL, NULL} /* sentinel */ 263 {NULL, NULL} /* sentinel */
187 }; 264 };
188 265
189 static struct PyModuleDef pwdmodule = { 266 static struct PyModuleDef pwdmodule = {
190 PyModuleDef_HEAD_INIT, 267 PyModuleDef_HEAD_INIT,
191 "pwd", 268 "pwd",
192 pwd__doc__, 269 pwd__doc__,
193 -1, 270 -1,
194 pwd_methods, 271 pwd_methods,
(...skipping 15 matching lines...) Expand all
210 if (!initialized) { 287 if (!initialized) {
211 if (PyStructSequence_InitType2(&StructPwdType, 288 if (PyStructSequence_InitType2(&StructPwdType,
212 &struct_pwd_type_desc) < 0) 289 &struct_pwd_type_desc) < 0)
213 return NULL; 290 return NULL;
214 initialized = 1; 291 initialized = 1;
215 } 292 }
216 Py_INCREF((PyObject *) &StructPwdType); 293 Py_INCREF((PyObject *) &StructPwdType);
217 PyModule_AddObject(m, "struct_passwd", (PyObject *) &StructPwdType); 294 PyModule_AddObject(m, "struct_passwd", (PyObject *) &StructPwdType);
218 return m; 295 return m;
219 } 296 }
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+