bool ValidatePasswd()

in src/oslogin_utils.cc [509:547]


bool ValidatePasswd(struct passwd* result, BufferManager* buf, int* errnop) {
  // OS Login disallows uids less than 1000.
  if (result->pw_uid < 1000) {
    *errnop = EINVAL;
    return false;
  }
  if (result->pw_gid == 0) {
    *errnop = EINVAL;
    return false;
  }
  if (strlen(result->pw_name) == 0) {
    *errnop = EINVAL;
    return false;
  }
  if (strlen(result->pw_dir) == 0) {
    string home_dir = "/home/";
    home_dir.append(result->pw_name);
    if (!buf->AppendString(home_dir, &result->pw_dir, errnop)) {
      return false;
    }
  }
  if (strlen(result->pw_shell) == 0) {
    if (!buf->AppendString(DEFAULT_SHELL, &result->pw_shell, errnop)) {
      return false;
    }
  }
  if (strlen(result->pw_passwd) == 0) {
    if (!buf->AppendString(DEFAULT_PASSWD, &result->pw_passwd, errnop)) {
      return false;
    }
  }

  // OS Login reserves the GECOS field.
  if (!buf->AppendString("", &result->pw_gecos, errnop)) {
    return false;
  }

  return true;
}