version 1.15, 2006/08/03 03:34:41 |
version 1.16, 2008/06/13 04:40:22 |
|
|
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/stat.h> |
#include <sys/stat.h> |
|
|
|
#include <fcntl.h> |
#include <pwd.h> |
#include <pwd.h> |
#include <stdio.h> |
#include <stdio.h> |
#include <stdarg.h> |
#include <stdarg.h> |
|
|
user_key_allowed2(struct passwd *pw, Key *key, char *file) |
user_key_allowed2(struct passwd *pw, Key *key, char *file) |
{ |
{ |
char line[SSH_MAX_PUBKEY_BYTES]; |
char line[SSH_MAX_PUBKEY_BYTES]; |
int found_key = 0; |
int found_key = 0, fd; |
FILE *f; |
FILE *f; |
u_long linenum = 0; |
u_long linenum = 0; |
struct stat st; |
struct stat st; |
|
|
|
|
debug("trying public key file %s", file); |
debug("trying public key file %s", file); |
|
|
/* Fail quietly if file does not exist */ |
/* |
if (stat(file, &st) < 0) { |
* Open the file containing the authorized keys |
/* Restore the privileged uid. */ |
* Fail quietly if file does not exist |
|
*/ |
|
if ((fd = open(file, O_RDONLY|O_NONBLOCK)) == -1) { |
restore_uid(); |
restore_uid(); |
return 0; |
return 0; |
} |
} |
/* Open the file containing the authorized keys. */ |
if (fstat(fd, &st) < 0) { |
f = fopen(file, "r"); |
close(fd); |
if (!f) { |
restore_uid(); |
/* Restore the privileged uid. */ |
return 0; |
|
} |
|
if (!S_ISREG(st.st_mode)) { |
|
logit("User %s authorized keys %s is not a regular file", |
|
pw->pw_name, file); |
|
close(fd); |
|
restore_uid(); |
|
return 0; |
|
} |
|
unset_nonblock(fd); |
|
if ((f = fdopen(fd, "r")) == NULL) { |
|
close(fd); |
restore_uid(); |
restore_uid(); |
return 0; |
return 0; |
} |
} |