From 5c0e770d3be85b7ff7eb9534ca1add1883d2530f Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Fri, 22 Jun 2001 01:47:29 +0000 Subject: [PATCH] * adm_conn.c, kpasswd.c, srv_net.c: Changed various char string variables into macros, for better format/argument checking under gcc. * main.c (pwd_change): Use strncpy instead of sprintf to copy error message text into buffer. Use goto rather than repeated code. (main): Use %lx for params.mask. Make debug_level volatile. Delete unused variables oldnames, rlen. * srv_net.c (net_find_slave): Initialize "found". (net_dispatch): Make "kret" volatile, so longjmp won't clobber it. (net_slaves_active): Variable deleted. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@13469 dc483132-0cff-0310-8789-dd5450dbe970 --- src/kadmin/v5passwdd/ChangeLog | 17 +++++++++++++ src/kadmin/v5passwdd/adm_conn.c | 2 +- src/kadmin/v5passwdd/kpasswd.c | 42 ++++++++++++++++----------------- src/kadmin/v5passwdd/main.c | 30 +++++++++++------------ src/kadmin/v5passwdd/srv_net.c | 34 +++++++++++++------------- 5 files changed, 71 insertions(+), 54 deletions(-) diff --git a/src/kadmin/v5passwdd/ChangeLog b/src/kadmin/v5passwdd/ChangeLog index 66e04ade5..5aefb1902 100644 --- a/src/kadmin/v5passwdd/ChangeLog +++ b/src/kadmin/v5passwdd/ChangeLog @@ -1,3 +1,20 @@ +2001-06-21 Ken Raeburn + + * adm_conn.c, kpasswd.c, srv_net.c: Changed various char string + variables into macros, for better format/argument checking under + gcc. + + * main.c (pwd_change): Use strncpy instead of sprintf to copy + error message text into buffer. Use goto rather than repeated + code. + (main): Use %lx for params.mask. Make debug_level volatile. + Delete unused variables oldnames, rlen. + + * srv_net.c (net_find_slave): Initialize "found". + (net_dispatch): Make "kret" volatile, so longjmp won't clobber + it. + (net_slaves_active): Variable deleted. + 2001-06-21 Ezra Peisach * main.c: Add prototype for daemon if needed. diff --git a/src/kadmin/v5passwdd/adm_conn.c b/src/kadmin/v5passwdd/adm_conn.c index 4428be950..e96c7f1e3 100644 --- a/src/kadmin/v5passwdd/adm_conn.c +++ b/src/kadmin/v5passwdd/adm_conn.c @@ -43,7 +43,7 @@ /* * Strings */ -static char *kadm_cache_name_fmt = "FILE:/tmp/tkt_kadm_%d"; +#define kadm_cache_name_fmt "FILE:/tmp/tkt_kadm_%d" /* * Prototypes for local functions diff --git a/src/kadmin/v5passwdd/kpasswd.c b/src/kadmin/v5passwdd/kpasswd.c index 2e435f426..42d81094c 100644 --- a/src/kadmin/v5passwdd/kpasswd.c +++ b/src/kadmin/v5passwdd/kpasswd.c @@ -54,33 +54,33 @@ /* * Local data. */ -static const char *kpwd_serror_head = "server"; -static const char *kpwd_change_prompt_1 = " Enter new password: "; -static const char *kpwd_change_prompt_2 = "Re-enter new password: "; -static const char *kpwd_old_password_prompt = " Enter old password: "; -static const char *kpwd_old_pwd_name_fmt = "Enter old password for %s: "; +#define kpwd_serror_head "server" +#define kpwd_change_prompt_1 " Enter new password: " +#define kpwd_change_prompt_2 "Re-enter new password: " +#define kpwd_old_password_prompt " Enter old password: " +#define kpwd_old_pwd_name_fmt "Enter old password for %s: " #ifdef LANGUAGES_SUPPORTED -static const char *kpwd_usage_error_fmt = "%s: usage is %s [-u user] [-l language]\n"; -static const char *kpwd_getoptstring = "l:u:"; +#define kpwd_usage_error_fmt "%s: usage is %s [-u user] [-l language]\n" +#define kpwd_getoptstring "l:u:" #else /* LANGUAGES_SUPPORTED */ -static const char *kpwd_usage_error_fmt = "%s: usage is %s [-u user]\n"; -static const char *kpwd_getoptstring = "u:"; +#define kpwd_usage_error_fmt "%s: usage is %s [-u user]\n" +#define kpwd_getoptstring "u:" #endif /* LANGUAGES_SUPPORTED */ -static const char *kpwd_extra_args = "extra arguments"; +#define kpwd_extra_args "extra arguments" #if 0 -static const char *kpwd_bad_option_fmt = "%s: unrecognized option -%c.\n"; +#define kpwd_bad_option_fmt "%s: unrecognized option -%c.\n" #endif -static const char *kpwd_no_memory_fmt = "%s: not enough resources to allocate %d bytes for %s.\n"; -static const char *kpwd_bad_client_fmt = "%s: %s%s%s %s not recognized by the server.\n"; -static const char *kpwd_no_server_fmt = "%s: cannot find server for %s.\n"; -static const char *kpwd_incorrect_fmt = "%s: incorrect password\n"; -static const char *kpwd_cant_connect_fmt = "%s: cannot contact server (%s).\n"; -static const char *kpwd_proto_error_fmt = "%s: protocol error during %s request (%s).\n"; -static const char *kpwd_pwproto_unsupp_fmt = "%s: %s request not supported by server.\n"; -static const char *kpwd_pwproto_error = "%s: server error (%s) during %s request.\n"; -static const char *kpwd_pwd_unacceptable = "%s: your new password is unacceptable to the server, %s.\n"; -static const char *kpwd_read_pass_error = "%s: error (%s) reading passwords.\n"; +#define kpwd_no_memory_fmt "%s: not enough resources to allocate %d bytes for %s.\n" +#define kpwd_bad_client_fmt "%s: %s%s%s %s not recognized by the server.\n" +#define kpwd_no_server_fmt "%s: cannot find server for %s.\n" +#define kpwd_incorrect_fmt "%s: incorrect password\n" +#define kpwd_cant_connect_fmt "%s: cannot contact server (%s).\n" +#define kpwd_proto_error_fmt "%s: protocol error during %s request (%s).\n" +#define kpwd_pwproto_unsupp_fmt "%s: %s request not supported by server.\n" +#define kpwd_pwproto_error "%s: server error (%s) during %s request.\n" +#define kpwd_pwd_unacceptable "%s: your new password is unacceptable to the server, %s.\n" +#define kpwd_read_pass_error "%s: error (%s) reading passwords.\n" static const char *kpwd_password_text = "passwords"; #if 0 diff --git a/src/kadmin/v5passwdd/main.c b/src/kadmin/v5passwdd/main.c index 80520b06f..ae6824726 100644 --- a/src/kadmin/v5passwdd/main.c +++ b/src/kadmin/v5passwdd/main.c @@ -50,10 +50,11 @@ static void usage() int main(int argc, char *argv[]) { - int ret, nofork; + int ret; + volatile int nofork; int timeout = -1; krb5_error_code code; - int debug_level = 0; + volatile int debug_level = 0; #if POSIX_SIGNALS struct sigaction s_action; #endif /* POSIX_SIGNALS */ @@ -272,44 +273,43 @@ pwd_change(kcontext, debug_level, auth_context, ticket, ret = krb5_timeofday(kcontext, &now); if (ret) { - sprintf(err_str, error_message(ret)); + /* XXX - The only caller is known to use a 1K buffer. */ + system_error: + strncpy(err_str, error_message(ret), 1024); return(KRB5_ADM_SYSTEM_ERROR); } if((ret = kadm5_get_principal(global_server_handle, principal, - &princ, - KADM5_PRINCIPAL_NORMAL_MASK)) != - KADM5_OK) { - sprintf(err_str, error_message(ret)); - return(KRB5_ADM_SYSTEM_ERROR); + &princ, + KADM5_PRINCIPAL_NORMAL_MASK)) != + KADM5_OK) { + goto system_error; } if(princ.aux_attributes & KADM5_POLICY) { if((ret=kadm5_get_policy(global_server_handle, princ.policy, &pol)) != KADM5_OK) { (void) kadm5_free_principal_ent(global_server_handle, &princ); - sprintf(err_str, error_message(ret)); - return(KRB5_ADM_SYSTEM_ERROR); + goto system_error; } if((now - princ.last_pwd_change) < pol.pw_min_life && !(princ.attributes & KRB5_KDB_REQUIRES_PWCHANGE)) { (void) kadm5_free_policy_ent(global_server_handle, &pol); (void) kadm5_free_principal_ent(global_server_handle, &princ); - sprintf(err_str, error_message(ret)); + /* XXX - The only caller is known to use a 1K buffer. */ + strncpy(err_str, error_message(ret), 1024); return(KRB5_ADM_PW_UNACCEPT); } ret = kadm5_free_policy_ent(global_server_handle, &pol); if (ret) { (void) kadm5_free_principal_ent(global_server_handle, &princ); - sprintf(err_str, error_message(ret)); - return(KRB5_ADM_SYSTEM_ERROR); + goto system_error; } } ret = kadm5_free_principal_ent(global_server_handle, &princ); if (ret) { - sprintf(err_str, error_message(ret)); - return(KRB5_ADM_SYSTEM_ERROR); + goto system_error; } /* ok, it's not too early to change the password. change it. */ diff --git a/src/kadmin/v5passwdd/srv_net.c b/src/kadmin/v5passwdd/srv_net.c index 14115e3b3..693eda02b 100644 --- a/src/kadmin/v5passwdd/srv_net.c +++ b/src/kadmin/v5passwdd/srv_net.c @@ -84,23 +84,23 @@ typedef struct _net_slave_info { /* * Error messages. */ -static const char *net_waiterr_msg = "\004child wait failed - cannot reap children"; +#define net_waiterr_msg "\004child wait failed - cannot reap children" #if 0 -static const char *net_def_realm_fmt = "%s: cannot get default realm (%s).\n"; +#define net_def_realm_fmt "%s: cannot get default realm (%s).\n" #endif -static const char *net_no_mem_fmt = "%s: cannot get memory.\n"; -static const char *net_parse_srv_fmt = "%s: cannot parse server name %s (%s).\n"; -static const char *net_no_hostname_fmt = "%s: cannot get our host name (%s).\n"; -static const char *net_no_hostent_fmt = "%s: cannot get our host entry (%s).\n"; -static const char *net_no_servent_fmt = "%s: cannot get service entry for %s (%s).\n"; -static const char *net_sockerr_fmt = "%s: cannot open network socket (%s).\n"; -static const char *net_soerr_fmt = "%s: cannot set socket options (%s).\n"; -static const char *net_binderr_fmt = "%s: cannot bind to network address (%s).\n"; - -static const char *net_select_fmt = "\004select failed"; -static const char *net_cl_disp_fmt = "\004client dispatch failed"; -static const char *net_not_ready_fmt = "\004select error - no socket to read"; -static const char *net_dispatch_msg = "network dispatch"; +#define net_no_mem_fmt "%s: cannot get memory.\n" +#define net_parse_srv_fmt "%s: cannot parse server name %s (%s).\n" +#define net_no_hostname_fmt "%s: cannot get our host name (%s).\n" +#define net_no_hostent_fmt "%s: cannot get our host entry (%s).\n" +#define net_no_servent_fmt "%s: cannot get service entry for %s (%s).\n" +#define net_sockerr_fmt "%s: cannot open network socket (%s).\n" +#define net_soerr_fmt "%s: cannot set socket options (%s).\n" +#define net_binderr_fmt "%s: cannot bind to network address (%s).\n" + +#define net_select_fmt "\004select failed" +#define net_cl_disp_fmt "\004client dispatch failed" +#define net_not_ready_fmt "\004select error - no socket to read" +#define net_dispatch_msg "network dispatch" static int net_debug_level = 0; @@ -153,7 +153,7 @@ static net_slave_info * net_find_slave(id) net_slave_type id; { - int i, found; + int i, found = 0; for (i=0; i