usr.bin/ssh/auth.c
/* return ok if key exists in sysfile or userfile */
return ok if key exists in sysfile or userfile
return ok if key exists in sysfile or userfile
HostStatus
check_key_in_hostfiles(struct passwd *pw, Key *key, const char *host,
    const char *sysfile, const char *userfile)
{
	char *user_hostfile;
	struct stat st;
	HostStatus host_status;
	struct hostkeys *hostkeys;
	const struct hostkey_entry *found;
	hostkeys = init_hostkeys();
	load_hostkeys(hostkeys, host, sysfile);
	if (userfile != NULL) {
		user_hostfile = tilde_expand_filename(userfile, pw->pw_uid);
		if (options.strict_modes &&
		    (stat(user_hostfile, &st) == 0) &&
		    ((st.st_uid != 0 && st.st_uid != pw->pw_uid) ||
		    (st.st_mode & 022) != 0)) {
			logit("Authentication refused for %.100s: "
			    "bad owner or modes for %.200s",
			    pw->pw_name, user_hostfile);
			auth_debug_add("Ignored %.200s: bad ownership or modes",
			    user_hostfile);
		} else {
			temporarily_use_uid(pw);
			load_hostkeys(hostkeys, host, user_hostfile);
			restore_uid();
		}
		free(user_hostfile);
	}
	host_status = check_key_in_hostkeys(hostkeys, key, &found);
	if (host_status == HOST_REVOKED)
		error("WARNING: revoked key for %s attempted authentication",
		    found->host);
	else if (host_status == HOST_OK)
		debug("%s: key for %s found at %s:%ld", __func__,
		    found->host, found->file, found->line);
	else
		debug("%s: key for host %s not found", __func__, host);
	free_hostkeys(hostkeys);
	return host_status;
}
HostStatus check_key_in_hostfiles ( struct passwd * pw , Key * key , const char * host , const char * sysfile , const char * userfile ) { char * user_hostfile ; struct stat st ; HostStatus host_status ; struct hostkeys * hostkeys ; const struct hostkey_entry * found ; hostkeys = init_hostkeys ( ) ; load_hostkeys ( hostkeys , host , sysfile ) ; if ( userfile != NULL ) { user_hostfile = tilde_expand_filename ( userfile , pw -> pw_uid ) ; if ( options . strict_modes && ( stat ( user_hostfile , & st ) == 0 ) && ( ( st . st_uid != 0 && st . st_uid != pw -> pw_uid ) || ( st . st_mode & 022 ) != 0 ) ) { logit ( " " " " , pw -> pw_name , user_hostfile ) ; auth_debug_add ( " " , user_hostfile ) ; } else { temporarily_use_uid ( pw ) ; load_hostkeys ( hostkeys , host , user_hostfile ) ; restore_uid ( ) ; } free ( user_hostfile ) ; } host_status = check_key_in_hostkeys ( hostkeys , key , & found ) ; if ( host_status == HOST_REVOKED ) error ( " " , found -> host ) ; else if ( host_status == HOST_OK ) debug ( " " , __func__ , found -> host , found -> file , found -> line ) ; else debug ( " " , __func__ , host ) ; free_hostkeys ( hostkeys ) ; return host_status ; }
return ok if key exists in sysfile or userfile
return ok if key exists in sysfile or userfile