From: Theodore Tso Date: Fri, 24 Dec 1993 22:32:17 +0000 (+0000) Subject: Lots of bugs, cleanup... X-Git-Tag: krb5-1.0-beta3~84 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=bc2578fd62852dae832939b2d1d6b3aff21ceccb;p=krb5.git Lots of bugs, cleanup... git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@3264 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/kadmin/client/kadmin.c b/src/kadmin/client/kadmin.c index 62fdec822..27ea4b053 100644 --- a/src/kadmin/client/kadmin.c +++ b/src/kadmin/client/kadmin.c @@ -50,6 +50,15 @@ static char rcsid_kadmin[] = #include #include +/* + * Try no preauthentication first; then try the encrypted timestamp + */ +int preauth_search_list[] = { + 0, + KRB5_PADATA_ENC_TIMESTAMP, + -1 + }; + krb5_error_code get_first_ticket PROTOTYPE((krb5_ccache, krb5_principal)); @@ -59,6 +68,8 @@ struct sockaddr_in local_sin, remote_sin; krb5_creds my_creds; void get_def_princ(); +void decode_kadmind_reply(); +int print_status_message(); main(argc,argv) int argc; @@ -494,29 +505,27 @@ repeat: exit(1); } free(inbuf.data); - - memcpy(&rd_priv_resp.appl_code, msg_data.data, 1); - memcpy(&rd_priv_resp.oper_code, msg_data.data + 1, 1); - memcpy(&rd_priv_resp.retn_code, msg_data.data + 2, 1); - + + decode_kadmind_reply(msg_data, &rd_priv_resp); free(msg_data.data); + if (!((rd_priv_resp.appl_code == KADMIN) && - (rd_priv_resp.retn_code == KADMGOOD))) { - fprintf(stderr, "Generic Error During kadmin Termination!\n"); + (rd_priv_resp.retn_code == KADMGOOD))) { + if (rd_priv_resp.message) + fprintf(stderr, "%s\n", rd_priv_resp.message); + else + fprintf(stderr, "Generic Error During kadmin Termination!\n"); retval = 1; } else { fprintf(stderr, "\nHave a Good Day.\n\n"); } - free(send_cksum.contents); + if (rd_priv_resp.message) + free(rd_priv_resp.message); - - if (retval) { - fprintf(stderr, "\n\nkadmin terminating - %s.\n\n", - kadmind_kadmin_response[rd_priv_resp.retn_code]); - exit(1); - } - exit(0); + free(send_cksum.contents); + + exit(retval); } krb5_error_code @@ -533,6 +542,7 @@ OLDDECLARG(krb5_principal, client) krb5_error_code retval; char *password; int pwsize; + int i; if ((retval = krb5_unparse_name(client, &client_name))) { fprintf(stderr, "Unable to Unparse Client Name!\n"); @@ -583,28 +593,34 @@ OLDDECLARG(krb5_principal, client) } /* Build Request for Initial Credentials */ - if ((retval = krb5_get_in_tkt_with_password( - 0, /* options */ - my_addresses, - KRB5_PADATA_ENC_TIMESTAMP, /* do preauth */ - ETYPE_DES_CBC_CRC, /* etype */ - KEYTYPE_DES, - password, - cache, - &my_creds, - 0 ))) { - fprintf(stderr, "\nUnable to Get Initial Credentials : %s!\n", - error_message(retval)); - (void) memset(password, 0, pwsize); - free(password); - krb5_free_addresses(my_addresses); - return(1); + for (i=0; preauth_search_list[i] >= 0; i++) { + retval = krb5_get_in_tkt_with_password( + 0, /* options */ + my_addresses, + /* do random preauth */ + preauth_search_list[i], + ETYPE_DES_CBC_CRC, /* etype */ + KEYTYPE_DES, + password, + cache, + &my_creds, + 0); + if (retval != KRB5KDC_PREAUTH_FAILED && + retval != KRB5KRB_ERR_GENERIC) + break; } - + /* Do NOT Forget to zap password */ memset((char *) password, 0, pwsize); free(password); krb5_free_addresses(my_addresses); + + if (retval) { + fprintf(stderr, "\nUnable to Get Initial Credentials : %s!\n", + error_message(retval)); + return(1); + } + return(0); } @@ -771,3 +787,45 @@ usage() fprintf(stderr, " the -n option is used.\n\n"); exit(0); } + +void decode_kadmind_reply(data, response) + krb5_data data; + kadmin_requests *response; +{ + response->appl_code = data.data[0]; + response->oper_code = data.data[1]; + response->retn_code = data.data[2]; + if (data.length > 3 && data.data[3]) { + response->message = malloc(data.length - 2); + if (response->message) { + memcpy(response->message, data.data + 3, data.length - 3); + response->message[data.length - 3] = 0; + } + } else + response->message = NULL; + + return; +} + +int print_status_message(response, success_msg) + kadmin_requests *response; + char *success_msg; +{ + int retval = 1; + + if (response->appl_code == KADMIN) { + if (response->retn_code == KADMGOOD) { + fprintf(stderr, "%s\n", success_msg); + retval = 0; + } else if (response->retn_code == KADMBAD) + fprintf(stderr, "%s\n", response->message); + else + fprintf(stderr, "ERROR: unknown return code from server.\n"); + } else + fprintf(stderr, "ERROR: unknown application code from server.\n"); + + if (response->message) + free(response->message); + + return retval; +} diff --git a/src/kadmin/client/kadmin_add.c b/src/kadmin/client/kadmin_add.c index 425e26ff4..bf3465686 100644 --- a/src/kadmin/client/kadmin_add.c +++ b/src/kadmin/client/kadmin_add.c @@ -45,6 +45,9 @@ static char rcsid_kadmin_add[] = #include #include +void decode_kadmind_reply(); +int print_status_message(); + krb5_error_code kadm_add_user(my_creds, rep_ret, local_addr, foreign_addr, local_socket, seqno, oper_type, principal) @@ -144,8 +147,14 @@ char *principal; free(inbuf.data); if (msg_data.data[2] == KADMBAD) { - fprintf(stderr, "Principal Already Exists!\n\n"); - return(0); + decode_kadmind_reply(msg_data, &rd_priv_resp); + + if (rd_priv_resp.message) { + fprintf(stderr, "%s\n\n", rd_priv_resp.message); + free(rd_priv_resp.message); + } else + fprintf(stderr, "Generic error from server.\n\n"); + return(0); } #ifdef MACH_PASS @@ -258,18 +267,13 @@ char *principal; } free(inbuf.data); - memcpy(&rd_priv_resp.appl_code, msg_data.data, 1); - memcpy(&rd_priv_resp.oper_code, msg_data.data + 1, 1); - memcpy(&rd_priv_resp.retn_code, msg_data.data + 2, 1); - - free(msg_data.data); + decode_kadmind_reply(msg_data, &rd_priv_resp); + + free(inbuf.data); + free(msg_data.data); + + retval = print_status_message(&rd_priv_resp, + "Database Addition Successful."); - if (!((rd_priv_resp.appl_code == KADMIN) && - (rd_priv_resp.retn_code == KADMGOOD))) { - fprintf(stderr, "Generic Error During kadmin Addition!\n"); - retval = 1; - } else { - fprintf(stderr, "\nDatabase Addition Successful.\n"); - } return(retval); } diff --git a/src/kadmin/client/kadmin_adr.c b/src/kadmin/client/kadmin_adr.c index e52e80acd..d239932a3 100644 --- a/src/kadmin/client/kadmin_adr.c +++ b/src/kadmin/client/kadmin_adr.c @@ -45,6 +45,9 @@ static char rcsid_kadmin_adr[] = #include #include +void decode_kadmind_reply(); +int print_status_message(); + krb5_error_code kadm_add_user_rnd(my_creds, rep_ret, local_addr, foreign_addr, local_socket, seqno, principal) @@ -140,19 +143,14 @@ char *principal; free(inbuf.data); return(1); } + + decode_kadmind_reply(msg_data, &rd_priv_resp); + free(inbuf.data); - - memcpy(&rd_priv_resp.appl_code, msg_data.data, 1); - memcpy(&rd_priv_resp.oper_code, msg_data.data + 1, 1); - memcpy(&rd_priv_resp.retn_code, msg_data.data + 2, 1); - - free(msg_data.data); - - if (!((rd_priv_resp.appl_code == KADMIN) && - (rd_priv_resp.retn_code == KADMGOOD))) - fprintf(stderr, "Principal already exists!\n"); - else - fprintf(stderr, "\nDatabase Addition Successful.\n"); + free(msg_data.data); + retval = print_status_message(&rd_priv_resp, + "Database Addition Successful."); + return(retval); } diff --git a/src/kadmin/client/kadmin_cpr.c b/src/kadmin/client/kadmin_cpr.c index 41f53eb87..a5273e011 100644 --- a/src/kadmin/client/kadmin_cpr.c +++ b/src/kadmin/client/kadmin_cpr.c @@ -46,6 +46,9 @@ static char rcsid_kadmin_cpr[] = #include #include +void decode_kadmind_reply(); +int print_status_message(); + krb5_error_code kadm_cpw_user_rnd(my_creds, rep_ret, local_addr, foreign_addr, local_socket, seqno, principal) @@ -142,18 +145,14 @@ char *principal; } free(inbuf.data); - memcpy(&rd_priv_resp.appl_code, msg_data.data, 1); - memcpy(&rd_priv_resp.oper_code, msg_data.data + 1, 1); - memcpy(&rd_priv_resp.retn_code, msg_data.data + 2, 1); - + decode_kadmind_reply(msg_data, &rd_priv_resp); + + free(inbuf.data); free(msg_data.data); - - if (!((rd_priv_resp.appl_code == KADMIN) && - (rd_priv_resp.retn_code == KADMGOOD))) - fprintf(stderr, "Principal does NOT exist!\n"); - else - fprintf(stderr, "\nPassword Modification Successful.\n"); + print_status_message(&rd_priv_resp, + "Password Modification Successful."); + return(0); } diff --git a/src/kadmin/client/kadmin_cpw.c b/src/kadmin/client/kadmin_cpw.c index 697e1bde0..57a5f8f05 100644 --- a/src/kadmin/client/kadmin_cpw.c +++ b/src/kadmin/client/kadmin_cpw.c @@ -46,6 +46,9 @@ static char rcsid_kadmin_cpw[] = #include #include +void decode_kadmind_reply(); +int print_status_message(); + krb5_error_code kadm_cpw_user(my_creds, rep_ret, local_addr, foreign_addr, local_socket, seqno, oper_type, principal) @@ -146,7 +149,13 @@ char *principal; free(inbuf.data); if (msg_data.data[2] == KADMBAD) { - fprintf(stderr, "Principal Does NOT Exist!\n\n"); + decode_kadmind_reply(msg_data, &rd_priv_resp); + + if (rd_priv_resp.message) { + fprintf(stderr, "%s\n\n", rd_priv_resp.message); + free(rd_priv_resp.message); + } else + fprintf(stderr, "Generic error from server.\n\n"); return(0); } @@ -262,20 +271,14 @@ char *principal; free(inbuf.data); return(1); } - free(inbuf.data); - memcpy(&rd_priv_resp.appl_code, msg_data.data, 1); - memcpy(&rd_priv_resp.oper_code, msg_data.data + 1, 1); - memcpy(&rd_priv_resp.retn_code, msg_data.data + 2, 1); - + decode_kadmind_reply(msg_data, &rd_priv_resp); + + free(inbuf.data); free(msg_data.data); - - if (!((rd_priv_resp.appl_code == KADMIN) && - (rd_priv_resp.retn_code == KADMGOOD))) { - fprintf(stderr, "Generic Error During kadmin Password Modification!\n"); - return(1); - } else { - fprintf(stderr, "\nPassword Modification Successful.\n"); - } + + print_status_message(&rd_priv_resp, + "Password Modification Successful."); + return(0); } diff --git a/src/kadmin/client/kadmin_del.c b/src/kadmin/client/kadmin_del.c index c76aa1e0b..793f3442d 100644 --- a/src/kadmin/client/kadmin_del.c +++ b/src/kadmin/client/kadmin_del.c @@ -43,6 +43,9 @@ static char rcsid_kadmin_del[] = #include #include +void decode_kadmind_reply(); +int print_status_message(); + krb5_error_code kadm_del_user(my_creds, rep_ret, local_addr, foreign_addr, local_socket, seqno, principal) @@ -137,17 +140,13 @@ char *principal; return(1); } - memcpy(&rd_priv_resp.appl_code, msg_data.data, 1); - memcpy(&rd_priv_resp.oper_code, msg_data.data + 1, 1); - memcpy(&rd_priv_resp.retn_code, msg_data.data + 2, 1); + decode_kadmind_reply(msg_data, &rd_priv_resp); free(inbuf.data); free(msg_data.data); - if (!((rd_priv_resp.appl_code == KADMIN) && - (rd_priv_resp.retn_code == KADMGOOD))) - fprintf(stderr, "Principal Does NOT Exist!\n"); - else - fprintf(stderr, "\nDatabase Deletion Successful.\n"); + print_status_message(&rd_priv_resp, + "Database Deletion Successful."); + return(0); } diff --git a/src/kadmin/client/kadmin_inq.c b/src/kadmin/client/kadmin_inq.c index 0b7b04289..90f4fb9d9 100644 --- a/src/kadmin/client/kadmin_inq.c +++ b/src/kadmin/client/kadmin_inq.c @@ -44,6 +44,9 @@ static char rcsid_kadmin_inq[] = #include #include +void decode_kadmind_reply(); +int print_status_message(); + krb5_error_code kadm_inq_user(my_creds, rep_ret, local_addr, foreign_addr, local_socket, seqno, principal) @@ -59,7 +62,6 @@ char *principal; char username[755]; int count; krb5_error_code retval; /* return code */ - char *my_data; if ((inbuf.data = (char *) calloc(1, 3 + sizeof(username))) == (char *) 0) { @@ -148,16 +150,23 @@ char *principal; } if (msg_data.data[2] == KADMBAD) { - fprintf(stderr, "Principal Does Not Exist!\n\n"); + decode_kadmind_reply(msg_data, &rd_priv_resp); + + if (rd_priv_resp.message) { + fprintf(stderr, "%s\n\n", rd_priv_resp.message); + free(rd_priv_resp.message); + } else + fprintf(stderr, "Generic error from server.\n\n"); return(0); } - if ((my_data = (char *) calloc(1, msg_data.length + 1)) == (char *) 0) { - fprintf(stderr, "No Memory Allocating Inquiry Buffer!\n"); - return(1); + my_data = malloc(msg_data.length + 1); + if (!my_data) { + fprintf(stderr, "kadmin_inq: Couldn't allocate space for my_data!\n"); + exit(1); } - - (void) memcpy(my_data, msg_data.data, msg_data.length); + memcpy(my_data, msg_data.data, msg_data.length); + my_data[msg_data.length] = 0; /* Print Inquiry Information */ fprintf(stdout, "%s\n", my_data); @@ -221,18 +230,13 @@ char *principal; } free(inbuf.data); - memcpy(&rd_priv_resp.appl_code, msg_data.data, 1); - memcpy(&rd_priv_resp.oper_code, msg_data.data + 1, 1); - memcpy(&rd_priv_resp.retn_code, msg_data.data + 2, 1); - + decode_kadmind_reply(msg_data, &rd_priv_resp); + + free(inbuf.data); free(msg_data.data); - - if (!((rd_priv_resp.appl_code == KADMIN) && - (rd_priv_resp.retn_code == KADMGOOD))) { - fprintf(stderr, "Generic Error During kadmin Inquiry!\n"); - retval = 1; - } else { - fprintf(stderr, "\nDatabase Inquiry Successful.\n"); - } + + print_status_message(&rd_priv_resp, + "Password Inquiry Successful."); + return(0); } diff --git a/src/kadmin/client/kadmin_mod.c b/src/kadmin/client/kadmin_mod.c index 25a6587c1..9828f6012 100644 --- a/src/kadmin/client/kadmin_mod.c +++ b/src/kadmin/client/kadmin_mod.c @@ -44,6 +44,9 @@ static char rcsid_kadmin_mod[] = #include #include +void decode_kadmind_reply(); +int print_status_message(); + krb5_error_code kadm_mod_user(my_creds, rep_ret, local_addr, foreign_addr, local_socket, seqno, principal) @@ -141,7 +144,13 @@ char *principal; free(msg_data.data); if (msg_data.data[2] == KADMBAD) { - fprintf(stderr, "Principal Does NOT Exist!\n\n"); + decode_kadmind_reply(msg_data, &rd_priv_resp); + + if (rd_priv_resp.message) { + fprintf(stderr, "%s\n\n", rd_priv_resp.message); + free(rd_priv_resp.message); + } else + fprintf(stderr, "Generic error from server.\n\n"); return(0); } @@ -204,20 +213,15 @@ char *principal; free(inbuf.data); return(1); } - free(inbuf.data); - memcpy(&rd_priv_resp.appl_code, msg_data.data, 1); - memcpy(&rd_priv_resp.oper_code, msg_data.data + 1, 1); - memcpy(&rd_priv_resp.retn_code, msg_data.data + 2, 1); + decode_kadmind_reply(msg_data, &rd_priv_resp); + + free(inbuf.data); free(msg_data.data); - if (!((rd_priv_resp.appl_code == KADMIN) && - (rd_priv_resp.retn_code == KADMGOOD))) { - fprintf(stderr, "Error Performing kadmin service!\n"); - retval = 1; - } else { - fprintf(stderr, "\nDatabase Modification Successful.\n"); - } + print_status_message(&rd_priv_resp, + "Database Modification Successful."); + return(0); }