static void parse_opt(int argc, char **argv) { int c; poptContext optCon; const char *no_arg; struct poptOption optionsTable[] = { { "loops" , 'n', POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_INT, &arg_loops , 0, "pp loops", "count" }, { "time" , 't', POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_INT, &arg_maxtime, 0, "max time", "ms" }, { "maxsize" , 0, POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_INT, &arg_maxmsize , 0, "maximal messagesize", "size" }, { "once" , '1', POPT_ARGFLAG_OR | POPT_ARG_VAL, &arg_run_once, 1, "stop after one client", NULL }, { "verbose" , 'v', POPT_ARG_NONE, NULL , 'v', "increase verbosity", NULL }, POPT_AUTOHELP POPT_TABLEEND }; optCon = poptGetContext(NULL, argc, (const char **) argv, optionsTable, 0); poptSetOtherOptionHelp(optCon, "[serveraddr]"); while ((c = poptGetNextOpt(optCon)) >= 0) { switch (c) { // c = poptOption.val; case 'v': arg_verbose++; break; //default: fprintf(stderr, "unhandled popt value %d\n", c); break; } } if (c < -1) { /* an error occurred during option processing */ fprintf(stderr, "%s: %s\n", poptBadOption(optCon, POPT_BADOPTION_NOALIAS), poptStrerror(c)); poptPrintHelp(optCon, stderr, 0); exit(1); } // arg_1 = poptGetArg(optCon); // arg_2 = poptGetArg(optCon); /* if (arg_client)*/ { const char *server = poptGetArg(optCon); if (server) arg_server_addr = server; } no_arg = poptGetArg(optCon); // should return NULL if (no_arg) { fprintf(stderr, "%s: %s\n", no_arg, poptStrerror(POPT_ERROR_BADOPT)); poptPrintHelp(optCon, stderr, 0); exit(1); } poptFreeContext(optCon); }
static void parse_opt(int argc, char **argv) { int c; poptContext optCon; const char *no_arg; struct poptOption optionsTable[] = { { "loops" , 'n', POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_INT, &arg_loops , 0, "pp loops", "count" }, { "time" , 't', POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_INT, &arg_maxtime, 0, "max time", "ms" }, { "maxsize" , 0, POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_INT, &arg_maxmsize , 0, "maximal messagesize", "size" }, { "nokill" , 'k', POPT_ARGFLAG_OR | POPT_ARG_VAL, &arg_nokill, 1, "Dont kill the server afterwards", NULL }, { "port" , 'p', POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_STRING, &arg_port, 0, "server port to use", "port" }, { "verbose" , 'v', POPT_ARG_NONE, NULL , 'v', "increase verbosity", NULL }, POPT_AUTOHELP POPT_TABLEEND }; optCon = poptGetContext(NULL, argc, (const char **) argv, optionsTable, 0); poptSetOtherOptionHelp(optCon, "[serveraddr]"); while ((c = poptGetNextOpt(optCon)) >= 0) { switch (c) { // c = poptOption.val; case 'v': arg_verbose++; break; } } if (c < -1) { /* an error occurred during option processing */ fprintf(stderr, "%s: %s\n", poptBadOption(optCon, POPT_BADOPTION_NOALIAS), poptStrerror(c)); poptPrintHelp(optCon, stderr, 0); exit(1); } // arg_1 = poptGetArg(optCon); // arg_2 = poptGetArg(optCon); arg_servername = poptGetArg(optCon); is_server = !arg_servername; no_arg = poptGetArg(optCon); // should return NULL if (no_arg) { fprintf(stderr, "%s: %s\n", no_arg, poptStrerror(POPT_ERROR_BADOPT)); poptPrintHelp(optCon, stderr, 0); exit(1); } poptFreeContext(optCon); }
static rs_result rdiff_patch(poptContext opcon) { /* patch BASIS [DELTA [NEWFILE]] */ FILE *basis_file, *delta_file, *new_file; char const *basis_name; rs_stats_t stats; rs_result result; if (!(basis_name = poptGetArg(opcon))) { rdiff_usage("Usage for patch: " "rdiff [OPTIONS] patch BASIS [DELTA [NEW]]"); return RS_SYNTAX_ERROR; } basis_file = rs_file_open(basis_name, "rb"); delta_file = rs_file_open(poptGetArg(opcon), "rb"); new_file = rs_file_open(poptGetArg(opcon), "wb"); rdiff_no_more_args(opcon); result = rs_patch_file(basis_file, delta_file, new_file, &stats); rs_file_close(new_file); rs_file_close(delta_file); rs_file_close(basis_file); if (show_stats) rs_log_stats(&stats); return result; }
void parse_opt(int argc, char **argv) { int c; poptContext optCon; const char *no_arg; struct poptOption optionsTable[] = { { "send" , 's', POPT_ARGFLAG_OR | POPT_ARG_VAL, &arg_send, 1, "first send", NULL }, { "lport" , 'l', POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_INT, &arg_listenport, 0, "listen on port", "port" }, { "lname" , 'n', POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_STRING, &arg_listenname, 0, "listen on name", "name" }, { "verbose" , 'v', POPT_ARG_NONE, NULL , 'v', "increase verbosity", NULL }, POPT_AUTOHELP POPT_TABLEEND }; optCon = poptGetContext(NULL, argc, (const char **) argv, optionsTable, 0); poptSetOtherOptionHelp(optCon, "[peer address]"); while ((c = poptGetNextOpt(optCon)) >= 0) { switch (c) { // c = poptOption.val; case 'v': arg_verbose++; break; //default: fprintf(stderr, "unhandled popt value %d\n", c); break; } } if (c < -1) { /* an error occurred during option processing */ fprintf(stderr, "%s: %s\n", poptBadOption(optCon, POPT_BADOPTION_NOALIAS), poptStrerror(c)); poptPrintHelp(optCon, stderr, 0); exit(1); } { const char *s; s = poptGetArg(optCon); if (s) { arg_peer_str = s; } } no_arg = poptGetArg(optCon); // should return NULL if (no_arg) { fprintf(stderr, "%s: %s\n", no_arg, poptStrerror(POPT_ERROR_BADOPT)); poptPrintHelp(optCon, stderr, 0); exit(1); } poptFreeContext(optCon); }
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; }
int main(int argc, const char *argv[]) { const char *config_file = get_dyn_CONFIGFILE(); const char *sequence = ""; poptContext pc; char *buff; TALLOC_CTX *ctx = talloc_stackframe(); struct poptOption long_options[] = { POPT_AUTOHELP POPT_COMMON_VERSION POPT_TABLEEND }; load_case_tables(); pc = poptGetContext(NULL, argc, argv, long_options, POPT_CONTEXT_KEEP_FIRST); poptSetOtherOptionHelp(pc, "[OPTION...] <sequence-string>"); while(poptGetNextOpt(pc) != -1); setup_logging(poptGetArg(pc), true); sequence = poptGetArg(pc); if (sequence == NULL) { fprintf(stderr, "ERROR: missing sequence string\n"); return 1; } dbf = x_stderr; DEBUGLEVEL = 0; AllowDebugChange = false; if (!lp_load(config_file,false,true,false,true)) { fprintf(stderr,"Error loading services.\n"); return 1; } while(next_token_talloc(ctx, &sequence, &buff, NULL)) { printf("[%s]\n", buff); } talloc_free(ctx); return 0; }
int inputBox(const char * text, int height, int width, poptContext optCon, int flags, char ** result) { newtComponent form, entry, okay, cancel, answer, tb; char * val; int rc = DLG_OKAY; int top; val = poptGetArg(optCon); tb = textbox(height - 3 - buttonHeight, width - 2, text, flags, &top); form = newtForm(NULL, NULL, 0); entry = newtEntry(1, top + 1, val, width - 2, &val, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); newtFormAddComponents(form, tb, entry, NULL); addButtons(height, width, form, &okay, &cancel, flags); answer = newtRunForm(form); if (answer == cancel) rc = DLG_CANCEL; *result = val; return rc; }
static void rdiff_no_more_args(poptContext opcon) { if (poptGetArg(opcon)) { rdiff_usage("rdiff: too many arguments"); exit(RS_SYNTAX_ERROR); } }
/* options parameter can't be a local variable because caller can use the * returned poptContext which contains pointer inside the options array */ static poptContext do_parse_options(int argc, char const ** argv, vector<poptOption> & options, vector<string> & additional_params) { options = popt_options; int const nr_appended_options = sizeof(appended_options) / sizeof(appended_options[0]); options.insert(options.end(), appended_options, appended_options + nr_appended_options); poptContext con = op_poptGetContext(NULL, argc, argv, &options[0], 0); if (showvers) { show_version(argv[0]); } char const * file; while ((file = poptGetArg(con)) != 0) { additional_params.push_back(file); } for (size_t i = 0 ; i < options_list.size() ; ++i) { options_list[i]->post_process(); } return con; }
/* * The 'view <options>' first level command */ int cmd_view(int argc, const char **argv) { int opt, ret = CMD_SUCCESS; static poptContext pc; pc = poptGetContext(NULL, argc, argv, long_options, 0); poptReadDefaultConfig(pc, 0); if (lttng_opt_mi) { WARN("mi does not apply to view command"); } while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_HELP: SHOW_HELP(); goto end; case OPT_LIST_OPTIONS: list_cmd_options(stdout, long_options); goto end; default: ret = CMD_UNDEFINED; goto end; } } opt_session_name = (char*) poptGetArg(pc); ret = view_trace(); end: poptFreeContext(pc); return ret; }
char * init(const int argc, const char **argv, const echoping_options global_external_options) { int value; char *msg = malloc(256); char *rest; /* popt variables */ struct poptOption options[] = { {"conninfo", 'c', POPT_ARG_STRING, &conninfo, 0, "Connection information for the Postgresql server. Something like 'host=foo dbname=bar''", ""}, {"readall", 'a', POPT_ARG_NONE, &readall, 0, "Read all the data sent by the Postgresql server", ""}, {"connect-each-time", 'e', POPT_ARG_NONE, &connect_each_time, 0, "(Re)Connect to the Postgresql server at each iteration", ""}, POPT_AUTOHELP POPT_TABLEEND }; global_options = global_external_options; if (global_options.udp) err_quit("UDP makes no sense for a PostgreSQL connection"); postgresql_poptcon = poptGetContext(NULL, argc, argv, options, POPT_CONTEXT_POSIXMEHARDER); while ((value = poptGetNextOpt(postgresql_poptcon)) > 0) { } if (value < -1) { sprintf(msg, "%s: %s", poptBadOption(postgresql_poptcon, POPT_BADOPTION_NOALIAS), poptStrerror(value)); postgresql_usage(msg); } request = poptGetArg(postgresql_poptcon); if (request == NULL) request = "SELECT now()"; rest = poptGetArg(postgresql_poptcon); if (rest != NULL) postgresql_usage("Erroneous additional arguments"); if (conninfo == NULL) conninfo = ""; return NULL; /* We only use the conninfo, echoping does not see * our hostname or port */ }
static rs_result rdiff_delta(poptContext opcon) { FILE *sig_file, *new_file, *delta_file; char const *sig_name; rs_result result; rs_signature_t *sumset; rs_stats_t stats; if (!(sig_name = poptGetArg(opcon))) { rdiff_usage("Usage for delta: " "rdiff [OPTIONS] delta SIGNATURE [NEWFILE [DELTA]]"); return RS_SYNTAX_ERROR; } sig_file = rs_file_open(sig_name, "rb"); new_file = rs_file_open(poptGetArg(opcon), "rb"); delta_file = rs_file_open(poptGetArg(opcon), "wb"); rdiff_no_more_args(opcon); result = rs_loadsig_file(sig_file, &sumset, &stats); if (result != RS_DONE) return result; if (show_stats) rs_log_stats(&stats); if ((result = rs_build_hash_table(sumset)) != RS_DONE) return result; result = rs_delta_file(sumset, new_file, delta_file, &stats); rs_free_sumset(sumset); rs_file_close(delta_file); rs_file_close(new_file); rs_file_close(sig_file); if (show_stats) rs_log_stats(&stats); return result; }
/* TODO: permit overriding macro setup on the command line */ static int doSign(poptContext optCon) { int rc = EXIT_FAILURE; char * passPhrase = NULL; char * name = rpmExpand("%{?_gpg_name}", NULL); struct rpmSignArgs sig = {NULL, 0, 0}; char *key = NULL; if (rstreq(name, "")) { fprintf(stderr, _("You must set \"%%_gpg_name\" in your macro file\n")); goto exit; } if (fileSigningKey) { addMacro(NULL, "_file_signing_key", NULL, fileSigningKey, RMIL_GLOBAL); } if (signfiles) { key = rpmExpand("%{?_file_signing_key}", NULL); if (rstreq(key, "")) { fprintf(stderr, _("You must set \"$$_file_signing_key\" in your macro file or on the command line with --fskpath\n")); goto exit; } if (fskpass) { #ifndef WITH_IMAEVM argerror(_("--fskpass may only be specified when signing files")); #else fileSigningKeyPassword = get_fskpass(); #endif } addMacro(NULL, "_file_signing_key_password", NULL, fileSigningKeyPassword, RMIL_CMDLINE); if (fileSigningKeyPassword) { memset(fileSigningKeyPassword, 0, strlen(fileSigningKeyPassword)); free(fileSigningKeyPassword); } sig.signfiles = 1; } const char *arg; rc = 0; while ((arg = poptGetArg(optCon)) != NULL) { rc += rpmPkgSign(arg, &sig); } exit: free(key); free(passPhrase); free(name); return rc; }
/** * Generate signature from remaining command line arguments. */ static rs_result rdiff_sig(poptContext opcon) { FILE *basis_file, *sig_file; rs_stats_t stats; rs_result result; basis_file = rs_file_open(poptGetArg(opcon), "rb"); sig_file = rs_file_open(poptGetArg(opcon), "wb"); rdiff_no_more_args(opcon); result = rs_sig_file(basis_file, sig_file, block_len, strong_len, &stats); if (result != RS_DONE) return result; if (show_stats) rs_log_stats(&stats); return result; }
/* * cmd_disable_events * * Disable event to trace session */ int cmd_disable_events(int argc, const char **argv) { int opt, ret = CMD_SUCCESS; static poptContext pc; char *session_name = NULL; pc = poptGetContext(NULL, argc, argv, long_options, 0); poptReadDefaultConfig(pc, 0); while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_HELP: usage(stdout); goto end; case OPT_USERSPACE: opt_userspace = 1; break; case OPT_LIST_OPTIONS: list_cmd_options(stdout, long_options); goto end; default: usage(stderr); ret = CMD_UNDEFINED; goto end; } } opt_event_list = (char*) poptGetArg(pc); if (opt_event_list == NULL && opt_disable_all == 0) { ERR("Missing event name(s).\n"); usage(stderr); ret = CMD_ERROR; goto end; } if (!opt_session_name) { session_name = get_session_name(); if (session_name == NULL) { ret = CMD_ERROR; goto end; } } else { session_name = opt_session_name; } ret = disable_events(session_name); end: if (!opt_session_name && session_name) { free(session_name); } poptFreeContext(pc); return ret; }
int main(int argc, char *argv[]){ char errbuf[PCAP_ERRBUF_SIZE], *device="any",*output_filename="/tmp/test.dump",*filter; const char *tmp; struct bpf_program fcode; int count=0; int timer=10; int c; poptContext context; struct poptOption optionsTable[] = { {"output", 'o', POPT_ARG_STRING, &output_filename, 'o'}, {"count", 'c', POPT_ARG_INT, &count, 'c'}, {"time", 't', POPT_ARG_INT, &timer, 't'}, {NULL,0,0,NULL,0} }; context = poptGetContext(NULL, argc, (const char **) argv, optionsTable, 0); poptSetOtherOptionHelp(context, "<tcpdump filter>"); while (poptGetNextOpt(context) >= 0) {} filter = (char *)malloc(256); strcpy (filter,""); while ((tmp = poptGetArg(context))!=NULL) { if (strcmp(filter,"")) filter = strcat(filter," "); filter = strcat(filter,tmp); } if (strcmp(filter,"")==0) filter = "port 3306"; poptFreeContext(context); printf("file=%s, count=%d, time=%d, filter=%s\n",output_filename,count,timer,filter); signal(SIGTERM, cleanup); signal(SIGALRM, cleanup); signal(SIGINT, cleanup); memset(errbuf,0,PCAP_ERRBUF_SIZE); descr = pcap_open_live(device,BUFSIZ,0,100,errbuf); if (descr == NULL) { fprintf(stderr, "Couldn't open device %s: %s\n", device, errbuf); return(2); } if (pcap_compile(descr, &fcode, filter, 0, 0) < 0){ fprintf(stderr,"can not analyze filter:%s\n", filter); exit(1); } if (pcap_setfilter(descr,&fcode) == -1) { fprintf(stderr, "filter can not use: %s\n", filter); exit(1); } dumper = pcap_dump_open(descr,output_filename); alarm(timer); pcap_loop(descr,count,write_captured_packet,NULL); pcap_close(descr); pcap_dump_close(dumper); exit(0); }
char* HREnextArg(){ if (optCon) { pthread_mutex_lock(&next_arg_mutex); char* res=HREstrdup(poptGetArg(optCon)); if (!res) { poptFreeContext(optCon); optCon=NULL; } pthread_mutex_unlock(&next_arg_mutex); return res; } return NULL; }
/** 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 DecodeCommandLine(int argc, const char **argv) { signed int c; poptContext optCon; // context for parsing command-line options struct poptOption optionsTable[] = { { "configfile", 'c', POPT_ARG_STRING, &sConfigFile, 0, NULL, NULL }, { "hostname", 'n', POPT_ARG_STRING, &sHostName, 0, NULL, NULL }, { "all", 'a', 0, 0, 'a', NULL, NULL }, { "verbose", 'v', 0, 0, 'v', NULL, NULL }, { "help", 'h', 0, 0, 'h', NULL, NULL }, { NULL, 0, 0, NULL, 0, NULL, NULL } }; if( argc < 2 ){ usage(argc,argv); } optCon = poptGetContext((const char *)NULL, argc, (const char **)argv, (const struct poptOption *)optionsTable, 0 ); while( ( c = poptGetNextOpt(optCon) ) >= 0 ) { switch(c){ case 'a': fDumpAll = TRUE; break; case 'h': usage(argc,argv); break; case 'v': verbose = TRUE; break; } } // // Make sure they supplied the name of a configuration key // if( ! fDumpAll ){ if( ( pOptionName = (char *)poptGetArg(optCon) ) == NULL ){ usage(argc,argv); } } poptFreeContext(optCon); }
void Popt::init(int argc, char *argv[], struct poptOption *optionsTable, const char *oh) { if(_optCon != NULL) { poptFreeContext(_optCon); } _optCon = poptGetContext(NULL, argc, const_cast<const char**>(argv), optionsTable, 0); assert(_optCon != NULL); poptSetOtherOptionHelp(_optCon, oh); const int opt = poptGetNextOpt(_optCon); if(opt != -1) { throw std::runtime_error("invalid command line"); } _args.clear(); const char *arg; while((arg = poptGetArg(_optCon)) != NULL) { _args.push_back(arg); } }
static rs_result rdiff_action(poptContext opcon) { const char *action; action = poptGetArg(opcon); if (!action) ; else if (isprefix(action, "signature")) return rdiff_sig(opcon); else if (isprefix(action, "delta")) return rdiff_delta(opcon); else if (isprefix(action, "patch")) return rdiff_patch(opcon); rdiff_usage("rdiff: You must specify an action: `signature', `delta', or `patch'."); return RS_SYNTAX_ERROR; }
int main(int argc, const char **argv) { int opt; poptContext pc; const char *patch; struct registry_context *h; const char *file = NULL; const char *remote = NULL; struct tevent_context *ev_ctx; struct poptOption long_options[] = { POPT_AUTOHELP {"remote", 'R', POPT_ARG_STRING, &remote, 0, "connect to specified remote server", NULL}, {"file", 'F', POPT_ARG_STRING, &file, 0, "file path", NULL }, POPT_COMMON_SAMBA POPT_COMMON_CREDENTIALS { NULL } }; pc = poptGetContext(argv[0], argc, argv, long_options,0); while((opt = poptGetNextOpt(pc)) != -1) { } ev_ctx = s4_event_context_init(NULL); if (remote) { h = reg_common_open_remote (remote, ev_ctx, cmdline_lp_ctx, cmdline_credentials); } else { h = reg_common_open_local (cmdline_credentials, ev_ctx, cmdline_lp_ctx); } if (h == NULL) return 1; patch = poptGetArg(pc); if (patch == NULL) { poptPrintUsage(pc, stderr, 0); return 1; } poptFreeContext(pc); reg_diff_apply(h, patch); return 0; }
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) { TALLOC_CTX *mem_ctx = NULL; int pc_debug = SSSDBG_DEFAULT; const char *pc_domain = NULL; const char *pc_user = NULL; struct poptOption long_options[] = { POPT_AUTOHELP { "debug", '\0', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_debug, 0, _("The debug level to run with"), NULL }, { "domain", 'd', POPT_ARG_STRING, &pc_domain, 0, _("The SSSD domain to use"), NULL }, POPT_TABLEEND }; poptContext pc = NULL; const char *user; struct sss_ssh_ent *ent; size_t i; char *repr; int ret; debug_prg_name = argv[0]; ret = set_locale(); if (ret != EOK) { DEBUG(SSSDBG_CRIT_FAILURE, ("set_locale() failed (%d): %s\n", ret, strerror(ret))); ERROR("Error setting the locale\n"); ret = EXIT_FAILURE; goto fini; } mem_ctx = talloc_new(NULL); if (!mem_ctx) { ERROR("Not enough memory\n"); ret = EXIT_FAILURE; goto fini; } /* parse parameters */ pc = poptGetContext(NULL, argc, argv, long_options, 0); poptSetOtherOptionHelp(pc, "USER"); while ((ret = poptGetNextOpt(pc)) > 0) ; debug_level = debug_convert_old_level(pc_debug); if (ret != -1) { BAD_POPT_PARAMS(pc, poptStrerror(ret), ret, fini); } pc_user = poptGetArg(pc); if (pc_user == NULL) { BAD_POPT_PARAMS(pc, _("User not specified\n"), ret, fini); } /* append domain to username if domain is specified */ if (pc_domain) { user = talloc_asprintf(mem_ctx, "%s@%s", pc_user, pc_domain); if (!user) { ERROR("Not enough memory\n"); ret = EXIT_FAILURE; goto fini; } } else { user = pc_user; } /* look up public keys */ ret = sss_ssh_get_ent(mem_ctx, SSS_SSH_GET_USER_PUBKEYS, user, NULL, &ent); if (ret != EOK) { DEBUG(SSSDBG_CRIT_FAILURE, ("sss_ssh_get_ent() failed (%d): %s\n", ret, strerror(ret))); ERROR("Error looking up public keys\n"); ret = EXIT_FAILURE; goto fini; } /* print results */ for (i = 0; i < ent->num_pubkeys; i++) { repr = sss_ssh_format_pubkey(mem_ctx, ent, &ent->pubkeys[i], SSS_SSH_FORMAT_OPENSSH, NULL); if (!repr) { ERROR("Not enough memory\n"); ret = EXIT_FAILURE; goto fini; } printf("%s\n", repr); } ret = EXIT_SUCCESS; fini: poptFreeContext(pc); talloc_free(mem_ctx); return ret; }
/* Parse a all options. */ static bool parse_options (int argc, const char *argv[]) { int opt; struct poptOption optionsTable[] = { {"debug", 'd', POPT_ARG_INT, &opts.debug_level, 0, "Set debugging to LEVEL"}, {"cdrom-device", 'i', POPT_ARG_STRING|POPT_ARGFLAG_OPTIONAL, &source_name, OP_SOURCE_DEVICE, "show only info about CD-ROM device", "DEVICE"}, {"quiet", 'q', POPT_ARG_NONE, &opts.silent, 0, "Don't produce warning output" }, {"version", 'V', POPT_ARG_NONE, &opts.version_only, 0, "display version and copyright information and exit"}, POPT_AUTOHELP {NULL, 0, 0, NULL, 0} }; poptContext optCon = poptGetContext (NULL, argc, argv, optionsTable, 0); program_name = strrchr(argv[0],'/'); program_name = program_name ? strdup(program_name+1) : strdup(argv[0]); while ((opt = poptGetNextOpt (optCon)) != -1) { switch (opt) { case OP_SOURCE_DEVICE: if (opts.source_image != DRIVER_UNKNOWN) { report( stderr, "%s: another source type option given before.\n", program_name); report( stderr, "%s: give only one source type option.\n", program_name); break; } else { opts.source_image = DRIVER_DEVICE; source_name = fillout_device_name(source_name); break; } break; default: poptFreeContext(optCon); return false; } } { const char *remaining_arg = poptGetArg(optCon); if ( remaining_arg != NULL) { if (opts.source_image != DRIVER_UNKNOWN) { report( stderr, "%s: Source specified in option %s and as %s\n", program_name, source_name, remaining_arg); poptFreeContext(optCon); free(program_name); exit (EXIT_FAILURE); } if (opts.source_image == DRIVER_DEVICE) source_name = fillout_device_name(remaining_arg); else source_name = strdup(remaining_arg); if ( (poptGetArgs(optCon)) != NULL) { report( stderr, "%s: Source specified in previously %s and %s\n", program_name, source_name, remaining_arg); poptFreeContext(optCon); free(program_name); exit (EXIT_FAILURE); } } } poptFreeContext(optCon); return true; }
int main(int argc, const char **argv) { int ret = EXIT_SUCCESS; struct tools_ctx *tctx = NULL; const char *pc_username = NULL; int pc_debug = SSSDBG_DEFAULT; int pc_remove = 0; int pc_force = 0; int pc_kick = 0; poptContext pc = NULL; struct poptOption long_options[] = { POPT_AUTOHELP { "debug", '\0', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_debug, 0, _("The debug level to run with"), NULL }, { "remove", 'r', POPT_ARG_NONE, NULL, 'r', _("Remove home directory and mail spool"), NULL }, { "no-remove", 'R', POPT_ARG_NONE, NULL, 'R', _("Do not remove home directory and mail spool"), NULL }, { "force", 'f', POPT_ARG_NONE, NULL, 'f', _("Force removal of files not owned by the user"), NULL }, { "kick", 'k', POPT_ARG_NONE, NULL, 'k', _("Kill users' processes before removing him"), NULL }, POPT_TABLEEND }; debug_prg_name = argv[0]; ret = set_locale(); if (ret != EOK) { DEBUG(1, ("set_locale failed (%d): %s\n", ret, strerror(ret))); ERROR("Error setting the locale\n"); ret = EXIT_FAILURE; goto fini; } /* parse parameters */ pc = poptGetContext(NULL, argc, argv, long_options, 0); poptSetOtherOptionHelp(pc, "USERNAME"); while ((ret = poptGetNextOpt(pc)) > 0) { switch (ret) { case 'r': pc_remove = DO_REMOVE_HOME; break; case 'R': pc_remove = DO_NOT_REMOVE_HOME; break; case 'f': pc_force = DO_FORCE_REMOVAL; break; case 'k': pc_kick = 1; break; } } debug_level = debug_convert_old_level(pc_debug); if (ret != -1) { BAD_POPT_PARAMS(pc, poptStrerror(ret), ret, fini); } pc_username = poptGetArg(pc); if (pc_username == NULL) { BAD_POPT_PARAMS(pc, _("Specify user to delete\n"), ret, fini); } CHECK_ROOT(ret, debug_prg_name); ret = init_sss_tools(&tctx); if (ret != EOK) { DEBUG(1, ("init_sss_tools failed (%d): %s\n", ret, strerror(ret))); if (ret == ENOENT) { ERROR("Error initializing the tools - no local domain\n"); } else { ERROR("Error initializing the tools\n"); } ret = EXIT_FAILURE; goto fini; } /* if the domain was not given as part of FQDN, default to local domain */ ret = parse_name_domain(tctx, pc_username); if (ret != EOK) { ERROR("Invalid domain specified in FQDN\n"); ret = EXIT_FAILURE; goto fini; } /* * Fills in defaults for ops_ctx user did not specify. */ ret = userdel_defaults(tctx, tctx->confdb, tctx->octx, pc_remove); if (ret != EOK) { ERROR("Cannot set default values\n"); ret = EXIT_FAILURE; goto fini; } ret = sysdb_getpwnam_sync(tctx, tctx->sysdb, tctx->octx->name, tctx->octx); if (ret != EOK) { /* Error message will be printed in the switch */ goto done; } if ((tctx->octx->uid < tctx->local->id_min) || (tctx->local->id_max && tctx->octx->uid > tctx->local->id_max)) { ERROR("User %1$s is outside the defined ID range for domain\n", tctx->octx->name); ret = EXIT_FAILURE; goto fini; } if (pc_kick) { ret = kick_user(tctx); if (ret != EOK) { tctx->error = ret; goto done; } } /* userdel */ ret = userdel(tctx, tctx->sysdb, tctx->octx); if (ret != EOK) { goto done; } /* Set SELinux login context - must be done after transaction is done * b/c libselinux calls getpwnam */ ret = del_seuser(tctx->octx->name); if (ret != EOK) { ERROR("Cannot reset SELinux login context\n"); ret = EXIT_FAILURE; goto fini; } if (!pc_kick) { ret = is_logged_in(tctx, tctx->octx->uid); switch(ret) { case ENOENT: break; case EOK: ERROR("WARNING: The user (uid %1$lu) was still logged in when " "deleted.\n", (unsigned long) tctx->octx->uid); break; case ENOSYS: ERROR("Cannot determine if the user was logged in on this " "platform"); break; default: ERROR("Error while checking if the user was logged in\n"); break; } } ret = run_userdel_cmd(tctx); if (ret != EOK) { ERROR("The post-delete command failed: %1$s\n", strerror(ret)); goto fini; } if (tctx->octx->remove_homedir) { ret = remove_homedir(tctx, tctx->octx->home, tctx->octx->maildir, tctx->octx->name, tctx->octx->uid, pc_force); if (ret == EPERM) { ERROR("Not removing home dir - not owned by user\n"); } else if (ret != EOK) { ERROR("Cannot remove homedir: %1$s\n", strerror(ret)); ret = EXIT_FAILURE; goto fini; } } done: if (ret) { DEBUG(1, ("sysdb operation failed (%d)[%s]\n", ret, strerror(ret))); switch (ret) { case ENOENT: ERROR("No such user in local domain. " "Removing users only allowed in local domain.\n"); break; default: ERROR("Internal error. Could not remove user.\n"); break; } ret = EXIT_FAILURE; goto fini; } ret = EXIT_SUCCESS; fini: talloc_free(tctx); poptFreeContext(pc); exit(ret); }
int main(int argc, const char **argv) { static int list_users = False; static int verbose = False; static int spstyle = False; static int machine = False; static int add_user = False; static int delete_user = False; static int modify_user = False; uint32_t setparms, checkparms; int opt; static char *full_name = NULL; static char *acct_desc = NULL; static const char *user_name = NULL; static char *home_dir = NULL; static char *home_drive = NULL; static const char *backend = NULL; static char *backend_in = NULL; static char *backend_out = NULL; static int transfer_groups = False; static int transfer_account_policies = False; static int reset_account_policies = False; static int force_initialised_password = False; static char *logon_script = NULL; static char *profile_path = NULL; static char *user_domain = NULL; static char *account_control = NULL; static char *account_policy = NULL; static char *user_sid = NULL; static char *machine_sid = NULL; static long int account_policy_value = 0; bool account_policy_value_set = False; static int badpw_reset = False; static int hours_reset = False; static char *pwd_time_format = NULL; static int pw_from_stdin = False; struct pdb_methods *bin, *bout; static char *kickoff_time = NULL; TALLOC_CTX *frame = talloc_stackframe(); NTSTATUS status; poptContext pc; struct poptOption long_options[] = { POPT_AUTOHELP {"list", 'L', POPT_ARG_NONE, &list_users, 0, "list all users", NULL}, {"verbose", 'v', POPT_ARG_NONE, &verbose, 0, "be verbose", NULL }, {"smbpasswd-style", 'w',POPT_ARG_NONE, &spstyle, 0, "give output in smbpasswd style", NULL}, {"user", 'u', POPT_ARG_STRING, &user_name, 0, "use username", "USER" }, {"account-desc", 'N', POPT_ARG_STRING, &acct_desc, 0, "set account description", NULL}, {"fullname", 'f', POPT_ARG_STRING, &full_name, 0, "set full name", NULL}, {"homedir", 'h', POPT_ARG_STRING, &home_dir, 0, "set home directory", NULL}, {"drive", 'D', POPT_ARG_STRING, &home_drive, 0, "set home drive", NULL}, {"script", 'S', POPT_ARG_STRING, &logon_script, 0, "set logon script", NULL}, {"profile", 'p', POPT_ARG_STRING, &profile_path, 0, "set profile path", NULL}, {"domain", 'I', POPT_ARG_STRING, &user_domain, 0, "set a users' domain", NULL}, {"user SID", 'U', POPT_ARG_STRING, &user_sid, 0, "set user SID or RID", NULL}, {"machine SID", 'M', POPT_ARG_STRING, &machine_sid, 0, "set machine SID or RID", NULL}, {"create", 'a', POPT_ARG_NONE, &add_user, 0, "create user", NULL}, {"modify", 'r', POPT_ARG_NONE, &modify_user, 0, "modify user", NULL}, {"machine", 'm', POPT_ARG_NONE, &machine, 0, "account is a machine account", NULL}, {"delete", 'x', POPT_ARG_NONE, &delete_user, 0, "delete user", NULL}, {"backend", 'b', POPT_ARG_STRING, &backend, 0, "use different passdb backend as default backend", NULL}, {"import", 'i', POPT_ARG_STRING, &backend_in, 0, "import user accounts from this backend", NULL}, {"export", 'e', POPT_ARG_STRING, &backend_out, 0, "export user accounts to this backend", NULL}, {"group", 'g', POPT_ARG_NONE, &transfer_groups, 0, "use -i and -e for groups", NULL}, {"policies", 'y', POPT_ARG_NONE, &transfer_account_policies, 0, "use -i and -e to move account policies between backends", NULL}, {"policies-reset", 0, POPT_ARG_NONE, &reset_account_policies, 0, "restore default policies", NULL}, {"account-policy", 'P', POPT_ARG_STRING, &account_policy, 0,"value of an account policy (like maximum password age)",NULL}, {"value", 'C', POPT_ARG_LONG, &account_policy_value, 'C',"set the account policy to this value", NULL}, {"account-control", 'c', POPT_ARG_STRING, &account_control, 0, "Values of account control", NULL}, {"force-initialized-passwords", 0, POPT_ARG_NONE, &force_initialised_password, 0, "Force initialization of corrupt password strings in a passdb backend", NULL}, {"bad-password-count-reset", 'z', POPT_ARG_NONE, &badpw_reset, 0, "reset bad password count", NULL}, {"logon-hours-reset", 'Z', POPT_ARG_NONE, &hours_reset, 0, "reset logon hours", NULL}, {"time-format", 0, POPT_ARG_STRING, &pwd_time_format, 0, "The time format for time parameters", NULL }, {"password-from-stdin", 't', POPT_ARG_NONE, &pw_from_stdin, 0, "get password from standard in", NULL}, {"kickoff-time", 'K', POPT_ARG_STRING, &kickoff_time, 0, "set the kickoff time", NULL}, POPT_COMMON_SAMBA POPT_TABLEEND }; bin = bout = NULL; smb_init_locale(); setup_logging("pdbedit", DEBUG_STDOUT); pc = poptGetContext(NULL, argc, argv, long_options, POPT_CONTEXT_KEEP_FIRST); while((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case 'C': account_policy_value_set = True; break; } } poptGetArg(pc); /* Drop argv[0], the program name */ if (user_name == NULL) user_name = poptGetArg(pc); if (!lp_load_global(get_dyn_CONFIGFILE())) { fprintf(stderr, "Can't load %s - run testparm to debug it\n", get_dyn_CONFIGFILE()); exit(1); } if (!init_names()) exit(1); setparms = (backend ? BIT_BACKEND : 0) + (verbose ? BIT_VERBOSE : 0) + (spstyle ? BIT_SPSTYLE : 0) + (full_name ? BIT_FULLNAME : 0) + (home_dir ? BIT_HOMEDIR : 0) + (home_drive ? BIT_HDIRDRIVE : 0) + (logon_script ? BIT_LOGSCRIPT : 0) + (profile_path ? BIT_PROFILE : 0) + (user_domain ? BIT_USERDOMAIN : 0) + (machine ? BIT_MACHINE : 0) + (user_name ? BIT_USER : 0) + (list_users ? BIT_LIST : 0) + (force_initialised_password ? BIT_FIX_INIT : 0) + (user_sid ? BIT_USERSIDS : 0) + (machine_sid ? BIT_USERSIDS : 0) + (modify_user ? BIT_MODIFY : 0) + (add_user ? BIT_CREATE : 0) + (delete_user ? BIT_DELETE : 0) + (account_control ? BIT_ACCTCTRL : 0) + (account_policy ? BIT_ACCPOLICY : 0) + (account_policy_value_set ? BIT_ACCPOLVAL : 0) + (backend_in ? BIT_IMPORT : 0) + (backend_out ? BIT_EXPORT : 0) + (badpw_reset ? BIT_BADPWRESET : 0) + (hours_reset ? BIT_LOGONHOURS : 0) + (kickoff_time ? BIT_KICKOFFTIME : 0) + (acct_desc ? BIT_DESCRIPTION : 0); if (setparms & BIT_BACKEND) { /* HACK: set the global passdb backend by overwriting globals. * This way we can use regular pdb functions for default * operations that do not involve passdb migrations */ lp_set_cmdline("passdb backend", backend); } else { backend = lp_passdb_backend(); } if (!initialize_password_db(False, NULL)) { fprintf(stderr, "Can't initialize passdb backend.\n"); exit(1); } /* the lowest bit options are always accepted */ checkparms = setparms & ~MASK_ALWAYS_GOOD; if (checkparms & BIT_FIX_INIT) { return fix_users_list(); } /* account policy operations */ if ((checkparms & BIT_ACCPOLICY) && !(checkparms & ~(BIT_ACCPOLICY + BIT_ACCPOLVAL))) { uint32_t value; enum pdb_policy_type field = account_policy_name_to_typenum(account_policy); if (field == 0) { const char **names; int count; int i; account_policy_names_list(talloc_tos(), &names, &count); fprintf(stderr, "No account policy by that name!\n"); if (count !=0) { fprintf(stderr, "Account policy names are:\n"); for (i = 0; i < count ; i++) { d_fprintf(stderr, "%s\n", names[i]); } } TALLOC_FREE(names); exit(1); } if (!pdb_get_account_policy(field, &value)) { fprintf(stderr, "valid account policy, but unable to fetch value!\n"); if (!account_policy_value_set) exit(1); } printf("account policy \"%s\" description: %s\n", account_policy, account_policy_get_desc(field)); if (account_policy_value_set) { printf("account policy \"%s\" value was: %u\n", account_policy, value); if (!pdb_set_account_policy(field, account_policy_value)) { fprintf(stderr, "valid account policy, but unable to set value!\n"); exit(1); } printf("account policy \"%s\" value is now: %lu\n", account_policy, account_policy_value); exit(0); } else { printf("account policy \"%s\" value is: %u\n", account_policy, value); exit(0); } } if (reset_account_policies) { if (reinit_account_policies()) { exit(1); } exit(0); } /* import and export operations */ if (((checkparms & BIT_IMPORT) || (checkparms & BIT_EXPORT)) && !(checkparms & ~(BIT_IMPORT +BIT_EXPORT +BIT_USER))) { if (backend_in) { status = make_pdb_method_name(&bin, backend_in); } else { status = make_pdb_method_name(&bin, backend); } if (!NT_STATUS_IS_OK(status)) { fprintf(stderr, "Unable to initialize %s.\n", backend_in ? backend_in : backend); return 1; } if (backend_out) { status = make_pdb_method_name(&bout, backend_out); } else { status = make_pdb_method_name(&bout, backend); } if (!NT_STATUS_IS_OK(status)) { fprintf(stderr, "Unable to initialize %s.\n", backend_out ? backend_out : backend); return 1; } if (transfer_account_policies) { if (!(checkparms & BIT_USER)) { return export_account_policies(bin, bout); } } else if (transfer_groups) { if (!(checkparms & BIT_USER)) { return export_groups(bin, bout); } } else { return export_database(bin, bout, (checkparms & BIT_USER) ? user_name : NULL); } } /* if BIT_USER is defined but nothing else then threat it as -l -u for compatibility */ /* fake up BIT_LIST if only BIT_USER is defined */ if ((checkparms & BIT_USER) && !(checkparms & ~BIT_USER)) { checkparms += BIT_LIST; } /* modify flag is optional to maintain backwards compatibility */ /* fake up BIT_MODIFY if BIT_USER and at least one of MASK_USER_GOOD is defined */ if (!((checkparms & ~MASK_USER_GOOD) & ~BIT_USER) && (checkparms & MASK_USER_GOOD)) { checkparms += BIT_MODIFY; } /* list users operations */ if (checkparms & BIT_LIST) { if (!(checkparms & ~BIT_LIST)) { return print_users_list(verbose, spstyle); } if (!(checkparms & ~(BIT_USER + BIT_LIST))) { return print_user_info(user_name, verbose, spstyle); } } /* mask out users options */ checkparms &= ~MASK_USER_GOOD; /* if bad password count is reset, we must be modifying */ if (checkparms & BIT_BADPWRESET) { checkparms |= BIT_MODIFY; checkparms &= ~BIT_BADPWRESET; } /* if logon hours is reset, must modify */ if (checkparms & BIT_LOGONHOURS) { checkparms |= BIT_MODIFY; checkparms &= ~BIT_LOGONHOURS; } /* account operation */ if ((checkparms & BIT_CREATE) || (checkparms & BIT_MODIFY) || (checkparms & BIT_DELETE)) { /* check use of -u option */ if (!(checkparms & BIT_USER)) { fprintf (stderr, "Username not specified! (use -u option)\n"); return -1; } /* account creation operations */ if (!(checkparms & ~(BIT_CREATE + BIT_USER + BIT_MACHINE))) { if (checkparms & BIT_MACHINE) { return new_machine(user_name, machine_sid); } else { return new_user(user_name, full_name, home_dir, home_drive, logon_script, profile_path, user_sid, pw_from_stdin); } } /* account deletion operations */ if (!(checkparms & ~(BIT_DELETE + BIT_USER + BIT_MACHINE))) { if (checkparms & BIT_MACHINE) { return delete_machine_entry(user_name); } else { return delete_user_entry(user_name); } } /* account modification operations */ if (!(checkparms & ~(BIT_MODIFY + BIT_USER + BIT_MACHINE))) { if (checkparms & BIT_MACHINE) { return set_machine_info(user_name, account_control, machine_sid); } else { return set_user_info(user_name, full_name, home_dir, acct_desc, home_drive, logon_script, profile_path, account_control, user_sid, user_domain, badpw_reset, hours_reset, kickoff_time); } } } if (setparms >= 0x20) { fprintf (stderr, "Incompatible or insufficient options on command line!\n"); } poptPrintHelp(pc, stderr, 0); TALLOC_FREE(frame); return 1; }
/* int segs2name (poptContext *optCon, char **filename, int *seg_list); */ int main (int argc, char **argv) { int i, ret; LorsExnode *exnode; char *s; char *output_filename = "-"; char *filename; int same_name=0; int v; int file_cnt = 0; int opts = LORS_MANAGE_CAP; XndRc xndrc; poptContext optCon; /* context for parsing command-line options */ struct poptOption optionsTable[] = { { "samename", 'f', POPT_ARG_NONE, 0, SAME_OUTPUTNAME, "Save the modified exNode to the original exNode filename.", NULL }, { "outputfile", 'o', POPT_ARG_STRING, &output_filename, OUTPUTNAME, "Specify the name for the output exNode file.", NULL}, { "read-cap", 'r', POPT_ARG_NONE, 0, LORS_READ_CAP, "Delete the read capabilities from the exNode.", NULL}, { "write-cap", 'w', POPT_ARG_NONE, 0, LORS_WRITE_CAP, "Delete the write capabilities from the exNode.", NULL}, { "manage-cap", 'm', POPT_ARG_NONE, 0, LORS_MANAGE_CAP, "Delete the manage capabilities from the exNode.", NULL}, { "version", 'v', POPT_ARG_NONE, 0, LORS_VERSION, "Display Version information about this package.", NULL}, { "verbose", 'V', POPT_ARG_INT, &xndrc.verbose, VERBOSE, "Modify the level or mode of Verbosity in output messages.", "0"}, /* { "demo", 'D', POPT_ARG_NONE, 0, LORS_ARG_DEMO, "Add the messages understood by the LoRS View visualization.", NULL}, */ POPT_AUTOHELP { NULL, 0, 0, NULL, 0 } }; parse_xndrc_files(&xndrc); g_lors_demo = xndrc.demo; optCon = poptGetContext(NULL, argc, (const char **)argv, optionsTable, 0); poptSetOtherOptionHelp(optCon, "<filename>"); if ( argc < 2 ) { poptPrintUsage(optCon, stderr, 0); poptPrintHelp(optCon, stderr, 0); exit(EXIT_FAILURE); } while ( (v=poptGetNextOpt(optCon)) >= 0) { switch(v) { case LORS_READ_CAP: case LORS_WRITE_CAP: case LORS_MANAGE_CAP: opts |= v; break; case SAME_OUTPUTNAME: same_name = 1; break; case LORS_ARG_DEMO: g_lors_demo = (!g_lors_demo); break; case LORS_VERSION: { const char *package; double version; lorsGetLibraryVersion(&package, &version); fprintf(stderr, "Version: %s %f\n", package, version); exit(EXIT_FAILURE); break; } default: /*fprintf(stderr, "Unsupported option: %d\n", v);*/ break; } } g_db_level = xndrc.verbose; if ( v < -1 ) { fprintf(stderr, "error: %d\n", v); fprintf(stderr, "%s: %s\n", poptBadOption(optCon, POPT_BADOPTION_NOALIAS), poptStrerror(v)); } while ( (filename = (char *)poptGetArg(optCon)) != NULL ) { file_cnt++; /* output_filename= NULL;*/ if (same_name == 1) output_filename = filename; ret = lorsModifyFile(filename, output_filename, opts); if ( ret != LORS_SUCCESS ) { fprintf(stderr, "An error occured during modify: %d\n", ret); } } if ( file_cnt == 0 ) { fprintf(stderr, "Error. You must also provide a filename on " "which lors_modify operates.\n"); poptPrintHelp(optCon, stderr, 0); exit(EXIT_FAILURE); } free_xndrc(&xndrc); poptFreeContext(optCon); return 0; }