static bool CreateGoogleSudoersFile()

in src/oslogin_utils.cc [1342:1358]


static bool CreateGoogleSudoersFile(string sudoers_filename, const char *user_name) {
  std::ofstream sudoers_file;

  sudoers_file.open(sudoers_filename.c_str());

  if (!sudoers_file.is_open()) {
    // If we can't open the file (meaning we can't create it) we should report failure.
    return false;
  }

  sudoers_file << user_name << " ALL=(ALL) NOPASSWD: ALL\n";
  sudoers_file.close();

  chown(sudoers_filename.c_str(), 0, 0);
  chmod(sudoers_filename.c_str(), S_IRUSR | S_IRGRP);
  return true;
}