OSDN Git Service

Android.mk: enable pppd on non-arm platform
[android-x86/external-ppp.git] / pppd / main.c
index 8515c1e..64efefe 100644 (file)
@@ -360,15 +360,39 @@ main(argc, argv)
      */
     tty_init();
 
+    progname = *argv;
+
 #ifdef ANDROID_CHANGES
     {
         extern void pppox_init();
         pppox_init();
+        privileged = 1;
+    }
+    {
+        char *envargs = getenv("envargs");
+        if (envargs) {
+            int i;
+            /* Decode the arguments in-place and count the number of them.
+             * They were hex encoded using [A-P] instead of [0-9A-F]. */
+            for (argc = 0, i = 0; envargs[i] && envargs[i + 1]; i += 2) {
+                char c = ((envargs[i] - 'A') << 4) + (envargs[i + 1] - 'A');
+                if (c == 0) {
+                    ++argc;
+                }
+                envargs[i / 2 + 1] = c;
+            }
+            if (argc == 0 || (argv = malloc(sizeof(char *) * argc)) == NULL) {
+                fatal("Failed to parse envargs!");
+            }
+            for (envargs[0] = 0, i = 0; i < argc; ++envargs) {
+                if (envargs[0] == 0) {
+                    argv[i++] = &envargs[1];
+                }
+            }
+        }
     }
 #endif
 
-    progname = *argv;
-
     /*
      * Parse, in order, the system options file, the user's options file,
      * and the command line arguments.
@@ -398,6 +422,7 @@ main(argc, argv)
     if (debug)
        setlogmask(LOG_UPTO(LOG_DEBUG));
 
+#ifndef ANDROID_CHANGES
     /*
      * Check that we are running as root.
      */
@@ -406,6 +431,7 @@ main(argc, argv)
                     argv[0]);
        exit(EXIT_NOT_ROOT);
     }
+#endif
 
     if (!ppp_available()) {
        option_error("%s", no_ppp_msg);
@@ -825,6 +851,7 @@ static void
 create_pidfile(pid)
     int pid;
 {
+#ifndef ANDROID_CHANGES
     FILE *pidfile;
 
     slprintf(pidfilename, sizeof(pidfilename), "%s%s.pid",
@@ -836,12 +863,14 @@ create_pidfile(pid)
        error("Failed to create pid file %s: %m", pidfilename);
        pidfilename[0] = 0;
     }
+#endif
 }
 
 void
 create_linkpidfile(pid)
     int pid;
 {
+#ifndef ANDROID_CHANGES
     FILE *pidfile;
 
     if (linkname[0] == 0)
@@ -858,6 +887,7 @@ create_linkpidfile(pid)
        error("Failed to create pid file %s: %m", linkpidfile);
        linkpidfile[0] = 0;
     }
+#endif
 }
 
 /*
@@ -865,12 +895,14 @@ create_linkpidfile(pid)
  */
 void remove_pidfiles()
 {
+#ifndef ANDROID_CHANGES
     if (pidfilename[0] != 0 && unlink(pidfilename) < 0 && errno != ENOENT)
        warn("unable to delete pid file %s: %m", pidfilename);
     pidfilename[0] = 0;
     if (linkpidfile[0] != 0 && unlink(linkpidfile) < 0 && errno != ENOENT)
        warn("unable to delete pid file %s: %m", linkpidfile);
     linkpidfile[0] = 0;
+#endif
 }
 
 /*
@@ -1636,6 +1668,21 @@ run_program(prog, args, must_exist, done, arg)
     int pid;
     struct stat sbuf;
 
+#ifdef ANDROID_CHANGES
+    /* Originally linkname is used to create named pid files, which is
+    * meaningless to android. Here we use it as a suffix of program names,
+    * so different users can run their own program by specifying it. For
+    * example, "/etc/ppp/ip-up-vpn" will be executed when IPCP is up and
+    * linkname is "vpn". Note that "/" is not allowed for security reasons. */
+    char file[MAXPATHLEN];
+
+    if (linkname[0] && !strchr(linkname, '/')) {
+        snprintf(file, MAXPATHLEN, "%s-%s", prog, linkname);
+        file[MAXPATHLEN - 1] = '\0';
+        prog = file;
+    }
+#endif
+
     /*
      * First check if the file exists and is executable.
      * We don't use access() because that would use the