R_API bool r_run_parseline(RRunProfile *p, char *b) { int must_free = false; char *e = strchr (b, '='); if (!e || *b == '#') { return 0; } *e++ = 0; if (*e=='$') { must_free = true; e = r_sys_getenv (e); } if (!e) { return 0; } if (!strcmp (b, "program")) { p->_args[0] = p->_program = strdup (e); } else if (!strcmp (b, "system")) { p->_system = strdup (e); } else if (!strcmp (b, "runlib")) { p->_runlib = strdup (e); } else if (!strcmp (b, "runlib.fcn")) { p->_runlib_fcn = strdup (e); } else if (!strcmp (b, "aslr")) { p->_aslr = parseBool (e); } else if (!strcmp (b, "pid")) { p->_pid = atoi (e); } else if (!strcmp (b, "pidfile")) { p->_pidfile = strdup (e); } else if (!strcmp (b, "connect")) { p->_connect = strdup (e); } else if (!strcmp (b, "listen")) { p->_listen = strdup (e); } else if (!strcmp (b, "pty")) { p->_pty = parseBool (e); } else if (!strcmp (b, "stdio")) { if (e[0] == '!') { p->_stdio = strdup (e); } else { p->_stdout = strdup (e); p->_stderr = strdup (e); p->_stdin = strdup (e); } } else if (!strcmp (b, "stdout")) { p->_stdout = strdup (e); } else if (!strcmp (b, "stdin")) { p->_stdin = strdup (e); } else if (!strcmp (b, "stderr")) { p->_stderr = strdup (e); } else if (!strcmp (b, "input")) { p->_input = strdup (e); } else if (!strcmp (b, "chdir")) { p->_chgdir = strdup (e); } else if (!strcmp (b, "core")) { p->_docore = parseBool (e); } else if (!strcmp (b, "fork")) { p->_dofork = parseBool (e); } else if (!strcmp (b, "sleep")) { p->_r2sleep = atoi (e); } else if (!strcmp (b, "maxstack")) { p->_maxstack = atoi (e); } else if (!strcmp (b, "maxproc")) { p->_maxproc = atoi (e); } else if (!strcmp (b, "maxfd")) { p->_maxfd = atoi (e); } else if (!strcmp (b, "bits")) { p->_bits = atoi (e); } else if (!strcmp (b, "chroot")) { p->_chroot = strdup (e); } else if (!strcmp (b, "libpath")) { p->_libpath = strdup (e); } else if (!strcmp (b, "preload")) { p->_preload = strdup (e); } else if (!strcmp (b, "r2preload")) { p->_r2preload = parseBool (e); } else if (!strcmp (b, "r2preweb")) { r_sys_setenv ("RARUN2_WEB", "yes"); } else if (!strcmp (b, "setuid")) { p->_setuid = strdup (e); } else if (!strcmp (b, "seteuid")) { p->_seteuid = strdup (e); } else if (!strcmp (b, "setgid")) { p->_setgid = strdup (e); } else if (!strcmp (b, "setegid")) { p->_setegid = strdup (e); } else if (!strcmp (b, "nice")) { p->_nice = atoi (e); } else if (!strcmp (b, "timeout")) { p->_timeout = atoi (e); } else if (!strcmp (b, "timeoutsig")) { p->_timeout_sig = r_signal_from_string (e); } else if (!memcmp (b, "arg", 3)) { int n = atoi (b + 3); if (n >= 0 && n < R_RUN_PROFILE_NARGS) { p->_args[n] = getstr (e); p->_argc++; } else { eprintf ("Out of bounds args index: %d\n", n); } } else if (!strcmp (b, "envfile")) { char *p, buf[1024]; size_t len; FILE *fd = fopen (e, "r"); if (!fd) { eprintf ("Cannot open '%s'\n", e); if (must_free == true) { free (e); } return false; } for (;;) { if (!fgets (buf, sizeof (buf) - 1, fd)) { break; } if (feof (fd)) { break; } p = strchr (buf, '='); if (p) { *p++ = 0; len = strlen(p); if (p[len - 1] == '\n') { p[len - 1] = 0; } if (p[len - 2] == '\r') { p[len - 2] = 0; } r_sys_setenv (buf, p); } } fclose (fd); } else if (!strcmp (b, "unsetenv")) { r_sys_setenv (e, NULL); } else if (!strcmp (b, "setenv")) { char *V, *v = strchr (e, '='); if (v) { *v++ = 0; V = getstr (v); r_sys_setenv (e, V); free (V); } } else if (!strcmp(b, "clearenv")) { r_sys_clearenv (); } if (must_free == true) { free (e); } return true; }
R_API int r_run_parseline (RRunProfile *p, char *b) { int must_free = false; char *e = strchr (b, '='); if (!e) return 0; if (*b=='#') return 0; *e++ = 0; if (*e=='$') { must_free = true; e = r_sys_getenv (e); } if (e == NULL) return 0; if (!strcmp (b, "program")) p->_args[0] = p->_program = strdup (e); else if (!strcmp (b, "system")) p->_system = strdup (e); else if (!strcmp (b, "aslr")) p->_aslr = parseBool (e); else if (!strcmp (b, "pid")) p->_pid = atoi (e); else if (!strcmp (b, "pidfile")) p->_pidfile = strdup (e); else if (!strcmp (b, "connect")) p->_connect = strdup (e); else if (!strcmp (b, "listen")) p->_listen = strdup (e); else if (!strcmp (b, "stdio")) { if (e[0] == '!') { p->_stdio = strdup (e); } else { p->_stdout = strdup (e); p->_stderr = strdup (e); p->_stdin = strdup (e); } } else if (!strcmp (b, "stdout")) p->_stdout = strdup (e); else if (!strcmp (b, "stdin")) p->_stdin = strdup (e); else if (!strcmp (b, "stderr")) p->_stderr = strdup (e); else if (!strcmp (b, "input")) p->_input = strdup (e); else if (!strcmp (b, "chdir")) p->_chgdir = strdup (e); else if (!strcmp (b, "core")) p->_docore = parseBool (e); else if (!strcmp (b, "fork")) p->_dofork = parseBool (e); else if (!strcmp (b, "sleep")) p->_r2sleep = atoi (e); else if (!strcmp (b, "maxstack")) p->_maxstack = atoi (e); else if (!strcmp (b, "maxproc")) p->_maxproc = atoi (e); else if (!strcmp (b, "maxfd")) p->_maxfd = atoi (e); else if (!strcmp (b, "bits")) p->_bits = atoi (e); else if (!strcmp (b, "chroot")) p->_chroot = strdup (e); else if (!strcmp (b, "libpath")) p->_libpath = strdup (e); else if (!strcmp (b, "preload")) p->_preload = strdup (e); else if (!strcmp (b, "r2preload")) p->_r2preload = parseBool (e); else if (!strcmp (b, "r2preweb")) r_sys_setenv ("RARUN2_WEB", "yes"); else if (!strcmp (b, "setuid")) p->_setuid = strdup (e); else if (!strcmp (b, "seteuid")) p->_seteuid = strdup (e); else if (!strcmp (b, "setgid")) p->_setgid = strdup (e); else if (!strcmp (b, "setegid")) p->_setegid = strdup (e); else if (!strcmp (b, "nice")) p->_nice = atoi (e); else if (!memcmp (b, "arg", 3)) { int n = atoi (b + 3); if (n >= 0 && n < R_RUN_PROFILE_NARGS) { p->_args[n] = getstr (e); } else eprintf ("Out of bounds args index: %d\n", n); } else if (!strcmp (b, "timeout")) { p->_timeout = atoi (e); } else if (!strcmp (b, "timeoutsig")) { // TODO: support non-numeric signal numbers here p->_timeout_sig = atoi (e); } else if (!strcmp (b, "envfile")) { char *p, buf[1024]; FILE *fd = fopen (e, "r"); if (!fd) { eprintf ("Cannot open '%s'\n", e); if (must_free == true) free (e); return 0; } for (;;) { fgets (buf, sizeof (buf)-1, fd); if (feof (fd)) break; p = strchr (buf, '='); if (p) { *p = 0; r_sys_setenv (buf, p + 1); } } fclose (fd); } else if (!strcmp (b, "unsetenv")) { r_sys_setenv (e, NULL); } else if (!strcmp (b, "setenv")) { char *V, *v = strchr (e, '='); if (v) { *v++ = 0; V = getstr (v); r_sys_setenv (e, V); free (V); } } else if (!strcmp(b, "clearenv")) { r_sys_clearenv (); } if (must_free == true) free (e); return 1; }