void command_stop(void) { if (config.cmd_stop) { /*Spawn a child to run the program.*/ pid_t pid = fork(); if (pid == 0) { /* child process */ int argC; char **argV; // debug(1,"on-stop command found."); if (poptParseArgvString(config.cmd_stop, &argC, (const char ***)&argV) != 0) // note that argV should be free()'d after use, but we expect this fork to exit // eventually. debug(1, "Can't decipher on-stop command arguments"); else { // debug(1,"Executing on-stop command %s",config.cmd_stop); execv(argV[0], argV); warn("Execution of on-stop command failed to start"); debug(1, "Error executing on-stop command %s", config.cmd_stop); exit(127); /* only if execv fails */ } } else { if (config.cmd_blocking) { /* pid!=0 means parent process and if blocking is true, wait for process to finish */ pid_t rc = waitpid(pid, 0, 0); /* wait for child to exit */ if (rc != pid) { warn("Execution of on-stop command returned an error."); debug(1, "Stop command %s finished with error %d", config.cmd_stop, errno); } } // debug(1,"Continue after on-stop command"); } } }
void RTparseOptions(const char* argline,int *argc_p,char***argv_p){ int len=strlen(argline)+8; char cmdline[len]; sprintf(cmdline,"fake %s",argline); int res=poptParseArgvString(cmdline,argc_p,(const char ***)argv_p); if (res){ Fatal(1,error,"could not parse %s: %s",cmdline,poptStrerror(res)); } (*argv_p)[0]=strdup(HREgetApplication()); }
static void parse_libs_private (Package *pkg, const char *str, const char *path) { /* List of private libraries. Private libraries are libraries which are needed in the case of static linking or on platforms not supporting inter-library dependencies. They are not supposed to be used for libraries which are exposed through the library in question. An example of an exposed library is GTK+ exposing Glib. A common example of a private library is libm. Generally, if include another library's headers in your own, it's a public dependency and not a private one. */ char *trimmed; char **argv = NULL; int argc = 0; int result; if (pkg->libs_private_num > 0) { verbose_error ("Libs.private field occurs twice in '%s'\n", path); exit (1); } trimmed = trim_and_sub (pkg, str, path); if (trimmed && *trimmed) { result = poptParseArgvString (trimmed, &argc, &argv); if (result < 0) { verbose_error ("Couldn't parse Libs.private field into an argument vector: %s\n", poptStrerror (result)); exit (1); } } _do_parse_libs(pkg, argc, argv); g_free (argv); g_free (trimmed); pkg->libs_private_num++; }
static void configLine(poptContext con, char * line) { int nameLength = strlen(con->appName); char * opt; struct poptAlias alias; char * entryType; char * longName = NULL; char shortName = '\0'; if (strncmp(line, con->appName, nameLength)) return; line += nameLength; if (!*line || !isspace(*line)) return; while (*line && isspace(*line)) line++; entryType = line; while (!*line || !isspace(*line)) line++; *line++ = '\0'; while (*line && isspace(*line)) line++; if (!*line) return; opt = line; while (!*line || !isspace(*line)) line++; *line++ = '\0'; while (*line && isspace(*line)) line++; if (!*line) return; if (opt[0] == '-' && opt[1] == '-') longName = opt + 2; else if (opt[0] == '-' && !opt[2]) shortName = opt[1]; if (!strcmp(entryType, "alias")) { if (poptParseArgvString(line, &alias.argc, &alias.argv)) return; alias.longName = longName, alias.shortName = shortName; poptAddAlias(con, alias, 0); } else if (!strcmp(entryType, "exec")) { con->execs = realloc(con->execs, sizeof(*con->execs) * (con->numExecs + 1)); if (longName) con->execs[con->numExecs].longName = strdup(longName); else con->execs[con->numExecs].longName = NULL; con->execs[con->numExecs].shortName = shortName; con->execs[con->numExecs].script = strdup(line); con->numExecs++; } }
gboolean parse_cmdline(const char *s, int *argcPtr, char ***argvPtr, const HostNode *n) { gint i; const gchar **argv; if(poptParseArgvString(s, argcPtr, &argv) < 0) return FALSE; *argvPtr = g_new0(char*, *argcPtr+1); if(n) for(i=0;i<*argcPtr;i++) (*argvPtr)[i] = parse_string(argv[i], n); return TRUE; }
static rpmRC addOrAppendListEntry(Header h, rpmTagVal tag, const char * line) { int xx; int argc; const char **argv; if ((xx = poptParseArgvString(line, &argc, &argv))) { rpmlog(RPMLOG_ERR, _("Error parsing tag field: %s\n"), poptStrerror(xx)); return RPMRC_FAIL; } if (argc) headerPutStringArray(h, tag, argv, argc); argv = _free(argv); return RPMRC_OK; }
static void run_shell(struct torture_context *tctx) { char *cline; int argc; const char **argv; int ret; while (1) { cline = smb_readline("torture> ", NULL, NULL); if (cline == NULL) return; ret = poptParseArgvString(cline, &argc, &argv); if (ret != 0) { fprintf(stderr, "Error parsing line\n"); continue; } if (!strcmp(argv[0], "quit")) { return; } else if (!strcmp(argv[0], "set")) { if (argc < 3) { fprintf(stderr, "Usage: set <variable> <value>\n"); } else { char *name = talloc_asprintf(NULL, "torture:%s", argv[1]); lp_set_cmdline(tctx->lp_ctx, name, argv[2]); talloc_free(name); } } else if (!strcmp(argv[0], "help")) { fprintf(stderr, "Available commands:\n" " help - This help command\n" " run - Run test\n" " set - Change variables\n" "\n"); } else if (!strcmp(argv[0], "run")) { if (argc < 2) { fprintf(stderr, "Usage: run TEST-NAME [OPTIONS...]\n"); } else { run_test(tctx, argv[1]); } } free(cline); } }
static void addOrAppendListEntry(Header h, rpmTag tag, char * line) /*@modifies h @*/ { HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he)); int xx; int argc; const char **argv; xx = poptParseArgvString(line, &argc, &argv); if (argc) { he->tag = tag; he->t = RPM_STRING_ARRAY_TYPE; he->p.argv = argv; he->c = argc; he->append = 1; xx = headerPut(h, he, 0); he->append = 0; } argv = _free(argv); }
static void configLine(poptContext con, char * line) { int nameLength = strlen(con->appName); char * opt; struct poptAlias alias; if (strncmp(line, con->appName, nameLength)) return; line += nameLength; if (!*line || !isspace(*line)) return; while (*line && isspace(*line)) line++; if (!strncmp(line, "alias", 5)) { line += 5; if (!*line || !isspace(*line)) return; while (*line && isspace(*line)) line++; if (!*line) return; opt = line; while (*line && !isspace(*line)) line++; if (!*line) return; *line++ = '\0'; while (*line && isspace(*line)) line++; if (!*line) return; if (!strlen(opt)) return; if (poptParseArgvString(line, &alias.argc, &alias.argv)) return; if (opt[0] == '-' && opt[1] == '-') { alias.longName = opt + 2; alias.shortName = '\0'; poptAddAlias(con, alias, 0); } else if (opt[0] == '-' && !opt[2]) { alias.longName = NULL; alias.shortName = opt[1]; poptAddAlias(con, alias, 0); } } }
static void parse_libs (Package *pkg, const char *str, const char *path) { /* Strip out -l and -L flags, put them in a separate list. */ char *trimmed; char **argv = NULL; int argc = 0; int result; if (pkg->libs_num > 0) { verbose_error ("Libs field occurs twice in '%s'\n", path); exit (1); } trimmed = trim_and_sub (pkg, str, path); if (trimmed && *trimmed) { result = poptParseArgvString (trimmed, &argc, &argv); if (result < 0) { verbose_error ("Couldn't parse Libs field into an argument vector: %s\n", poptStrerror (result)); exit (1); } } _do_parse_libs(pkg, argc, argv); g_free (trimmed); g_free (argv); pkg->libs_num++; }
static WERROR process_cmd(struct regshell_context *ctx, char *line) { int argc; char **argv = NULL; int ret, i; if ((ret = poptParseArgvString(line, &argc, (const char ***) &argv)) != 0) { fprintf(stderr, "regshell: %s\n", poptStrerror(ret)); return WERR_INVALID_PARAM; } for(i = 0; regshell_cmds[i].name; i++) { if(!strcmp(regshell_cmds[i].name, argv[0]) || (regshell_cmds[i].alias && !strcmp(regshell_cmds[i].alias, argv[0]))) { return regshell_cmds[i].handle(ctx, argc, argv); } } fprintf(stderr, "No such command '%s'\n", argv[0]); return WERR_INVALID_PARAM; }
void launchVisualizer(NBodyState* st, const char* visArgs) { pid_t pid; char* path = NULL; char* newPath = NULL; int argc = 0; char* buf = NULL; char* p = NULL; char** argv = NULL; size_t argvSize = 0; size_t visArgsLen = 0; if (!st->scene) /* If there's no scene to share, there's no point */ return; pid = fork(); if (pid != 0) /* Parent */ return; /* Child */ /* Hack to close the shared memory access we inherit so we * don't count it when the visualizer actually opens it again */ if (detachSharedScene(st)) { warn("Error detaching child from shared"); return; } /* Put places convenient for testing. Not essential, failure of * any of these is OK */ path = getenv("PATH"); if (!path) { perror("Error getting PATH"); } else { if (asprintf(&newPath, ".:../bin/:%s", path) < 0) { perror("Appending to path"); } else { if (setenv("PATH", newPath, TRUE) < 0) { perror("Error setting PATH"); } free(newPath); } } /* Stick the program name at the head of the arguments passed in */ visArgsLen = visArgs ? strlen(visArgs) : 0; argvSize = visArgsLen + sizeof(nbodyGraphicsName) + 2; /* arguments + program name + space + null */ buf = mwCalloc(argvSize, sizeof(char)); p = stpcpy(buf, nbodyGraphicsName); p = stpcpy(p, " "); if (visArgs) { stpcpy(p, visArgs); } if (poptParseArgvString(buf, &argc, (const char***) &argv)) { free(buf); free(path); warn("Error parsing arguments for visualizer '%s'\n", visArgs); return; } if (execvp(argv[0], argv) < 0) { perror("Failed to launch visualizer"); } free(buf); free(argv); mw_finish(EXIT_SUCCESS); /* Unnecessary */ }
/* * @todo Single use by %%doc in files.c prevents static. */ rpmRC doScript(rpmSpec spec, rpmBuildFlags what, const char *name, const char *sb, int test) { const char * rootDir = spec->rootDir; char *scriptName = NULL; char * buildDir = rpmGenPath(rootDir, "%{_builddir}", ""); char * buildCmd = NULL; char * buildTemplate = NULL; char * buildPost = NULL; const char * mTemplate = NULL; const char * mCmd = NULL; const char * mPost = NULL; int argc = 0; const char **argv = NULL; FILE * fp = NULL; FD_t fd; FD_t xfd; pid_t pid; pid_t child; int status; rpmRC rc; switch (what) { case RPMBUILD_PREP: mTemplate = "%{__spec_prep_template}"; mPost = "%{__spec_prep_post}"; mCmd = "%{__spec_prep_cmd}"; break; case RPMBUILD_BUILD: mTemplate = "%{__spec_build_template}"; mPost = "%{__spec_build_post}"; mCmd = "%{__spec_build_cmd}"; break; case RPMBUILD_INSTALL: mTemplate = "%{__spec_install_template}"; mPost = "%{__spec_install_post}"; mCmd = "%{__spec_install_cmd}"; break; case RPMBUILD_CHECK: mTemplate = "%{__spec_check_template}"; mPost = "%{__spec_check_post}"; mCmd = "%{__spec_check_cmd}"; break; case RPMBUILD_CLEAN: mTemplate = "%{__spec_clean_template}"; mPost = "%{__spec_clean_post}"; mCmd = "%{__spec_clean_cmd}"; break; case RPMBUILD_RMBUILD: mTemplate = "%{__spec_clean_template}"; mPost = "%{__spec_clean_post}"; mCmd = "%{__spec_clean_cmd}"; break; case RPMBUILD_STRINGBUF: default: mTemplate = "%{___build_template}"; mPost = "%{___build_post}"; mCmd = "%{___build_cmd}"; break; } if ((what != RPMBUILD_RMBUILD) && sb == NULL) { rc = RPMRC_OK; goto exit; } fd = rpmMkTempFile(rootDir, &scriptName); if (fd == NULL || Ferror(fd)) { rpmlog(RPMLOG_ERR, _("Unable to open temp file.\n")); rc = RPMRC_FAIL; goto exit; } if (fdGetFILE(fd) == NULL) xfd = Fdopen(fd, "w.fpio"); else xfd = fd; if ((fp = fdGetFILE(xfd)) == NULL) { rc = RPMRC_FAIL; goto exit; } if (*rootDir == '\0') rootDir = "/"; buildTemplate = rpmExpand(mTemplate, NULL); buildPost = rpmExpand(mPost, NULL); (void) fputs(buildTemplate, fp); if (what != RPMBUILD_PREP && what != RPMBUILD_RMBUILD && spec->buildSubdir) fprintf(fp, "cd '%s'\n", spec->buildSubdir); if (what == RPMBUILD_RMBUILD) { if (spec->buildSubdir) fprintf(fp, "rm -rf '%s'\n", spec->buildSubdir); } else if (sb != NULL) fprintf(fp, "%s", sb); (void) fputs(buildPost, fp); (void) Fclose(xfd); if (test) { rc = RPMRC_OK; goto exit; } if (buildDir && buildDir[0] != '/') { rc = RPMRC_FAIL; goto exit; } buildCmd = rpmExpand(mCmd, " ", scriptName, NULL); (void) poptParseArgvString(buildCmd, &argc, &argv); rpmlog(RPMLOG_NOTICE, _("Executing(%s): %s\n"), name, buildCmd); if (!(child = fork())) { /* NSPR messes with SIGPIPE, reset to default for the kids */ signal(SIGPIPE, SIG_DFL); errno = 0; (void) execvp(argv[0], (char *const *)argv); rpmlog(RPMLOG_ERR, _("Exec of %s failed (%s): %s\n"), scriptName, name, strerror(errno)); _exit(127); /* exit 127 for compatibility with bash(1) */ } pid = waitpid(child, &status, 0); if (!WIFEXITED(status) || WEXITSTATUS(status)) { rpmlog(RPMLOG_ERR, _("Bad exit status from %s (%s)\n"), scriptName, name); rc = RPMRC_FAIL; } else rc = RPMRC_OK; exit: if (scriptName) { if (rc == RPMRC_OK) (void) unlink(scriptName); scriptName = _free(scriptName); } argv = _free(argv); buildCmd = _free(buildCmd); buildTemplate = _free(buildTemplate); buildPost = _free(buildPost); buildDir = _free(buildDir); return rc; }
int parseFiles(rpmSpec spec) { int nextPart, res = PART_ERROR; Package pkg; int rc, argc; int arg; const char ** argv = NULL; const char *name = NULL; int flag = PART_SUBNAME; poptContext optCon = NULL; struct poptOption optionsTable[] = { { NULL, 'n', POPT_ARG_STRING, &name, 'n', NULL, NULL}, { NULL, 'f', POPT_ARG_STRING, NULL, 'f', NULL, NULL}, { 0, 0, 0, 0, 0, NULL, NULL} }; /* XXX unmask %license while parsing %files */ addMacro(spec->macros, "license", NULL, "%%license", RMIL_SPEC); if ((rc = poptParseArgvString(spec->line, &argc, &argv))) { rpmlog(RPMLOG_ERR, _("line %d: Error parsing %%files: %s\n"), spec->lineNum, poptStrerror(rc)); goto exit; } optCon = poptGetContext(NULL, argc, argv, optionsTable, 0); while ((arg = poptGetNextOpt(optCon)) > 0) { if (arg == 'n') { flag = PART_NAME; } } if (arg < -1) { rpmlog(RPMLOG_ERR, _("line %d: Bad option %s: %s\n"), spec->lineNum, poptBadOption(optCon, POPT_BADOPTION_NOALIAS), spec->line); goto exit; } if (poptPeekArg(optCon)) { if (name == NULL) name = poptGetArg(optCon); if (poptPeekArg(optCon)) { rpmlog(RPMLOG_ERR, _("line %d: Too many names: %s\n"), spec->lineNum, spec->line); goto exit; } } if (lookupPackage(spec, name, flag, &pkg)) { rpmlog(RPMLOG_ERR, _("line %d: Package does not exist: %s\n"), spec->lineNum, spec->line); goto exit; } for (arg=1; arg<argc; arg++) { if (rstreq(argv[arg], "-f") && argv[arg+1]) { char *file = rpmGetPath(argv[arg+1], NULL); argvAdd(&(pkg->fileFile), file); free(file); } } pkg->fileList = argvNew(); if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) { nextPart = PART_NONE; } else if (rc < 0) { goto exit; } else { while (! (nextPart = isPart(spec->line))) { argvAdd(&(pkg->fileList), spec->line); if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) { nextPart = PART_NONE; break; } else if (rc < 0) { goto exit; } } } res = nextPart; exit: delMacro(NULL, "license"); free(argv); poptFreeContext(optCon); return res; }
int parseScript(rpmSpec spec, int parsePart) { /* There are a few options to scripts: */ /* <pkg> */ /* -n <pkg> */ /* -p <sh> */ /* -p "<sh> <args>..." */ /* -f <file> */ const char *p; const char **progArgv = NULL; int progArgc; const char *partname = NULL; rpmTagVal reqtag = 0; rpmTagVal tag = 0; rpmsenseFlags tagflags = 0; rpmTagVal progtag = 0; rpmTagVal flagtag = 0; rpmscriptFlags scriptFlags = 0; int flag = PART_SUBNAME; Package pkg; StringBuf sb = NULL; int nextPart; int index; char * reqargs = NULL; int res = PART_ERROR; /* assume failure */ int rc, argc; int arg; const char **argv = NULL; poptContext optCon = NULL; const char *name = NULL; const char *prog = "/bin/sh"; const char *file = NULL; struct poptOption optionsTable[] = { { NULL, 'p', POPT_ARG_STRING, &prog, 'p', NULL, NULL}, { NULL, 'n', POPT_ARG_STRING, &name, 'n', NULL, NULL}, { NULL, 'f', POPT_ARG_STRING, &file, 'f', NULL, NULL}, { NULL, 'e', POPT_BIT_SET, &scriptFlags, RPMSCRIPT_FLAG_EXPAND, NULL, NULL}, { NULL, 'q', POPT_BIT_SET, &scriptFlags, RPMSCRIPT_FLAG_QFORMAT, NULL, NULL}, { 0, 0, 0, 0, 0, NULL, NULL} }; switch (parsePart) { case PART_PRE: tag = RPMTAG_PREIN; tagflags = RPMSENSE_SCRIPT_PRE; progtag = RPMTAG_PREINPROG; flagtag = RPMTAG_PREINFLAGS; partname = "%pre"; break; case PART_POST: tag = RPMTAG_POSTIN; tagflags = RPMSENSE_SCRIPT_POST; progtag = RPMTAG_POSTINPROG; flagtag = RPMTAG_POSTINFLAGS; partname = "%post"; break; case PART_PREUN: tag = RPMTAG_PREUN; tagflags = RPMSENSE_SCRIPT_PREUN; progtag = RPMTAG_PREUNPROG; flagtag = RPMTAG_PREUNFLAGS; partname = "%preun"; break; case PART_POSTUN: tag = RPMTAG_POSTUN; tagflags = RPMSENSE_SCRIPT_POSTUN; progtag = RPMTAG_POSTUNPROG; flagtag = RPMTAG_POSTUNFLAGS; partname = "%postun"; break; case PART_PRETRANS: tag = RPMTAG_PRETRANS; tagflags = RPMSENSE_PRETRANS; progtag = RPMTAG_PRETRANSPROG; flagtag = RPMTAG_PRETRANSFLAGS; partname = "%pretrans"; break; case PART_POSTTRANS: tag = RPMTAG_POSTTRANS; tagflags = RPMSENSE_POSTTRANS; progtag = RPMTAG_POSTTRANSPROG; flagtag = RPMTAG_POSTTRANSFLAGS; partname = "%posttrans"; break; case PART_VERIFYSCRIPT: tag = RPMTAG_VERIFYSCRIPT; tagflags = RPMSENSE_SCRIPT_VERIFY; progtag = RPMTAG_VERIFYSCRIPTPROG; flagtag = RPMTAG_VERIFYSCRIPTFLAGS; partname = "%verifyscript"; break; case PART_TRIGGERPREIN: tag = RPMTAG_TRIGGERSCRIPTS; tagflags = 0; reqtag = RPMTAG_TRIGGERPREIN; progtag = RPMTAG_TRIGGERSCRIPTPROG; flagtag = RPMTAG_TRIGGERSCRIPTFLAGS; partname = "%triggerprein"; break; case PART_TRIGGERIN: tag = RPMTAG_TRIGGERSCRIPTS; tagflags = 0; reqtag = RPMTAG_TRIGGERIN; progtag = RPMTAG_TRIGGERSCRIPTPROG; flagtag = RPMTAG_TRIGGERSCRIPTFLAGS; partname = "%triggerin"; break; case PART_TRIGGERUN: tag = RPMTAG_TRIGGERSCRIPTS; tagflags = 0; reqtag = RPMTAG_TRIGGERUN; progtag = RPMTAG_TRIGGERSCRIPTPROG; flagtag = RPMTAG_TRIGGERSCRIPTFLAGS; partname = "%triggerun"; break; case PART_TRIGGERPOSTUN: tag = RPMTAG_TRIGGERSCRIPTS; tagflags = 0; reqtag = RPMTAG_TRIGGERPOSTUN; progtag = RPMTAG_TRIGGERSCRIPTPROG; flagtag = RPMTAG_TRIGGERSCRIPTFLAGS; partname = "%triggerpostun"; break; case PART_FILETRIGGERIN: tag = RPMTAG_FILETRIGGERSCRIPTS; tagflags = 0; reqtag = RPMTAG_FILETRIGGERIN; progtag = RPMTAG_FILETRIGGERSCRIPTPROG; flagtag = RPMTAG_FILETRIGGERSCRIPTFLAGS; partname = "%filetriggerin"; break; case PART_FILETRIGGERUN: tag = RPMTAG_FILETRIGGERSCRIPTS; tagflags = 0; reqtag = RPMTAG_FILETRIGGERUN; progtag = RPMTAG_FILETRIGGERSCRIPTPROG; flagtag = RPMTAG_FILETRIGGERSCRIPTFLAGS; partname = "%filetriggerun"; break; case PART_FILETRIGGERPOSTUN: tag = RPMTAG_FILETRIGGERSCRIPTS; tagflags = 0; reqtag = RPMTAG_FILETRIGGERPOSTUN; progtag = RPMTAG_FILETRIGGERSCRIPTPROG; flagtag = RPMTAG_FILETRIGGERSCRIPTFLAGS; partname = "%filetriggerpostun"; break; case PART_TRANSFILETRIGGERIN: tag = RPMTAG_TRANSFILETRIGGERSCRIPTS; tagflags = 0; reqtag = RPMTAG_TRANSFILETRIGGERIN; progtag = RPMTAG_TRANSFILETRIGGERSCRIPTPROG; flagtag = RPMTAG_TRANSFILETRIGGERSCRIPTFLAGS; partname = "%transfiletriggerin"; break; case PART_TRANSFILETRIGGERUN: tag = RPMTAG_TRANSFILETRIGGERSCRIPTS; tagflags = 0; reqtag = RPMTAG_TRANSFILETRIGGERUN; progtag = RPMTAG_TRANSFILETRIGGERSCRIPTPROG; flagtag = RPMTAG_TRANSFILETRIGGERSCRIPTFLAGS; partname = "%transfiletriggerun"; break; case PART_TRANSFILETRIGGERPOSTUN: tag = RPMTAG_TRANSFILETRIGGERSCRIPTS; tagflags = 0; reqtag = RPMTAG_TRANSFILETRIGGERPOSTUN; progtag = RPMTAG_TRANSFILETRIGGERSCRIPTPROG; flagtag = RPMTAG_TRANSFILETRIGGERSCRIPTFLAGS; partname = "%transfiletriggerpostun"; break; } if (tag == RPMTAG_TRIGGERSCRIPTS || tag == RPMTAG_FILETRIGGERSCRIPTS || tag == RPMTAG_TRANSFILETRIGGERSCRIPTS) { /* break line into two */ char *s = strstr(spec->line, "--"); if (!s) { rpmlog(RPMLOG_ERR, _("line %d: triggers must have --: %s\n"), spec->lineNum, spec->line); return PART_ERROR; } *s = '\0'; reqargs = xstrdup(s + 2); } if ((rc = poptParseArgvString(spec->line, &argc, &argv))) { rpmlog(RPMLOG_ERR, _("line %d: Error parsing %s: %s\n"), spec->lineNum, partname, poptStrerror(rc)); goto exit; } optCon = poptGetContext(NULL, argc, argv, optionsTable, 0); while ((arg = poptGetNextOpt(optCon)) > 0) { switch (arg) { case 'p': if (prog[0] == '<') { if (prog[strlen(prog)-1] != '>') { rpmlog(RPMLOG_ERR, _("line %d: internal script must end " "with \'>\': %s\n"), spec->lineNum, prog); goto exit; } } else if (prog[0] != '/') { rpmlog(RPMLOG_ERR, _("line %d: script program must begin " "with \'/\': %s\n"), spec->lineNum, prog); goto exit; } break; case 'n': flag = PART_NAME; break; } } if (arg < -1) { rpmlog(RPMLOG_ERR, _("line %d: Bad option %s: %s\n"), spec->lineNum, poptBadOption(optCon, POPT_BADOPTION_NOALIAS), spec->line); goto exit; } if (poptPeekArg(optCon)) { if (name == NULL) name = poptGetArg(optCon); if (poptPeekArg(optCon)) { rpmlog(RPMLOG_ERR, _("line %d: Too many names: %s\n"), spec->lineNum, spec->line); goto exit; } } if (lookupPackage(spec, name, flag, &pkg)) { rpmlog(RPMLOG_ERR, _("line %d: Package does not exist: %s\n"), spec->lineNum, spec->line); goto exit; } if (tag != RPMTAG_TRIGGERSCRIPTS) { if (headerIsEntry(pkg->header, progtag)) { rpmlog(RPMLOG_ERR, _("line %d: Second %s\n"), spec->lineNum, partname); goto exit; } } if ((rc = poptParseArgvString(prog, &progArgc, &progArgv))) { rpmlog(RPMLOG_ERR, _("line %d: Error parsing %s: %s\n"), spec->lineNum, partname, poptStrerror(rc)); goto exit; } sb = newStringBuf(); if ((rc = readLine(spec, STRIP_NOTHING)) > 0) { nextPart = PART_NONE; } else if (rc < 0) { goto exit; } else { while (! (nextPart = isPart(spec->line))) { appendStringBuf(sb, spec->line); if ((rc = readLine(spec, STRIP_NOTHING)) > 0) { nextPart = PART_NONE; break; } else if (rc < 0) { goto exit; } } } stripTrailingBlanksStringBuf(sb); p = getStringBuf(sb); #ifdef WITH_LUA if (rstreq(progArgv[0], "<lua>")) { rpmlua lua = NULL; /* Global state. */ if (rpmluaCheckScript(lua, p, partname) != RPMRC_OK) { goto exit; } (void) rpmlibNeedsFeature(pkg, "BuiltinLuaScripts", "4.2.2-1"); } else #endif if (progArgv[0][0] == '<') { rpmlog(RPMLOG_ERR, _("line %d: unsupported internal script: %s\n"), spec->lineNum, progArgv[0]); goto exit; } else { (void) addReqProv(pkg, RPMTAG_REQUIRENAME, progArgv[0], NULL, (tagflags | RPMSENSE_INTERP), 0); } if (scriptFlags) { rpmlibNeedsFeature(pkg, "ScriptletExpansion", "4.9.0-1"); } /* Trigger script insertion is always delayed in order to */ /* get the index right. */ if (tag == RPMTAG_TRIGGERSCRIPTS || tag == RPMTAG_FILETRIGGERSCRIPTS || tag == RPMTAG_TRANSFILETRIGGERSCRIPTS) { if (progArgc > 1) { rpmlog(RPMLOG_ERR, _("line %d: interpreter arguments not allowed in triggers: %s\n"), spec->lineNum, prog); goto exit; } /* Add file/index/prog triple to the trigger file list */ index = addTriggerIndex(pkg, file, p, progArgv[0], scriptFlags, tag); /* Generate the trigger tags */ if (parseRCPOT(spec, pkg, reqargs, reqtag, index, tagflags)) goto exit; } else { struct rpmtd_s td; /* * XXX Ancient rpm uses STRING, not STRING_ARRAY type here. Construct * the td manually and preserve legacy compat for now... */ rpmtdReset(&td); td.tag = progtag; td.count = progArgc; if (progArgc == 1) { td.data = (void *) *progArgv; td.type = RPM_STRING_TYPE; } else { (void) rpmlibNeedsFeature(pkg, "ScriptletInterpreterArgs", "4.0.3-1"); td.data = progArgv; td.type = RPM_STRING_ARRAY_TYPE; } headerPut(pkg->header, &td, HEADERPUT_DEFAULT); if (*p != '\0') { headerPutString(pkg->header, tag, p); } if (scriptFlags) { headerPutUint32(pkg->header, flagtag, &scriptFlags, 1); } if (file) { switch (parsePart) { case PART_PRE: pkg->preInFile = xstrdup(file); break; case PART_POST: pkg->postInFile = xstrdup(file); break; case PART_PREUN: pkg->preUnFile = xstrdup(file); break; case PART_POSTUN: pkg->postUnFile = xstrdup(file); break; case PART_PRETRANS: pkg->preTransFile = xstrdup(file); break; case PART_POSTTRANS: pkg->postTransFile = xstrdup(file); break; case PART_VERIFYSCRIPT: pkg->verifyFile = xstrdup(file); break; } } } res = nextPart; exit: free(reqargs); freeStringBuf(sb); free(progArgv); free(argv); poptFreeContext(optCon); return res; }
/** * Parse %setup macro. * @todo FIXME: Option -q broken when not immediately after %setup. * @param spec build info * @param line current line from spec file * @return 0 on success */ static int doSetupMacro(Spec spec, const char * line) /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/ /*@modifies spec->buildSubdir, spec->macros, spec->prep, spec->packages->header, rpmGlobalMacroContext, fileSystem, internalState @*/ { char buf[BUFSIZ]; rpmiob before = NULL; rpmiob after = NULL; poptContext optCon; int argc; const char ** argv; int arg; const char * optArg; int rc; rpmuint32_t num; rpmRC ec = RPMRC_FAIL; /* XXX assume failure */ /*@-mods@*/ leaveDirs = skipDefaultAction = 0; createDir = quietly = 0; dirName = NULL; /*@=mods@*/ if ((rc = poptParseArgvString(line, &argc, &argv))) { rpmlog(RPMLOG_ERR, _("Error parsing %%setup: %s\n"), poptStrerror(rc)); goto exit; } before = rpmiobNew(0); after = rpmiobNew(0); optCon = poptGetContext(NULL, argc, argv, optionsTable, 0); while ((arg = poptGetNextOpt(optCon)) > 0) { optArg = poptGetOptArg(optCon); /* We only parse -a and -b here */ if (parseNum(optArg, &num)) { rpmlog(RPMLOG_ERR, _("line %d: Bad arg to %%setup: %s\n"), spec->lineNum, (optArg ? optArg : "???")); optCon = poptFreeContext(optCon); argv = _free(argv); goto exit; } { const char *chptr = doUntar(spec, num, quietly); if (chptr == NULL) goto exit; (void) rpmiobAppend((arg == 'a' ? after : before), chptr, 1); } } if (arg < -1) { rpmlog(RPMLOG_ERR, _("line %d: Bad %%setup option %s: %s\n"), spec->lineNum, poptBadOption(optCon, POPT_BADOPTION_NOALIAS), poptStrerror(arg)); optCon = poptFreeContext(optCon); argv = _free(argv); goto exit; } if (dirName) { spec->buildSubdir = xstrdup(dirName); } else { const char *N, *V; (void) headerNEVRA(spec->packages->header, &N, NULL, &V, NULL, NULL); (void) snprintf(buf, sizeof(buf), "%s-%s", N, V); buf[sizeof(buf)-1] = '\0'; N = _free(N); V = _free(V); spec->buildSubdir = xstrdup(buf); } addMacro(spec->macros, "buildsubdir", NULL, spec->buildSubdir, RMIL_SPEC); optCon = poptFreeContext(optCon); argv = _free(argv); /* cd to the build dir */ { const char * buildDirURL = rpmGenPath(spec->rootURL, "%{_builddir}", ""); const char *buildDir; (void) urlPath(buildDirURL, &buildDir); rc = rpmioMkpath(buildDir, 0755, -1, -1); sprintf(buf, "cd '%s'", buildDir); spec->prep = rpmiobAppend(spec->prep, buf, 1); buildDirURL = _free(buildDirURL); } /* delete any old sources */ if (!leaveDirs) { sprintf(buf, "rm -rf '%s'", spec->buildSubdir); spec->prep = rpmiobAppend(spec->prep, buf, 1); } /* check if source is a ruby gem */ { struct Source *sp; for (sp = spec->sources; sp != NULL; sp = sp->next) { if ((sp->flags & RPMFILE_SOURCE) && (sp->num == 0)) { break; } } if (sp != NULL) { char *t = strrchr(sp->source, '.'); if(t && !strcasecmp(t, ".gem")) createDir = 1; } } /* if necessary, create and cd into the proper dir */ if (createDir) { char *mkdir_p; mkdir_p = rpmExpand("%{?__mkdir_p}%{!?__mkdir_p:mkdir -p}", NULL); if (!mkdir_p) mkdir_p = xstrdup("mkdir -p"); sprintf(buf, "%s '%s'\ncd '%s'", mkdir_p, spec->buildSubdir, spec->buildSubdir); mkdir_p = _free(mkdir_p); spec->prep = rpmiobAppend(spec->prep, buf, 1); } /* do the default action */ if (!createDir && !skipDefaultAction) { const char *chptr = doUntar(spec, 0, quietly); if (chptr == NULL) goto exit; spec->prep = rpmiobAppend(spec->prep, chptr, 1); } spec->prep = rpmiobAppend(spec->prep, rpmiobStr(before), 0); if (!createDir) { sprintf(buf, "cd '%s'", spec->buildSubdir); spec->prep = rpmiobAppend(spec->prep, buf, 1); } if (createDir && !skipDefaultAction) { const char * chptr = doUntar(spec, 0, quietly); if (chptr == NULL) goto exit; spec->prep = rpmiobAppend(spec->prep, chptr, 1); } spec->prep = rpmiobAppend(spec->prep, rpmiobStr(after), 0); /* XXX FIXME: owner & group fixes were conditioned on !geteuid() */ /* Fix the owner, group, and permissions of the setup build tree */ { /*@observer@*/ static const char *fixmacs[] = { "%{_fixowner}", "%{_fixgroup}", "%{_fixperms}", NULL }; const char ** fm; for (fm = fixmacs; *fm; fm++) { const char *fix; fix = rpmExpand(*fm, " .", NULL); if (fix && *fix != '%') spec->prep = rpmiobAppend(spec->prep, fix, 1); fix = _free(fix); } } ec = RPMRC_OK; exit: before = rpmiobFree(before); after = rpmiobFree(after); return ec; }
/*@-compmempass@*/ /* FIX: item->option.longName kept, not dependent. */ static void configLine(poptContext con, char * line) /*@modifies con @*/ { /*@-type@*/ int nameLength = strlen(con->appName); /*@=type@*/ const char * entryType; const char * opt; poptItem item = alloca(sizeof(*item)); int i, j; /*@-boundswrite@*/ memset(item, 0, sizeof(*item)); /*@-type@*/ if (strncmp(line, con->appName, nameLength)) return; /*@=type@*/ line += nameLength; if (*line == '\0' || !isspace(*line)) return; while (*line != '\0' && isspace(*line)) line++; entryType = line; while (*line == '\0' || !isspace(*line)) line++; *line++ = '\0'; while (*line != '\0' && isspace(*line)) line++; if (*line == '\0') return; opt = line; while (*line == '\0' || !isspace(*line)) line++; *line++ = '\0'; while (*line != '\0' && isspace(*line)) line++; if (*line == '\0') return; /*@-temptrans@*/ /* FIX: line alias is saved */ if (opt[0] == '-' && opt[1] == '-') item->option.longName = opt + 2; else if (opt[0] == '-' && opt[2] == '\0') item->option.shortName = opt[1]; /*@=temptrans@*/ if (poptParseArgvString(line, &item->argc, &item->argv)) return; /*@-modobserver@*/ item->option.argInfo = POPT_ARGFLAG_DOC_HIDDEN; for (i = 0, j = 0; i < item->argc; i++, j++) { const char * f; if (!strncmp(item->argv[i], "--POPTdesc=", sizeof("--POPTdesc=")-1)) { f = item->argv[i] + sizeof("--POPTdesc="); if (f[0] == '$' && f[1] == '"') f++; item->option.descrip = f; item->option.argInfo &= ~POPT_ARGFLAG_DOC_HIDDEN; j--; } else if (!strncmp(item->argv[i], "--POPTargs=", sizeof("--POPTargs=")-1)) { f = item->argv[i] + sizeof("--POPTargs="); if (f[0] == '$' && f[1] == '"') f++; item->option.argDescrip = f; item->option.argInfo &= ~POPT_ARGFLAG_DOC_HIDDEN; item->option.argInfo |= POPT_ARG_STRING; j--; } else if (j != i) item->argv[j] = item->argv[i]; } if (j != i) { item->argv[j] = NULL; item->argc = j; } /*@=modobserver@*/ /*@=boundswrite@*/ /*@-nullstate@*/ /* FIX: item->argv[] may be NULL */ if (!strcmp(entryType, "alias")) (void) poptAddItem(con, item, 0); else if (!strcmp(entryType, "exec")) (void) poptAddItem(con, item, 1); /*@=nullstate@*/ }
static int runGPG(sigTarget sigt, const char *sigfile) { int pid = 0, status; FD_t fnamedPipe = NULL; char *namedPipeName = NULL; unsigned char buf[BUFSIZ]; ssize_t count; ssize_t wantCount; rpm_loff_t size; int rc = 1; /* assume failure */ namedPipeName = mkTempFifo(); rpmPushMacro(NULL, "__plaintext_filename", NULL, namedPipeName, -1); rpmPushMacro(NULL, "__signature_filename", NULL, sigfile, -1); if (!(pid = fork())) { char *const *av; char *cmd = NULL; const char *gpg_path = rpmExpand("%{?_gpg_path}", NULL); if (gpg_path && *gpg_path != '\0') (void) setenv("GNUPGHOME", gpg_path, 1); unsetenv("MALLOC_CHECK_"); cmd = rpmExpand("%{?__gpg_sign_cmd}", NULL); rc = poptParseArgvString(cmd, NULL, (const char ***)&av); if (!rc) rc = execve(av[0], av+1, environ); rpmlog(RPMLOG_ERR, _("Could not exec %s: %s\n"), "gpg", strerror(errno)); _exit(EXIT_FAILURE); } rpmPopMacro(NULL, "__plaintext_filename"); rpmPopMacro(NULL, "__signature_filename"); fnamedPipe = Fopen(namedPipeName, "w"); if (!fnamedPipe) { rpmlog(RPMLOG_ERR, _("Fopen failed\n")); goto exit; } if (Fseek(sigt->fd, sigt->start, SEEK_SET) < 0) { rpmlog(RPMLOG_ERR, _("Could not seek in file %s: %s\n"), sigt->fileName, Fstrerror(sigt->fd)); goto exit; } size = sigt->size; wantCount = size < sizeof(buf) ? size : sizeof(buf); while ((count = Fread(buf, sizeof(buf[0]), wantCount, sigt->fd)) > 0) { Fwrite(buf, sizeof(buf[0]), count, fnamedPipe); if (Ferror(fnamedPipe)) { rpmlog(RPMLOG_ERR, _("Could not write to pipe\n")); goto exit; } size -= count; wantCount = size < sizeof(buf) ? size : sizeof(buf); } if (count < 0) { rpmlog(RPMLOG_ERR, _("Could not read from file %s: %s\n"), sigt->fileName, Fstrerror(sigt->fd)); goto exit; } Fclose(fnamedPipe); fnamedPipe = NULL; (void) waitpid(pid, &status, 0); pid = 0; if (!WIFEXITED(status) || WEXITSTATUS(status)) { rpmlog(RPMLOG_ERR, _("gpg exec failed (%d)\n"), WEXITSTATUS(status)); } else { rc = 0; } exit: if (fnamedPipe) Fclose(fnamedPipe); if (pid) waitpid(pid, &status, 0); if (namedPipeName) { rpmRmTempFifo(namedPipeName); free(namedPipeName); } return rc; }
static rpmRC processPolicies(rpmSpec spec, Package pkg, int test) { const char *path = NULL; char *name = NULL; char *types = NULL; uint32_t flags = 0; poptContext optCon = NULL; rpmRC rc = RPMRC_FAIL; struct poptOption optionsTable[] = { {"name", 'n', POPT_ARG_STRING, &name, 'n', NULL, NULL}, {"types", 't', POPT_ARG_STRING, &types, 't', NULL, NULL}, {"base", 'b', POPT_ARGFLAG_OR, &flags, RPMPOL_FLAG_BASE, NULL, NULL}, POPT_TABLEEND }; if (!spec || !pkg) { goto exit; } for (ARGV_const_t pol = pkg->policyList; *pol != NULL; pol++) { ModuleRec mod; const char *line = *pol; const char **argv = NULL; int argc = 0; int err; if ((err = poptParseArgvString(line, &argc, &argv))) { rpmlog(RPMLOG_ERR, _("Error parsing %s: %s\n"), line, poptStrerror(err)); goto exit; } if (!rstreq(argv[0], "%semodule")) { rpmlog(RPMLOG_ERR, _("Expecting %%semodule tag: %s\n"), line); goto exit; } optCon = poptGetContext(NULL, argc, argv, optionsTable, 0); while (poptGetNextOpt(optCon) > 0) { } path = poptGetArg(optCon); if (!path) { rpmlog(RPMLOG_ERR, _("Missing module path in line: %s\n"), line); goto exit; } if (poptPeekArg(optCon)) { rpmlog(RPMLOG_ERR, _("Too many arguments in line: %s\n"), line); goto exit; } mod = newModule(path, name, types, flags); if (!mod) { goto exit; } if (writeModuleToHeader(mod, pkg) != RPMRC_OK) { freeModule(mod); goto exit; } freeModule(mod); } rc = RPMRC_OK; exit: return rc; }
void batch_mode(const char *filename) { FILE *fp; char *buf; char *ext_buf; int argc; const char **argv; poptContext optCon; int c; bool is_invalid = false; bool employee = false; bool guest = false; bool arrival = false; bool departure = false; int32_t timestamp = -1; const char *token = NULL; const char *name = NULL; int32_t room = -1; const char *log_file_name = NULL; struct log_entry l; int ret; const char *tmp = NULL; const char *last_log_file = NULL; int fd = -1; int64_t data_size = 0; uint8_t *data_buf = NULL; uint8_t salt[SALT_SIZE]; uint8_t key_buf[KEY_LEN]; uint8_t nonce[NONCE_SIZE]; uint8_t *mac_key = key_buf; uint8_t *enc_key = key_buf + MAC_KEY_LEN; struct gallery g; size_t log_entry_buf_size; struct poptOption optionsTable[] = { { NULL, 'T', POPT_ARG_INT, ×tamp, 0, NULL, NULL}, { NULL, 'K', POPT_ARG_STRING, &token, 'K', NULL, NULL}, { NULL, 'E', POPT_ARG_STRING, &name, 'E', NULL, NULL}, { NULL, 'G', POPT_ARG_STRING, &name, 'G', NULL, NULL}, { NULL, 'A', POPT_ARG_NONE, NULL, 'A', NULL, NULL}, { NULL, 'L', POPT_ARG_NONE, NULL, 'L', NULL, NULL}, { NULL, 'R', POPT_ARG_INT, &room, 0, NULL, NULL}, { NULL, 0, 0, NULL, 0, NULL, NULL} }; buf = calloc(BATCH_BUFSIZ, 1); if (!buf) invalid(true); fp = fopen(filename, "r"); if (!fp) invalid(true); while (fgets(buf, BATCH_BUFSIZ, fp)) { ext_buf = calloc(2 + strlen(buf) + 1, 1); memcpy(ext_buf, "l ", 2); memcpy(ext_buf + 2, buf, strlen(buf)); poptParseArgvString(ext_buf, &argc, &argv); optCon = poptGetContext(NULL, argc, argv, optionsTable, 0); is_invalid = false; employee = guest = arrival = departure = false; timestamp = -1; token = NULL; name = NULL; room = -1; log_file_name = NULL; while ((c = poptGetNextOpt(optCon)) >= 0) { switch(c) { case 'E': if (guest) is_invalid = true; employee = true; break; case 'G': if (employee) is_invalid = true; guest = true; break; case 'A': if (departure) is_invalid = true; arrival = true; break; case 'L': if (arrival) is_invalid = true; departure = true; break; case 'K': break; } } log_file_name = poptGetArg(optCon); if (!log_file_name) is_invalid = true; tmp = poptPeekArg(optCon); if (tmp) { is_invalid = true; } if (log_file_name && !validate_filename(log_file_name)) is_invalid = true; if (!timestamp || !token || !(employee || guest) || !(arrival || departure)) is_invalid = true; if (employee && guest) is_invalid = true; if (is_invalid) { invalid(false); free(ext_buf); continue; } l.timestamp = (uint32_t) timestamp; l.room = room; l.action = arrival ? ARRIVAL : DEPARTURE; l.type = guest ? GUEST : EMPLOYEE; l.name = strdup(name); integrity_violation = false; if (!last_log_file || (strcmp(last_log_file, log_file_name) != 0)) { if (last_log_file && (fd > -1)) { ret = enc_mac_write(fd, enc_key, mac_key, salt, data_buf, data_size); if (ret != CAPSTONE_EXIT_SUCCESS) { invalid(false); continue; } close(fd); fd = -1; } fd = read_or_create_log(log_file_name, token, salt, nonce, key_buf, &data_buf, &data_size); if (fd == -1) { invalid(false); continue; } init_gallery_state(&g); ret = read_log_buf(data_buf, data_size, &g); last_log_file = strdup(log_file_name); } if (!update_gallery_state(&g, &l)) { invalid(false); continue; } log_entry_buf_size = append_log_entry_to_buffer(&data_buf, data_size, &l); if (log_entry_buf_size == 0) { invalid(false); continue; } data_size += log_entry_buf_size; free((void *)l.name); l.name = NULL; free(ext_buf); } ret = enc_mac_write(fd, enc_key, mac_key, salt, data_buf, data_size); if (ret != CAPSTONE_EXIT_SUCCESS) { invalid(false); } close(fd); fclose(fp); free(buf); buf = NULL; }
int parseFiles(rpmSpec spec) { int nextPart, res = PART_ERROR; Package pkg; int rc, argc; int arg; const char ** argv = NULL; const char *name = NULL; int flag = PART_SUBNAME; poptContext optCon = NULL; struct poptOption optionsTable[] = { { NULL, 'n', POPT_ARG_STRING, &name, 'n', NULL, NULL}, { NULL, 'f', POPT_ARG_STRING, NULL, 'f', NULL, NULL}, { 0, 0, 0, 0, 0, NULL, NULL} }; /* XXX unmask %license while parsing %files */ rpmPushMacro(spec->macros, "license", NULL, "%%license", RMIL_SPEC); if ((rc = poptParseArgvString(spec->line, &argc, &argv))) { rpmlog(RPMLOG_ERR, _("line %d: Error parsing %%files: %s\n"), spec->lineNum, poptStrerror(rc)); goto exit; } optCon = poptGetContext(NULL, argc, argv, optionsTable, 0); while ((arg = poptGetNextOpt(optCon)) > 0) { if (arg == 'n') { flag = PART_NAME; } } if (arg < -1) { rpmlog(RPMLOG_ERR, _("line %d: Bad option %s: %s\n"), spec->lineNum, poptBadOption(optCon, POPT_BADOPTION_NOALIAS), spec->line); goto exit; } if (poptPeekArg(optCon)) { if (name == NULL) name = poptGetArg(optCon); if (poptPeekArg(optCon)) { rpmlog(RPMLOG_ERR, _("line %d: Too many names: %s\n"), spec->lineNum, spec->line); goto exit; } } if (lookupPackage(spec, name, flag, &pkg)) goto exit; /* * This should be an error, but its surprisingly commonly abused for the * effect of multiple -f arguments in versions that dont support it. * Warn but preserve behavior, except for leaking memory. */ if (pkg->fileList != NULL) { rpmlog(RPMLOG_WARNING, _("line %d: multiple %%files for package '%s'\n"), spec->lineNum, rpmstrPoolStr(pkg->pool, pkg->name)); pkg->fileList = argvFree(pkg->fileList); } for (arg=1; arg<argc; arg++) { if (rstreq(argv[arg], "-f") && argv[arg+1]) { char *file = rpmGetPath(argv[arg+1], NULL); argvAdd(&(pkg->fileFile), file); free(file); } } pkg->fileList = argvNew(); if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) { nextPart = PART_NONE; } else if (rc < 0) { goto exit; } else { while (! (nextPart = isPart(spec->line))) { argvAdd(&(pkg->fileList), spec->line); if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) { nextPart = PART_NONE; break; } else if (rc < 0) { goto exit; } } } res = nextPart; exit: rpmPopMacro(NULL, "license"); free(argv); poptFreeContext(optCon); return res; }
int parseFiles(rpmSpec spec) { int nextPart, res = PART_ERROR; Package pkg; int rc, argc; int arg; const char ** argv = NULL; const char *name = NULL; const char *file = NULL; int flag = PART_SUBNAME; poptContext optCon = NULL; struct poptOption optionsTable[] = { { NULL, 'n', POPT_ARG_STRING, &name, 'n', NULL, NULL}, { NULL, 'f', POPT_ARG_STRING, &file, 'f', NULL, NULL}, { 0, 0, 0, 0, 0, NULL, NULL} }; if ((rc = poptParseArgvString(spec->line, &argc, &argv))) { rpmlog(RPMLOG_ERR, _("line %d: Error parsing %%files: %s\n"), spec->lineNum, poptStrerror(rc)); goto exit; } optCon = poptGetContext(NULL, argc, argv, optionsTable, 0); while ((arg = poptGetNextOpt(optCon)) > 0) { if (arg == 'n') { flag = PART_NAME; } } if (arg < -1) { rpmlog(RPMLOG_ERR, _("line %d: Bad option %s: %s\n"), spec->lineNum, poptBadOption(optCon, POPT_BADOPTION_NOALIAS), spec->line); goto exit; } if (poptPeekArg(optCon)) { if (name == NULL) name = poptGetArg(optCon); if (poptPeekArg(optCon)) { rpmlog(RPMLOG_ERR, _("line %d: Too many names: %s\n"), spec->lineNum, spec->line); goto exit; } } if (lookupPackage(spec, name, flag, &pkg)) { rpmlog(RPMLOG_ERR, _("line %d: Package does not exist: %s\n"), spec->lineNum, spec->line); goto exit; } if (pkg->fileList != NULL) { rpmlog(RPMLOG_ERR, _("line %d: Second %%files list\n"), spec->lineNum); goto exit; } if (file) { /* XXX not necessary as readline has expanded already, but won't hurt. */ pkg->fileFile = rpmGetPath(file, NULL); } pkg->fileList = newStringBuf(); if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) { nextPart = PART_NONE; } else if (rc < 0) { goto exit; } else { while (! (nextPart = isPart(spec->line))) { appendStringBuf(pkg->fileList, spec->line); if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) { nextPart = PART_NONE; break; } else if (rc < 0) { goto exit; } } } res = nextPart; exit: argv = _free(argv); optCon = poptFreeContext(optCon); return res; }
static void parse_cflags (Package *pkg, const char *str, const char *path) { /* Strip out -I flags, put them in a separate list. */ char *trimmed; char **argv = NULL; int argc = 0; int result; int i; if (pkg->I_cflags || pkg->other_cflags) { verbose_error ("Cflags field occurs twice in '%s'\n", path); exit (1); } trimmed = trim_and_sub (pkg, str, path); if (trimmed && *trimmed) { result = poptParseArgvString (trimmed, &argc, &argv); if (result < 0) { verbose_error ("Couldn't parse Cflags field into an argument vector: %s\n", poptStrerror (result)); exit (1); } } i = 0; while (i < argc) { char *tmp = trim_string (argv[i]); char *arg = strdup_escape_shell(tmp); char *p = arg; g_free(tmp); if (p[0] == '-' && p[1] == 'I') { p += 2; while (*p && isspace ((guchar)*p)) ++p; pkg->I_cflags = g_slist_prepend (pkg->I_cflags, g_strconcat ("-I", p, NULL)); } else { if (*arg != '\0') pkg->other_cflags = g_slist_prepend (pkg->other_cflags, g_strdup (arg)); if (strcmp("-idirafter", arg) == 0) { char *n; tmp = trim_string(argv[++i]); n = strdup_escape_shell(tmp); pkg->other_cflags = g_slist_prepend(pkg->other_cflags, n); g_free(tmp); } } g_free (arg); ++i; } g_free (argv); g_free (trimmed); }
int parseDescription(Spec spec) /*@globals name, lang @*/ /*@modifies name, lang @*/ { rpmParseState nextPart = (rpmParseState) RPMRC_FAIL; /* assume error */ rpmiob iob = NULL; int flag = PART_SUBNAME; Package pkg; int rc, argc; int arg; const char **argv = NULL; poptContext optCon = NULL; spectag t = NULL; { char * se = strchr(spec->line, '#'); if (se) { *se = '\0'; while (--se >= spec->line && strchr(" \t\n\r", *se) != NULL) *se = '\0'; } } if ((rc = poptParseArgvString(spec->line, &argc, &argv))) { rpmlog(RPMLOG_ERR, _("line %d: Error parsing %%description: %s\n"), spec->lineNum, poptStrerror(rc)); goto exit; } name = NULL; lang = RPMBUILD_DEFAULT_LANG; optCon = poptGetContext(NULL, argc, argv, optionsTable, 0); while ((arg = poptGetNextOpt(optCon)) > 0) {;} if (name != NULL) flag = PART_NAME; if (arg < -1) { rpmlog(RPMLOG_ERR, _("line %d: Bad option %s: %s\n"), spec->lineNum, poptBadOption(optCon, POPT_BADOPTION_NOALIAS), spec->line); goto exit; } if (poptPeekArg(optCon)) { if (name == NULL) name = poptGetArg(optCon); if (poptPeekArg(optCon)) { rpmlog(RPMLOG_ERR, _("line %d: Too many names: %s\n"), spec->lineNum, spec->line); goto exit; } } if (lookupPackage(spec, name, flag, &pkg) != RPMRC_OK) { rpmlog(RPMLOG_ERR, _("line %d: Package does not exist: %s\n"), spec->lineNum, spec->line); goto exit; } /* Lose the inheirited %description (if present). */ if (spec->packages->header != pkg->header) { HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he)); int xx; he->tag = RPMTAG_DESCRIPTION; xx = headerGet(pkg->header, he, 0); he->p.ptr = _free(he->p.ptr); if (xx && he->t == RPM_STRING_TYPE) xx = headerDel(pkg->header, he, 0); } t = stashSt(spec, pkg->header, RPMTAG_DESCRIPTION, lang); iob = rpmiobNew(0); if ((rc = readLine(spec, STRIP_TRAILINGSPACE | STRIP_COMMENTS)) > 0) { nextPart = PART_NONE; goto exit; } if (rc < 0) { nextPart = (rpmParseState) RPMRC_FAIL; goto exit; } while ((nextPart = isPart(spec)) == PART_NONE) { iob = rpmiobAppend(iob, spec->line, 1); if (t) t->t_nlines++; if ((rc = readLine(spec, STRIP_TRAILINGSPACE | STRIP_COMMENTS)) > 0) { nextPart = PART_NONE; break; } if (rc) { nextPart = (rpmParseState) RPMRC_FAIL; goto exit; } } iob = rpmiobRTrim(iob); if (!(noLang && strcmp(lang, RPMBUILD_DEFAULT_LANG))) { const char * s = rpmiobStr(iob); (void) headerAddI18NString(pkg->header, RPMTAG_DESCRIPTION, s, lang); } exit: iob = rpmiobFree(iob); argv = _free(argv); optCon = poptFreeContext(optCon); return nextPart; }
void CAESAR_INIT_GRAPH(void) { char *opencaesar_args, *opencaesar_prog,*ltsmin_options; int argc; char **argv; opencaesar_prog = getenv ("OPEN_CAESAR_PROG"); if (opencaesar_prog == NULL) CAESAR_ERROR ("undefined environment variable $OPEN_CAESAR_PROG"); opencaesar_args = getenv ("OPEN_CAESAR_FILE"); if (opencaesar_args == NULL) CAESAR_ERROR ("undefined environment variable $OPEN_CAESAR_FILE"); ltsmin_options = getenv ("LTSMIN_OPTIONS"); if (ltsmin_options == NULL) CAESAR_ERROR ("undefined environment variable $LTSMIN_OPTIONS"); int len=strlen(opencaesar_prog)+strlen(ltsmin_options)+strlen(opencaesar_args); char cmdline[len+6]; sprintf(cmdline,"%s %s %s",opencaesar_prog,ltsmin_options,opencaesar_args); int res=poptParseArgvString(cmdline,&argc,(void*)(&argv)); if (res){ Abort("could not parse %s: %s",opencaesar_args,poptStrerror(res)); } char *files[2]; HREinitBegin(argv[0]); HREaddOptions(options,"Options"); HREinitStart(&argc,&argv,1,1,(char**)files,"<model>"); Warning(info,"loading model from %s",files[0]); model=GBcreateBase(); GBsetChunkMethods(model,new_string_index,NULL, (int2chunk_t)SIgetC, (chunk2int_t)SIputC, (chunkatint_t)SIputCAt, (get_count_t)SIgetCount); GBloadFile(model,files[0],&model); ltstype=GBgetLTStype(model); N = lts_type_get_state_length(ltstype); K = dm_nrows(GBgetDMInfo(model)); Warning(info,"length is %d, there are %d groups",N,K); state_labels=lts_type_get_state_label_count(ltstype); edge_labels=lts_type_get_edge_label_count(ltstype); Warning(info,"There are %d state labels and %d edge labels",state_labels,edge_labels); if (edge_encode){ edge_size=edge_labels+N+state_labels; Warning(info,"encoding state information on edges"); } else { edge_size=edge_labels; Warning(info,"state information is hidden"); } CAESAR_HINT_SIZE_STATE = N*sizeof(int); CAESAR_HINT_HASH_SIZE_STATE = CAESAR_HINT_SIZE_STATE; CAESAR_HINT_SIZE_LABEL = edge_size*sizeof(int); CAESAR_HINT_HASH_SIZE_LABEL = CAESAR_HINT_SIZE_LABEL; Warning(info,"CAESAR_HINT_SIZE_STATE=%lu CAESAR_HINT_SIZE_LABEL=%lu", (unsigned long)CAESAR_HINT_SIZE_STATE,(unsigned long)CAESAR_HINT_SIZE_LABEL); }
/* * @todo Single use by %%doc in files.c prevents static. */ rpmRC doScript(Spec spec, int what, const char *name, rpmiob iob, int test) { const char * rootURL = spec->rootURL; const char * rootDir; const char * scriptName = NULL; const char * buildDirURL = rpmGenPath(rootURL, "%{_builddir}", ""); const char * buildScript; const char * buildCmd = NULL; const char * buildTemplate = NULL; const char * buildPost = NULL; const char * mTemplate = NULL; const char * mCmd = NULL; const char * mPost = NULL; int argc = 0; const char **argv = NULL; FILE * fp = NULL; urlinfo u = NULL; rpmop op = NULL; int ix = -1; FD_t fd; FD_t xfd; int status; rpmRC rc; size_t i; switch (what) { case RPMBUILD_PREP: name = "%prep"; iob = spec->prep; op = memset(alloca(sizeof(*op)), 0, sizeof(*op)); ix = RPMSCRIPT_PREP; mTemplate = "%{__spec_prep_template}"; mPost = "%{__spec_prep_post}"; mCmd = "%{__spec_prep_cmd}"; break; case RPMBUILD_BUILD: name = "%build"; iob = spec->build; op = memset(alloca(sizeof(*op)), 0, sizeof(*op)); ix = RPMSCRIPT_BUILD; mTemplate = "%{__spec_build_template}"; mPost = "%{__spec_build_post}"; mCmd = "%{__spec_build_cmd}"; break; case RPMBUILD_INSTALL: name = "%install"; iob = spec->install; op = memset(alloca(sizeof(*op)), 0, sizeof(*op)); ix = RPMSCRIPT_INSTALL; mTemplate = "%{__spec_install_template}"; mPost = "%{__spec_install_post}"; mCmd = "%{__spec_install_cmd}"; break; case RPMBUILD_CHECK: name = "%check"; iob = spec->check; op = memset(alloca(sizeof(*op)), 0, sizeof(*op)); ix = RPMSCRIPT_CHECK; mTemplate = "%{__spec_check_template}"; mPost = "%{__spec_check_post}"; mCmd = "%{__spec_check_cmd}"; break; case RPMBUILD_CLEAN: name = "%clean"; iob = spec->clean; mTemplate = "%{__spec_clean_template}"; mPost = "%{__spec_clean_post}"; mCmd = "%{__spec_clean_cmd}"; break; case RPMBUILD_RMBUILD: name = "--clean"; mTemplate = "%{__spec_clean_template}"; mPost = "%{__spec_clean_post}"; mCmd = "%{__spec_clean_cmd}"; break; /* support "%track" script/section */ case RPMBUILD_TRACK: name = "%track"; iob = NULL; if (spec->foo) for (i = 0; i < spec->nfoo; i++) { if (spec->foo[i].str == NULL || spec->foo[i].iob == NULL) continue; if (xstrcasecmp(spec->foo[i].str, "track")) continue; iob = spec->foo[i].iob; /*@loopbreak@*/ break; } mTemplate = "%{__spec_track_template}"; mPost = "%{__spec_track_post}"; mCmd = "%{__spec_track_cmd}"; break; case RPMBUILD_STRINGBUF: default: mTemplate = "%{___build_template}"; mPost = "%{___build_post}"; mCmd = "%{___build_cmd}"; break; } assert(name != NULL); if ((what != RPMBUILD_RMBUILD) && iob == NULL) { rc = RPMRC_OK; goto exit; } if (rpmTempFile(rootURL, &scriptName, &fd) || fd == NULL || Ferror(fd)) { rpmlog(RPMLOG_ERR, _("Unable to open temp file.\n")); rc = RPMRC_FAIL; goto exit; } if (fdGetFp(fd) == NULL) xfd = Fdopen(fd, "w.fpio"); else xfd = fd; /*@-type@*/ /* FIX: cast? */ if ((fp = fdGetFp(xfd)) == NULL) { rc = RPMRC_FAIL; goto exit; } /*@=type@*/ (void) urlPath(rootURL, &rootDir); if (*rootDir == '\0') rootDir = "/"; (void) urlPath(scriptName, &buildScript); buildTemplate = rpmExpand(mTemplate, NULL); buildPost = rpmExpand(mPost, NULL); (void) fputs(buildTemplate, fp); /* support "%track" script/section */ if (what != RPMBUILD_PREP && what != RPMBUILD_RMBUILD && spec->buildSubdir && what != RPMBUILD_TRACK) fprintf(fp, "cd '%s'\n", spec->buildSubdir); if (what == RPMBUILD_RMBUILD) { if (spec->buildSubdir) fprintf(fp, "rm -rf '%s'\n", spec->buildSubdir); } else if (iob != NULL) fprintf(fp, "%s", rpmiobStr(iob)); (void) fputs(buildPost, fp); (void) Fclose(xfd); if (test) { rc = RPMRC_OK; goto exit; } if (buildDirURL && buildDirURL[0] != '/' && (urlSplit(buildDirURL, &u) != 0)) { rc = RPMRC_FAIL; goto exit; } switch (urlType(u)) { case URL_IS_HTTPS: case URL_IS_HTTP: case URL_IS_FTP: addMacro(spec->macros, "_remsh", NULL, "%{__remsh}", RMIL_SPEC); addMacro(spec->macros, "_remhost", NULL, u->host, RMIL_SPEC); if (strcmp(rootDir, "/")) addMacro(spec->macros, "_remroot", NULL, rootDir, RMIL_SPEC); break; case URL_IS_UNKNOWN: case URL_IS_DASH: case URL_IS_PATH: case URL_IS_HKP: default: break; } buildCmd = rpmExpand(mCmd, " ", buildScript, NULL); (void) poptParseArgvString(buildCmd, &argc, &argv); if (what != RPMBUILD_TRACK) /* support "%track" script/section */ rpmlog(RPMLOG_NOTICE, _("Executing(%s): %s\n"), name, buildCmd); /* Run the script with a stopwatch. */ if (op != NULL) (void) rpmswEnter(op, 0); status = rpmsqExecve(argv); if (ix >= 0 && ix < RPMSCRIPT_MAX) spec->sstates[ix] = (RPMSCRIPT_STATE_EXEC | RPMSCRIPT_STATE_REAPED) | (status & 0xffff); if (!WIFEXITED(status) || WEXITSTATUS(status)) { rpmlog(RPMLOG_ERR, _("Bad exit status from %s (%s)\n"), scriptName, name); rc = RPMRC_FAIL; } else rc = RPMRC_OK; if (op != NULL) { static unsigned int scale = 1000; (void) rpmswExit(op, 0); if (ix >= 0 && ix < RPMSCRIPT_MAX) spec->smetrics[ix] += op->usecs / scale; } exit: if (scriptName) { #if defined(RPM_VENDOR_OPENPKG) /* always-remove-tempfiles */ /* Unconditionally remove temporary files ("rpm-tmp.XXXXX") which were generated for the executed scripts. In OpenPKG we run the scripts in debug mode ("set -x") anyway, so we never need to see the whole generated script -- not even if it breaks. Instead we would just have temporary files staying around forever. */ #else if (rc == RPMRC_OK) #endif (void) Unlink(scriptName); scriptName = _free(scriptName); } switch (urlType(u)) { case URL_IS_HTTPS: case URL_IS_HTTP: case URL_IS_FTP: delMacro(spec->macros, "_remsh"); delMacro(spec->macros, "_remhost"); if (strcmp(rootDir, "/")) delMacro(spec->macros, "_remroot"); break; case URL_IS_UNKNOWN: case URL_IS_DASH: case URL_IS_PATH: case URL_IS_HKP: default: break; } argv = _free(argv); buildCmd = _free(buildCmd); buildTemplate = _free(buildTemplate); buildPost = _free(buildPost); buildDirURL = _free(buildDirURL); return rc; }
/*@-compmempass@*/ /* FIX: item->option.longName kept, not dependent. */ static int poptConfigLine(poptContext con, char * line) /*@globals fileSystem, internalState @*/ /*@modifies con, fileSystem, internalState @*/ { char *b = NULL; size_t nb = 0; char * se = line; const char * appName; const char * entryType; const char * opt; struct poptItem_s item_buf; poptItem item = &item_buf; int i, j; int rc = POPT_ERROR_BADCONFIG; if (con->appName == NULL) goto exit; memset(item, 0, sizeof(*item)); appName = se; while (*se != '\0' && !_isspaceptr(se)) se++; if (*se == '\0') goto exit; else *se++ = '\0'; if (configAppMatch(con, appName)) goto exit; while (*se != '\0' && _isspaceptr(se)) se++; entryType = se; while (*se != '\0' && !_isspaceptr(se)) se++; if (*se != '\0') *se++ = '\0'; while (*se != '\0' && _isspaceptr(se)) se++; if (*se == '\0') goto exit; opt = se; while (*se != '\0' && !_isspaceptr(se)) se++; if (opt[0] == '-' && *se == '\0') goto exit; if (*se != '\0') *se++ = '\0'; while (*se != '\0' && _isspaceptr(se)) se++; if (opt[0] == '-' && *se == '\0') goto exit; /*@-temptrans@*/ /* FIX: line alias is saved */ if (opt[0] == '-' && opt[1] == '-') item->option.longName = opt + 2; else if (opt[0] == '-' && opt[2] == '\0') item->option.shortName = opt[1]; else { const char * fn = opt; /* XXX handle globs and directories in fn? */ if ((rc = poptReadFile(fn, &b, &nb, POPT_READFILE_TRIMNEWLINES)) != 0) goto exit; if (b == NULL || nb == 0) goto exit; /* Append remaining text to the interpolated file option text. */ if (*se != '\0') { size_t nse = strlen(se) + 1; if ((b = realloc(b, (nb + nse))) == NULL) /* XXX can't happen */ goto exit; (void) stpcpy( stpcpy(&b[nb-1], " "), se); nb += nse; } se = b; /* Use the basename of the path as the long option name. */ { const char * longName = strrchr(fn, '/'); if (longName != NULL) longName++; else longName = fn; if (longName == NULL) /* XXX can't happen. */ goto exit; /* Single character basenames are treated as short options. */ if (longName[1] != '\0') item->option.longName = longName; else item->option.shortName = longName[0]; } } /*@=temptrans@*/ if (poptParseArgvString(se, &item->argc, &item->argv)) goto exit; /*@-modobserver@*/ item->option.argInfo = POPT_ARGFLAG_DOC_HIDDEN; for (i = 0, j = 0; i < item->argc; i++, j++) { const char * f; if (!strncmp(item->argv[i], "--POPTdesc=", sizeof("--POPTdesc=")-1)) { f = item->argv[i] + sizeof("--POPTdesc="); if (f[0] == '$' && f[1] == '"') f++; item->option.descrip = f; item->option.argInfo &= ~POPT_ARGFLAG_DOC_HIDDEN; j--; } else if (!strncmp(item->argv[i], "--POPTargs=", sizeof("--POPTargs=")-1)) { f = item->argv[i] + sizeof("--POPTargs="); if (f[0] == '$' && f[1] == '"') f++; item->option.argDescrip = f; item->option.argInfo &= ~POPT_ARGFLAG_DOC_HIDDEN; item->option.argInfo |= POPT_ARG_STRING; j--; } else if (j != i) item->argv[j] = item->argv[i]; } if (j != i) { item->argv[j] = NULL; item->argc = j; } /*@=modobserver@*/ /*@-nullstate@*/ /* FIX: item->argv[] may be NULL */ if (!strcmp(entryType, "alias")) rc = poptAddItem(con, item, 0); else if (!strcmp(entryType, "exec")) rc = poptAddItem(con, item, 1); /*@=nullstate@*/ exit: rc = 0; /* XXX for now, always return success */ if (b) free(b); return rc; }
void nbLaunchVisualizer(NBodyState* st, const char* visArgs) { pid_t pid; const char* path = NULL; char* newPath = NULL; int argc = 0; char* buf = NULL; char* p = NULL; char** argv = NULL; size_t argvSize = 0; size_t visArgsLen = 0; char idArg[128]; if (!st->scene) /* If there's no scene to share, there's no point */ return; if (st->usesExact) { mw_printf("Visualizer broken with Exact\n"); return; } pid = fork(); if (pid != 0) /* Parent */ return; /* Child */ /* Put places convenient for testing. Not essential, failure of * any of these is OK */ path = getenv("PATH"); if (!path) { mwPerror("Error getting PATH"); } else { if (asprintf(&newPath, ".:../bin/:%s", path) < 0) { mwPerror("Appending to path"); } else { if (setenv("PATH", newPath, TRUE) < 0) { mwPerror("Error setting PATH"); } free(newPath); } } if (snprintf(idArg, sizeof(idArg), "--instance-id=%d ", st->scene->instanceId) == sizeof(idArg)) mw_panic("Buffer too small for --instance-id visualizer argument\n"); /* Stick the program name at the head of the arguments passed in */ visArgsLen = visArgs ? strlen(visArgs) : 0; argvSize = visArgsLen + sizeof(idArg) + sizeof(nbodyGraphicsName) + 2; /* arguments + program name + space + null */ buf = mwCalloc(argvSize, sizeof(char)); p = stpcpy(buf, nbodyGraphicsName); p = stpcpy(p, " "); p = stpcpy(p, idArg); if (visArgs) { stpcpy(p, visArgs); } if (poptParseArgvString(buf, &argc, (const char***) &argv)) { mw_printf("Error parsing arguments for visualizer '%s'\n", visArgs); free(buf); return; } if (execvp(argv[0], argv) < 0) { mwPerror("Failed to launch visualizer '%s'", argv[0]); } free(buf); free(argv); mw_finish(EXIT_SUCCESS); /* Unnecessary */ }
int net_rpc_shell(struct net_context *c, int argc, const char **argv) { NTSTATUS status; struct rpc_sh_ctx *ctx; if (argc != 0 || c->display_usage) { d_printf("%s\nnet rpc shell\n", _("Usage:")); return -1; } if (libnetapi_net_init(&c->netapi_ctx) != 0) { return -1; } libnetapi_set_username(c->netapi_ctx, c->opt_user_name); libnetapi_set_password(c->netapi_ctx, c->opt_password); if (c->opt_kerberos) { libnetapi_set_use_kerberos(c->netapi_ctx); } ctx = talloc(NULL, struct rpc_sh_ctx); if (ctx == NULL) { d_fprintf(stderr, _("talloc failed\n")); return -1; } status = net_make_ipc_connection(c, 0, &(ctx->cli)); if (!NT_STATUS_IS_OK(status)) { d_fprintf(stderr, _("Could not open connection: %s\n"), nt_errstr(status)); return -1; } ctx->cmds = sh_cmds; ctx->whoami = "net rpc"; ctx->parent = NULL; status = net_get_remote_domain_sid(ctx->cli, ctx, &ctx->domain_sid, &ctx->domain_name); if (!NT_STATUS_IS_OK(status)) { return -1; } d_printf(_("Talking to domain %s (%s)\n"), ctx->domain_name, sid_string_tos(ctx->domain_sid)); this_ctx = ctx; while(1) { char *prompt = NULL; char *line = NULL; int ret; if (asprintf(&prompt, "%s> ", this_ctx->whoami) < 0) { break; } line = smb_readline(prompt, NULL, completion_fn); SAFE_FREE(prompt); if (line == NULL) { break; } ret = poptParseArgvString(line, &argc, &argv); if (ret == POPT_ERROR_NOARG) { SAFE_FREE(line); continue; } if (ret != 0) { d_fprintf(stderr, _("cmdline invalid: %s\n"), poptStrerror(ret)); SAFE_FREE(line); return false; } if ((line[0] != '\n') && (!net_sh_process(c, this_ctx, argc, argv))) { SAFE_FREE(line); break; } SAFE_FREE(line); } cli_shutdown(ctx->cli); TALLOC_FREE(ctx); return 0; }
int poptReadDefaultConfig(poptContext con, int useEnv) { char * envName, * envValue; char * fn, * home, * chptr; int rc, skip; struct poptAlias alias; if (!con->appName) return 0; rc = poptReadConfigFile(con, "/etc/popt"); if (rc) return rc; if (getuid() != geteuid()) return 0; if ((home = getenv("HOME"))) { fn = (char*)alloca(strlen(home) + 20); sprintf(fn, "%s/.popt", home); rc = poptReadConfigFile(con, fn); if (rc) return rc; } envName = (char*)alloca(strlen(con->appName) + 20); strcpy(envName, con->appName); chptr = envName; while (*chptr) { *chptr = toupper(*chptr); chptr++; } strcat(envName, "_POPT_ALIASES"); if (useEnv && (envValue = getenv(envName))) { envValue = strcpy((char*)alloca(strlen(envValue) + 1), envValue); while (envValue && *envValue) { chptr = strchr(envValue, '='); if (!chptr) { envValue = strchr(envValue, '\n'); if (envValue) envValue++; continue; } *chptr = '\0'; skip = 0; if (!strncmp(envValue, "--", 2)) { alias.longName = envValue + 2; alias.shortName = '\0'; } else if (*envValue == '-' && strlen(envValue) == 2) { alias.longName = NULL; alias.shortName = envValue[1]; } else { skip = 1; } envValue = chptr + 1; chptr = strchr(envValue, '\n'); if (chptr) *chptr = '\0'; if (!skip) { poptParseArgvString(envValue, &alias.argc, &alias.argv); poptAddAlias(con, alias, 0); } if (chptr) envValue = chptr + 1; else envValue = NULL; } } return 0; }