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

Side by Side Diff: Modules/pwdmodule.c

Issue 23670: Modifications to support iOS as a development platform
Patch Set: Created 3 years, 8 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 | « Modules/posixmodule.c ('k') | Modules/Setup.embedded » ('j') | 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
4 #ifdef __APPLE__
5 # include "TargetConditionals.h"
6 #endif /* __APPLE__ */
3 7
4 #include "Python.h" 8 #include "Python.h"
5 #include "posixmodule.h" 9 #include "posixmodule.h"
6 10
7 #include <pwd.h> 11 #include <pwd.h>
8 12
9 #include "clinic/pwdmodule.c.h" 13 #include "clinic/pwdmodule.c.h"
10 /*[clinic input] 14 /*[clinic input]
11 module pwd 15 module pwd
12 [clinic start generated code]*/ 16 [clinic start generated code]*/
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 uid_t uid; 115 uid_t uid;
112 struct passwd *p; 116 struct passwd *p;
113 117
114 if (!_Py_Uid_Converter(uidobj, &uid)) { 118 if (!_Py_Uid_Converter(uidobj, &uid)) {
115 if (PyErr_ExceptionMatches(PyExc_OverflowError)) 119 if (PyErr_ExceptionMatches(PyExc_OverflowError))
116 PyErr_Format(PyExc_KeyError, 120 PyErr_Format(PyExc_KeyError,
117 "getpwuid(): uid not found"); 121 "getpwuid(): uid not found");
118 return NULL; 122 return NULL;
119 } 123 }
120 if ((p = getpwuid(uid)) == NULL) { 124 if ((p = getpwuid(uid)) == NULL) {
125 // iPhone has a "user" with UID 501, username "mobile"; but the simulator
126 // doesn't reflect this. Generate a simulated response.
127 #if TARGET_IPHONE_SIMULATOR
128 if (uid == 501) {
129 struct passwd mp;
130 mp.pw_name = "mobile";
131 mp.pw_passwd = "/smx7MYTQIi2M";
132 mp.pw_uid = 501;
133 mp.pw_gid = 501;
134 mp.pw_gecos = "Mobile User";
135 mp.pw_dir = "/var/mobile";
136 mp.pw_shell = "/bin/sh";
137 return mkpwent(&mp);
138 }
139 #endif
121 PyObject *uid_obj = _PyLong_FromUid(uid); 140 PyObject *uid_obj = _PyLong_FromUid(uid);
122 if (uid_obj == NULL) 141 if (uid_obj == NULL)
123 return NULL; 142 return NULL;
124 PyErr_Format(PyExc_KeyError, 143 PyErr_Format(PyExc_KeyError,
125 "getpwuid(): uid not found: %S", uid_obj); 144 "getpwuid(): uid not found: %S", uid_obj);
126 Py_DECREF(uid_obj); 145 Py_DECREF(uid_obj);
127 return NULL; 146 return NULL;
128 } 147 }
129 return mkpwent(p); 148 return mkpwent(p);
130 } 149 }
(...skipping 15 matching lines...) Expand all
146 { 165 {
147 char *name; 166 char *name;
148 struct passwd *p; 167 struct passwd *p;
149 PyObject *bytes, *retval = NULL; 168 PyObject *bytes, *retval = NULL;
150 169
151 if ((bytes = PyUnicode_EncodeFSDefault(arg)) == NULL) 170 if ((bytes = PyUnicode_EncodeFSDefault(arg)) == NULL)
152 return NULL; 171 return NULL;
153 if (PyBytes_AsStringAndSize(bytes, &name, NULL) == -1) 172 if (PyBytes_AsStringAndSize(bytes, &name, NULL) == -1)
154 goto out; 173 goto out;
155 if ((p = getpwnam(name)) == NULL) { 174 if ((p = getpwnam(name)) == NULL) {
175 // iPhone has a "user" with UID 501, username "mobile"; but the simulator
176 // doesn't reflect this. Generate a simulated response.
177 #if TARGET_IPHONE_SIMULATOR
178 if (strcmp(name, "mobile") == 0) {
179 struct passwd mp;
180 mp.pw_name = "mobile";
181 mp.pw_passwd = "/smx7MYTQIi2M";
182 mp.pw_uid = 501;
183 mp.pw_gid = 501;
184 mp.pw_gecos = "Mobile User";
185 mp.pw_dir = "/var/mobile";
186 mp.pw_shell = "/bin/sh";
187 retval = mkpwent(&mp);
188 goto out;
189 }
190 #endif
156 PyErr_Format(PyExc_KeyError, 191 PyErr_Format(PyExc_KeyError,
157 "getpwnam(): name not found: %s", name); 192 "getpwnam(): name not found: %s", name);
158 goto out; 193 goto out;
159 } 194 }
160 retval = mkpwent(p); 195 retval = mkpwent(p);
161 out: 196 out:
162 Py_DECREF(bytes); 197 Py_DECREF(bytes);
163 return retval; 198 return retval;
164 } 199 }
165 200
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 if (!initialized) { 264 if (!initialized) {
230 if (PyStructSequence_InitType2(&StructPwdType, 265 if (PyStructSequence_InitType2(&StructPwdType,
231 &struct_pwd_type_desc) < 0) 266 &struct_pwd_type_desc) < 0)
232 return NULL; 267 return NULL;
233 initialized = 1; 268 initialized = 1;
234 } 269 }
235 Py_INCREF((PyObject *) &StructPwdType); 270 Py_INCREF((PyObject *) &StructPwdType);
236 PyModule_AddObject(m, "struct_passwd", (PyObject *) &StructPwdType); 271 PyModule_AddObject(m, "struct_passwd", (PyObject *) &StructPwdType);
237 return m; 272 return m;
238 } 273 }
OLDNEW
« no previous file with comments | « Modules/posixmodule.c ('k') | Modules/Setup.embedded » ('j') | no next file with comments »

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