From 194217eb7255ba12db21639a038ce63aeeb6d687 Mon Sep 17 00:00:00 2001 From: Ezra Peisach Date: Fri, 22 Jun 2001 11:27:35 +0000 Subject: [PATCH] * login.c: Much cleanup to reduce globals and shadowing * krlogind.c (main): Change sin to sock_in. * krshd.c: Change sin to sock_in to not shadow global. Change some local variables to not shadow others. 2 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@13487 dc483132-0cff-0310-8789-dd5450dbe970 --- src/appl/bsd/ChangeLog | 9 +++++ src/appl/bsd/krlogind.c | 12 +++---- src/appl/bsd/krshd.c | 36 +++++++++---------- src/appl/bsd/login.c | 80 ++++++++++++++++++++++++----------------- 4 files changed, 81 insertions(+), 56 deletions(-) diff --git a/src/appl/bsd/ChangeLog b/src/appl/bsd/ChangeLog index ff4e9b9cf..41572ad3d 100644 --- a/src/appl/bsd/ChangeLog +++ b/src/appl/bsd/ChangeLog @@ -1,3 +1,12 @@ +2001-06-21 Ezra Peisach + + * login.c: Much cleanup to reduce globals and shadowing. + + * krlogind.c (main): Change sin to sock_in. + + * krshd.c: Change sin to sock_in to not shadow global. Change some + local variables to not shadow others. + 2001-06-20 Ezra Peisach * login.c (read_env_vars_from_file: Only define if diff --git a/src/appl/bsd/krlogind.c b/src/appl/bsd/krlogind.c index 4f0b1f818..51edb7e52 100644 --- a/src/appl/bsd/krlogind.c +++ b/src/appl/bsd/krlogind.c @@ -478,7 +478,7 @@ int main(argc, argv) if (debug_port || do_fork) { int s; struct servent *ent; - struct sockaddr_in sin; + struct sockaddr_in sock_in; if (!debug_port) { if (do_encrypt) { @@ -499,16 +499,16 @@ int main(argc, argv) fprintf(stderr, "Error in socket: %s\n", strerror(errno)); exit(2); } - memset((char *) &sin, 0,sizeof(sin)); - sin.sin_family = AF_INET; - sin.sin_port = htons(debug_port); - sin.sin_addr.s_addr = INADDR_ANY; + memset((char *) &sock_in, 0,sizeof(sock_in)); + sock_in.sin_family = AF_INET; + sock_in.sin_port = htons(debug_port); + sock_in.sin_addr.s_addr = INADDR_ANY; if (!do_fork) (void) setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)); - if ((bind(s, (struct sockaddr *) &sin, sizeof(sin))) < 0) { + if ((bind(s, (struct sockaddr *) &sock_in, sizeof(sock_in))) < 0) { fprintf(stderr, "Error in bind: %s\n", strerror(errno)); exit(2); } diff --git a/src/appl/bsd/krshd.c b/src/appl/bsd/krshd.c index ef3508c2c..1fd63f929 100644 --- a/src/appl/bsd/krshd.c +++ b/src/appl/bsd/krshd.c @@ -427,22 +427,22 @@ int main(argc, argv) if (debug_port) { int s; - struct sockaddr_in sin; + struct sockaddr_in sock_in; if ((s = socket(AF_INET, SOCK_STREAM, PF_UNSPEC)) < 0) { fprintf(stderr, "Error in socket: %s\n", strerror(errno)); exit(2); } - memset((char *) &sin, 0,sizeof(sin)); - sin.sin_family = AF_INET; - sin.sin_port = htons(debug_port); - sin.sin_addr.s_addr = INADDR_ANY; + memset((char *) &sock_in, 0,sizeof(sock_in)); + sock_in.sin_family = AF_INET; + sock_in.sin_port = htons(debug_port); + sock_in.sin_addr.s_addr = INADDR_ANY; (void) setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)); - if ((bind(s, (struct sockaddr *) &sin, sizeof(sin))) < 0) { + if ((bind(s, (struct sockaddr *) &sock_in, sizeof(sock_in))) < 0) { fprintf(stderr, "Error in bind: %s\n", strerror(errno)); exit(2); } @@ -1416,13 +1416,13 @@ if(port) */ if (getenv("KRB5CCNAME")) { int i; - char *buf = (char *)malloc(strlen(getenv("KRB5CCNAME")) - +strlen("KRB5CCNAME=")+1); - if (buf) { - sprintf(buf, "KRB5CCNAME=%s",getenv("KRB5CCNAME")); + char *buf2 = (char *)malloc(strlen(getenv("KRB5CCNAME")) + +strlen("KRB5CCNAME=")+1); + if (buf2) { + sprintf(buf2, "KRB5CCNAME=%s",getenv("KRB5CCNAME")); for (i = 0; envinit[i]; i++); - envinit[i] =buf; + envinit[i] = buf2; } } @@ -1450,16 +1450,16 @@ if(port) for(cnt=0; cnt < num_env; cnt++) { int i; - char *buf; + char *buf2; if(getenv(save_env[cnt])) { - buf = (char *)malloc(strlen(getenv(save_env[cnt])) + buf2 = (char *)malloc(strlen(getenv(save_env[cnt])) +strlen(save_env[cnt]+2)); - if (buf) { - sprintf(buf, "%s=%s", save_env[cnt], + if (buf2) { + sprintf(buf2, "%s=%s", save_env[cnt], getenv(save_env[cnt])); for (i = 0; envinit[i]; i++); - envinit[i] =buf; + envinit[i] = buf2; } } } @@ -1475,7 +1475,7 @@ if(port) if (!strncmp(cmdbuf, "rcp ", 4) || (do_encrypt && !strncmp(cmdbuf, "-x rcp ", 7))) { char *copy; - struct stat s; + struct stat s2; int offst = 0; copy = malloc(strlen(cmdbuf) + 1); @@ -1497,7 +1497,7 @@ if(port) } else { strncat(cmdbuf, "/rcp", sizeof(cmdbuf) - 1 - strlen(cmdbuf)); } - if (stat((char *)cmdbuf + offst, &s) >= 0) + if (stat((char *)cmdbuf + offst, &s2) >= 0) strncat(cmdbuf, cp, sizeof(cmdbuf) - 1 - strlen(cmdbuf)); else strncpy(cmdbuf, copy, sizeof(cmdbuf) - 1 - strlen(cmdbuf)); diff --git a/src/appl/bsd/login.c b/src/appl/bsd/login.c index b5de2a48a..c7c0f4423 100644 --- a/src/appl/bsd/login.c +++ b/src/appl/bsd/login.c @@ -301,7 +301,11 @@ extern int setenv(char *, char *, int); */ int timeout = 300; +#if 0 char term[64], *hostname, *username; +#else +char term[64], *username; +#endif extern int errno; @@ -506,13 +510,17 @@ int krbflag; /* set if tickets have been obtained */ #ifdef KRB4_GET_TICKETS static int got_v4_tickets; AUTH_DAT *kdata = (AUTH_DAT *) NULL; -KTEXT ticket = (KTEXT) NULL; char tkfile[MAXPATHLEN]; -char realm[REALM_SZ]; #endif +#ifdef KRB4_GET_TICKETS +void k_init (ttyn, realm) + char *ttyn; + char *realm; +#else void k_init (ttyn) char *ttyn; +#endif { #ifdef KRB5_GET_TICKETS krb5_error_code retval; @@ -636,8 +644,8 @@ int have_v5_tickets (me) #ifdef KRB4_CONVERT int -try_convert524(kcontext, me, use_ccache) - krb5_context kcontext; +try_convert524(kctx, me, use_ccache) + krb5_context kctx; krb5_principal me; int use_ccache; { @@ -649,7 +657,7 @@ try_convert524(kcontext, me, use_ccache) /* or do this directly with krb524_convert_creds_kdc */ - krb524_init_ets(kcontext); + krb524_init_ets(kctx); /* If we have forwarded v5 tickets, retrieve the credentials from * the cache; otherwise, the v5 credentials are in my_creds. @@ -657,11 +665,11 @@ try_convert524(kcontext, me, use_ccache) if (use_ccache) { /* cc->ccache, already set up */ /* client->me, already set up */ - kpccode = krb5_build_principal(kcontext, &kpcserver, - krb5_princ_realm(kcontext, me)->length, - krb5_princ_realm(kcontext, me)->data, + kpccode = krb5_build_principal(kctx, &kpcserver, + krb5_princ_realm(kctx, me)->length, + krb5_princ_realm(kctx, me)->data, "krbtgt", - krb5_princ_realm(kcontext, me)->data, + krb5_princ_realm(kctx, me)->data, NULL); if (kpccode) { com_err("login/v4", kpccode, @@ -674,19 +682,19 @@ try_convert524(kcontext, me, use_ccache) increds.server = kpcserver; increds.times.endtime = 0; increds.keyblock.enctype = ENCTYPE_DES_CBC_CRC; - kpccode = krb5_get_credentials(kcontext, 0, ccache, + kpccode = krb5_get_credentials(kctx, 0, ccache, &increds, &v5creds); - krb5_free_principal(kcontext, kpcserver); + krb5_free_principal(kctx, kpcserver); increds.server = NULL; if (kpccode) { com_err("login/v4", kpccode, "getting V5 credentials"); return 0; } - kpccode = krb524_convert_creds_kdc(kcontext, v5creds, &v4creds); - krb5_free_creds(kcontext, v5creds); + kpccode = krb524_convert_creds_kdc(kctx, v5creds, &v4creds); + krb5_free_creds(kctx, v5creds); } else - kpccode = krb524_convert_creds_kdc(kcontext, &my_creds, &v4creds); + kpccode = krb524_convert_creds_kdc(kctx, &my_creds, &v4creds); if (kpccode) { com_err("login/v4", kpccode, "converting to V4 credentials"); return 0; @@ -721,9 +729,10 @@ try_convert524(kcontext, me, use_ccache) #ifdef KRB4_GET_TICKETS int -try_krb4 (me, user_pwstring) +try_krb4 (me, user_pwstring, realm) krb5_principal me; char *user_pwstring; + char *realm; { int krbval, kpass_ok = 0; @@ -788,7 +797,7 @@ int verify_krb_v4_tgt (realm) KTEXT_ST ticket; AUTH_DAT authdata; unsigned long addr; - static /*const*/ char rcmd[] = "rcmd"; + static /*const*/ char rcmd_str[] = "rcmd"; #if 0 char key[8]; #endif @@ -809,13 +818,13 @@ int verify_krb_v4_tgt (realm) /* Do we have rcmd. keys? */ #if 0 /* Be paranoid. If srvtab exists, assume it must contain the right key. */ - have_keys = read_service_key (rcmd, phost, realm, 0, KEYFILE, key) + have_keys = read_service_key (rcmd_str, phost, realm, 0, KEYFILE, key) ? 0 : 1; memset (key, 0, sizeof (key)); #else have_keys = 0 == access (KEYFILE, F_OK); #endif - krbval = krb_mk_req (&ticket, rcmd, phost, realm, 0); + krbval = krb_mk_req (&ticket, rcmd_str, phost, realm, 0); if (krbval == KDC_PR_UNKNOWN) { /* * Our rcmd. principal isn't known -- just assume valid @@ -836,7 +845,7 @@ int verify_krb_v4_tgt (realm) return -1; } /* got ticket, try to use it */ - krbval = krb_rd_req (&ticket, rcmd, phost, addr, &authdata, ""); + krbval = krb_rd_req (&ticket, rcmd_str, phost, addr, &authdata, ""); if (krbval != KSUCCESS) { if (krbval == RD_AP_UNDEC && !have_keys) retval = 0; @@ -1050,9 +1059,11 @@ int main(argc, argv) #endif #ifdef KRB4_GET_TICKETS CREDENTIALS save_v4creds; + char realm[REALM_SZ]; #endif char *ccname = 0; /* name of forwarded cache */ char *tz = 0; + char *hostname; off_t lseek(); handler sa; @@ -1243,7 +1254,11 @@ int main(argc, argv) v5 needs to work, does v4? */ +#ifdef KRB4_GET_TICKETS + k_init (ttyn, realm); +#else k_init (ttyn); +#endif for (cnt = 0;; username = NULL) { #ifdef KRB5_GET_TICKETS @@ -1317,7 +1332,7 @@ int main(argc, argv) #ifdef KRB4_GET_TICKETS if (login_krb4_get_tickets && !(got_v5_tickets && login_krb4_convert)) - try_krb4(me, user_pwstring); + try_krb4(me, user_pwstring, realm); #endif krbflag = (got_v5_tickets #ifdef KRB4_GET_TICKETS @@ -1457,7 +1472,7 @@ int main(argc, argv) } quietlog = access(HUSHLOGIN, F_OK) == 0; - dolastlog(quietlog, tty); + dolastlog(hostname, quietlog, tty); if (!hflag && !rflag && !kflag && !Kflag && !eflag) { /* XXX */ static struct winsize win = { 0, 0, 0, 0 }; @@ -1499,15 +1514,15 @@ int main(argc, argv) controlling tty, which is the case (under SunOS at least.) */ { - int p = getpid(); - struct sigaction sa, osa; + int pid = getpid(); + struct sigaction sa2, osa; /* this will set the PGID to the PID. */ #ifdef HAVE_SETPGID - if (setpgid(p,p) < 0) + if (setpgid(pid,pid) < 0) perror("login.krb5: setpgid"); #elif defined(SETPGRP_TWOARG) - if (setpgrp(p,p) < 0) + if (setpgrp(pid,pid) < 0) perror("login.krb5: setpgrp"); #else if (setpgrp() < 0) @@ -1519,21 +1534,21 @@ int main(argc, argv) process group is the foreground pgrp of the tty, then this will suspend the child, which is bad. */ - sa.sa_flags = 0; - sa.sa_handler = SIG_IGN; - sigemptyset(&(sa.sa_mask)); + sa2.sa_flags = 0; + sa2.sa_handler = SIG_IGN; + sigemptyset(&(sa2.sa_mask)); - if (sigaction(SIGTTOU, &sa, &osa)) + if (sigaction(SIGTTOU, &sa2, &osa)) perror("login.krb5: sigaction(SIGTTOU, SIG_IGN)"); /* This will set the foreground process group of the controlling terminal to this process group (containing only this process). */ #ifdef HAVE_TCSETPGRP - if (tcsetpgrp(0, p) < 0) + if (tcsetpgrp(0, pid) < 0) perror("login.krb5: tcsetpgrp"); #else - if (ioctl(0, TIOCSPGRP, &p) < 0) + if (ioctl(0, TIOCSPGRP, &pid) < 0) perror("login.krb5: tiocspgrp"); #endif @@ -2117,7 +2132,8 @@ void checknologin() } } -void dolastlog(quiet, tty) +void dolastlog(hostname, quiet, tty) + char *hostname; int quiet; char *tty; { -- 2.26.2