#include <krb5/kdb.h>
#include <krb5/kdb_dbm.h>
+/*
+ * 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));
krb5_creds my_creds;
void get_def_princ();
+void decode_kadmind_reply();
+int print_status_message();
main(argc,argv)
int argc;
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
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");
}
/* 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);
}
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;
+}
#include <krb5/kdb.h>
#include <krb5/kdb_dbm.h>
+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)
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
}
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);
}
#include <krb5/kdb.h>
#include <krb5/kdb_dbm.h>
+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)
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);
}
#include <krb5/kdb.h>
#include <krb5/kdb_dbm.h>
+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)
}
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);
}
#include <krb5/kdb.h>
#include <krb5/kdb_dbm.h>
+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)
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);
}
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);
}
#include <krb5/kdb.h>
#include <krb5/kdb_dbm.h>
+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)
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);
}
#include <krb5/kdb.h>
#include <krb5/kdb_dbm.h>
+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)
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) {
}
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);
}
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);
}
#include <krb5/kdb.h>
#include <krb5/kdb_dbm.h>
+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)
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);
}
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);
}