int do_ipmacsec(int argc, char **argv) { if (argc < 1) ipmacsec_usage(); if (matches(*argv, "help") == 0) ipmacsec_usage(); if (genl_init_handle(&genl_rth, MACSEC_GENL_NAME, &genl_family)) exit(1); if (matches(*argv, "show") == 0) return do_show(argc-1, argv+1); if (matches(*argv, "add") == 0) return do_modify(CMD_ADD, argc-1, argv+1); if (matches(*argv, "set") == 0) return do_modify(CMD_UPD, argc-1, argv+1); if (matches(*argv, "delete") == 0) return do_modify(CMD_DEL, argc-1, argv+1); fprintf(stderr, "Command \"%s\" is unknown, try \"ip macsec help\".\n", *argv); exit(-1); }
int main( int argc, char **argv ) { int i; char *uri = NULL; char *host = "localhost"; int port = -1; char *manager = NULL; struct berval passwd = { 0, NULL }; char *entry = NULL; char *ava = NULL; char *value = NULL; int loops = LOOPS; int outerloops = 1; int retries = RETRIES; int delay = 0; int friendly = 0; int chaserefs = 0; tester_init( "slapd-modify", TESTER_MODIFY ); while ( ( i = getopt( argc, argv, "a:CD:e:FH:h:i:L:l:p:r:t:w:" ) ) != EOF ) { switch ( i ) { case 'C': chaserefs++; break; case 'F': friendly++; break; case 'H': /* the server uri */ uri = strdup( optarg ); break; case 'h': /* the servers host */ host = strdup( optarg ); break; case 'i': /* ignored (!) by now */ break; case 'p': /* the servers port */ if ( lutil_atoi( &port, optarg ) != 0 ) { usage( argv[0] ); } break; case 'D': /* the servers manager */ manager = strdup( optarg ); break; case 'w': /* the server managers password */ passwd.bv_val = strdup( optarg ); passwd.bv_len = strlen( optarg ); memset( optarg, '*', passwd.bv_len ); break; case 'e': /* entry to modify */ entry = strdup( optarg ); break; case 'a': ava = strdup( optarg ); break; case 'l': /* the number of loops */ if ( lutil_atoi( &loops, optarg ) != 0 ) { usage( argv[0] ); } break; case 'L': /* the number of outerloops */ if ( lutil_atoi( &outerloops, optarg ) != 0 ) { usage( argv[0] ); } break; case 'r': /* number of retries */ if ( lutil_atoi( &retries, optarg ) != 0 ) { usage( argv[0] ); } break; case 't': /* delay in seconds */ if ( lutil_atoi( &delay, optarg ) != 0 ) { usage( argv[0] ); } break; default: usage( argv[0] ); break; } } if (( entry == NULL ) || ( ava == NULL ) || ( port == -1 && uri == NULL )) usage( argv[0] ); if ( *entry == '\0' ) { fprintf( stderr, "%s: invalid EMPTY entry DN.\n", argv[0] ); exit( EXIT_FAILURE ); } if ( *ava == '\0' ) { fprintf( stderr, "%s: invalid EMPTY AVA.\n", argv[0] ); exit( EXIT_FAILURE ); } if ( !( value = strchr( ava, ':' ))) { fprintf( stderr, "%s: invalid AVA.\n", argv[0] ); exit( EXIT_FAILURE ); } *value++ = '\0'; while ( *value && isspace( (unsigned char) *value )) value++; uri = tester_uri( uri, host, port ); for ( i = 0; i < outerloops; i++ ) { do_modify( uri, manager, &passwd, entry, ava, value, loops, retries, delay, friendly, chaserefs ); } exit( EXIT_SUCCESS ); }
/* * The function "mon()" is the dialog user interface, called * from the simulation just after program start. */ void mon(void) { register int eoj = 1; static char cmd[LENCMD]; tcgetattr(0, &old_term); if (x_flag) { if (do_getfile(xfn) == 0) do_go(); } while (eoj) { next: printf(">>> "); fflush(stdout); if (fgets(cmd, LENCMD, stdin) == NULL) { putchar('\n'); goto next; } switch (*cmd) { case '\n': do_step(); break; case 't': do_trace(cmd + 1); break; case 'g': do_go(); break; case 'd': do_dump(cmd + 1); break; case 'l': do_list(cmd + 1); break; case 'm': do_modify(cmd + 1); break; case 'f': do_fill(cmd + 1); break; case 'v': do_move(cmd + 1); break; case 'x': do_reg(cmd + 1); break; case 'p': do_port(cmd + 1); break; case 'b': do_break(cmd + 1); break; case 'h': do_hist(cmd + 1); break; case 'z': do_count(cmd + 1); break; case 'c': do_clock(); break; case 's': do_show(); break; case '?': do_help(); break; case 'r': do_getfile(cmd + 1); break; case '!': do_unix(cmd + 1); break; case 'q': eoj = 0; break; default: puts("what??"); break; } } }
int exec_annotate(int argc, char **argv) { struct pkgdb *db = NULL; struct pkgdb_it *it = NULL; struct pkg *pkg = NULL; enum action action = NONE; const char *tag; const char *value; const char *pkgname; struct sbuf *input = NULL; int ch; int match = MATCH_EXACT; int retcode; int exitcode = EX_OK; int flags = 0; struct option longopts[] = { { "all", no_argument, NULL, 'a' }, { "add", no_argument, NULL, 'A' }, { "case-insensitive", no_argument, NULL, 'C' }, { "delete", no_argument, NULL, 'D' }, { "glob", no_argument, NULL, 'g' }, { "case-insensitive", no_argument, NULL, 'i' }, { "modify", no_argument, NULL, 'M' }, { "quiet", no_argument, NULL, 'q' }, { "show", no_argument, NULL, 'S' }, { "regex", no_argument, NULL, 'x' }, { "yes", no_argument, NULL, 'y' }, { NULL, 0, NULL, 0 }, }; /* Set default case sensitivity for searching */ pkgdb_set_case_sensitivity( pkg_object_bool(pkg_config_get("CASE_SENSITIVE_MATCH")) ); while ((ch = getopt_long(argc, argv, "+aACDgiMqSxy", longopts, NULL)) != -1) { switch (ch) { case 'a': match = MATCH_ALL; break; case 'A': action = ADD; break; case 'C': pkgdb_set_case_sensitivity(true); break; case 'D': action = DELETE; break; case 'g': match = MATCH_GLOB; break; case 'i': pkgdb_set_case_sensitivity(false); break; case 'M': action = MODIFY; break; case 'q': quiet = true; break; case 'S': action = SHOW; flags |= PKG_LOAD_ANNOTATIONS; break; case 'x': match = MATCH_REGEX; break; case 'y': yes = true; break; default: usage_annotate(); return (EX_USAGE); } } argc -= optind; argv += optind; if (action == NONE || (match == MATCH_ALL && argc < 1) || (match != MATCH_ALL && argc < 2)) { usage_annotate(); return (EX_USAGE); } if (match == MATCH_ALL) { pkgname = NULL; tag = argv[0]; value = (argc > 1) ? argv[1] : NULL; } else { pkgname = argv[0]; tag = argv[1]; value = (argc > 2) ? argv[2] : NULL; } if ((action == ADD || action == MODIFY) && value == NULL) { /* try and read data for the value from stdin. */ input = read_input(); value = sbuf_data(input); } retcode = pkgdb_access(PKGDB_MODE_READ|PKGDB_MODE_WRITE, PKGDB_DB_LOCAL); if (retcode == EPKG_ENODB) { if (match == MATCH_ALL) { exitcode = EX_OK; goto cleanup; } if (!quiet) warnx("No packages installed. Nothing to do!"); exitcode = EX_OK; goto cleanup; } else if (retcode == EPKG_ENOACCESS) { warnx("Insufficient privileges to modify the package database"); exitcode = EX_NOPERM; goto cleanup; } else if (retcode != EPKG_OK) { warnx("Error accessing the package database"); exitcode = EX_SOFTWARE; goto cleanup; } retcode = pkgdb_open(&db, PKGDB_DEFAULT); if (retcode != EPKG_OK) { return (EX_IOERR); } if (pkgdb_obtain_lock(db, PKGDB_LOCK_EXCLUSIVE) != EPKG_OK) { pkgdb_close(db); warnx("Cannot get an exclusive lock on a database, it is locked by another process"); return (EX_TEMPFAIL); } if ((it = pkgdb_query(db, pkgname, match)) == NULL) { exitcode = EX_IOERR; goto cleanup; } while ((retcode = pkgdb_it_next(it, &pkg, flags)) == EPKG_OK) { switch(action) { case NONE: /* Should never happen */ usage_annotate(); exitcode = EX_USAGE; break; case ADD: retcode = do_add(db, pkg, tag, value); break; case MODIFY: retcode = do_modify(db, pkg, tag, value); break; case DELETE: retcode = do_delete(db, pkg, tag); break; case SHOW: retcode = do_show(pkg, tag); break; } if (retcode == EPKG_WARN) exitcode = EX_DATAERR; if (retcode != EPKG_OK && retcode != EPKG_WARN) { exitcode = EX_IOERR; goto cleanup; } } cleanup: pkg_free(pkg); pkgdb_it_free(it); pkgdb_release_lock(db, PKGDB_LOCK_EXCLUSIVE); pkgdb_close(db); if (input != NULL) sbuf_delete(input); return (exitcode); }