int main()

in src/authorized_keys/authorized_keys_sk.cc [44:97]


int main(int argc, char* argv[]) {
  struct AuthOptions opts;
  struct sigaction sig;
  char *user_name;
  string user_response;
  bool is_sa = false;
  const char *progname = FileName(argv[0]);

  SetupSysLog(SYSLOG_IDENT, progname);

  if (argc != 2) {
    SysLogErr("usage: %s [username]", progname);
    goto fail;
  }

  sig = {};
  sig.sa_handler = signal_handler;
  sigemptyset(&sig.sa_mask);

  if (sigaction(SIGPIPE, &sig, NULL) == -1) {
    SysLogErr("Unable to initialize signal handler. Exiting.");
    goto fail;
  }

  user_name = argv[1];
  is_sa = (strncmp(user_name, "sa_", 3) == 0);

  opts = {};
  opts.security_key = true;

  if (AuthorizeUser(user_name, opts, &user_response)) {
    // At this point, we've verified the user can log in. Grab the ssh keys from
    // the user response.
    std::vector<string> ssh_keys;
    if (is_sa) {
      // Service accounts should continue to function when SK is enabled.
      ssh_keys = ParseJsonToSshKeys(user_response);
    } else {
      ssh_keys = ParseJsonToSshKeysSk(user_response);
    }

    // Print out all available keys.
    for (size_t i = 0; i < ssh_keys.size(); i++) {
      cout << ssh_keys[i] << endl;
    }
  }

  CloseSysLog();
  return SUCCESS;

fail:
  CloseSysLog();
  return FAIL;
}