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");
}
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;
}
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;
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;
}
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;
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;