From 0c2d56448b76244a9be6aa74cd1d9da52aa34398 Mon Sep 17 00:00:00 2001 From: Barry Jaspan Date: Mon, 21 Oct 1996 20:32:05 +0000 Subject: [PATCH] * tcl_kadm5.c: add unparse ability for V2 principal fields [krb5-admin/20] git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@9222 dc483132-0cff-0310-8789-dd5450dbe970 --- src/kadmin/testing/util/ChangeLog | 5 + src/kadmin/testing/util/tcl_kadm5.c | 219 ++++++++++++++++++++++++++-- 2 files changed, 215 insertions(+), 9 deletions(-) diff --git a/src/kadmin/testing/util/ChangeLog b/src/kadmin/testing/util/ChangeLog index 84a5977b4..50414d6dc 100644 --- a/src/kadmin/testing/util/ChangeLog +++ b/src/kadmin/testing/util/ChangeLog @@ -1,3 +1,8 @@ +Mon Oct 21 16:31:35 1996 Barry Jaspan + + * tcl_kadm5.c: add unparse ability for V2 principal fields + [krb5-admin/20] + Fri Oct 18 13:23:46 1996 Barry Jaspan * tcl_kadm5.c (unparse_principal_ent): don't unparse allocated diff --git a/src/kadmin/testing/util/tcl_kadm5.c b/src/kadmin/testing/util/tcl_kadm5.c index 515056a3c..cad3a93ad 100644 --- a/src/kadmin/testing/util/tcl_kadm5.c +++ b/src/kadmin/testing/util/tcl_kadm5.c @@ -467,6 +467,7 @@ static Tcl_DString *unparse_key_data(krb5_key_data *key_data, int n_key_data) static Tcl_DString *unparse_tl_data(krb5_tl_data *tl_data, int n_tl_data) { Tcl_DString *str; + char buf[2048]; if (! (str = malloc(sizeof(*str)))) { fprintf(stderr, "Out of memory!\n"); @@ -474,10 +475,15 @@ static Tcl_DString *unparse_tl_data(krb5_tl_data *tl_data, int n_tl_data) } Tcl_DStringInit(str); - if (n_tl_data > 0 && tl_data->tl_data_contents) - Tcl_DStringAppendElement(str, "[cannot unparse tl data yet]"); - else - Tcl_DStringAppendElement(str, ""); + for (; tl_data; tl_data = tl_data->tl_data_next) { + Tcl_DStringStartSublist(str); + sprintf(buf, "%d", tl_data->tl_data_type); + Tcl_DStringAppendElement(str, buf); + sprintf(buf, "%d", tl_data->tl_data_length); + Tcl_DStringAppendElement(str, buf); + Tcl_DStringAppendElement(str, tl_data->tl_data_contents); + Tcl_DStringEndSublist(str); + } return str; } @@ -784,7 +790,8 @@ static int parse_keysalts(Tcl_Interp *interp, char *list, retcode = TCL_ERROR; goto finished; } - if ((retcode = Tcl_GetInt(interp, argv1[1], &tmp)) + /* XXX this used to be argv1[1] too! */ + if ((retcode = Tcl_GetInt(interp, argv1[0], &tmp)) != TCL_OK) { Tcl_AppendElement(interp, "while parsing ks_enctype"); retcode = TCL_ERROR; @@ -804,8 +811,135 @@ static int parse_keysalts(Tcl_Interp *interp, char *list, finished: if (argv1) free(argv1); - if (*keysalts) - free(*keysalts); + free(argv); + return retcode; +} + +static int parse_key_data(Tcl_Interp *interp, char *list, + krb5_key_data **key_data, + int n_key_data) +{ + char **argv, **argv1 = NULL; + int i, tmp, argc, argc1, retcode; + + *key_data == NULL; + if (list == NULL) { + if (n_key_data != 0) { + sprintf(interp->result, "0 key_datas specified, " + "but n_key_data is %d", n_key_data); + retcode = TCL_ERROR; + goto finished; + } else + return TCL_OK; + } + + if ((retcode = Tcl_SplitList(interp, list, &argc, &argv)) != TCL_OK) { + return retcode; + } + if (argc != n_key_data) { + sprintf(interp->result, "%d key_datas specified, " + "but n_key_data is %d", argc, n_key_data); + retcode = TCL_ERROR; + goto finished; + } + + if (argc != 0) { + sprintf(interp->result, "cannot parse key_data yet"); + retcode = TCL_ERROR; + goto finished; + } + +finished: + free(argv); + return retcode; +} + +static int parse_tl_data(Tcl_Interp *interp, char *list, + krb5_tl_data **tlp, + int n_tl_data) +{ + krb5_tl_data *tl, *tl2; + char **argv, **argv1 = NULL; + int i, tmp, argc, argc1, retcode; + + *tlp == NULL; + if (list == NULL) { + if (n_tl_data != 0) { + sprintf(interp->result, "0 tl_datas specified, " + "but n_tl_data is %d", n_tl_data); + retcode = TCL_ERROR; + goto finished; + } else + return TCL_OK; + } + + if ((retcode = Tcl_SplitList(interp, list, &argc, &argv)) != TCL_OK) { + return retcode; + } + if (argc != n_tl_data) { + sprintf(interp->result, "%d tl_datas specified, " + "but n_tl_data is %d", argc, n_tl_data); + retcode = TCL_ERROR; + goto finished; + } + + tl = tl2 = NULL; + for (i = 0; i < n_tl_data; i++) { + tl2 = (krb5_tl_data *) malloc(sizeof(krb5_tl_data)); + memset(tl2, 0, sizeof(krb5_tl_data)); + tl2->tl_data_next = tl; + tl = tl2; + } + tl2 = tl; + + for (i = 0; i < n_tl_data; i++) { + if ((retcode = Tcl_SplitList(interp, argv[i], &argc1, &argv1)) != + TCL_OK) { + goto finished; + } + if (argc1 != 3) { + sprintf(interp->result, "wrong # fields in tl_data " + "(%d should be 3)", argc1); + retcode = TCL_ERROR; + goto finished; + } + if ((retcode = Tcl_GetInt(interp, argv1[0], &tmp)) + != TCL_OK) { + Tcl_AppendElement(interp, "while parsing tl_data_type"); + retcode = TCL_ERROR; + goto finished; + } + tl->tl_data_type = tmp; + if ((retcode = Tcl_GetInt(interp, argv1[1], &tmp)) + != TCL_OK) { + Tcl_AppendElement(interp, "while parsing tl_data_length"); + retcode = TCL_ERROR; + goto finished; + } + tl->tl_data_length = tmp; + if (tl->tl_data_length != strlen(argv1[2])) { + sprintf(interp->result, "specified length %d does not " + "match length %d of string \"%s\"", tmp, + strlen(argv1[2]), argv1[2]); + retcode = TCL_ERROR; + goto finished; + } + tl->tl_data_contents = (char *) malloc(tmp+1); + strcpy(tl->tl_data_contents, argv1[2]); + + free(argv1); + tl = tl->tl_data_next; + } + if (tl != NULL) { + sprintf(interp->result, "tl is not NULL!"); + retcode = TCL_ERROR; + goto finished; + } + *tlp = tl2; + +finished: + if (argv1) + free(argv1); free(argv); return retcode; } @@ -979,8 +1113,9 @@ static int parse_principal_ent(Tcl_Interp *interp, char *list, return tcl_ret; } - if (argc != 12) { - sprintf(interp->result, "wrong # args in principal structure (%d should be 12)", + if (argc != 12 && argc != 20) { + sprintf(interp->result, + "wrong # args in principal structure (%d should be 12 or 20)", argc); retcode = TCL_ERROR; goto finished; @@ -1094,6 +1229,72 @@ static int parse_principal_ent(Tcl_Interp *interp, char *list, goto finished; } + if (argc == 12) goto finished; + + if ((tcl_ret = Tcl_GetInt(interp, argv[12], &tmp)) + != TCL_OK) { + Tcl_AppendElement(interp, "while parsing max_renewable_life"); + retcode = TCL_ERROR; + goto finished; + } + princ->max_renewable_life = tmp; + + if ((tcl_ret = Tcl_GetInt(interp, argv[13], &tmp)) + != TCL_OK) { + Tcl_AppendElement(interp, "while parsing last_success"); + retcode = TCL_ERROR; + goto finished; + } + princ->last_success = tmp; + + if ((tcl_ret = Tcl_GetInt(interp, argv[14], &tmp)) + != TCL_OK) { + Tcl_AppendElement(interp, "while parsing last_failed"); + retcode = TCL_ERROR; + goto finished; + } + princ->last_failed = tmp; + + if ((tcl_ret = Tcl_GetInt(interp, argv[15], &tmp)) + != TCL_OK) { + Tcl_AppendElement(interp, "while parsing fail_auth_count"); + retcode = TCL_ERROR; + goto finished; + } + princ->fail_auth_count = tmp; + + if ((tcl_ret = Tcl_GetInt(interp, argv[16], &tmp)) + != TCL_OK) { + Tcl_AppendElement(interp, "while parsing n_key_data"); + retcode = TCL_ERROR; + goto finished; + } + princ->n_key_data = tmp; + + if ((tcl_ret = Tcl_GetInt(interp, argv[17], &tmp)) + != TCL_OK) { + Tcl_AppendElement(interp, "while parsing n_tl_data"); + retcode = TCL_ERROR; + goto finished; + } + princ->n_tl_data = tmp; + + if ((tcl_ret = parse_key_data(interp, argv[18], + &princ->key_data, + princ->n_key_data)) != TCL_OK) { + Tcl_AppendElement(interp, "while parsing key_data"); + retcode = TCL_ERROR; + goto finished; + } + + if ((tcl_ret = parse_tl_data(interp, argv[19], + &princ->tl_data, + princ->n_tl_data)) != TCL_OK) { + Tcl_AppendElement(interp, "while parsing tl_data"); + retcode = TCL_ERROR; + goto finished; + } + finished: free(argv); *out_princ = princ; -- 2.26.2