summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2008-07-02 22:37:30 +1000
committerDarren Tucker <dtucker@zip.com.au>2008-07-02 22:37:30 +1000
commit33c787f23c0267c679ad3e3f8bc4679c6ced5ea3 (patch)
treeb444437050374e67966df54450358b5506b797ea
parent7499b0cca021f14c615cbfef170aba3e24cf8d4d (diff)
- dtucker@cvs.openbsd.org 2008/07/02 12:03:51
[auth-rsa.c auth.c auth2-pubkey.c auth.h] Merge duplicate host key file checks, based in part on a patch from Rob Holland via bz #1348 . Also checks for non-regular files during protocol 1 RSA auth. ok djm@
-rw-r--r--ChangeLog7
-rw-r--r--auth-rsa.c23
-rw-r--r--auth.c45
-rw-r--r--auth.h5
-rw-r--r--auth2-pubkey.c38
5 files changed, 58 insertions, 60 deletions
diff --git a/ChangeLog b/ChangeLog
index 9e7326d85..dc8048939 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -28,6 +28,11 @@
28 [sshd_config sshd_config.5 sshd.8 servconf.c] 28 [sshd_config sshd_config.5 sshd.8 servconf.c]
29 increase default size of ssh protocol 1 ephemeral key from 768 to 1024 29 increase default size of ssh protocol 1 ephemeral key from 768 to 1024
30 bits; prodded by & ok dtucker@ ok deraadt@ 30 bits; prodded by & ok dtucker@ ok deraadt@
31 - dtucker@cvs.openbsd.org 2008/07/02 12:03:51
32 [auth-rsa.c auth.c auth2-pubkey.c auth.h]
33 Merge duplicate host key file checks, based in part on a patch from Rob
34 Holland via bz #1348 . Also checks for non-regular files during protocol
35 1 RSA auth. ok djm@
31 36
3220080630 3720080630
33 - (djm) OpenBSD CVS Sync 38 - (djm) OpenBSD CVS Sync
@@ -4511,4 +4516,4 @@
4511 OpenServer 6 and add osr5bigcrypt support so when someone migrates 4516 OpenServer 6 and add osr5bigcrypt support so when someone migrates
4512 passwords between UnixWare and OpenServer they will still work. OK dtucker@ 4517 passwords between UnixWare and OpenServer they will still work. OK dtucker@
4513 4518
4514$Id: ChangeLog,v 1.5046 2008/07/02 12:35:43 dtucker Exp $ 4519$Id: ChangeLog,v 1.5047 2008/07/02 12:37:30 dtucker Exp $
diff --git a/auth-rsa.c b/auth-rsa.c
index 69f9a5896..bf5462076 100644
--- a/auth-rsa.c
+++ b/auth-rsa.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: auth-rsa.c,v 1.72 2006/11/06 21:25:27 markus Exp $ */ 1/* $OpenBSD: auth-rsa.c,v 1.73 2008/07/02 12:03:51 dtucker Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -173,7 +173,6 @@ auth_rsa_key_allowed(struct passwd *pw, BIGNUM *client_n, Key **rkey)
173 u_int bits; 173 u_int bits;
174 FILE *f; 174 FILE *f;
175 u_long linenum = 0; 175 u_long linenum = 0;
176 struct stat st;
177 Key *key; 176 Key *key;
178 177
179 /* Temporarily use the user's uid. */ 178 /* Temporarily use the user's uid. */
@@ -182,27 +181,9 @@ auth_rsa_key_allowed(struct passwd *pw, BIGNUM *client_n, Key **rkey)
182 /* The authorized keys. */ 181 /* The authorized keys. */
183 file = authorized_keys_file(pw); 182 file = authorized_keys_file(pw);
184 debug("trying public RSA key file %s", file); 183 debug("trying public RSA key file %s", file);
185 184 f = auth_openkeyfile(file, pw, options.strict_modes);
186 /* Fail quietly if file does not exist */
187 if (stat(file, &st) < 0) {
188 /* Restore the privileged uid. */
189 restore_uid();
190 xfree(file);
191 return (0);
192 }
193 /* Open the file containing the authorized keys. */
194 f = fopen(file, "r");
195 if (!f) { 185 if (!f) {
196 /* Restore the privileged uid. */
197 restore_uid();
198 xfree(file);
199 return (0);
200 }
201 if (options.strict_modes &&
202 secure_filename(f, file, pw, line, sizeof(line)) != 0) {
203 xfree(file); 186 xfree(file);
204 fclose(f);
205 logit("Authentication refused: %s", line);
206 restore_uid(); 187 restore_uid();
207 return (0); 188 return (0);
208 } 189 }
diff --git a/auth.c b/auth.c
index f94c7d1d5..c2d298f1b 100644
--- a/auth.c
+++ b/auth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: auth.c,v 1.78 2007/09/21 08:15:29 djm Exp $ */ 1/* $OpenBSD: auth.c,v 1.79 2008/07/02 12:03:51 dtucker Exp $ */
2/* 2/*
3 * Copyright (c) 2000 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000 Markus Friedl. All rights reserved.
4 * 4 *
@@ -32,6 +32,7 @@
32#include <netinet/in.h> 32#include <netinet/in.h>
33 33
34#include <errno.h> 34#include <errno.h>
35#include <fcntl.h>
35#ifdef HAVE_PATHS_H 36#ifdef HAVE_PATHS_H
36# include <paths.h> 37# include <paths.h>
37#endif 38#endif
@@ -410,7 +411,7 @@ check_key_in_hostfiles(struct passwd *pw, Key *key, const char *host,
410 * 411 *
411 * Returns 0 on success and -1 on failure 412 * Returns 0 on success and -1 on failure
412 */ 413 */
413int 414static int
414secure_filename(FILE *f, const char *file, struct passwd *pw, 415secure_filename(FILE *f, const char *file, struct passwd *pw,
415 char *err, size_t errlen) 416 char *err, size_t errlen)
416{ 417{
@@ -470,6 +471,46 @@ secure_filename(FILE *f, const char *file, struct passwd *pw,
470 return 0; 471 return 0;
471} 472}
472 473
474FILE *
475auth_openkeyfile(const char *file, struct passwd *pw, int strict_modes)
476{
477 char line[1024];
478 struct stat st;
479 int fd;
480 FILE *f;
481
482 /*
483 * Open the file containing the authorized keys
484 * Fail quietly if file does not exist
485 */
486 if ((fd = open(file, O_RDONLY|O_NONBLOCK)) == -1)
487 return NULL;
488
489 if (fstat(fd, &st) < 0) {
490 close(fd);
491 return NULL;
492 }
493 if (!S_ISREG(st.st_mode)) {
494 logit("User %s authorized keys %s is not a regular file",
495 pw->pw_name, file);
496 close(fd);
497 return NULL;
498 }
499 unset_nonblock(fd);
500 if ((f = fdopen(fd, "r")) == NULL) {
501 close(fd);
502 return NULL;
503 }
504 if (options.strict_modes &&
505 secure_filename(f, file, pw, line, sizeof(line)) != 0) {
506 fclose(f);
507 logit("Authentication refused: %s", line);
508 return NULL;
509 }
510
511 return f;
512}
513
473struct passwd * 514struct passwd *
474getpwnamallow(const char *user) 515getpwnamallow(const char *user)
475{ 516{
diff --git a/auth.h b/auth.h
index f752c1220..6a70f0eb6 100644
--- a/auth.h
+++ b/auth.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: auth.h,v 1.60 2007/09/21 08:15:29 djm Exp $ */ 1/* $OpenBSD: auth.h,v 1.61 2008/07/02 12:03:51 dtucker Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2000 Markus Friedl. All rights reserved. 4 * Copyright (c) 2000 Markus Friedl. All rights reserved.
@@ -166,8 +166,7 @@ void abandon_challenge_response(Authctxt *);
166char *authorized_keys_file(struct passwd *); 166char *authorized_keys_file(struct passwd *);
167char *authorized_keys_file2(struct passwd *); 167char *authorized_keys_file2(struct passwd *);
168 168
169int 169FILE *auth_openkeyfile(const char *, struct passwd *, int);
170secure_filename(FILE *, const char *, struct passwd *, char *, size_t);
171 170
172HostStatus 171HostStatus
173check_key_in_hostfiles(struct passwd *, Key *, const char *, 172check_key_in_hostfiles(struct passwd *, Key *, const char *,
diff --git a/auth2-pubkey.c b/auth2-pubkey.c
index 306515000..daa751ca0 100644
--- a/auth2-pubkey.c
+++ b/auth2-pubkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: auth2-pubkey.c,v 1.17 2008/06/13 14:18:51 dtucker Exp $ */ 1/* $OpenBSD: auth2-pubkey.c,v 1.18 2008/07/02 12:03:51 dtucker Exp $ */
2/* 2/*
3 * Copyright (c) 2000 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000 Markus Friedl. All rights reserved.
4 * 4 *
@@ -182,10 +182,9 @@ static int
182user_key_allowed2(struct passwd *pw, Key *key, char *file) 182user_key_allowed2(struct passwd *pw, Key *key, char *file)
183{ 183{
184 char line[SSH_MAX_PUBKEY_BYTES]; 184 char line[SSH_MAX_PUBKEY_BYTES];
185 int found_key = 0, fd; 185 int found_key = 0;
186 FILE *f; 186 FILE *f;
187 u_long linenum = 0; 187 u_long linenum = 0;
188 struct stat st;
189 Key *found; 188 Key *found;
190 char *fp; 189 char *fp;
191 190
@@ -193,37 +192,10 @@ user_key_allowed2(struct passwd *pw, Key *key, char *file)
193 temporarily_use_uid(pw); 192 temporarily_use_uid(pw);
194 193
195 debug("trying public key file %s", file); 194 debug("trying public key file %s", file);
195 f = auth_openkeyfile(file, pw, options.strict_modes);
196 196
197 /* 197 if (!f) {
198 * Open the file containing the authorized keys 198 xfree(file);
199 * Fail quietly if file does not exist
200 */
201 if ((fd = open(file, O_RDONLY|O_NONBLOCK)) == -1) {
202 restore_uid();
203 return 0;
204 }
205 if (fstat(fd, &st) < 0) {
206 close(fd);
207 restore_uid();
208 return 0;
209 }
210 if (!S_ISREG(st.st_mode)) {
211 logit("User %s authorized keys %s is not a regular file",
212 pw->pw_name, file);
213 close(fd);
214 restore_uid();
215 return 0;
216 }
217 unset_nonblock(fd);
218 if ((f = fdopen(fd, "r")) == NULL) {
219 close(fd);
220 restore_uid();
221 return 0;
222 }
223 if (options.strict_modes &&
224 secure_filename(f, file, pw, line, sizeof(line)) != 0) {
225 fclose(f);
226 logit("Authentication refused: %s", line);
227 restore_uid(); 199 restore_uid();
228 return 0; 200 return 0;
229 } 201 }