9 #include <kadm5/admin.h>
10 #include <kadm5/server_internal.h>
12 #include "import_err.h"
13 #include "kdb5_util.h"
16 #define LINESIZE 32768 /* XXX */
17 #define PLURAL(count) (((count) == 1) ? error_message(IMPORT_SINGLE_RECORD) : error_message(IMPORT_PLURAL_RECORDS))
19 static int parse_pw_hist_ent(current, hist)
21 osa_pw_hist_ent *hist;
29 hist->key_data = (krb5_key_data *) malloc(hist->n_key_data *
30 sizeof(krb5_key_data));
31 if (hist->key_data == NULL)
33 memset(hist->key_data, 0, sizeof(krb5_key_data)*hist->n_key_data);
35 for (i = 0; i < hist->n_key_data; i++) {
36 krb5_key_data *key_data = &hist->key_data[i];
38 key_data->key_data_ver = 1;
40 if((cp = nstrtok((char *) NULL, "\t")) == NULL) {
41 com_err(NULL, IMPORT_BAD_RECORD, "%s", current);
45 key_data->key_data_type[0] = atoi(cp);
47 if((cp = nstrtok((char *) NULL, "\t")) == NULL) {
48 com_err(NULL, IMPORT_BAD_RECORD, "%s", current);
52 key_data->key_data_length[0] = atoi(cp);
54 if((cp = nstrtok((char *) NULL, "\t")) == NULL) {
55 com_err(NULL, IMPORT_BAD_RECORD, "%s", current);
59 if(!(key_data->key_data_contents[0] =
60 (krb5_octet *) malloc(key_data->key_data_length[0]+1))) {
64 for(j = 0; j < key_data->key_data_length[0]; j++) {
65 if(sscanf(cp, "%02x", &tmp) != 1) {
66 com_err(NULL, IMPORT_BAD_RECORD, "%s", current);
70 key_data->key_data_contents[0][j] = tmp;
71 cp = strchr(cp, ' ') + 1;
80 * Function: parse_principal
82 * Purpose: parse principal line in db dump file
85 * <return value> 0 on success, error code on failure
88 * principal database to be opened.
89 * nstrtok(3) to have a valid buffer in memory.
98 int process_ov_principal(fname, kcontext, filep, verbose, linenop)
100 krb5_context kcontext;
108 krb5_tl_data tl_data;
109 krb5_principal princ;
117 if (fgets(line, LINESIZE, filep) == (char *) NULL) {
118 return IMPORT_BAD_FILE;
120 if((cp = nstrtok(line, "\t")) == NULL)
121 return IMPORT_BAD_FILE;
122 if((rec = (osa_princ_ent_t) malloc(sizeof(osa_princ_ent_rec))) == NULL)
124 memset(rec, 0, sizeof(osa_princ_ent_rec));
125 if((ret = krb5_parse_name(kcontext, cp, &princ)))
127 krb5_unparse_name(kcontext, princ, ¤t);
128 if((cp = nstrtok((char *) NULL, "\t")) == NULL) {
129 com_err(NULL, IMPORT_BAD_RECORD, "%s", current);
134 if((rec->policy = (char *) malloc(strlen(cp)+1)) == NULL) {
138 strcpy(rec->policy, cp);
139 } else rec->policy = NULL;
141 if((cp = nstrtok((char *) NULL, "\t")) == NULL) {
142 com_err(NULL, IMPORT_BAD_RECORD, "%s", current);
146 rec->aux_attributes = strtol(cp, (char **)NULL, 16);
147 if((cp = nstrtok((char *) NULL, "\t")) == NULL) {
148 com_err(NULL, IMPORT_BAD_RECORD, "%s", current);
152 rec->old_key_len = atoi(cp);
153 if((cp = nstrtok((char *) NULL, "\t")) == NULL) {
154 com_err(NULL, IMPORT_BAD_RECORD, "%s", current);
158 rec->old_key_next = atoi(cp);
159 if((cp = nstrtok((char *) NULL, "\t")) == NULL) {
160 com_err(NULL, IMPORT_BAD_RECORD, "%s", current);
164 rec->admin_history_kvno = atoi(cp);
165 if (! rec->old_key_len) {
166 rec->old_keys = NULL;
168 if(!(rec->old_keys = (osa_pw_hist_ent *)
169 malloc(sizeof(osa_pw_hist_ent) * rec->old_key_len))) {
173 memset(rec->old_keys,0,
174 sizeof(osa_pw_hist_ent) * rec->old_key_len);
175 for(x = 0; x < rec->old_key_len; x++)
176 parse_pw_hist_ent(current, &rec->old_keys[x]);
179 xdralloc_create(&xdrs, XDR_ENCODE);
180 if (! xdr_osa_princ_ent_rec(&xdrs, rec)) {
182 ret = KADM5_XDR_FAILURE;
186 tl_data.tl_data_type = KRB5_TL_KADM_DATA;
187 tl_data.tl_data_length = xdr_getpos(&xdrs);
188 tl_data.tl_data_contents = (krb5_octet *) xdralloc_getdata(&xdrs);
191 ret = krb5_db_get_principal(kcontext, princ, &kdb, &one, &more);
195 ret = krb5_dbe_update_tl_data(kcontext, &kdb, &tl_data);
199 ret = krb5_db_put_principal(kcontext, &kdb, &one);
209 krb5_free_principal(kcontext, princ);
210 osa_free_princ_ent(rec);