void test_action::read_action_normal() { char buffer[100]; uint32_t total = 0; eosio_assert( current_receiver() == N(testapi), "current_receiver() == N(testapi)" ); eosio_assert(action_size() == sizeof(dummy_action), "action_size() == sizeof(dummy_action)"); total = read_action(buffer, 30); eosio_assert(total == sizeof(dummy_action) , "read_action(30)" ); total = read_action(buffer, 100); eosio_assert(total == sizeof(dummy_action) , "read_action(100)" ); total = read_action(buffer, 5); eosio_assert(total == 5 , "read_action(5)" ); total = read_action(buffer, sizeof(dummy_action) ); eosio_assert(total == sizeof(dummy_action), "read_action(sizeof(dummy_action))" ); dummy_action *dummy13 = reinterpret_cast<dummy_action *>(buffer); eosio_assert(dummy13->a == DUMMY_ACTION_DEFAULT_A, "dummy13->a == DUMMY_ACTION_DEFAULT_A"); eosio_assert(dummy13->b == DUMMY_ACTION_DEFAULT_B, "dummy13->b == DUMMY_ACTION_DEFAULT_B"); eosio_assert(dummy13->c == DUMMY_ACTION_DEFAULT_C, "dummy13->c == DUMMY_ACTION_DEFAULT_C"); }
int perform_action(char *action_str) { char cmd[MAX_CMD_SIZE]; int status; if (actions_file == NULL) return 1; if (!read_action(action_str, cmd, MAX_CMD_SIZE)) { log_write(LL_WARN, "Failed to read actions file: %s", actions_file); return 0; } if (cmd[0] == '\0') { log_write(LL_DETAIL, "Missing action for `%s'", action_str); return 0; } status = system(cmd); if (status == -1 || status == 0x7F00) { log_write(LL_WARN, "Failed to execute action command"); return 0; } status = status >> 8 & 0xFF; if (status == 0) { log_write(LL_DETAIL, "Action command done"); } else { log_write(LL_INFO, "Action command exited with status %d", status); } return 1; }
static int read_action(options& opt, std::vector<std::string> const& args) { auto tmp_args(args); int ret_action = read_action(opt, tmp_args); if(!tmp_args.empty()) { std::cerr << "Unrecognized commandline argument(s):"; for(auto const& arg : tmp_args) std::cerr << ' ' << arg; std::cerr << std::endl; return EXIT_FAILURE; } return ret_action; }
void read_from(ReadSource in, Level::Condition& level_condition) { uint8_t section[12]; read(in, level_condition.condition); in.shift(1); read(in, section, 12); read(in, level_condition.subjectObject); read(in, level_condition.directObject); read_action(in, level_condition); read(in, level_condition.flags); read(in, level_condition.direction); BytesSlice sub(section, 12); switch (level_condition.condition) { case kCounterCondition: case kCounterGreaterCondition: case kCounterNotCondition: read(sub, level_condition.conditionArgument.counter); break; case kDestructionCondition: case kOwnerCondition: case kNoShipsLeftCondition: case kZoomLevelCondition: read(sub, level_condition.conditionArgument.longValue); break; case kVelocityLessThanEqualToCondition: read(sub, level_condition.conditionArgument.fixedValue); case kTimeCondition: level_condition.conditionArgument.timeValue = ticks(read<int32_t>(sub)); break; case kProximityCondition: case kDistanceGreaterCondition: read(sub, level_condition.conditionArgument.unsignedLongValue); break; case kCurrentMessageCondition: case kCurrentComputerCondition: read(sub, level_condition.conditionArgument.location); break; } }
static twin_bool_t pboot_proc_client_sock(int sock, twin_file_op_t ops, void *closure) { struct device_context *dev_ctx = closure; uint8_t action; if (read_action(sock, &action)) goto out_err; if (action == DEV_ACTION_ADD_DEVICE) { if (!read_device(sock, dev_ctx)) goto out_err; } else if (action == DEV_ACTION_ADD_OPTION) { if (dev_ctx->device_idx == -1) { LOG("option, but no device has been sent?\n"); goto out_err; } if (!read_option(sock, dev_ctx)) goto out_err; } else if (action == DEV_ACTION_REMOVE_DEVICE) { char *dev_id = read_string(sock); if (!dev_id) goto out_err; LOG("remove device %s\n", dev_id); pboot_remove_device(dev_id); } else { LOG("unsupported action %d\n", action); goto out_err; } return TWIN_TRUE; out_err: close(sock); return TWIN_FALSE; }
int main (int argc, char**argv) { //option variables bool do_help = false, do_version = false, do_test = false, has_opt = false, opt_armor = false, opt_yes = false, opt_fingerprint = false, opt_clearsign = false, opt_import_no_action = false; std::string recipient, user, input, output, name, filter, action_param, detach_sign, symmetric; char action = 0; int c, option_index; for (;;) { static struct option long_opts[] = { {"help", 0, 0, 'h' }, {"version", 0, 0, 'V' }, {"test", 0, 0, 'T' }, //global options {"armor", 0, 0, 'a' }, {"yes", 0, 0, 'y' }, {"recipient", 1, 0, 'r' }, {"user", 1, 0, 'u' }, //I/O redirection from default stdin/out {"in", 1, 0, 'R' }, {"out", 1, 0, 'o' }, //keyring management {"list", 0, 0, 'k' }, {"import", 0, 0, 'i' }, {"export", 0, 0, 'p' }, {"delete", 1, 0, 'x' }, {"rename", 1, 0, 'm' }, {"list-secret", 0, 0, 'K' }, {"import-secret", 0, 0, 'I' }, {"export-secret", 0, 0, 'P' }, {"delete-secret", 1, 0, 'X' }, {"rename-secret", 1, 0, 'M' }, {"gen-key", 1, 0, 'g' }, {"name", 1, 0, 'N' }, {"filter", 1, 0, 'F' }, {"fingerprint", 0, 0, 'f' }, {"no-action", 0, 0, 'n' }, //actions {"sign", 0, 0, 's' }, {"verify", 0, 0, 'v' }, {"encrypt", 0, 0, 'e' }, {"decrypt", 0, 0, 'd' }, //action options {"clearsign", 0, 0, 'C' }, {"detach-sign", 1, 0, 'b' }, {"symmetric", 1, 0, 'S' }, {0, 0, 0, 0 } }; option_index = -1; c = getopt_long (argc, argv, "hVTayr:u:R:o:kipx:m:KIPX:M:g:N:F:fnsvedCb:S:", long_opts, &option_index); if (c == -1) break; has_opt = true; switch (c) { case '?': case ':': case 'h': do_help = true; break; #define read_flag(ch,var) case ch: var=true; break; #define read_single_opt(ch,var,errmsg) \ case ch: if(var.length()) {progerr(errmsg); do_help=true;}\ else var=optarg; break; #define read_action(ch) read_action_comb(ch,0,0) #define read_action_comb(ch, hit, comb) \ case ch: \ if(hit && action==hit) { \ action=comb; \ if(optarg) action_param=optarg; \ } else if(action) { \ progerr("please specify a single action"); \ do_help=true; \ } else { \ action=ch; \ if(optarg) action_param=optarg; \ } break; read_flag ('V', do_version) read_flag ('T', do_test) read_flag ('a', opt_armor) read_flag ('y', opt_yes) read_single_opt ('r', recipient, "specify only one recipient") read_single_opt ('u', user, "specify only one local user") read_single_opt ('R', input, "cannot accept multiple inputs") read_single_opt ('o', output, "cannot accept multiple outputs") read_action ('k') read_action ('i') read_action ('p') read_action ('x') read_action ('m') read_action ('K') read_action ('I') read_action ('P') read_action ('X') read_action ('M') read_action ('g') read_single_opt ('N', name, "please specify single name") read_single_opt ('F', filter, "please specify single filter string") read_flag ('f', opt_fingerprint) read_flag ('n', opt_import_no_action) /* * combinations of s+e and d+v are possible. result is * 'E' = "big encrypt with sig" and 'D' "big decrypt * with verify". */ read_action_comb ('s', 'e', 'E') read_action_comb ('v', 'd', 'D') read_action_comb ('e', 's', 'E') read_action_comb ('d', 'v', 'D') read_flag ('C', opt_clearsign) read_single_opt ('b', detach_sign, "specify only one detach-sign file") read_single_opt ('S', symmetric, "specify only one symmetric parameter") #undef read_flag #undef read_single_opt #undef read_action default: //which doesn't just happen. do_help = true; break; } } if (optind != argc) { progerr ("unmatched non-option parameters"); do_help = true; } if ( (!has_opt) || do_help) { print_help (argv[0]); return 0; } if (do_version) { print_version(); return 0; } /* * something will be happening, therefore init everything */ keyring KR; algorithm_suite AS; //register all available algorithms fill_algorithm_suite (AS); /* * cin/cout redirection */ int exitval = 0; if (input.length() && !redirect_cin (input) ) { progerr ("could not open input file"); exitval = 1; goto exit; } if (output.length() && !redirect_cout (output) ) { progerr ("could not redirect to output file"); exitval = 1; goto exit; } /* * check the option flags and do whatever was requested */ if (do_test) { test(); goto exit; } if (symmetric.length() ) switch (action) { case 's': case 'v': break; default: progerr ("specified action doesn't support symmetric operation"); exitval = 1; goto exit; } switch (action) { case 'g': exitval = action_gen_key (action_param, name, KR, AS); break; case 'e': exitval = action_encrypt (recipient, opt_armor, KR, AS); break; case 'd': exitval = action_decrypt (opt_armor, KR, AS); break; case 's': exitval = action_sign (user, opt_armor, detach_sign, opt_clearsign, symmetric, KR, AS); break; case 'v': exitval = action_verify (opt_armor, detach_sign, opt_clearsign, opt_yes, symmetric, KR, AS); break; case 'E': exitval = action_sign_encrypt (user, recipient, opt_armor, KR, AS); break; case 'D': exitval = action_decrypt_verify (opt_armor, opt_yes, KR, AS); break; case 'k': exitval = action_list (opt_fingerprint, filter, KR); break; case 'i': exitval = action_import (opt_armor, opt_import_no_action, opt_yes, opt_fingerprint, filter, name, KR); break; case 'p': exitval = action_export (opt_armor, filter, name, KR); break; case 'x': exitval = action_delete (opt_yes, action_param, KR); break; case 'm': exitval = action_rename (opt_yes, action_param, name, KR); break; case 'K': exitval = action_list_sec (opt_fingerprint, filter, KR); break; case 'I': exitval = action_import_sec (opt_armor, opt_import_no_action, opt_yes, opt_fingerprint, filter, name, KR); break; case 'P': exitval = action_export_sec (opt_armor, opt_yes, filter, name, KR); break; case 'X': exitval = action_delete_sec (opt_yes, action_param, KR); break; case 'M': exitval = action_rename_sec (opt_yes, action_param, name, KR); break; default: progerr ("no action specified, use `--help'"); exitval = 1; break; } /* * all done. * keyring is _not_ automatically saved here to prevent frequent * rewriting and due the fact that everything that modifies it _must_ * also ensure and verify that it was written back correctly. */ exit: if (!KR.close() ) { progerr ("could not close keyring, " "something weird is going to happen."); } return exitval; }
int main(int argc, char *argv[]) { int exit_code = EXIT_FAILURE; char *response = NULL; u2fh_devs *devs = NULL; u2fh_rc rc; OP *action = NULL; char device_state = 'u'; u2fh_rc device_disappeared_rc = U2FH_OK; char *device_disappeared_msg = NULL; reset_quit_timer(); rc = u2fh_global_init(0); if (rc != U2FH_OK) { report_error(rc, "global_init"); exit(1); } rc = u2fh_devs_init(&devs); if (rc != U2FH_OK) { report_error(rc, "devs_init"); goto done; } while (1) { int need_sleep = 1; rc = u2fh_devs_discover(devs, NULL); if (device_disappeared_rc != U2FH_OK && rc != U2FH_NO_U2F_DEVICE) { report_error(device_disappeared_rc, device_disappeared_msg); free(response); free(action); action = NULL; } if (rc != U2FH_OK && rc != U2FH_NO_U2F_DEVICE) { report_error(rc, "devs_discover"); goto done; } if (rc == U2FH_OK && device_state == 'm') { printf("j"); fflush(stdout); device_state = 'p'; need_sleep = 0; } if (rc == U2FH_NO_U2F_DEVICE && device_state != 'm') { printf("i"); fflush(stdout); device_state = 'm'; } device_disappeared_rc = U2FH_OK; if (!action) { action = read_action(1000); if (action) reset_quit_timer(); } else if (need_sleep) sleep(1); if (action && (rc == U2FH_OK || action->op == 'e')) { if (action->op == 'e') goto done; else if (action->op == 'r' || action->op == 's') { int requests_count = 0; do { int i = 0; do { if (action->op == 'r') { rc = u2fh_register(devs, action->challenges[i], action->domain, &response, U2FH_REQUEST_USER_PRESENCE | U2FH_REQUEST_NON_BLOCKING); } else { rc = u2fh_authenticate(devs, action->challenges[i], action->domain, &response, U2FH_REQUEST_USER_PRESENCE | U2FH_REQUEST_NON_BLOCKING); } i++; } while (action->challenges[i] && rc == U2FH_AUTHENTICATOR_ERROR); if (rc == U2FH_NOT_FINISHED_ERROR) { if (device_state != 'b') { printf("b"); fflush(stdout); device_state = 'b'; } sleep(1); } else break; } while (requests_count++ < 15); if (requests_count >= 15) { report_error(U2FH_TIMEOUT_ERROR, NULL); } else if (rc != U2FH_OK) { device_disappeared_rc = rc; device_disappeared_msg = action->op == 'r' ? "register" : "authenticate"; continue; } else { printf("r%04lx%s", strlen(response), response); fflush(stdout); } free(response); free(action); action = NULL; } else { report_error(U2FH_TRANSPORT_ERROR, NULL); goto done; } } } done: u2fh_devs_done(devs); u2fh_global_done(); exit(exit_code); }
void test_action::now() { uint32_t tmp = 0; uint32_t total = read_action(&tmp, sizeof(uint32_t)); eosio_assert( total == sizeof(uint32_t), "total == sizeof(uint32_t)"); eosio_assert( tmp == ::now(), "tmp == now()" ); }
void test_action::test_current_sender() { account_name cur_send; read_action(&cur_send, sizeof(account_name)); eosio_assert( current_sender() == cur_send, "the current sender does not match" ); }
void test_action::test_current_receiver() { account_name cur_rec; read_action(&cur_rec, sizeof(account_name)); eosio_assert( current_receiver() == cur_rec, "the current receiver does not match" ); }
void test_action::test_publication_time() { uint32_t pub_time = 0; read_action(&pub_time, sizeof(uint32_t)); eosio_assert( pub_time == publication_time(), "pub_time == publication_time()" ); }
void test_action::read_action_to_64k() { uint32_t total = read_action( (void *)((1<<16)-2), action_size()); }
void test_action::read_action_to_0() { uint32_t total = read_action((void *)0, action_size()); }
transition read_transition(deserializer & d) { name n = read_name(d); name pp = read_name(d); action a = read_action(d); return transition(n, a, pp); }