int main()

in src/authorized_keys/authorized_keys.cc [42:83]


int main(int argc, char *argv[]) {
  struct AuthOptions opts;
  struct sigaction sig;
  char *user_name;
  string user_response;
  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];
  opts = {};

  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 = ParseJsonToSshKeys(user_response);
    for (size_t i = 0; i < ssh_keys.size(); i++) {
      cout << ssh_keys[i] << endl;
    }
  }

  CloseSysLog();
  return SUCCESS;

fail:
  CloseSysLog();
  return FAIL;
}