Changeset 2066 for trunk/server/common/patches/krb5-kuserok-scripts.patch
- Timestamp:
- Nov 22, 2011, 12:45:17 AM (11 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
-
trunk/server/common/patches/krb5-kuserok-scripts.patch
r1693 r2066 1 1 # scripts.mit.edu krb5 kuserok patch 2 2 # Copyright (C) 2006 Tim Abbott <tabbott@mit.edu> 3 # 2011 Alexander Chernyakhovsky <achernya@mit.edu> 3 4 # 4 5 # This program is free software; you can redistribute it and/or … … 18 19 # See /COPYRIGHT in this repository for more information. 19 20 # 20 --- krb5-1. 6.3/src/lib/krb5/os/kuserok.c.old 2009-04-08 06:17:06.000000000 -040021 +++ krb5-1. 6.3/src/lib/krb5/os/kuserok.c 2009-04-08 06:17:18.000000000 -040022 @@ -3 1,6 +31,7 @@23 #if !defined(_WIN32) 21 --- krb5-1.9/src/lib/krb5/os/kuserok.c.old 2011-04-16 19:09:58.000000000 -0400 22 +++ krb5-1.9/src/lib/krb5/os/kuserok.c 2011-04-16 19:34:23.000000000 -0400 23 @@ -32,6 +32,7 @@ 24 #if !defined(_WIN32) /* Not yet for Windows */ 24 25 #include <stdio.h> 25 26 #include <pwd.h> … … 28 29 #if defined(_AIX) && defined(_IBMR2) 29 30 #include <sys/access.h> 30 @@ -71,7 +72,6 @@ 31 @@ -51,39 +52,6 @@ 32 enum result { ACCEPT, REJECT, PASS }; 33 34 /* 35 - * Find the k5login filename for luser, either in the user's homedir or in a 36 - * configured directory under the username. 37 - */ 38 -static krb5_error_code 39 -get_k5login_filename(krb5_context context, const char *luser, 40 - const char *homedir, char **filename_out) 41 -{ 42 - krb5_error_code ret; 43 - char *dir, *filename; 44 - 45 - *filename_out = NULL; 46 - ret = profile_get_string(context->profile, KRB5_CONF_LIBDEFAULTS, 47 - KRB5_CONF_K5LOGIN_DIRECTORY, NULL, NULL, &dir); 48 - if (ret != 0) 49 - return ret; 50 - 51 - if (dir == NULL) { 52 - /* Look in the user's homedir. */ 53 - if (asprintf(&filename, "%s/.k5login", homedir) < 0) 54 - return ENOMEM; 55 - } else { 56 - /* Look in the configured directory. */ 57 - if (asprintf(&filename, "%s/%s", dir, luser) < 0) 58 - ret = ENOMEM; 59 - profile_release_string(dir); 60 - if (ret) 61 - return ret; 62 - } 63 - *filename_out = filename; 64 - return 0; 65 -} 66 - 67 -/* 68 * Determine whether principal is authorized to log in as luser according to 69 * the user's k5login file. Return ACCEPT if the k5login file authorizes the 70 * principal, PASS if the k5login file does not exist, or REJECT if the k5login 71 @@ -93,13 +61,12 @@ 72 static enum result 73 k5login_ok(krb5_context context, krb5_principal principal, const char *luser) 31 74 { 32 struct stat sbuf;33 struct passwd *pwd;34 - char pbuf[MAXPATHLEN];35 krb5_boolean isok = FALSE;36 FILE *fp;37 char kuser[MAX_USERNAME];38 @@ -79,71 +79,35 @@ 39 char linebuf[BUFSIZ];40 char *newline;41 int gobble;75 - int authoritative = TRUE, gobble; 76 + int authoritative = TRUE; 77 enum result result = REJECT; 78 - char *filename = NULL, *princname = NULL; 79 - char *newline, linebuf[BUFSIZ], pwbuf[BUFSIZ]; 80 - struct stat sbuf; 81 + char *princname = NULL; 82 + char pwbuf[BUFSIZ]; 83 struct passwd pwx, *pwd; 84 - FILE *fp = NULL; 42 85 + int pid, status; 43 86 44 /* no account => no access */45 char pwbuf[BUFSIZ];46 struct passwd pwx; 87 if (profile_get_boolean(context->profile, KRB5_CONF_LIBDEFAULTS, 88 KRB5_CONF_K5LOGIN_AUTHORITATIVE, NULL, TRUE, 89 @@ -110,46 +77,29 @@ 47 90 if (k5_getpwnam_r(luser, &pwx, pwbuf, sizeof(pwbuf), &pwd) != 0) 48 return(FALSE);49 - (void) strncpy(pbuf, pwd->pw_dir, sizeof(pbuf) - 1); 50 - pbuf[sizeof(pbuf) - 1] = '\0';51 - (void) strncat(pbuf, "/.k5login", sizeof(pbuf) - 1 - strlen(pbuf));91 goto cleanup; 92 93 - if (get_k5login_filename(context, luser, pwd->pw_dir, &filename) != 0) 94 - goto cleanup; 52 95 - 53 - if (access(pbuf, F_OK)) { /* not accessible */ 54 - /* 55 - * if he's trying to log in as himself, and there is no .k5login file, 56 - * let him. To find out, call 57 - * krb5_aname_to_localname to convert the principal to a name 58 - * which we can string compare. 59 - */ 60 - if (!(krb5_aname_to_localname(context, principal, 61 - sizeof(kuser), kuser)) 62 - && (strcmp(kuser, luser) == 0)) { 63 - return(TRUE); 64 - } 96 - if (access(filename, F_OK) != 0) { 97 - result = PASS; 98 - goto cleanup; 65 99 - } 66 if (krb5_unparse_name(context, principal, &princname)) 67 return(FALSE); /* no hope of matching */ 100 - 101 if (krb5_unparse_name(context, principal, &princname) != 0) 102 goto cleanup; 68 103 69 - /* open ~/.k5login */ 70 - if ((fp = fopen(pbuf, "r")) == NULL) { 71 - free(princname); 72 - return(FALSE); 73 - } 104 - fp = fopen(filename, "r"); 105 - if (fp == NULL) 106 + if ((pid = fork()) == -1) 107 goto cleanup; 74 108 - set_cloexec_file(fp); 75 - /* 76 - * For security reasons, the .k5login file must be owned either by 77 - * the user himself, or by root. Otherwise, don't grant access. 78 - */ 79 - if (fstat(fileno(fp), &sbuf)) { 80 - fclose(fp); 81 - free(princname); 82 - return(FALSE); 83 + if ((pid = fork()) == -1) { 84 + free(princname); 85 + return(FALSE); 109 - 110 - /* For security reasons, the .k5login file must be owned either by 111 - * the user or by root. */ 112 - if (fstat(fileno(fp), &sbuf)) 113 - goto cleanup; 114 - if (sbuf.st_uid != pwd->pw_uid && !FILE_OWNER_OK(sbuf.st_uid)) 115 - goto cleanup; 116 - 117 - /* Check each line. */ 118 - while (result != ACCEPT && (fgets(linebuf, sizeof(linebuf), fp) != NULL)) { 119 - newline = strrchr(linebuf, '\n'); 120 - if (newline != NULL) 121 - *newline = '\0'; 122 - if (strcmp(linebuf, princname) == 0) 123 - result = ACCEPT; 124 - /* Clean up the rest of the line if necessary. */ 125 - if (newline == NULL) 126 - while (((gobble = getc(fp)) != EOF) && gobble != '\n'); 127 + 128 + if (pid == 0) { 129 + char *args[4]; 130 +#define ADMOF_PATH "/usr/local/sbin/ssh-admof" 131 + args[0] = ADMOF_PATH; 132 + args[1] = (char *) luser; 133 + args[2] = princname; 134 + args[3] = NULL; 135 + execv(ADMOF_PATH, args); 136 + exit(1); 86 137 } 87 - if (sbuf.st_uid != pwd->pw_uid && !FILE_OWNER_OK(sbuf.st_uid)) { 88 - fclose(fp); 89 - free(princname); 90 - return(FALSE); 91 + if (pid == 0) { 92 + char *args[4]; 93 +#define ADMOF_PATH "/usr/local/sbin/ssh-admof" 94 + args[0] = ADMOF_PATH; 95 + args[1] = (char *) luser; 96 + args[2] = princname; 97 + args[3] = NULL; 98 + execv(ADMOF_PATH, args); 99 + exit(1); 100 } 101 - 102 - /* check each line */ 103 - while (!isok && (fgets(linebuf, BUFSIZ, fp) != NULL)) { 104 - /* null-terminate the input string */ 105 - linebuf[BUFSIZ-1] = '\0'; 106 - newline = NULL; 107 - /* nuke the newline if it exists */ 108 - if ((newline = strchr(linebuf, '\n'))) 109 - *newline = '\0'; 110 - if (!strcmp(linebuf, princname)) { 111 - isok = TRUE; 112 - continue; 113 - } 114 - /* clean up the rest of the line if necessary */ 115 - if (!newline) 116 - while (((gobble = getc(fp)) != EOF) && gobble != '\n'); 138 117 139 + if (waitpid(pid, &status, 0) > 0 && WIFEXITED(status) && WEXITSTATUS(status) == 33) { 118 + isok=TRUE;119 140 + result = ACCEPT; 141 + } 120 142 + 143 cleanup: 121 144 free(princname); 122 - fclose(fp); 123 return(isok); 145 - free(filename); 146 - if (fp != NULL) 147 - fclose(fp); 148 /* If k5login files are non-authoritative, never reject. */ 149 return (!authoritative && result == REJECT) ? PASS : result; 124 150 } 125
Note: See TracChangeset
for help on using the changeset viewer.