From 04fdc5335e74fbb83557ed297a9d6cf546fb66a9 Mon Sep 17 00:00:00 2001 From: Ezra Peisach Date: Tue, 5 Jun 2001 16:53:24 +0000 Subject: [PATCH] * authorization.c, heuristic.c, krb_auth_su.c, main.c, setenv.c: Cleanup assignments in conditionals. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@13272 dc483132-0cff-0310-8789-dd5450dbe970 --- src/clients/ksu/ChangeLog | 5 ++ src/clients/ksu/authorization.c | 38 ++++++---- src/clients/ksu/heuristic.c | 126 +++++++++++++++++++------------- src/clients/ksu/krb_auth_su.c | 3 +- src/clients/ksu/main.c | 3 +- src/clients/ksu/setenv.c | 3 +- 6 files changed, 111 insertions(+), 67 deletions(-) diff --git a/src/clients/ksu/ChangeLog b/src/clients/ksu/ChangeLog index 0772244a1..f2dc459d9 100644 --- a/src/clients/ksu/ChangeLog +++ b/src/clients/ksu/ChangeLog @@ -1,3 +1,8 @@ +2001-06-05 Ezra Peisach + + * authorization.c, heuristic.c, krb_auth_su.c, main.c, setenv.c: + Cleanup assignments in conditionals. + 2001-04-03 Tom Yu * setenv.c: Add conditionals for compilation of setenv, unsetenv, diff --git a/src/clients/ksu/authorization.c b/src/clients/ksu/authorization.c index a2e540936..6d98a78b9 100644 --- a/src/clients/ksu/authorization.c +++ b/src/clients/ksu/authorization.c @@ -86,7 +86,8 @@ krb5_error_code krb5_authorization(context, principal, luser, if ((pwd = getpwnam(luser)) == NULL) return 0; - if (retval = krb5_unparse_name(context, principal, &princname)) + retval = krb5_unparse_name(context, principal, &princname); + if (retval) return retval; #ifdef DEBUG @@ -146,7 +147,9 @@ krb5_error_code krb5_authorization(context, principal, luser, fprintf(stderr, "In krb5_authorization: principal to be authorized %s\n", princname); - if (retval = k5login_lookup( login_fp, princname, &retbool)){ + + retval = k5login_lookup(login_fp, princname, &retbool); + if (retval) { auth_cleanup(users_fp, login_fp, princname); return retval; } @@ -157,8 +160,9 @@ krb5_error_code krb5_authorization(context, principal, luser, } if ((!k5users_flag) && (retbool == FALSE) ){ - if(retval = k5users_lookup (users_fp, princname, - cmd, &retbool, out_fcmd)){ + retval = k5users_lookup (users_fp, princname, + cmd, &retbool, out_fcmd); + if(retval) { auth_cleanup(users_fp, login_fp, princname); return retval; } @@ -201,10 +205,9 @@ krb5_error_code k5login_lookup (fp, princname, found) char * lp; krb5_boolean loc_found = FALSE; - - if (retval = get_line(fp, &line )){ + retval = get_line(fp, &line); + if (retval) return retval; - } while (line){ fprinc = get_first_token (line, &lp); @@ -222,7 +225,10 @@ krb5_error_code k5login_lookup (fp, princname, found) } free (line); - if (retval = get_line(fp, &line )){ return retval;} + + retval = get_line(fp, &line); + if (retval) + return retval; } @@ -263,7 +269,8 @@ krb5_error_code k5users_lookup (fp, princname, cmd, found, out_fcmd) char * loc_fcmd = NULL; krb5_boolean loc_found = FALSE; - if (retval = get_line(fp, &line )) + retval = get_line(fp, &line); + if (retval) return retval; while (line){ @@ -307,7 +314,7 @@ krb5_error_code k5users_lookup (fp, princname, cmd, found, out_fcmd) } } - }while (fcmd = get_next_token( &lp)); + }while ((fcmd = get_next_token( &lp))); } free (line); break; @@ -315,7 +322,11 @@ krb5_error_code k5users_lookup (fp, princname, cmd, found, out_fcmd) } free (line); - if (retval = get_line(fp, &line )){ return retval;} + + retval = get_line(fp, &line); + if (retval) { + return retval; + } } *out_fcmd = loc_fcmd; @@ -397,7 +408,7 @@ krb5_boolean fcmd_resolve(fcmd, out_fcmd, out_err) i++; - } while(tc = get_next_token (&lp)); + } while((tc = get_next_token (&lp))); tmp_fcmd[i] = NULL; *out_fcmd = tmp_fcmd; @@ -589,7 +600,8 @@ krb5_error_code get_line (fp, out_line) line[0] = '\0'; while (( r = fgets(line_ptr, BUFSIZ , fp)) != NULL){ - if (newline = strchr(line_ptr, '\n')){ + newline = strchr(line_ptr, '\n'); + if (newline) { *newline = '\0'; break; } diff --git a/src/clients/ksu/heuristic.c b/src/clients/ksu/heuristic.c index f941ea97d..76d697744 100644 --- a/src/clients/ksu/heuristic.c +++ b/src/clients/ksu/heuristic.c @@ -52,7 +52,8 @@ krb5_error_code get_all_princ_from_file (fp, plist) if (!(temp_list = (char **) malloc( CHUNK * sizeof(char *)))) return errno; - if (retval = get_line(fp, &line )) + retval = get_line(fp, &line); + if (retval) return retval; while (line){ @@ -73,7 +74,9 @@ krb5_error_code get_all_princ_from_file (fp, plist) free (line); - if (retval = get_line(fp, &line )){ return retval;} + retval = get_line(fp, &line); + if (retval) + return retval; } temp_list[count] = NULL; @@ -158,7 +161,8 @@ filter(fp, cmd, k5users_list, k5users_filt_list) while(k5users_list[i]){ - if (retval= k5users_lookup(fp, k5users_list[i], cmd, &found, &out_cmd)) + retval= k5users_lookup(fp, k5users_list[i], cmd, &found, &out_cmd); + if (retval) return retval; if (found == FALSE){ @@ -233,21 +237,24 @@ get_authorized_princ_names(luser, cmd, princ_list) return 0; } - if(retval = get_all_princ_from_file (users_fp, &k5users_list)){ + retval = get_all_princ_from_file (users_fp, &k5users_list); + if(retval) { close_time(k5users_flag,users_fp, k5login_flag,login_fp); return retval; } rewind(users_fp); - if(retval = filter(users_fp,cmd, k5users_list, &k5users_filt_list)){ + retval = filter(users_fp,cmd, k5users_list, &k5users_filt_list); + if(retval) { close_time(k5users_flag,users_fp, k5login_flag, login_fp); return retval; } } if (!k5login_flag){ - if(retval = get_all_princ_from_file (login_fp, &k5login_list)){ + retval = get_all_princ_from_file (login_fp, &k5login_list); + if(retval) { close_time(k5users_flag,users_fp, k5login_flag,login_fp); return retval; } @@ -256,13 +263,13 @@ get_authorized_princ_names(luser, cmd, princ_list) close_time(k5users_flag,users_fp, k5login_flag, login_fp); if (cmd) { - if (retval = list_union(k5login_list, - k5users_filt_list, &combined_list)){ - close_time(k5users_flag,users_fp, k5login_flag,login_fp); - return retval; - } - *princ_list = combined_list; - return 0; + retval = list_union(k5login_list, k5users_filt_list, &combined_list); + if (retval){ + close_time(k5users_flag,users_fp, k5login_flag,login_fp); + return retval; + } + *princ_list = combined_list; + return 0; } else { if (k5users_filt_list != NULL) free(k5users_filt_list); @@ -332,29 +339,30 @@ krb5_error_code get_closest_principal(context, plist, client, found) while(plist[i]){ - if (retval = krb5_parse_name(context, plist[i], &temp_client)) + retval = krb5_parse_name(context, plist[i], &temp_client); + if (retval) return retval; - + pnelem = krb5_princ_size(context, temp_client); - + if ( cnelem > pnelem){ i++; continue; } - + if (krb5_princ_realm(context, *client)->length == krb5_princ_realm(context, temp_client)->length && (!memcmp (krb5_princ_realm(context, *client)->data, krb5_princ_realm(context, temp_client)->data, krb5_princ_realm(context, temp_client)->length))){ - + got_one = TRUE; for(j =0; j < cnelem; j ++){ krb5_data *p1 = krb5_princ_component(context, *client, j); krb5_data *p2 = krb5_princ_component(context, temp_client, j); - + if ((p1->length != p2->length) || memcmp(p1->data,p2->data,p1->length)){ got_one = FALSE; @@ -373,7 +381,7 @@ krb5_error_code get_closest_principal(context, plist, client, found) } i++; } - + if (best_client) { *found = TRUE; *client = best_client; @@ -405,18 +413,20 @@ krb5_error_code find_either_ticket (context, cc, client, end_server, found) if ( ! stat(cc_source_name, &st_temp)){ - if (retval = find_ticket(context, cc, client, end_server, &temp_found)) + retval = find_ticket(context, cc, client, end_server, &temp_found); + if (retval) return retval; if (temp_found == FALSE){ - if (retval = krb5_tgtname(context, - krb5_princ_realm(context, client), - krb5_princ_realm(context, client), - &kdc_server)){ - return retval ; - } + retval = krb5_tgtname(context, + krb5_princ_realm(context, client), + krb5_princ_realm(context, client), + &kdc_server); + if (retval) + return retval; - if(retval = find_ticket(context, cc,client, kdc_server, &temp_found)) + retval = find_ticket(context, cc,client, kdc_server, &temp_found); + if(retval) return retval; } else if (auth_debug) @@ -445,10 +455,12 @@ krb5_error_code find_ticket (context, cc, client, server, found) memset((char *) &tgtq, 0, sizeof(tgtq)); memset((char *) &tgt, 0, sizeof(tgt)); - if (retval= krb5_copy_principal(context, client, &tgtq.client)) + retval= krb5_copy_principal(context, client, &tgtq.client); + if (retval) return retval; - if (retval= krb5_copy_principal(context, server, &tgtq.server)) + retval= krb5_copy_principal(context, server, &tgtq.server); + if (retval) return retval ; retval = krb5_cc_retrieve_cred(context, cc, KRB5_TC_MATCH_SRV_NAMEONLY | KRB5_TC_SUPPORTED_KTYPES, @@ -489,7 +501,8 @@ krb5_error_code find_princ_in_list (context, princ, plist, found) if (!plist) return 0; - if (retval = krb5_unparse_name(context, princ, &princname)) + retval = krb5_unparse_name(context, princ, &princname); + if (retval) return retval; while (plist[i] ){ @@ -558,14 +571,18 @@ krb5_error_code get_best_princ_for_target(context, source_uid, target_uid, cc_source_name = krb5_cc_get_name(context, cc_source); - if (! stat(cc_source_name, &st_temp)) - if (retval = krb5_cc_get_principal(context, cc_source, &cc_def_princ)) + if (! stat(cc_source_name, &st_temp)) { + retval = krb5_cc_get_principal(context, cc_source, &cc_def_princ); + if (retval) return retval; + } - - if (retval=krb5_parse_name(context, target_user, &target_client)) + retval=krb5_parse_name(context, target_user, &target_client); + if (retval) return retval; - if (retval=krb5_parse_name(context, source_user, &source_client)) + + retval=krb5_parse_name(context, source_user, &source_client); + if (retval) return retval; if (source_uid == 0){ @@ -614,7 +631,8 @@ krb5_error_code get_best_princ_for_target(context, source_uid, target_uid, return 0; }else{ - if (retval = get_authorized_princ_names(target_user, cmd, &aplist)) + retval = get_authorized_princ_names(target_user, cmd, &aplist); + if (retval) return retval; /* .k5users or .k5login exist, but no authorization */ @@ -626,8 +644,9 @@ krb5_error_code get_best_princ_for_target(context, source_uid, target_uid, } } - if (retval = krb5_sname_to_principal(context, hostname, NULL, - KRB5_NT_SRV_HST, &end_server)) + retval = krb5_sname_to_principal(context, hostname, NULL, + KRB5_NT_SRV_HST, &end_server); + if (retval) return retval; @@ -649,15 +668,18 @@ krb5_error_code get_best_princ_for_target(context, source_uid, target_uid, for (i= 0; i < count; i ++){ if(princ_trials[i].p) { - if (retval= find_princ_in_list(context, princ_trials[i].p, aplist, &found)) + retval= find_princ_in_list(context, princ_trials[i].p, aplist, + &found); + if (retval) return retval; if (found == TRUE){ princ_trials[i].found = TRUE; - if (retval = find_either_ticket (context, cc_source, - princ_trials[i].p, - end_server, &found)) + retval = find_either_ticket (context, cc_source, + princ_trials[i].p, + end_server, &found); + if (retval) return retval; if (found == TRUE){ *client = princ_trials[i].p; @@ -674,12 +696,13 @@ krb5_error_code get_best_princ_for_target(context, source_uid, target_uid, i=0; while (aplist[i]){ - - if (retval = krb5_parse_name(context, aplist[i], &temp_client)) + retval = krb5_parse_name(context, aplist[i], &temp_client); + if (retval) return retval; - if (retval = find_either_ticket (context, cc_source, temp_client, - end_server, &found)) + retval = find_either_ticket (context, cc_source, temp_client, + end_server, &found); + if (retval) return retval; if (found == TRUE){ @@ -711,14 +734,17 @@ krb5_error_code get_best_princ_for_target(context, source_uid, target_uid, #ifdef PRINC_LOOK_AHEAD for (i=0; i < count; i ++){ if (princ_trials[i].p){ - if(retval=krb5_copy_principal(context, princ_trials[i].p, - &temp_client)) + retval=krb5_copy_principal(context, princ_trials[i].p, + &temp_client); + if(retval) return retval; /* get the client name that is the closest to the three princ in trials */ - if(retval=get_closest_principal(context, aplist, &temp_client, & found)) + retval=get_closest_principal(context, aplist, &temp_client, + &found); + if(retval) return retval; if (found == TRUE){ diff --git a/src/clients/ksu/krb_auth_su.c b/src/clients/ksu/krb_auth_su.c index cfb270320..4e6bf127b 100644 --- a/src/clients/ksu/krb_auth_su.c +++ b/src/clients/ksu/krb_auth_su.c @@ -344,7 +344,8 @@ krb5_keyblock * tkt_ses_key; } /* Check to make sure ticket hasn't expired */ - if (retval = krb5_check_exp(context, tkt->enc_part2->times)) { + retval = krb5_check_exp(context, tkt->enc_part2->times); + if (retval) { if (auth_debug && (retval == KRB5KRB_AP_ERR_TKT_EXPIRED)) { fprintf(stderr, "krb5_verify_tkt_def: ticket has expired"); diff --git a/src/clients/ksu/main.c b/src/clients/ksu/main.c index 9e28c0d6f..17b33cdca 100644 --- a/src/clients/ksu/main.c +++ b/src/clients/ksu/main.c @@ -116,7 +116,6 @@ krb5_boolean stored = FALSE; krb5_principal kdc_server; krb5_boolean zero_password; char * dir_of_cc_target; -char * dir_of_cc_source; options.opt = KRB5_DEFAULT_OPTIONS; options.lifetime = KRB5_DEFAULT_TKT_LIFE; @@ -799,7 +798,7 @@ krb5_seteuid(0); /*So we have some chance of sweeping up*/ default: if (auth_debug){ printf(" The child pid is %ld\n", (long) child_pid); - printf(" The parent pid is %d\n", getpid()); + printf(" The parent pid is %ld\n", (long) getpid()); } while ((ret_pid = waitpid(child_pid, &statusp, WUNTRACED)) != -1) { if (WIFSTOPPED(statusp)) { diff --git a/src/clients/ksu/setenv.c b/src/clients/ksu/setenv.c index 2633a9d11..173a2ba5f 100644 --- a/src/clients/ksu/setenv.c +++ b/src/clients/ksu/setenv.c @@ -26,6 +26,7 @@ * "value". If rewrite is set, replace any current value. */ #ifndef HAVE_SETENV +int setenv(name, value, rewrite) register char *name, *value; int rewrite; @@ -43,7 +44,7 @@ setenv(name, value, rewrite) if (!rewrite) return(0); if (strlen(C) >= l_value) { /* old larger; copy over */ - while (*C++ = *value++); + while ((*C++ = *value++)); return(0); } } -- 2.26.2