int main(int argc, const char **argv) { NET_API_STATUS status; struct libnetapi_ctx *ctx = NULL; const char *hostname = NULL; const char *domain = NULL; uint8_t *buffer = NULL; poptContext pc; int opt; struct poptOption long_options[] = { POPT_AUTOHELP POPT_COMMON_LIBNETAPI_EXAMPLES POPT_TABLEEND }; status = libnetapi_init(&ctx); if (status != 0) { return status; } pc = poptGetContext("getdc", argc, argv, long_options, 0); poptSetOtherOptionHelp(pc, "hostname domainname"); while((opt = poptGetNextOpt(pc)) != -1) { } if (!poptPeekArg(pc)) { poptPrintHelp(pc, stderr, 0); goto out; } hostname = poptGetArg(pc); if (!poptPeekArg(pc)) { poptPrintHelp(pc, stderr, 0); goto out; } domain = poptGetArg(pc); /* NetGetDCName */ status = NetGetDCName(hostname, domain, &buffer); if (status != 0) { printf("GetDcName failed with: %s\n", libnetapi_errstr(status)); } else { printf("%s\n", (char *)buffer); } out: NetApiBufferFree(buffer); libnetapi_free(ctx); poptFreeContext(pc); return status; }
int main(int argc, const char **argv) { NET_API_STATUS status; struct libnetapi_ctx *ctx = NULL; const char *hostname = NULL; const char *sharename = NULL; poptContext pc; int opt; struct poptOption long_options[] = { POPT_AUTOHELP POPT_COMMON_LIBNETAPI_EXAMPLES POPT_TABLEEND }; status = libnetapi_init(&ctx); if (status != 0) { return status; } pc = poptGetContext("share_del", argc, argv, long_options, 0); poptSetOtherOptionHelp(pc, "hostname sharename"); while((opt = poptGetNextOpt(pc)) != -1) { } if (!poptPeekArg(pc)) { poptPrintHelp(pc, stderr, 0); goto out; } hostname = poptGetArg(pc); if (!poptPeekArg(pc)) { poptPrintHelp(pc, stderr, 0); goto out; } sharename = poptGetArg(pc); /* NetShareDel */ status = NetShareDel(hostname, sharename, 0); if (status != 0) { printf("NetShareDel failed with: %s\n", libnetapi_get_error_string(ctx, status)); goto out; } out: libnetapi_free(ctx); poptFreeContext(pc); return status; }
/** Process command line arguements and decide how to proceed. * Includes explanatory text for inline help and self-documentation. */ int main( int argc, char *argv[] ) { int descend_flag = 0, hadoop_flag = 0, stats_flag = 0, verbose_flag = 0, json_flag = 0; int count = 0, ret_val = 0; g_dir_arg = "."; /// set the default directory argument to "here" poptContext pc; struct poptOption po[] = { {"descend", 'd', POPT_ARG_NONE, &descend_flag, 0, UNIMPL"Parallelise and descend into subdirectories.", NULL}, {"stats", 's', POPT_ARG_NONE, &stats_flag, 0, "Print detailed statistics.", NULL}, {"verbose", 'v', POPT_ARG_NONE, &verbose_flag, 0, UNIMPL"Expand statistics output for each subdirectory.", NULL}, {"json", 'j', POPT_ARG_NONE, &json_flag, 0, UNIMPL"Write output in JSON format.", NULL}, POPT_AUTOHELP POPT_TABLEEND }; pc = poptGetContext(NULL, argc, (const char **)argv, po, 0); poptSetOtherOptionHelp(pc, "[directory]"); while ( (count = poptGetNextOpt(pc) ) >= 0 ) { printf("poptGetNextOpt return val %d\n", count); } for ( count = 0 ; poptPeekArg(pc) != NULL ; ++count ) { asprintf(&g_dir_arg, (char*)poptGetArg(pc)); if ( count > 0 ) { poptPrintUsage(pc, stderr, 0); goto EXITNOW; } } if ( descend_flag + hadoop_flag + stats_flag + verbose_flag + json_flag > 5 ) { poptPrintUsage(pc, stderr, 0); goto EXITNOW; } else { if ( descend_flag != POPT_ARG_NONE ) printf("%s: %s %s\n", PROGNAME, UNIMPL, "descend"); else if ( stats_flag != POPT_ARG_NONE ) ret_val = getdirent(g_dir_arg); else if ( verbose_flag != POPT_ARG_NONE ) printf("%s: %s %s\n", PROGNAME, UNIMPL, "verbose"); else if ( json_flag != POPT_ARG_NONE ) printf("%s: %s %s\n", PROGNAME, UNIMPL, "json"); else ret_val = quickcount(g_dir_arg); } if ( ret_val == 0 ) { exit(EXIT_SUCCESS); } else { goto EXITNOW; } EXITNOW: exit(EXIT_FAILURE); }
void process_all_options(int argc, const char **argv, struct poptOption *options) { poptContext opts = process_options(argc, argv, options, "[OPTIONS]..."); const char *opt = poptPeekArg(opts); if (opt) { fprintf(stderr, "unexpected operand: %s\n", opt); poptPrintUsage(opts, stderr, 0); exit(1); } poptFreeContext(opts); }
int main(int argc, char *argv[]) { int ec = EXIT_FAILURE; poptContext optCon = NULL; const char *arg; xsetprogname(argv[0]); /* Portability call -- see system.h */ optCon = rpmcliInit(argc, argv, optionsTable); if (argc <= 1) { printUsage(optCon, stderr, 0); goto exit; } if (poptPeekArg(optCon) == NULL) { argerror(_("no arguments given")); } if (fileSigningKey && !signfiles) { argerror(_("--fskpath may only be specified when signing files")); } switch (mode) { case MODE_ADDSIGN: case MODE_RESIGN: ec = doSign(optCon); break; case MODE_DELSIGN: ec = 0; while ((arg = poptGetArg(optCon)) != NULL) { ec += rpmPkgDelSign(arg); } break; default: argerror(_("only one major mode may be specified")); break; } exit: rpmcliFini(optCon); return ec; }
int main(int argc, char *argv[]) { int provides = 0; int requires = 0; poptContext optCon; struct poptOption opts[] = { { "provides", 'P', POPT_ARG_VAL, &provides, -1, NULL, NULL }, { "requires", 'R', POPT_ARG_VAL, &requires, -1, NULL, NULL }, { "filter-private", 0, POPT_ARG_VAL, &filter_private, -1, NULL, NULL }, { "soname-only", 0, POPT_ARG_VAL, &soname_only, -1, NULL, NULL }, { "no-fake-soname", 0, POPT_ARG_VAL, &fake_soname, 0, NULL, NULL }, { "no-filter-soname", 0, POPT_ARG_VAL, &filter_soname, 0, NULL, NULL }, { "require-interp", 0, POPT_ARG_VAL, &require_interp, -1, NULL, NULL }, POPT_AUTOHELP POPT_TABLEEND }; optCon = poptGetContext(argv[0], argc, (const char **) argv, opts, 0); if (argc < 2 || poptGetNextOpt(optCon) == 0) { poptPrintUsage(optCon, stderr, 0); exit(EXIT_FAILURE); } /* Normally our data comes from stdin, but permit args too */ if (poptPeekArg(optCon)) { const char *fn; while ((fn = poptGetArg(optCon)) != NULL) { (void) processFile(fn, requires); } } else { char fn[BUFSIZ]; while (fgets(fn, sizeof(fn), stdin) != NULL) { fn[strlen(fn)-1] = '\0'; (void) processFile(fn, requires); } } poptFreeContext(optCon); return 0; }
int main(int argc, const char *argv[]) { int opt; int retval = 0; enum acl_mode mode = SMB_ACL_SET; static char *the_acl = NULL; fstring sharename; bool force_acl = False; int snum; poptContext pc; bool initialize_sid = False; struct poptOption long_options[] = { POPT_AUTOHELP { "remove", 'r', POPT_ARG_STRING, &the_acl, 'r', "Delete an ACE", "ACL" }, { "modify", 'm', POPT_ARG_STRING, &the_acl, 'm', "Modify an acl", "ACL" }, { "add", 'a', POPT_ARG_STRING, &the_acl, 'a', "Add an ACE", "ACL" }, { "replace", 'R', POPT_ARG_STRING, &the_acl, 'R', "Set share mission ACL", "ACLS" }, { "view", 'v', POPT_ARG_NONE, NULL, 'v', "View current share permissions" }, { "machine-sid", 'M', POPT_ARG_NONE, NULL, 'M', "Initialize the machine SID" }, { "force", 'F', POPT_ARG_NONE, NULL, 'F', "Force storing the ACL", "ACLS" }, POPT_COMMON_SAMBA { NULL } }; if ( !(ctx = talloc_stackframe()) ) { fprintf( stderr, "Failed to initialize talloc context!\n"); return -1; } /* set default debug level to 1 regardless of what smb.conf sets */ setup_logging( "sharesec", True ); DEBUGLEVEL_CLASS[DBGC_ALL] = 1; dbf = x_stderr; x_setbuf( x_stderr, NULL ); pc = poptGetContext("sharesec", argc, argv, long_options, 0); poptSetOtherOptionHelp(pc, "sharename\n"); while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case 'r': the_acl = smb_xstrdup(poptGetOptArg(pc)); mode = SMB_ACL_DELETE; break; case 'm': the_acl = smb_xstrdup(poptGetOptArg(pc)); mode = SMB_ACL_MODIFY; break; case 'a': the_acl = smb_xstrdup(poptGetOptArg(pc)); mode = SMB_ACL_ADD; break; case 'R': the_acl = smb_xstrdup(poptGetOptArg(pc)); mode = SMB_ACL_SET; break; case 'v': mode = SMB_ACL_VIEW; break; case 'F': force_acl = True; break; case 'M': initialize_sid = True; break; } } setlinebuf(stdout); load_case_tables(); lp_load( get_dyn_CONFIGFILE(), False, False, False, True ); /* check for initializing secrets.tdb first */ if ( initialize_sid ) { DOM_SID *sid = get_global_sam_sid(); if ( !sid ) { fprintf( stderr, "Failed to retrieve Machine SID!\n"); return 3; } printf ("%s\n", sid_string_tos( sid ) ); return 0; } if ( mode == SMB_ACL_VIEW && force_acl ) { fprintf( stderr, "Invalid combination of -F and -v\n"); return -1; } /* get the sharename */ if(!poptPeekArg(pc)) { poptPrintUsage(pc, stderr, 0); return -1; } fstrcpy(sharename, poptGetArg(pc)); snum = lp_servicenumber( sharename ); if ( snum == -1 && !force_acl ) { fprintf( stderr, "Invalid sharename: %s\n", sharename); return -1; } retval = change_share_sec(ctx, sharename, the_acl, mode); talloc_destroy(ctx); return retval; }
int main(int argc, const char **argv) { NET_API_STATUS status; struct libnetapi_ctx *ctx = NULL; const char *hostname = NULL; const char *sharename = NULL; const char *comment = "NetApi generated Share comment"; uint32_t level = 1004; uint8_t *buffer = NULL; uint32_t parm_err = 0; struct SHARE_INFO_1004 i1004; poptContext pc; int opt; struct poptOption long_options[] = { POPT_AUTOHELP POPT_COMMON_LIBNETAPI_EXAMPLES POPT_TABLEEND }; status = libnetapi_init(&ctx); if (status != 0) { return status; } pc = poptGetContext("share_setinfo", argc, argv, long_options, 0); poptSetOtherOptionHelp(pc, "hostname sharename comment"); while((opt = poptGetNextOpt(pc)) != -1) { } if (!poptPeekArg(pc)) { poptPrintHelp(pc, stderr, 0); goto out; } hostname = poptGetArg(pc); if (!poptPeekArg(pc)) { poptPrintHelp(pc, stderr, 0); goto out; } sharename = poptGetArg(pc); if (poptPeekArg(pc)) { comment = poptGetArg(pc); } /* NetShareSetInfo */ switch (level) { case 1004: i1004.shi1004_remark = comment; buffer = (uint8_t *)&i1004; break; default: break; } status = NetShareSetInfo(hostname, sharename, level, buffer, &parm_err); if (status != 0) { printf("NetShareSetInfo failed with: %s\n", libnetapi_get_error_string(ctx, status)); goto out; } out: libnetapi_free(ctx); poptFreeContext(pc); return status; }
int main( int argc, char *argv[] ) { TALLOC_CTX *frame = talloc_stackframe(); int opt; REGF_FILE *infile, *outfile; REGF_NK_REC *nk; char *orig_filename, *new_filename; struct poptOption long_options[] = { POPT_AUTOHELP { "change-sid", 'c', POPT_ARG_STRING, NULL, 'c', "Provides SID to change" }, { "new-sid", 'n', POPT_ARG_STRING, NULL, 'n', "Provides SID to change to" }, { "verbose", 'v', POPT_ARG_NONE, &opt_verbose, 'v', "Verbose output" }, POPT_COMMON_SAMBA POPT_COMMON_VERSION POPT_TABLEEND }; poptContext pc; load_case_tables(); /* setup logging options */ setup_logging( "profiles", DEBUG_STDERR); pc = poptGetContext("profiles", argc, (const char **)argv, long_options, POPT_CONTEXT_KEEP_FIRST); poptSetOtherOptionHelp(pc, "<profilefile>"); /* Now, process the arguments */ while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case 'c': change = 1; if (!string_to_sid(&old_sid, poptGetOptArg(pc))) { fprintf(stderr, "Argument to -c should be a SID in form of S-1-5-...\n"); poptPrintUsage(pc, stderr, 0); exit(254); } break; case 'n': new_val = 1; if (!string_to_sid(&new_sid, poptGetOptArg(pc))) { fprintf(stderr, "Argument to -n should be a SID in form of S-1-5-...\n"); poptPrintUsage(pc, stderr, 0); exit(253); } break; } } poptGetArg(pc); if (!poptPeekArg(pc)) { poptPrintUsage(pc, stderr, 0); exit(1); } if ((!change && new_val) || (change && !new_val)) { fprintf(stderr, "You must specify both -c and -n if one or the other is set!\n"); poptPrintUsage(pc, stderr, 0); exit(252); } orig_filename = talloc_strdup(frame, poptPeekArg(pc)); if (!orig_filename) { exit(ENOMEM); } new_filename = talloc_asprintf(frame, "%s.new", orig_filename); if (!new_filename) { exit(ENOMEM); } if (!(infile = regfio_open( orig_filename, O_RDONLY, 0))) { fprintf( stderr, "Failed to open %s!\n", orig_filename ); fprintf( stderr, "Error was (%s)\n", strerror(errno) ); exit (1); } if ( !(outfile = regfio_open( new_filename, (O_RDWR|O_CREAT|O_TRUNC), (S_IRUSR|S_IWUSR) )) ) { fprintf( stderr, "Failed to open new file %s!\n", new_filename ); fprintf( stderr, "Error was (%s)\n", strerror(errno) ); exit (1); } /* actually do the update now */ if ((nk = regfio_rootkey( infile )) == NULL) { fprintf(stderr, "Could not get rootkey\n"); exit(3); } if (!copy_registry_tree( infile, nk, NULL, outfile, "")) { fprintf(stderr, "Failed to write updated registry file!\n"); exit(2); } /* cleanup */ regfio_close(infile); regfio_close(outfile); poptFreeContext(pc); TALLOC_FREE(frame); return 0; }
int main(int argc, const char **argv) { NET_API_STATUS status; struct libnetapi_ctx *ctx = NULL; const char *hostname = NULL; const char *username = NULL; uint32_t level = 0; uint8_t *buffer = NULL; uint32_t entries_read = 0; uint32_t total_entries = 0; int i; struct GROUP_USERS_INFO_0 *info0 = NULL; struct GROUP_USERS_INFO_1 *info1 = NULL; poptContext pc; int opt; struct poptOption long_options[] = { POPT_AUTOHELP POPT_COMMON_LIBNETAPI_EXAMPLES POPT_TABLEEND }; status = libnetapi_init(&ctx); if (status != 0) { return status; } pc = poptGetContext("user_getgroups", argc, argv, long_options, 0); poptSetOtherOptionHelp(pc, "hostname username level"); while((opt = poptGetNextOpt(pc)) != -1) { } if (!poptPeekArg(pc)) { poptPrintHelp(pc, stderr, 0); goto out; } hostname = poptGetArg(pc); if (!poptPeekArg(pc)) { poptPrintHelp(pc, stderr, 0); goto out; } username = poptGetArg(pc); if (poptPeekArg(pc)) { level = atoi(poptGetArg(pc)); } /* NetUserGetGroups */ do { status = NetUserGetGroups(hostname, username, level, &buffer, (uint32_t)-1, &entries_read, &total_entries); if (status == 0 || status == ERROR_MORE_DATA) { switch (level) { case 0: info0 = (struct GROUP_USERS_INFO_0 *)buffer; break; case 1: info1 = (struct GROUP_USERS_INFO_1 *)buffer; break; default: break; } for (i=0; i<entries_read; i++) { switch (level) { case 0: printf("#%d group: %s\n", i, info0->grui0_name); info0++; break; case 1: printf("#%d group: %s\n", i, info1->grui1_name); printf("#%d attributes: %d\n", i, info1->grui1_attributes); info1++; break; default: break; } } NetApiBufferFree(buffer); } } while (status == ERROR_MORE_DATA); if (status != 0) { printf("NetUserGetGroups failed with: %s\n", libnetapi_get_error_string(ctx, status)); } out: libnetapi_free(ctx); poptFreeContext(pc); return status; }
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; }
int main(int argc, const char **argv) { poptContext opt_con; /* context for parsing command-line options */ int rc; uint16_t a_height, a_width, b_height, b_width; size_t a_no_anchors, b_no_anchors; vector2 *a_anchors, *b_anchors; float *a_results, *b_results, *results; opt_con = poptGetContext(NULL, argc, argv, cli_options, 0); poptSetOtherOptionHelp(opt_con, "[OPTIONS] <file1> <file2>"); // Check for sufficient number of command line arguments if (argc < 3) { poptPrintUsage(opt_con, stderr, 0); poptFreeContext(opt_con); exit(EXIT_FAILURE); } // Parse the command line arguments. while ((rc = poptGetNextOpt(opt_con)) >= 0) { switch (rc) { default: break; } } if (rc < -1) { /* an error occurred during option processing */ fprintf(stderr, "%s: %s\n", poptBadOption(opt_con, POPT_BADOPTION_NOALIAS), poptStrerror(rc)); poptFreeContext(opt_con); exit(EXIT_FAILURE); } // Handle the left-over arguments. if (poptPeekArg(opt_con) != NULL) { file[0] = strdup(poptGetArg(opt_con)); } else { fprintf(stderr, "error: missing input file name\n"); fflush(stderr); poptPrintUsage(opt_con, stderr, 0); poptFreeContext(opt_con); exit(EXIT_FAILURE); } // Handle the left-over arguments. if (poptPeekArg(opt_con) != NULL) { file[1] = strdup(poptGetArg(opt_con)); } else { fprintf(stderr, "error: missing input file name\n"); fflush(stderr); poptPrintUsage(opt_con, stderr, 0); poptFreeContext(opt_con); exit(EXIT_FAILURE); } for (ls2_output_variant var = AVERAGE_ERROR; var < NUM_VARIANTS; var++) { if (compare[var] == NULL) continue; ls2_hdf5_read_locbased(file[0], var, &a_anchors, &a_no_anchors, &a_results, &a_width, &a_height); ls2_hdf5_read_locbased(file[1], var, &b_anchors, &b_no_anchors, &b_results, &b_width, &b_height); if (a_width != b_width || a_height != b_height) { fprintf(stderr, "Sizes differ. Cannot continue.\n"); exit(EXIT_FAILURE); } /* Check whether both images are comparable. */ if (a_no_anchors != b_no_anchors) { fprintf(stderr, "warning: number of anchors do not match\n"); } else { for (size_t i = 0; i < a_no_anchors; i++) { if (a_anchors[i].x != b_anchors[i].x || a_anchors[i].y != b_anchors[i].y) { fprintf(stderr, "warning: anchor positions differ\n"); } } } /* Compute the difference between both images. * A positive number means that image one has the larger error. * A negative number means that image two has the larger error. */ results = calloc((size_t)(a_width * a_height), sizeof(float)); for (uint16_t y = 0; y < a_height; y++) { for (uint16_t x = 0; x < a_width; x++) { const int i = x + y * a_width; results[i] = a_results[i] - b_results[i]; } } float mu, sigma, min, max; ls2_statistics(results, (size_t) a_width * a_height, &mu, &sigma, &min, &max); fprintf(stdout, "Average difference = %f, sdev = %f, min = %f, " "max = %f\n", mu, sigma, min, max); ls2_cairo_write_png_diff(compare[var], a_anchors, a_no_anchors, results, a_width, a_height, similarity, dynamic); } exit(EXIT_SUCCESS); }
static int HREcallPopt(int argc,char*argv[],struct poptOption optionsTable[], int min_args,int max_args,char*args[],const char* arg_help){ optCon=poptGetContext(NULL, argc,(const char**)argv, optionsTable, 0); if (arg_help){ snprintf(user_usage, sizeof user_usage, "[OPTIONS] %s",arg_help); poptSetOtherOptionHelp(optCon, user_usage); } for(;;){ int res=poptGetNextOpt(optCon); switch(res){ case PRINT_VERSION: if (strcmp(GIT_VERSION,"")) { fprintf(stdout,"%s\n",GIT_VERSION); } else { fprintf(stdout,"%s\n",PACKAGE_STRING); } return 1; case PRINT_HELP:{ HREprintHelp(); return 1; } case PRINT_USAGE: HREprintUsage(); return 1; default: break; } if (res==-1) break; if (res==POPT_ERROR_BADOPT){ Print(error,"bad option: %s (use --help for help)",poptBadOption(optCon,0)); return 1; } if (res<0) { Abort("option parse error: %s",poptStrerror(res)); } else { Abort("option %s has unexpected return %d",poptBadOption(optCon,0),res); } } for(int i=0;i<min_args;i++){ args[i] = HREstrdup (poptGetArg (optCon)); if (!args[i]) { Print(error,"not enough arguments"); HREprintUsage(); return 1; } } if (max_args >= min_args) { for(int i=min_args;i<max_args;i++){ if (poptPeekArg(optCon)){ args[i] = HREstrdup (poptGetArg (optCon)); } else { args[i]=NULL; } } if (poptPeekArg(optCon)!=NULL) { Print(error,"too many arguments"); HREprintUsage(); return 1; } poptFreeContext(optCon); optCon=NULL; } return 0; }
/**************************************************************************** main program ****************************************************************************/ int main(int argc, const char *argv[]) { int opt; unsigned int lookup_type = 0x0; fstring lookup; static bool find_master=False; static bool lookup_by_ip = False; poptContext pc = NULL; TALLOC_CTX *frame = talloc_stackframe(); int rc = 0; struct poptOption long_options[] = { POPT_AUTOHELP { "broadcast", 'B', POPT_ARG_STRING, NULL, 'B', "Specify address to use for broadcasts", "BROADCAST-ADDRESS" }, { "flags", 'f', POPT_ARG_NONE, NULL, 'f', "List the NMB flags returned" }, { "unicast", 'U', POPT_ARG_STRING, NULL, 'U', "Specify address to use for unicast" }, { "master-browser", 'M', POPT_ARG_NONE, NULL, 'M', "Search for a master browser" }, { "recursion", 'R', POPT_ARG_NONE, NULL, 'R', "Set recursion desired in package" }, { "status", 'S', POPT_ARG_NONE, NULL, 'S', "Lookup node status as well" }, { "translate", 'T', POPT_ARG_NONE, NULL, 'T', "Translate IP addresses into names" }, { "root-port", 'r', POPT_ARG_NONE, NULL, 'r', "Use root port 137 (Win95 only replies to this)" }, { "lookup-by-ip", 'A', POPT_ARG_NONE, NULL, 'A', "Do a node status on <name> as an IP Address" }, POPT_COMMON_SAMBA POPT_COMMON_CONNECTION { 0, 0, 0, 0 } }; *lookup = 0; load_case_tables(); setup_logging(argv[0], DEBUG_STDOUT); pc = poptGetContext("nmblookup", argc, argv, long_options, POPT_CONTEXT_KEEP_FIRST); poptSetOtherOptionHelp(pc, "<NODE> ..."); while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case 'f': give_flags = true; break; case 'M': find_master = true; break; case 'R': recursion_desired = true; break; case 'S': find_status = true; break; case 'r': RootPort = true; break; case 'A': lookup_by_ip = true; break; case 'B': if (interpret_string_addr(&bcast_addr, poptGetOptArg(pc), NI_NUMERICHOST)) { got_bcast = True; use_bcast = True; } break; case 'U': if (interpret_string_addr(&bcast_addr, poptGetOptArg(pc), 0)) { got_bcast = True; use_bcast = False; } break; case 'T': translate_addresses = !translate_addresses; break; } } poptGetArg(pc); /* Remove argv[0] */ if(!poptPeekArg(pc)) { poptPrintUsage(pc, stderr, 0); rc = 1; goto out; } if (!lp_load_global(get_dyn_CONFIGFILE())) { fprintf(stderr, "Can't load %s - run testparm to debug it\n", get_dyn_CONFIGFILE()); } load_interfaces(); if (!open_sockets()) { rc = 1; goto out; } while(poptPeekArg(pc)) { char *p; struct in_addr ip; fstrcpy(lookup,poptGetArg(pc)); if(lookup_by_ip) { struct sockaddr_storage ss; ip = interpret_addr2(lookup); in_addr_to_sockaddr_storage(&ss, ip); fstrcpy(lookup,"*"); if (!do_node_status(lookup, lookup_type, &ss)) { rc = 1; } continue; } if (find_master) { if (*lookup == '-') { fstrcpy(lookup,"\01\02__MSBROWSE__\02"); lookup_type = 1; } else { lookup_type = 0x1d; } } p = strchr_m(lookup,'#'); if (p) { *p = '\0'; sscanf(++p,"%x",&lookup_type); } if (!query_one(lookup, lookup_type)) { rc = 1; d_printf( "name_query failed to find name %s", lookup ); if( 0 != lookup_type ) { d_printf( "#%02x", lookup_type ); } d_printf( "\n" ); } } out: poptFreeContext(pc); TALLOC_FREE(frame); 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 */ 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 main (int argc, char **argv) { gchar c; /* used for argument parsing */ const gchar *filename; gint width = 0; gint height = 0; poptContext optCon; /* context for parsing command-line options */ const struct poptOption optionsTable[] = { {"width", 'w', POPT_ARG_INT, &width, 0, "Width of the output image (to be resized)", "Width"}, {"height", 'h', POPT_ARG_INT, &height, 0, "Height of the output image (to be resized)", "Height"}, POPT_AUTOHELP {NULL, 0, 0, NULL, 0} }; optCon = poptGetContext (NULL, argc, (const char **) argv, optionsTable, 0); poptSetOtherOptionHelp (optCon, "[options] <filename>"); if (argc < 2) { poptPrintUsage (optCon, stderr, 0); return 1; } while ((c = poptGetNextOpt (optCon)) >= 0) { switch (c) { case 'w': if (width <= 0) { width = 0; } break; case 'h': if (height <= 0) { height = 0; } break; } } filename = poptGetArg (optCon); if ((filename == NULL) || !(poptPeekArg (optCon) == NULL)) { poptPrintUsage (optCon, stderr, 0); g_printerr ("\n\tYou must to specify the output filename" " such as screenshot.png\n"); return -1; } if (c < -1) { /* an error occurred during option processing */ g_printerr ("%s: %s\n", poptBadOption (optCon, POPT_BADOPTION_NOALIAS), poptStrerror (c)); return 1; } gdk_init (&argc, &argv); take_screenshot (filename, width, height); poptFreeContext (optCon); return 0; }
int main(int argc, const char** argv) { struct poptOption opt_table[] = { { "device", 'f', POPT_ARG_STRING, &device, 'f' }, { "board", 'b', POPT_ARG_STRING, &device, 'b' }, { "shell", 's', POPT_ARG_STRING, &device, 's' }, { "verbose", 'v', POPT_ARG_INT, &acq200_debug, 0 }, { "version", 0, POPT_ARG_NONE, 0, 'V' }, { "while", 'w', POPT_ARG_STRING, &poll_while, 'p' }, { "until", 'u', POPT_ARG_STRING, &poll_until, 'p' }, { "timeout", 't', POPT_ARG_INT, &timeout, 't', "timeout in seconds"}, POPT_AUTOHELP POPT_TABLEEND }; int rc; poptContext opt_context = poptGetContext(argv[0], argc, argv, opt_table, 0); while ( (rc = poptGetNextOpt(opt_context)) > 0 ){ switch(rc){ case 's': do_shell = 1; break; } } if (device == 0){ err("usage acqcmd -f DEVICE command ..."); return -1; } Transport *t = Transport::getTransport(device); if (poll_while){ rc = t->acqcmd("getState", response, MAXBUF); while (strstr(response, poll_while)){ rc = t->waitStateChange(timeout, response, MAXBUF); if (rc < 0){ exit(rc); } } }else if (poll_until){ rc = t->acqcmd("getState", response, MAXBUF); while (strstr(response, poll_until) == 0){ rc = t->waitStateChange(timeout, response, MAXBUF); if (rc < 0){ exit(rc); } } }else{ if (poptPeekArg(opt_context)){ for (int first=1; poptPeekArg(opt_context); first=0){ if (!first){ strcat(command, " "); } strcat(command, poptGetArg(opt_context)); } if (do_shell){ rc = t->acq2sh(command, response, MAXBUF); }else{ rc = t->acqcmd(command, response, MAXBUF); } puts(response); if (STATUS_IS_OK(rc)){ return 0; }else{ exit(rc); } }else{ // no batch processing at this time. exit(0); } } }
int main(int argc, const char *argv[]) { const char *config_file = get_dyn_CONFIGFILE(); int s; static int silent_mode = False; static int show_all_parameters = False; int ret = 0; poptContext pc; static char *parameter_name = NULL; static const char *section_name = NULL; const char *cname; const char *caddr; static int show_defaults; static int skip_logic_checks = 0; struct poptOption long_options[] = { POPT_AUTOHELP {"suppress-prompt", 's', POPT_ARG_VAL, &silent_mode, 1, "Suppress prompt for enter"}, {"verbose", 'v', POPT_ARG_NONE, &show_defaults, 1, "Show default options too"}, {"skip-logic-checks", 'l', POPT_ARG_NONE, &skip_logic_checks, 1, "Skip the global checks"}, {"show-all-parameters", '\0', POPT_ARG_VAL, &show_all_parameters, True, "Show the parameters, type, possible values" }, {"parameter-name", '\0', POPT_ARG_STRING, ¶meter_name, 0, "Limit testparm to a named parameter" }, {"section-name", '\0', POPT_ARG_STRING, §ion_name, 0, "Limit testparm to a named section" }, POPT_COMMON_VERSION POPT_COMMON_DEBUGLEVEL POPT_COMMON_OPTION POPT_TABLEEND }; TALLOC_CTX *frame = talloc_stackframe(); load_case_tables(); /* * Set the default debug level to 2. * Allow it to be overridden by the command line, * not by smb.conf. */ lp_set_cmdline("log level", "2"); pc = poptGetContext(NULL, argc, argv, long_options, POPT_CONTEXT_KEEP_FIRST); poptSetOtherOptionHelp(pc, "[OPTION...] <config-file> [host-name] [host-ip]"); while(poptGetNextOpt(pc) != -1); if (show_all_parameters) { show_parameter_list(); exit(0); } setup_logging(poptGetArg(pc), DEBUG_STDERR); if (poptPeekArg(pc)) config_file = poptGetArg(pc); cname = poptGetArg(pc); caddr = poptGetArg(pc); poptFreeContext(pc); if ( cname && ! caddr ) { printf ( "ERROR: You must specify both a machine name and an IP address.\n" ); ret = 1; goto done; } fprintf(stderr,"Load smb config files from %s\n",config_file); if (!lp_load_with_registry_shares(config_file,False,True,False,True)) { fprintf(stderr,"Error loading services.\n"); ret = 1; goto done; } fprintf(stderr,"Loaded services file OK.\n"); if (skip_logic_checks == 0) { ret = do_global_checks(); } for (s=0;s<1000;s++) { if (VALID_SNUM(s)) if (strlen(lp_servicename(talloc_tos(), s)) > 12) { fprintf(stderr, "WARNING: You have some share names that are longer than 12 characters.\n" ); fprintf(stderr, "These may not be accessible to some older clients.\n" ); fprintf(stderr, "(Eg. Windows9x, WindowsMe, and smbclient prior to Samba 3.0.)\n" ); break; } } for (s=0;s<1000;s++) { if (VALID_SNUM(s) && (skip_logic_checks == 0)) { do_per_share_checks(s); } } if (!section_name && !parameter_name) { fprintf(stderr, "Server role: %s\n\n", server_role_str(lp_server_role())); } if (!cname) { if (!silent_mode) { fprintf(stderr,"Press enter to see a dump of your service definitions\n"); fflush(stdout); getc(stdin); } if (parameter_name || section_name) { bool isGlobal = False; s = GLOBAL_SECTION_SNUM; if (!section_name) { section_name = GLOBAL_NAME; isGlobal = True; } else if ((isGlobal=!strwicmp(section_name, GLOBAL_NAME)) == 0 && (s=lp_servicenumber(section_name)) == -1) { fprintf(stderr,"Unknown section %s\n", section_name); ret = 1; goto done; } if (parameter_name) { if (!dump_a_parameter( s, parameter_name, stdout, isGlobal)) { fprintf(stderr,"Parameter %s unknown for section %s\n", parameter_name, section_name); ret = 1; goto done; } } else { if (isGlobal == True) lp_dump(stdout, show_defaults, 0); else lp_dump_one(stdout, show_defaults, s); } goto done; } lp_dump(stdout, show_defaults, lp_numservices()); } if(cname && caddr){ /* this is totally ugly, a real `quick' hack */ for (s=0;s<1000;s++) { if (VALID_SNUM(s)) { if (allow_access(lp_hosts_deny(-1), lp_hosts_allow(-1), cname, caddr) && allow_access(lp_hosts_deny(s), lp_hosts_allow(s), cname, caddr)) { fprintf(stderr,"Allow connection from %s (%s) to %s\n", cname,caddr,lp_servicename(talloc_tos(), s)); } else { fprintf(stderr,"Deny connection from %s (%s) to %s\n", cname,caddr,lp_servicename(talloc_tos(), s)); } } } } done: gfree_loadparm(); TALLOC_FREE(frame); return ret; }
int main(int argc, const char **argv) { NET_API_STATUS status; struct libnetapi_ctx *ctx = NULL; const char *hostname = NULL; const char *groupname = NULL; struct LOCALGROUP_MEMBERS_INFO_0 *g0; struct LOCALGROUP_MEMBERS_INFO_3 *g3; uint32_t total_entries = 0; uint8_t *buffer = NULL; uint32_t level = 3; const char **names = NULL; int i = 0; poptContext pc; int opt; struct poptOption long_options[] = { POPT_AUTOHELP POPT_COMMON_LIBNETAPI_EXAMPLES POPT_TABLEEND }; status = libnetapi_init(&ctx); if (status != 0) { return status; } pc = poptGetContext("localgroup_addmembers", argc, argv, long_options, 0); poptSetOtherOptionHelp(pc, "hostname groupname member1 member2 ..."); while((opt = poptGetNextOpt(pc)) != -1) { } if (!poptPeekArg(pc)) { poptPrintHelp(pc, stderr, 0); goto out; } hostname = poptGetArg(pc); if (!poptPeekArg(pc)) { poptPrintHelp(pc, stderr, 0); goto out; } groupname = poptGetArg(pc); if (!poptPeekArg(pc)) { poptPrintHelp(pc, stderr, 0); goto out; } names = poptGetArgs(pc); for (i=0; names[i] != NULL; i++) { total_entries++; } switch (level) { case 0: status = NetApiBufferAllocate(sizeof(struct LOCALGROUP_MEMBERS_INFO_0) * total_entries, (void **)&g0); if (status) { printf("NetApiBufferAllocate failed with: %s\n", libnetapi_get_error_string(ctx, status)); goto out; } for (i=0; i<total_entries; i++) { if (!ConvertStringSidToSid(names[i], &g0[i].lgrmi0_sid)) { printf("could not convert sid\n"); goto out; } } buffer = (uint8_t *)g0; break; case 3: status = NetApiBufferAllocate(sizeof(struct LOCALGROUP_MEMBERS_INFO_3) * total_entries, (void **)&g3); if (status) { printf("NetApiBufferAllocate failed with: %s\n", libnetapi_get_error_string(ctx, status)); goto out; } for (i=0; i<total_entries; i++) { g3[i].lgrmi3_domainandname = names[i]; } buffer = (uint8_t *)g3; break; default: break; } /* NetLocalGroupAddMembers */ status = NetLocalGroupAddMembers(hostname, groupname, level, buffer, total_entries); if (status != 0) { printf("NetLocalGroupAddMembers failed with: %s\n", libnetapi_get_error_string(ctx, status)); } out: libnetapi_free(ctx); poptFreeContext(pc); return status; }
int main(const int ac, const char* av[]) { poptContext optCon=0; gint rc; gint status = 0; const gchar* arg; struct error* err; #ifdef __DEBUG g_mem_set_vtable(glib_mem_profiler_table); #endif err = e_new(); /* check if we have enough privileges */ #ifndef __WIN32__ unsetenv("LD_LIBRARY_PATH"); #else putenv("LD_LIBRARY_PATH"); putenv("LD_LIBRARY_PATH="); #endif /* load blacklists from SPKG_CONFDIR */ gchar** bl_symopts = load_blacklist(SPKG_CONFDIR "/symopts_blacklist"); if (bl_symopts) cmd_opts.bl_symopts = bl_symopts; /* preset ROOT */ cmd_opts.root = getenv("ROOT"); /* initialize popt context */ optCon = poptGetContext("spkg", ac, av, opts, 0); poptSetOtherOptionHelp(optCon, "<command> [options] [packages...]"); /* parse options */ while ((rc = poptGetNextOpt(optCon)) != -1) { if (rc == 1) verbose++; else if (rc == 2) quiet++; if (rc < -1) { fprintf(stderr, "ERROR: Invalid argument: %s (%s)\n", poptStrerror(rc), poptBadOption(optCon, POPT_BADOPTION_NOALIAS)); goto err_1; } } /* these are help handlers */ if (help) { printf( PACKAGE_STRING "\n" "\n" "Written by Ondrej Jirman, 2005-2006.\n" "\n" "This is free software. Not like a beer or like in a \"freedom\",\n" "but like in \"I don't care what you are going to do with it.\"\n" "\n" ); poptPrintHelp(optCon, stdout, 0); printf( "\n" "Examples:\n" " spkg -i <packages> [--install]\n" " spkg -u <packages> [--upgrade]\n" " spkg -vd <packages> [--verbose --remove]\n" " spkg -l kde* [--list]\n" " spkg -vnu <packages> [--upgrade --verbose --dry-run]\n" "\n" "Official website: http://spkg.megous.com\n" "Bug reports can be sent to <*****@*****.**>.\n" ); goto out; } if (usage) { printf("Usage: spkg [-i|-u|-d|-l] [--root=ROOT] [-n] [-s] [-q] [-v] [packages...]\n"); goto out; } if (version) { printf("%s\n", PACKAGE_STRING); goto out; } /* check verbosity options */ if (verbose && quiet) { fprintf(stderr, "ERROR: Verbose or quiet?\n"); goto err_1; } cmd_opts.verbosity += verbose; cmd_opts.verbosity -= quiet; /* check command options */ switch (command) { case CMD_INSTALL: if (!cmd_opts.dryrun && !is_root()) goto err_noroot; if (poptPeekArg(optCon) == 0) goto err_nopackages; break; case CMD_UPGRADE: if (!cmd_opts.dryrun && !is_root()) goto err_noroot; if (poptPeekArg(optCon) == 0) goto err_nopackages; break; case CMD_REMOVE: if (!cmd_opts.dryrun && !is_root()) goto err_noroot; if (poptPeekArg(optCon) == 0) goto err_nopackages; break; case CMD_LIST: break; case 0: if (poptPeekArg(optCon) == 0) { printf("Usage: spkg [-i|-u|-d|-l] [--root=ROOT] [-n] [-s] [-q] [-v] [packages...]\n"); goto out; } if (!cmd_opts.dryrun && !is_root()) goto err_noroot; command = CMD_UPGRADE; install_new = TRUE; break; default: fprintf(stderr, "ERROR: Schizofrenic command usage.\n"); goto err_1; } /* init signal trap */ if (sig_trap(err)) goto err_2; /* open db */ gboolean readonly = cmd_opts.dryrun || !is_root(); if (db_open(cmd_opts.root, readonly, err)) goto err_2; switch (command) { case CMD_INSTALL: { while ((arg = poptGetArg(optCon)) != 0 && !sig_break) { if (cmd_install(arg, &cmd_opts, err)) { if (e_errno(err) & CMD_EXIST) { gchar* pkgname = parse_pkgname(arg, 5); _inform("Skipping package %s (package with same base name is already installed)...", pkgname ? pkgname : arg); g_free(pkgname); e_clean(err); } else { e_print(err); e_clean(err); status = 2; } } } } break; case CMD_UPGRADE: { while ((arg = poptGetArg(optCon)) != 0 && !sig_break) { if (cmd_upgrade(arg, &cmd_opts, err)) { if (install_new && (e_errno(err) & CMD_NOTEX)) { e_clean(err); if (cmd_install(arg, &cmd_opts, err)) { e_print(err); e_clean(err); status = 2; } } else if (e_errno(err) & CMD_NOTEX) { gchar* pkgname = parse_pkgname(arg, 5); _inform("Skipping package %s (package with same base name is NOT installed)...", pkgname ? pkgname : arg); g_free(pkgname); e_clean(err); } else if (e_errno(err) & CMD_EXIST) { gchar* pkgname = parse_pkgname(arg, 5); _inform("Skipping package %s (already uptodate)...", pkgname ? pkgname : arg); g_free(pkgname); e_clean(err); } else { e_print(err); e_clean(err); status = 2; } } } } break; case CMD_REMOVE: { while ((arg = poptGetArg(optCon)) != 0 && !sig_break) { if (cmd_remove(arg, &cmd_opts, err)) { e_print(err); e_clean(err); status = 2; } } } break; case CMD_LIST: { GSList* arglist = NULL; while ((arg = poptGetArg(optCon)) != 0) arglist = g_slist_append(arglist, g_strdup(arg)); if (cmd_list(arglist, &cmd_opts, err)) { e_print(err); e_clean(err); status = 2; } g_slist_foreach(arglist, (GFunc)g_free, 0); g_slist_free(arglist); } break; } db_close(); out: poptFreeContext(optCon); e_free(err); #ifdef __DEBUG g_mem_profile(); #endif /* 0 = all ok * 1 = command line error * 2 = package manager error */ return status; err_1: status = 1; goto out; err_2: status = 2; e_print(err); goto out; err_nopackages: fprintf(stderr, "ERROR: No packages specified.\n"); goto err_1; err_noroot: fprintf(stderr, "ERROR: You need root privileges to run this command. Try using --dry-run.\n"); goto err_1; }
/* main program */ int main(int argc, const char *argv[]) { bool ret = true; struct interface *ifaces; struct tevent_context *ev; poptContext pc; int opt; enum { OPT_BROADCAST_ADDRESS = 1000, OPT_UNICAST_ADDRESS, OPT_FIND_MASTER, OPT_WINS_LOOKUP, OPT_NODE_STATUS, OPT_ROOT_PORT, OPT_LOOKUP_BY_IP, OPT_CASE_SENSITIVE }; struct poptOption long_options[] = { POPT_AUTOHELP { "broadcast", 'B', POPT_ARG_STRING, NULL, OPT_BROADCAST_ADDRESS, "Specify address to use for broadcasts", "BROADCAST-ADDRESS" }, { "unicast", 'U', POPT_ARG_STRING, NULL, OPT_UNICAST_ADDRESS, "Specify address to use for unicast", NULL }, { "master-browser", 'M', POPT_ARG_NONE, NULL, OPT_FIND_MASTER, "Search for a master browser", NULL }, { "wins", 'W', POPT_ARG_NONE, NULL, OPT_WINS_LOOKUP, "Do a WINS lookup", NULL }, { "status", 'S', POPT_ARG_NONE, NULL, OPT_NODE_STATUS, "Lookup node status as well", NULL }, { "root-port", 'r', POPT_ARG_NONE, NULL, OPT_ROOT_PORT, "Use root port 137 (Win95 only replies to this)", NULL }, { "lookup-by-ip", 'A', POPT_ARG_NONE, NULL, OPT_LOOKUP_BY_IP, "Do a node status on <name> as an IP Address", NULL }, { "case-sensitive", 0, POPT_ARG_NONE, NULL, OPT_CASE_SENSITIVE, "Don't uppercase the name before sending", NULL }, POPT_COMMON_SAMBA { 0, 0, 0, 0 } }; pc = poptGetContext("nmblookup", argc, argv, long_options, POPT_CONTEXT_KEEP_FIRST); poptSetOtherOptionHelp(pc, "<NODE> ..."); while ((opt = poptGetNextOpt(pc)) != -1) { switch(opt) { case OPT_BROADCAST_ADDRESS: options.broadcast_address = poptGetOptArg(pc); break; case OPT_UNICAST_ADDRESS: options.unicast_address = poptGetOptArg(pc); break; case OPT_FIND_MASTER: options.find_master = true; break; case OPT_WINS_LOOKUP: options.wins_lookup = true; break; case OPT_NODE_STATUS: options.node_status = true; break; case OPT_ROOT_PORT: options.root_port = true; break; case OPT_LOOKUP_BY_IP: options.lookup_by_ip = true; break; case OPT_CASE_SENSITIVE: options.case_sensitive = true; break; } } /* swallow argv[0] */ poptGetArg(pc); if(!poptPeekArg(pc)) { poptPrintUsage(pc, stderr, 0); exit(1); } load_interfaces(NULL, lp_interfaces(cmdline_lp_ctx), &ifaces); ev = s4_event_context_init(talloc_autofree_context()); while (poptPeekArg(pc)) { const char *name = poptGetArg(pc); ret &= process_one(cmdline_lp_ctx, ev, ifaces, name, lp_nbt_port(cmdline_lp_ctx)); } talloc_free(ev); talloc_free(ifaces); poptFreeContext(pc); if (!ret) { return 1; } return 0; }
int main(int argc, const char **argv) { NET_API_STATUS status; struct libnetapi_ctx *ctx = NULL; const char *hostname = NULL; uint32_t level = 0; uint8_t *buffer = NULL; uint32_t entries_read = 0; uint32_t total_entries = 0; uint32_t resume_handle = 0; int i; struct SHARE_INFO_0 *i0 = NULL; struct SHARE_INFO_1 *i1 = NULL; struct SHARE_INFO_2 *i2 = NULL; poptContext pc; int opt; struct poptOption long_options[] = { POPT_AUTOHELP POPT_COMMON_LIBNETAPI_EXAMPLES POPT_TABLEEND }; status = libnetapi_init(&ctx); if (status != 0) { return status; } pc = poptGetContext("share_enum", argc, argv, long_options, 0); poptSetOtherOptionHelp(pc, "hostname level"); while((opt = poptGetNextOpt(pc)) != -1) { } if (!poptPeekArg(pc)) { poptPrintHelp(pc, stderr, 0); goto out; } hostname = poptGetArg(pc); if (poptPeekArg(pc)) { level = atoi(poptGetArg(pc)); } /* NetShareEnum */ do { status = NetShareEnum(hostname, level, &buffer, (uint32_t)-1, &entries_read, &total_entries, &resume_handle); if (status == 0 || status == ERROR_MORE_DATA) { printf("total entries: %d\n", total_entries); switch (level) { case 0: i0 = (struct SHARE_INFO_0 *)buffer; break; case 1: i1 = (struct SHARE_INFO_1 *)buffer; break; case 2: i2 = (struct SHARE_INFO_2 *)buffer; break; default: break; } for (i=0; i<entries_read; i++) { switch (level) { case 0: printf("#%d netname: %s\n", i, i0->shi0_netname); i0++; break; case 1: printf("#%d netname: %s\n", i, i1->shi1_netname); printf("#%d type: %d\n", i, i1->shi1_type); printf("#%d remark: %s\n", i, i1->shi1_remark); i1++; break; case 2: printf("#%d netname: %s\n", i, i2->shi2_netname); printf("#%d type: %d\n", i, i2->shi2_type); printf("#%d remark: %s\n", i, i2->shi2_remark); printf("#%d permissions: %d\n", i, i2->shi2_permissions); printf("#%d max users: %d\n", i, i2->shi2_max_uses); printf("#%d current users: %d\n", i, i2->shi2_current_uses); printf("#%d path: %s\n", i, i2->shi2_path); printf("#%d password: %s\n", i, i2->shi2_passwd); i2++; break; default: break; } } NetApiBufferFree(buffer); } } while (status == ERROR_MORE_DATA); if (status != 0) { printf("NetShareEnum failed with: %s\n", libnetapi_get_error_string(ctx, status)); } out: libnetapi_free(ctx); poptFreeContext(pc); return status; }
int main(int argc, const char **argv) { int i; char c; int linestoread = 1; char *outpath = NULL; char *errpath = NULL; poptContext poptcxt; const char **addl = NULL; const char *regexp = NULL; const char *command = NULL; unsigned long numaddl = 0; CDCDiscoveryResults *discovery; // I/O defaults. in = stdin; out = stdout; err = stderr; struct poptOption options[] = { // --output,-o { "output", 'o', POPT_ARG_STRING, &outpath, 0, "output file (DEFAULT=stdout)", "path|-" }, // --error,-e { "error", 'e', POPT_ARG_STRING, &errpath, 0, "error file (DEFAULT=stderr)", "path|-" }, // --lines,-l { "lines", 'l', POPT_ARG_INT, &linestoread, 0, "Number of lines to read from the serial port before exiting. Zero is the same as -r. (DEFAULT=1)" }, // --help,-? POPT_AUTOHELP // end { NULL, 0, 0, NULL, 0 } }; // Process popt options. poptcxt = poptGetContext(NULL, argc, argv, options, 0); poptSetOtherOptionHelp( poptcxt, "[OPTIONS]* <command> <regexp> (additional port)+" ); if (argc < 2) { usage(poptcxt, 0, 0, 0); } while ((c = poptGetNextOpt(poptcxt)) >= 0) { ; } if (c < -1) { // An error occurred during option processing. fprintf( stderr, "%s: %s\n", poptBadOption(poptcxt, POPT_BADOPTION_NOALIAS), poptStrerror(c) ); return 1; } // Check error file. if (errpath && strcmp(errpath, "-") != 0) { err = fopen(errpath, "a"); if (!err) { usage(poptcxt, 2, "Cannot open error file path", errpath); } } // Check output file. if (outpath && strcmp(outpath, "-") != 0) { out = fopen(outpath, "a"); if (!out) { usage(poptcxt, 3, "Cannot open output file path", outpath); } } // Get the command and regular expression query. command = poptGetArg(poptcxt); regexp = poptGetArg(poptcxt); if ((command == NULL) || (regexp == NULL)) { usage( poptcxt, 1, "Please specify", "<command> <regex>" ); } // Additional ports to check. while (poptPeekArg(poptcxt)) { addl = (const char**)realloc(addl, (++numaddl) * sizeof(char*)); addl[numaddl] = poptGetArg(poptcxt); } // Discovery. discovery = cdc_discover(command, regexp, linestoread, numaddl, addl); for (i=0; i<discovery->matches; i++) { fprintf(out, "%s\n", discovery->match[i]); } cdc_discover_free_results(discovery); // Cleanup. if (numaddl) { free(addl); } poptFreeContext(poptcxt); return 0; }
int main(int argc, const char **argv) { const char *config_file = get_dyn_CONFIGFILE(); int ret = 0; poptContext pc; char *count_str = NULL; int i, count = 1; struct poptOption long_options[] = { POPT_AUTOHELP {"count", 'c', POPT_ARG_STRING, &count_str, 1, "Load config <count> number of times"}, POPT_COMMON_DEBUGLEVEL POPT_TABLEEND }; TALLOC_CTX *frame = talloc_stackframe(); load_case_tables(); DEBUGLEVEL_CLASS[DBGC_ALL] = 0; pc = poptGetContext(NULL, argc, argv, long_options, POPT_CONTEXT_KEEP_FIRST); poptSetOtherOptionHelp(pc, "[OPTION...] <config-file>"); while(poptGetNextOpt(pc) != -1); setup_logging(poptGetArg(pc), True); if (poptPeekArg(pc)) { config_file = poptGetArg(pc); } poptFreeContext(pc); if (count_str != NULL) { count = atoi(count_str); } dbf = x_stderr; /* Don't let the debuglevel be changed by smb.conf. */ AllowDebugChange = False; for (i=0; i < count; i++) { printf("call lp_load() #%d: ", i+1); if (!lp_load_with_registry_shares(config_file, False, /* global only */ True, /* save defaults */ False, /*add_ipc */ True)) /*init globals */ { printf("ERROR.\n"); ret = 1; goto done; } printf("ok.\n"); } done: gfree_loadparm(); TALLOC_FREE(frame); return ret; }
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; }
int main(int argc, char *argv[]) { poptContext optCon = NULL; ARGV_t av = NULL; rpmfc fc = NULL; int ec = 1; char buf[BUFSIZ]; xsetprogname(argv[0]); /* Portability call -- see system.h */ optCon = rpmcliInit(argc, argv, optionsTable); if (optCon == NULL) goto exit; /* normally files get passed through stdin but also accept files as args */ if (poptPeekArg(optCon)) { const char *arg; while ((arg = poptGetArg(optCon)) != NULL) { argvAdd(&av, arg); } } else { while (fgets(buf, sizeof(buf), stdin) != NULL) { char *be = buf + strlen(buf) - 1; while (strchr("\r\n", *be) != NULL) *be-- = '\0'; argvAdd(&av, buf); } } /* Make sure file names are sorted. */ argvSort(av, NULL); /* Build file/package class and dependency dictionaries. */ fc = rpmfcCreate(getenv("RPM_BUILD_ROOT"), 0); if (rpmfcClassify(fc, av, NULL) || rpmfcApply(fc)) goto exit; if (_rpmfc_debug) rpmfcPrint(buf, fc, NULL); if (print_provides) rpmdsPrint(NULL, rpmfcProvides(fc), stdout); if (print_requires) rpmdsPrint(NULL, rpmfcRequires(fc), stdout); if (print_recommends) rpmdsPrint(NULL, rpmfcRecommends(fc), stdout); if (print_suggests) rpmdsPrint(NULL, rpmfcSuggests(fc), stdout); if (print_supplements) rpmdsPrint(NULL, rpmfcSupplements(fc), stdout); if (print_enhances) rpmdsPrint(NULL, rpmfcEnhances(fc), stdout); if (print_conflicts) rpmdsPrint(NULL, rpmfcConflicts(fc), stdout); if (print_obsoletes) rpmdsPrint(NULL, rpmfcObsoletes(fc), stdout); ec = 0; exit: argvFree(av); rpmfcFree(fc); rpmcliFini(optCon); return ec; }
static WERROR cmd_witness_RegisterEx(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) { static char hostname[MAXHOSTNAMELEN] = {'\0'}; NTSTATUS status; WERROR result = WERR_OK; TALLOC_CTX *frame = talloc_stackframe(); struct policy_handle hnd; const char *net_name = NULL; const char *ip_addr = NULL; const char *share_name = NULL; const char *client_name = hostname; long version = WITNESS_V2; long flags = 0; long timeout = 0; int c; poptContext optCon; struct poptOption optionsTable[] = { {"version", 'v', POPT_ARG_LONG|POPT_ARGFLAG_SHOW_DEFAULT, &version, WITNESS_V2, "witness version", "version"}, {"V1", '1', POPT_ARG_LONG|POPT_ARG_VAL, &version, WITNESS_V1, "witness version 1", NULL}, {"V2", '2', POPT_ARG_LONG|POPT_ARG_VAL, &version, WITNESS_V2, "witness version 2", NULL}, {"net", 'n', POPT_ARG_STRING|POPT_ARGFLAG_SHOW_DEFAULT, &net_name, 0, "net name", NULL}, {"ip", 'i', POPT_ARG_STRING|POPT_ARGFLAG_SHOW_DEFAULT, &ip_addr, 0, "ip address", NULL}, {"share", 's', POPT_ARG_STRING|POPT_ARGFLAG_SHOW_DEFAULT, &share_name, 0, "share name", NULL}, {"client", 'c', POPT_ARG_STRING|POPT_ARGFLAG_SHOW_DEFAULT|POPT_ARGFLAG_OPTIONAL, &client_name, 0, "client name", NULL}, {"flags", 'f', POPT_ARG_LONG|POPT_ARGFLAG_OR|POPT_ARGFLAG_SHOW_DEFAULT, &flags, 0, "flags", NULL}, {"timeout", 't', POPT_ARG_LONG|POPT_ARGFLAG_SHOW_DEFAULT, &timeout, 0, "timeout", NULL}, { NULL, 0, 0, NULL, 0 } }; use_only_one_rpc_pipe_hack(cli); if (hostname[0] == '\0') { gethostname (hostname, sizeof(hostname)); } optCon = poptGetContext(NULL, argc, argv, optionsTable, 0); while ((c = poptGetNextOpt(optCon)) >= 0) { } if (c < -1) { /* an error occurred during option processing */ d_fprintf(stderr, "%s: %s\n", poptBadOption(optCon, POPT_BADOPTION_NOALIAS), poptStrerror(c)); goto done; } if (argc < 2 || poptPeekArg(optCon) != NULL) { poptPrintHelp(optCon, stderr, 0); goto done; } status = dcerpc_witness_RegisterEx(cli->binding_handle, frame, &hnd, version, net_name, share_name, ip_addr, client_name, flags, timeout, &result); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("dcerpc_witness_RegisterEx failed, status: %s\n", nt_errstr(status))); result = ntstatus_to_werror(status); goto done; } if (!W_ERROR_IS_OK(result)) { DEBUG(0, ("dcerpc_witness_RegisterEx failed, error: %s\n", win_errstr(result))); goto done; } d_printf("%x:%s\n", hnd.handle_type, GUID_string(frame, &hnd.uuid)); done: poptFreeContext(optCon); talloc_free(frame); return result; }
int main(int argc, const char **argv) { NET_API_STATUS status; struct libnetapi_ctx *ctx = NULL; const char *hostname = NULL; const char *username = NULL; uint32_t level = 0; uint32_t parm_err = 0; uint8_t *buffer = NULL; const char *val = NULL; struct USER_INFO_0 u0; struct USER_INFO_1 u1; struct USER_INFO_2 u2; struct USER_INFO_3 u3; struct USER_INFO_4 u4; struct USER_INFO_21 u21; struct USER_INFO_22 u22; struct USER_INFO_1003 u1003; struct USER_INFO_1005 u1005; struct USER_INFO_1006 u1006; struct USER_INFO_1007 u1007; struct USER_INFO_1008 u1008; struct USER_INFO_1009 u1009; struct USER_INFO_1010 u1010; struct USER_INFO_1011 u1011; struct USER_INFO_1012 u1012; struct USER_INFO_1014 u1014; struct USER_INFO_1017 u1017; struct USER_INFO_1020 u1020; struct USER_INFO_1024 u1024; struct USER_INFO_1051 u1051; struct USER_INFO_1052 u1052; struct USER_INFO_1053 u1053; poptContext pc; int opt; struct poptOption long_options[] = { POPT_AUTOHELP POPT_COMMON_LIBNETAPI_EXAMPLES POPT_TABLEEND }; status = libnetapi_init(&ctx); if (status != 0) { return status; } pc = poptGetContext("user_setinfo", argc, argv, long_options, 0); poptSetOtherOptionHelp(pc, "hostname username level"); while((opt = poptGetNextOpt(pc)) != -1) { } if (!poptPeekArg(pc)) { poptPrintHelp(pc, stderr, 0); goto out; } hostname = poptGetArg(pc); if (!poptPeekArg(pc)) { poptPrintHelp(pc, stderr, 0); goto out; } username = poptGetArg(pc); if (!poptPeekArg(pc)) { poptPrintHelp(pc, stderr, 0); goto out; } level = atoi(poptGetArg(pc)); if (!poptPeekArg(pc)) { poptPrintHelp(pc, stderr, 0); goto out; } val = poptGetArg(pc); /* NetUserSetInfo */ switch (level) { case 0: u0.usri0_name = val; buffer = (uint8_t *)&u0; break; case 1: case 2: case 3: case 4: break; case 21: break; case 22: break; case 1003: u1003.usri1003_password = val; buffer = (uint8_t *)&u1003; break; case 1005: u1005.usri1005_priv = atoi(val); buffer = (uint8_t *)&u1005; break; case 1006: u1006.usri1006_home_dir = val; buffer = (uint8_t *)&u1006; break; case 1007: u1007.usri1007_comment = val; buffer = (uint8_t *)&u1007; break; case 1008: u1008.usri1008_flags = atoi(val); buffer = (uint8_t *)&u1008; break; case 1009: u1009.usri1009_script_path = val; buffer = (uint8_t *)&u1009; break; case 1010: u1010.usri1010_auth_flags = atoi(val); buffer = (uint8_t *)&u1010; break; case 1011: u1011.usri1011_full_name = val; buffer = (uint8_t *)&u1011; break; case 1012: u1012.usri1012_usr_comment = val; buffer = (uint8_t *)&u1012; break; case 1014: u1014.usri1014_workstations = val; buffer = (uint8_t *)&u1014; break; case 1017: u1017.usri1017_acct_expires = atoi(val); buffer = (uint8_t *)&u1017; break; case 1020: break; case 1024: u1024.usri1024_country_code = atoi(val); buffer = (uint8_t *)&u1024; break; case 1051: u1051.usri1051_primary_group_id = atoi(val); buffer = (uint8_t *)&u1051; break; case 1052: u1052.usri1052_profile = val; buffer = (uint8_t *)&u1052; break; case 1053: u1053.usri1053_home_dir_drive = val; buffer = (uint8_t *)&u1053; break; default: break; } status = NetUserSetInfo(hostname, username, level, buffer, &parm_err); if (status != 0) { printf("NetUserSetInfo failed with: %s\n", libnetapi_get_error_string(ctx, status)); goto out; } out: libnetapi_free(ctx); poptFreeContext(pc); return status; }
int main(int argc, char *argv[]) { rpmts ts = NULL; QVA_t qva = &rpmQVKArgs; poptContext optCon; int ec = 0; xsetprogname(argv[0]); /* Portability call -- see system.h */ optCon = rpmcliInit(argc, argv, optionsTable); if (rpmcliPipeOutput && initPipe()) exit(EXIT_FAILURE); if (target) { rpmFreeMacros(NULL); rpmFreeRpmrc(); rpmReadConfigFiles(rpmcliRcfile, target); } ts = rpmtsCreate(); switch (mode) { case MODE_QUERY: if (!poptPeekArg(optCon)) argerror(_("no arguments given for query")); qva->qva_queryFormat = queryformat; qva->qva_source = source; qva->qva_specQuery = rpmspecQuery; ec = rpmcliQuery(ts, qva, (ARGV_const_t) poptGetArgs(optCon)); break; case MODE_PARSE: { const char * spath; if (!poptPeekArg(optCon)) argerror(_("no arguments given for parse")); while ((spath = poptGetArg(optCon)) != NULL) { rpmSpec spec = rpmSpecParse(spath, (RPMSPEC_ANYARCH|RPMSPEC_FORCE), NULL); if (spec == NULL) { ec++; continue; } fprintf(stdout, "%s", rpmSpecGetSection(spec, RPMBUILD_NONE)); rpmSpecFree(spec); } break; } case MODE_UNKNOWN: if (poptPeekArg(optCon) != NULL || argc <= 1 || rpmIsVerbose()) { printUsage(optCon, stderr, 0); ec = argc; } break; } rpmtsFree(ts); if (finishPipe()) ec = EXIT_FAILURE; free(qva->qva_queryFormat); rpmcliFini(optCon); return RETVAL(ec); }
int main(int argc, const char ** argv) #endif /*@globals rpmEVR, RPMVERSION, rpmGlobalMacroContext, rpmCLIMacroContext, h_errno, fileSystem, internalState@*/ /*@modifies fileSystem, internalState@*/ { poptContext optCon = rpmcliInit(argc, (char *const *)argv, optionsTable); rpmts ts = NULL; enum modes bigMode = MODE_UNKNOWN; #if defined(IAM_RPMQV) QVA_t qva = &rpmQVKArgs; #endif #ifdef IAM_RPMBT BTA_t ba = &rpmBTArgs; #endif #ifdef IAM_RPMEIU QVA_t ia = &rpmIArgs; #endif #if defined(IAM_RPMDB) QVA_t da = &rpmDBArgs; #endif #if defined(IAM_RPMK) QVA_t ka = &rpmQVKArgs; #endif #if defined(IAM_RPMBT) || defined(IAM_RPMK) char * passPhrase = ""; #endif pid_t pipeChild = 0; int ec = 0; int status; int p[2]; #ifdef IAM_RPMEIU int xx; #endif #if !defined(__GLIBC__) && !defined(__LCLINT__) environ = envp; #else /* XXX limit the fiddle up to linux for now. */ #if !defined(HAVE_SETPROCTITLE) && defined(__linux__) (void) initproctitle(argc, (char **)argv, environ); #endif #endif /* Set the major mode based on argv[0] */ /*@-nullpass@*/ #ifdef IAM_RPMBT if (!strcmp(__progname, "rpmb")) bigMode = MODE_BUILD; if (!strcmp(__progname, "lt-rpmb")) bigMode = MODE_BUILD; if (!strcmp(__progname, "rpmt")) bigMode = MODE_TARBUILD; if (!strcmp(__progname, "rpmbuild")) bigMode = MODE_BUILD; #endif #ifdef IAM_RPMQV if (!strcmp(__progname, "rpmq")) bigMode = MODE_QUERY; if (!strcmp(__progname, "lt-rpmq")) bigMode = MODE_QUERY; if (!strcmp(__progname, "rpmv")) bigMode = MODE_VERIFY; if (!strcmp(__progname, "rpmquery")) bigMode = MODE_QUERY; if (!strcmp(__progname, "rpmverify")) bigMode = MODE_VERIFY; #endif #ifdef RPMEIU if (!strcmp(__progname, "rpme")) bigMode = MODE_ERASE; if (!strcmp(__progname, "rpmi")) bigMode = MODE_INSTALL; if (!strcmp(__progname, "lt-rpmi")) bigMode = MODE_INSTALL; if (!strcmp(__progname, "rpmu")) bigMode = MODE_INSTALL; #endif /*@=nullpass@*/ #if defined(IAM_RPMQV) /* Jumpstart option from argv[0] if necessary. */ switch (bigMode) { case MODE_QUERY: qva->qva_mode = 'q'; break; case MODE_VERIFY: qva->qva_mode = 'V'; break; case MODE_CHECKSIG: qva->qva_mode = 'K'; break; case MODE_RESIGN: qva->qva_mode = 'R'; break; case MODE_INSTALL: case MODE_ERASE: case MODE_BUILD: case MODE_REBUILD: case MODE_RECOMPILE: case MODE_TARBUILD: case MODE_REBUILDDB: case MODE_UNKNOWN: default: break; } #endif rpmcliConfigured(); #ifdef IAM_RPMBT switch (ba->buildMode) { case 'b': bigMode = MODE_BUILD; break; case 't': bigMode = MODE_TARBUILD; break; case 'B': bigMode = MODE_REBUILD; break; case 'C': bigMode = MODE_RECOMPILE; break; } if ((ba->buildAmount & RPMBUILD_RMSOURCE) && bigMode == MODE_UNKNOWN) bigMode = MODE_BUILD; if ((ba->buildAmount & RPMBUILD_RMSPEC) && bigMode == MODE_UNKNOWN) bigMode = MODE_BUILD; #endif /* IAM_RPMBT */ #ifdef IAM_RPMDB if (bigMode == MODE_UNKNOWN || (bigMode & MODES_DB)) { if (da->rebuild) { if (bigMode != MODE_UNKNOWN) argerror(_("only one major mode may be specified")); else bigMode = MODE_REBUILDDB; } } #endif /* IAM_RPMDB */ #ifdef IAM_RPMQV if (bigMode == MODE_UNKNOWN || (bigMode & MODES_QV)) { switch (qva->qva_mode) { case 'q': bigMode = MODE_QUERY; break; case 'V': bigMode = MODE_VERIFY; break; } if (qva->qva_sourceCount) { if (qva->qva_sourceCount > 2) argerror(_("one type of query/verify may be performed at a " "time")); } if (qva->qva_flags && (bigMode & ~MODES_QV)) argerror(_("unexpected query flags")); if (qva->qva_queryFormat && (bigMode & ~MODES_QV)) argerror(_("unexpected query format")); if (qva->qva_source != RPMQV_PACKAGE && (bigMode & ~MODES_QV)) argerror(_("unexpected query source")); } #endif /* IAM_RPMQV */ #ifdef IAM_RPMEIU if (bigMode == MODE_UNKNOWN || (bigMode & MODES_IE)) { int iflags = (ia->installInterfaceFlags & (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL)); int eflags = (ia->installInterfaceFlags & INSTALL_ERASE); if (iflags & eflags) argerror(_("only one major mode may be specified")); else if (iflags) bigMode = MODE_INSTALL; else if (eflags) bigMode = MODE_ERASE; } #endif /* IAM_RPMEIU */ #ifdef IAM_RPMK if (bigMode == MODE_UNKNOWN || (bigMode & MODES_K)) { switch (ka->qva_mode) { case RPMSIGN_NONE: ka->sign = 0; break; case RPMSIGN_IMPORT_PUBKEY: case RPMSIGN_CHK_SIGNATURE: bigMode = MODE_CHECKSIG; ka->sign = 0; break; case RPMSIGN_ADD_SIGNATURE: case RPMSIGN_NEW_SIGNATURE: case RPMSIGN_DEL_SIGNATURE: bigMode = MODE_RESIGN; ka->sign = (ka->qva_mode != RPMSIGN_DEL_SIGNATURE); break; } } #endif /* IAM_RPMK */ #if defined(IAM_RPMEIU) if (!( bigMode == MODE_INSTALL ) && (ia->probFilter & (RPMPROB_FILTER_REPLACEPKG | RPMPROB_FILTER_OLDPACKAGE))) argerror(_("only installation, upgrading, rmsource and rmspec may be forced")); if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_FORCERELOCATE)) argerror(_("files may only be relocated during package installation")); if (ia->relocations && ia->qva_prefix) argerror(_("cannot use --prefix with --relocate or --excludepath")); if (bigMode != MODE_INSTALL && ia->relocations) argerror(_("--relocate and --excludepath may only be used when installing new packages")); if (bigMode != MODE_INSTALL && ia->qva_prefix) argerror(_("--prefix may only be used when installing new packages")); if (ia->qva_prefix && ia->qva_prefix[0] != '/') argerror(_("arguments to --prefix must begin with a /")); if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & INSTALL_HASH)) argerror(_("--hash (-h) may only be specified during package " "installation")); if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & INSTALL_PERCENT)) argerror(_("--percent may only be specified during package " "installation")); if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_REPLACEPKG)) argerror(_("--replacepkgs may only be specified during package " "installation")); if (bigMode != MODE_INSTALL && (ia->transFlags & RPMTRANS_FLAG_NODOCS)) argerror(_("--excludedocs may only be specified during package " "installation")); if (bigMode != MODE_INSTALL && ia->incldocs) argerror(_("--includedocs may only be specified during package " "installation")); if (ia->incldocs && (ia->transFlags & RPMTRANS_FLAG_NODOCS)) argerror(_("only one of --excludedocs and --includedocs may be " "specified")); if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREARCH)) argerror(_("--ignorearch may only be specified during package " "installation")); if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREOS)) argerror(_("--ignoreos may only be specified during package " "installation")); if ((ia->installInterfaceFlags & INSTALL_ALLMATCHES) && bigMode != MODE_ERASE) argerror(_("--allmatches may only be specified during package " "erasure")); if ((ia->transFlags & RPMTRANS_FLAG_ALLFILES) && bigMode != MODE_INSTALL) argerror(_("--allfiles may only be specified during package " "installation")); if ((ia->transFlags & RPMTRANS_FLAG_JUSTDB) && bigMode != MODE_INSTALL && bigMode != MODE_ERASE) argerror(_("--justdb may only be specified during package " "installation and erasure")); if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE && (ia->transFlags & (RPMTRANS_FLAG_NOSCRIPTS | _noTransScripts | _noTransTriggers))) argerror(_("script disabling options may only be specified during " "package installation and erasure")); if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE && (ia->transFlags & (RPMTRANS_FLAG_NOTRIGGERS | _noTransTriggers))) argerror(_("trigger disabling options may only be specified during " "package installation and erasure")); if (ia->noDeps & (bigMode & ~MODES_FOR_NODEPS)) argerror(_("--nodeps may only be specified during package " "building, rebuilding, recompilation, installation, " "erasure, and verification")); if ((ia->transFlags & RPMTRANS_FLAG_TEST) && (bigMode & ~MODES_FOR_TEST)) argerror(_("--test may only be specified during package installation, " "erasure, and building")); #endif /* IAM_RPMEIU */ if (rpmioRootDir && rpmioRootDir[1] && (bigMode & ~MODES_FOR_ROOT)) argerror(_("--root (-r) may only be specified during " "installation, erasure, querying, and " "database rebuilds")); if (rpmioRootDir) { switch (urlIsURL(rpmioRootDir)) { default: if (bigMode & MODES_FOR_ROOT) break; /*@fallthrough@*/ case URL_IS_UNKNOWN: if (rpmioRootDir[0] != '/') argerror(_("arguments to --root (-r) must begin with a /")); break; } } #if defined(RPM_VENDOR_OPENPKG) /* integrity-checking */ integrity_check(__progname, bigMode); #endif #if defined(IAM_RPMBT) || defined(IAM_RPMK) if (0 #if defined(IAM_RPMBT) || ba->sign #endif #if defined(IAM_RPMK) || ka->sign #endif ) /*@-branchstate@*/ { if (bigMode == MODE_REBUILD || bigMode == MODE_BUILD || bigMode == MODE_RESIGN || bigMode == MODE_TARBUILD) { const char ** av; struct stat sb; int errors = 0; if ((av = poptGetArgs(optCon)) == NULL) { fprintf(stderr, _("no files to sign\n")); errors++; } else while (*av) { if (Stat(*av, &sb)) { fprintf(stderr, _("cannot access file %s\n"), *av); errors++; } av++; } if (errors) { ec = errors; goto exit; } if (poptPeekArg(optCon) #if defined(IAM_RPMBT) && !ba->nopassword #endif #if defined(IAM_RPMK) && !ka->nopassword #endif ) { passPhrase = Getpass(_("Enter pass phrase: ")); if (rpmCheckPassPhrase(passPhrase)) { fprintf(stderr, _("Pass phrase check failed\n")); ec = EXIT_FAILURE; goto exit; } fprintf(stderr, _("Pass phrase is good.\n")); /* XXX Getpass() should realloc instead. */ passPhrase = xstrdup(passPhrase); } } } /*@=branchstate@*/ #endif /* IAM_RPMBT || IAM_RPMK */ if (rpmioPipeOutput) { if (pipe(p) < 0) { fprintf(stderr, _("creating a pipe for --pipe failed: %m\n")); goto exit; } if (!(pipeChild = fork())) { (void) close(p[1]); (void) dup2(p[0], STDIN_FILENO); (void) close(p[0]); (void) execl("/bin/sh", "/bin/sh", "-c", rpmioPipeOutput, NULL); fprintf(stderr, _("exec failed\n")); } (void) close(p[0]); (void) dup2(p[1], STDOUT_FILENO); (void) close(p[1]); } ts = rpmtsCreate(); (void) rpmtsSetRootDir(ts, rpmioRootDir); switch (bigMode) { #ifdef IAM_RPMDB case MODE_REBUILDDB: { rpmVSFlags vsflags = rpmExpandNumeric("%{_vsflags_rebuilddb}"); rpmVSFlags ovsflags; if (rpmcliQueryFlags & VERIFY_DIGEST) vsflags |= _RPMVSF_NODIGESTS; if (rpmcliQueryFlags & VERIFY_SIGNATURE) vsflags |= _RPMVSF_NOSIGNATURES; ovsflags = rpmtsSetVSFlags(ts, vsflags); ec = rpmtsRebuildDB(ts); vsflags = rpmtsSetVSFlags(ts, ovsflags); } break; #endif /* IAM_RPMDB */ #ifdef IAM_RPMBT case MODE_REBUILD: case MODE_RECOMPILE: { const char * pkg; int nbuilds = 0; while (!rpmIsVerbose()) rpmIncreaseVerbosity(); if (!poptPeekArg(optCon)) argerror(_("no packages files given for rebuild")); ba->buildAmount = RPMBUILD_PREP | RPMBUILD_BUILD | RPMBUILD_INSTALL | RPMBUILD_CHECK; if (bigMode == MODE_REBUILD) { ba->buildAmount |= RPMBUILD_PACKAGEBINARY; ba->buildAmount |= RPMBUILD_RMSOURCE; ba->buildAmount |= RPMBUILD_RMSPEC; ba->buildAmount |= RPMBUILD_CLEAN; ba->buildAmount |= RPMBUILD_RMBUILD; } while ((pkg = poptGetArg(optCon))) { if (nbuilds++ > 0) { rpmFreeMacros(NULL); rpmFreeRpmrc(); (void) rpmReadConfigFiles(NULL, NULL); } ba->specFile = NULL; ba->cookie = NULL; ec = rpmInstallSource(ts, pkg, &ba->specFile, &ba->cookie); if (ec == 0) { ba->rootdir = rpmioRootDir; ba->passPhrase = passPhrase; ec = build(ts, ba, NULL); } ba->cookie = _free(ba->cookie); ba->specFile = _free(ba->specFile); if (ec) /*@loopbreak@*/ break; } } break; case MODE_BUILD: case MODE_TARBUILD: { int nbuilds = 0; #if defined(RPM_VENDOR_OPENPKG) /* no-auto-verbose-increase-for-track-and-fetch */ if (ba->buildChar != 't' && ba->buildChar != 'f') #endif while (!rpmIsVerbose()) rpmIncreaseVerbosity(); switch (ba->buildChar) { case 'a': ba->buildAmount |= RPMBUILD_PACKAGESOURCE; /*@fallthrough@*/ case 'b': ba->buildAmount |= RPMBUILD_PACKAGEBINARY; ba->buildAmount |= RPMBUILD_CLEAN; #if defined(RPM_VENDOR_MANDRIVA) if ((ba->buildChar == 'a' || ba->buildChar == 'b') && ba->shortCircuit) #else if ((ba->buildChar == 'b') && ba->shortCircuit) #endif /*@innerbreak@*/ break; /*@fallthrough@*/ case 'i': ba->buildAmount |= RPMBUILD_INSTALL; ba->buildAmount |= RPMBUILD_CHECK; if ((ba->buildChar == 'i') && ba->shortCircuit) /*@innerbreak@*/ break; /*@fallthrough@*/ case 'c': ba->buildAmount |= RPMBUILD_BUILD; if ((ba->buildChar == 'c') && ba->shortCircuit) /*@innerbreak@*/ break; /*@fallthrough@*/ case 'p': ba->buildAmount |= RPMBUILD_PREP; /*@innerbreak@*/ break; case 'l': ba->buildAmount |= RPMBUILD_FILECHECK; /*@innerbreak@*/ break; case 's': ba->buildAmount |= RPMBUILD_PACKAGESOURCE; #if defined(RPM_VENDOR_OPENPKG) || defined(RPM_VENDOR_MANDRIVA) || defined(RPM_VENDOR_ARK) /* no-deps-on-building-srpms */ /* enforce no dependency checking when rolling a source RPM */ ba->noDeps = 1; #endif /*@innerbreak@*/ break; case 't': /* support extracting the "%track" script/section */ ba->buildAmount |= RPMBUILD_TRACK; /* enforce no dependency checking and expansion of %setup, %patch and %prep macros */ ba->noDeps = 1; rpmDefineMacro(NULL, "setup #", RMIL_CMDLINE); rpmDefineMacro(NULL, "patch #", RMIL_CMDLINE); rpmDefineMacro(NULL, "prep %%prep", RMIL_CMDLINE); /*@innerbreak@*/ break; case 'f': ba->buildAmount |= RPMBUILD_FETCHSOURCE; ba->noDeps = 1; /*@innerbreak@*/ break; } if (!poptPeekArg(optCon)) { if (bigMode == MODE_BUILD) argerror(_("no spec files given for build")); else argerror(_("no tar files given for build")); } while ((ba->specFile = poptGetArg(optCon))) { if (nbuilds++ > 0) { rpmFreeMacros(NULL); rpmFreeRpmrc(); (void) rpmReadConfigFiles(NULL, NULL); } ba->rootdir = rpmioRootDir; ba->passPhrase = passPhrase; ba->cookie = NULL; ec = build(ts, ba, NULL); if (ec) /*@loopbreak@*/ break; } } break; #endif /* IAM_RPMBT */ #ifdef IAM_RPMEIU case MODE_ERASE: ia->depFlags = global_depFlags; if (ia->noDeps) ia->installInterfaceFlags |= INSTALL_NODEPS; if (!poptPeekArg(optCon)) { if (ia->rbtid == 0) argerror(_("no packages given for erase")); ia->transFlags |= RPMTRANS_FLAG_NOFDIGESTS; ia->probFilter |= RPMPROB_FILTER_OLDPACKAGE; ia->rbCheck = rpmcliInstallCheck; ia->rbOrder = rpmcliInstallOrder; ia->rbRun = rpmcliInstallRun; ec += rpmRollback(ts, ia, NULL); } else { ec += rpmErase(ts, ia, (const char **) poptGetArgs(optCon)); } break; case MODE_INSTALL: /* RPMTRANS_FLAG_KEEPOBSOLETE */ ia->depFlags = global_depFlags; if (!ia->incldocs) { if (ia->transFlags & RPMTRANS_FLAG_NODOCS) { ; } else if (rpmExpandNumeric("%{_excludedocs}")) ia->transFlags |= RPMTRANS_FLAG_NODOCS; } if (ia->noDeps) ia->installInterfaceFlags |= INSTALL_NODEPS; /* we've already ensured !(!ia->prefix && !ia->relocations) */ /*@-branchstate@*/ if (ia->qva_prefix) { xx = rpmfiAddRelocation(&ia->relocations, &ia->nrelocations, NULL, ia->qva_prefix); xx = rpmfiAddRelocation(&ia->relocations, &ia->nrelocations, NULL, NULL); } else if (ia->relocations) { xx = rpmfiAddRelocation(&ia->relocations, &ia->nrelocations, NULL, NULL); } /*@=branchstate@*/ if (!poptPeekArg(optCon)) { if (ia->rbtid == 0) argerror(_("no packages given for install")); ia->transFlags |= RPMTRANS_FLAG_NOFDIGESTS; ia->probFilter |= RPMPROB_FILTER_OLDPACKAGE; ia->rbCheck = rpmcliInstallCheck; ia->rbOrder = rpmcliInstallOrder; ia->rbRun = rpmcliInstallRun; /*@i@*/ ec += rpmRollback(ts, ia, NULL); } else { /*@-compdef -compmempass@*/ /* FIX: ia->relocations[0].newPath undefined */ ec += rpmcliInstall(ts, ia, (const char **)poptGetArgs(optCon)); /*@=compdef =compmempass@*/ } break; #endif /* IAM_RPMEIU */ #ifdef IAM_RPMQV case MODE_QUERY: if (!poptPeekArg(optCon) && !(qva->qva_source == RPMQV_ALL || qva->qva_source == RPMQV_HDLIST)) argerror(_("no arguments given for query")); qva->depFlags = global_depFlags; qva->qva_specQuery = rpmspecQuery; ec = rpmcliQuery(ts, qva, (const char **) poptGetArgs(optCon)); qva->qva_specQuery = NULL; break; case MODE_VERIFY: { rpmVerifyFlags verifyFlags = VERIFY_ALL; qva->depFlags = global_depFlags; verifyFlags &= ~qva->qva_flags; qva->qva_flags = (rpmQueryFlags) verifyFlags; if (!poptPeekArg(optCon) && !(qva->qva_source == RPMQV_ALL || qva->qva_source == RPMQV_HDLIST)) argerror(_("no arguments given for verify")); ec = rpmcliVerify(ts, qva, (const char **) poptGetArgs(optCon)); } break; #endif /* IAM_RPMQV */ #ifdef IAM_RPMK case MODE_CHECKSIG: { rpmVerifyFlags verifyFlags = (VERIFY_FDIGEST|VERIFY_HDRCHK|VERIFY_DIGEST|VERIFY_SIGNATURE); verifyFlags &= ~ka->qva_flags; ka->qva_flags = (rpmQueryFlags) verifyFlags; } /*@fallthrough@*/ case MODE_RESIGN: if (!poptPeekArg(optCon)) argerror(_("no arguments given")); ka->passPhrase = passPhrase; ec = rpmcliSign(ts, ka, (const char **)poptGetArgs(optCon)); break; #endif /* IAM_RPMK */ #if !defined(IAM_RPMQV) case MODE_QUERY: case MODE_VERIFY: #endif #if !defined(IAM_RPMK) case MODE_CHECKSIG: case MODE_RESIGN: #endif #if !defined(IAM_RPMDB) case MODE_REBUILDDB: #endif #if !defined(IAM_RPMBT) case MODE_BUILD: case MODE_REBUILD: case MODE_RECOMPILE: case MODE_TARBUILD: #endif #if !defined(IAM_RPMEIU) case MODE_INSTALL: case MODE_ERASE: #endif case MODE_UNKNOWN: #ifdef DYING /* XXX rpmIsVerbose alone stops usage spewage with every --eval */ if (poptPeekArg(optCon) != NULL || argc <= 1 || rpmIsVerbose()) { printUsage(optCon, stderr, 0); ec = argc; } #endif break; } #if defined(IAM_RPMBT) || defined(IAM_RPMK) exit: #endif /* IAM_RPMBT || IAM_RPMK */ (void)rpmtsFree(ts); ts = NULL; if (pipeChild) { (void) fclose(stdout); (void) waitpid(pipeChild, &status, 0); } #ifdef IAM_RPMQV qva->qva_queryFormat = _free(qva->qva_queryFormat); #endif #ifdef IAM_RPMBT freeNames(); /* XXX _specPool/_pkgPool teardown should be done somewhere else. */ { extern rpmioPool _pkgPool; extern rpmioPool _specPool; _pkgPool = rpmioFreePool(_pkgPool); _specPool = rpmioFreePool(_specPool); } #endif #ifdef IAM_RPMEIU ia->relocations = rpmfiFreeRelocations(ia->relocations); #endif optCon = rpmcliFini(optCon); /* XXX limit the fiddle up to linux for now. */ #if !defined(HAVE_SETPROCTITLE) && defined(__linux__) (void) finiproctitle(); #endif /* XXX don't overflow single byte exit status */ /* XXX status 255 is special to xargs(1) */ if (ec > 254) ec = 254; rpmlog(RPMLOG_DEBUG, D_("exit code: %d\n"), ec); /*@-globstate@*/ return ec; /*@=globstate@*/ }