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

Unified Diff: Modules/pwdmodule.c

Issue 23670: Modifications to support iOS as a development platform
Patch Set: Created 3 years, 8 months ago
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Modules/posixmodule.c ('k') | Modules/Setup.embedded » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Modules/pwdmodule.c Tue Mar 01 10:26:10 2016 +0200
+++ b/Modules/pwdmodule.c Wed Mar 02 00:01:35 2016 +0000
@@ -1,11 +1,15 @@
/* UNIX password file access module */
+#ifdef __APPLE__
+# include "TargetConditionals.h"
+#endif /* __APPLE__ */
+
#include "Python.h"
#include "posixmodule.h"
#include <pwd.h>
#include "clinic/pwdmodule.c.h"
/*[clinic input]
module pwd
@@ -113,16 +117,31 @@ pwd_getpwuid(PyModuleDef *module, PyObje
if (!_Py_Uid_Converter(uidobj, &uid)) {
if (PyErr_ExceptionMatches(PyExc_OverflowError))
PyErr_Format(PyExc_KeyError,
"getpwuid(): uid not found");
return NULL;
}
if ((p = getpwuid(uid)) == NULL) {
+// iPhone has a "user" with UID 501, username "mobile"; but the simulator
+// doesn't reflect this. Generate a simulated response.
+#if TARGET_IPHONE_SIMULATOR
+ if (uid == 501) {
+ struct passwd mp;
+ mp.pw_name = "mobile";
+ mp.pw_passwd = "/smx7MYTQIi2M";
+ mp.pw_uid = 501;
+ mp.pw_gid = 501;
+ mp.pw_gecos = "Mobile User";
+ mp.pw_dir = "/var/mobile";
+ mp.pw_shell = "/bin/sh";
+ return mkpwent(&mp);
+ }
+#endif
PyObject *uid_obj = _PyLong_FromUid(uid);
if (uid_obj == NULL)
return NULL;
PyErr_Format(PyExc_KeyError,
"getpwuid(): uid not found: %S", uid_obj);
Py_DECREF(uid_obj);
return NULL;
}
@@ -148,16 +167,32 @@ pwd_getpwnam_impl(PyModuleDef *module, P
struct passwd *p;
PyObject *bytes, *retval = NULL;
if ((bytes = PyUnicode_EncodeFSDefault(arg)) == NULL)
return NULL;
if (PyBytes_AsStringAndSize(bytes, &name, NULL) == -1)
goto out;
if ((p = getpwnam(name)) == NULL) {
+// iPhone has a "user" with UID 501, username "mobile"; but the simulator
+// doesn't reflect this. Generate a simulated response.
+#if TARGET_IPHONE_SIMULATOR
+ if (strcmp(name, "mobile") == 0) {
+ struct passwd mp;
+ mp.pw_name = "mobile";
+ mp.pw_passwd = "/smx7MYTQIi2M";
+ mp.pw_uid = 501;
+ mp.pw_gid = 501;
+ mp.pw_gecos = "Mobile User";
+ mp.pw_dir = "/var/mobile";
+ mp.pw_shell = "/bin/sh";
+ retval = mkpwent(&mp);
+ goto out;
+ }
+#endif
PyErr_Format(PyExc_KeyError,
"getpwnam(): name not found: %s", name);
goto out;
}
retval = mkpwent(p);
out:
Py_DECREF(bytes);
return retval;
« 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+