int main(int argc, char **argv) { GtkWidget *window; char *cmd; gtk_init(&argc, &argv); gtk_window_set_default_icon_from_file( DATA_DIR "/pixmaps/stoken-gui.png", NULL); cmd = parse_cmdline(argc, argv, IS_GUI); /* check for a couple of error conditions */ if (common_init(cmd)) error_dialog("Application error", "Unable to initialize crypto library."); if (!current_token) error_dialog("Missing token", "Please use 'stoken import' to add a new seed."); if (securid_devid_required(current_token)) error_dialog("Unsupported token", "Please use 'stoken' to handle tokens encrypted with a device ID."); /* check for token expiration */ token_days_left = securid_check_exp(current_token, time(NULL)); if (!opt_force && !opt_small) { if (token_days_left < 0) error_dialog("Token expired", "Please obtain a new token from your administrator."); if (token_days_left < EXP_WARN_DAYS) { char msg[BUFLEN]; sprintf(msg, "This token will expire in %d day%s.", token_days_left, token_days_left == 1 ? "" : "s"); warning_dialog(NULL, "Expiration warning", msg); } } /* request password / PIN, if missing */ if (request_credentials(current_token) != ERR_NONE) return 1; token_interval = securid_token_interval(current_token); token_uses_pin = securid_pin_required(current_token); window = opt_small ? create_small_app_window() : create_app_window(); update_tokencode(NULL); gtk_widget_show_all(window); g_timeout_add(250, update_tokencode, NULL); gtk_main(); return 0; }
int main(int argc, char **argv) { char *cmd = parse_cmdline(argc, argv, NOT_GUI); int rc; char buf[BUFLEN]; struct securid_token *t; rc = common_init(cmd); if (rc != ERR_NONE) die("can't initialize: %s\n", stoken_errstr[rc]); t = current_token; if (!t) die("error: no token present. Use 'stoken import' to add one.\n"); terminal_init(); if (!strcmp(cmd, "tokencode")) { int days_left = securid_check_exp(t, adjusted_time()); if (days_left < 0 && !opt_force) die("error: token has expired; use --force to override\n"); unlock_token(t, 1, NULL); securid_compute_tokencode(t, adjusted_time(), buf); puts(buf); if (days_left < 14 && !opt_force) warn("warning: token expires in %d day%s\n", days_left, days_left == 1 ? "" : "s"); } else if (!strcmp(cmd, "import")) { char *pass; unlock_token(t, 0, &pass); if (!opt_keep_password) { pass = xmalloc(BUFLEN); request_new_pass(pass); } t->is_smartphone = 0; securid_encode_token(t, pass, opt_new_devid, buf); rc = write_token_and_pin(buf, NULL, pass); if (rc != ERR_NONE) die("rcfile: error writing new token: %s\n", stoken_errstr[rc]); } else if (!strcmp(cmd, "export")) { char *pass; unlock_token(t, 0, &pass); if (opt_new_password) pass = opt_new_password; else if (!opt_keep_password) pass = NULL; t->is_smartphone = opt_iphone || opt_android; securid_encode_token(t, pass, opt_new_devid, buf); print_formatted(buf); } else if (!strcmp(cmd, "show")) { unlock_token(t, 0, NULL); securid_token_info(t, &print_token_info_line); } else if (!strcmp(cmd, "setpin")) { char *pass = NULL, pin[BUFLEN], confirm_pin[BUFLEN]; int len; if (opt_file || opt_token) die("error: setpin only operates on the rcfile token\n"); unlock_token(t, 0, &pass); if (opt_new_pin) { if (securid_pin_format_ok(opt_new_pin) != ERR_NONE) die("error: invalid --new-pin format\n"); strncpy(pin, opt_new_pin, BUFLEN); len = strlen(pin); } else { prompt("Enter new PIN: "); len = read_user_input(pin, BUFLEN, 1); if (len > 0 && securid_pin_format_ok(pin) != ERR_NONE) die("error: PIN must be 4-8 digits\n"); prompt("Confirm new PIN: "); read_user_input(confirm_pin, BUFLEN, 1); if (strcmp(pin, confirm_pin) != 0) die("error: PINs do not match\n"); } securid_encode_token(t, pass, NULL, buf); rc = write_token_and_pin(buf, len ? pin : NULL, pass); free(pass); if (rc != ERR_NONE) die("error: can't set PIN: %s\n", stoken_errstr[rc]); } else if (!strcmp(cmd, "setpass")) { char pass[BUFLEN]; unlock_token(t, 0, NULL); request_new_pass(pass); securid_encode_token(t, pass, NULL, buf); /* just print to stdout if it didn't come from the rcfile */ if (opt_file || opt_token) print_formatted(buf); else { rc = write_token_and_pin(buf, strlen(t->pin) ? t->pin : NULL, strlen(pass) ? pass : NULL); if (rc != ERR_NONE) die("error: can't set password: %s\n", stoken_errstr[rc]); } } else die("error: invalid command '%s'\n", cmd); return 0; }