1 #pragma ident "%Z%%M% %I% %E% SMI"
4 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
6 * Openvision retains the copyright to derivative works of
7 * this source code. Do *NOT* create a derivative of this
8 * source code before consulting with your legal department.
9 * Do *NOT* integrate *ANY* of this source code into another
10 * product before consulting with your legal department.
12 * For further information, read the top-level Openvision
13 * copyright which is contained in the top-level MIT Kerberos
16 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
30 #include <kadm5/admin.h>
31 #include <kadm5/server_internal.h>
33 #include "import_err.h"
34 #include "kdb5_util.h"
37 #define LINESIZE 32768 /* XXX */
38 #define PLURAL(count) (((count) == 1) ? error_message(IMPORT_SINGLE_RECORD) : error_message(IMPORT_PLURAL_RECORDS))
40 static int parse_pw_hist_ent(current
, hist
)
42 osa_pw_hist_ent
*hist
;
50 hist
->key_data
= (krb5_key_data
*) malloc(hist
->n_key_data
*
51 sizeof(krb5_key_data
));
52 if (hist
->key_data
== NULL
)
54 memset(hist
->key_data
, 0, sizeof(krb5_key_data
)*hist
->n_key_data
);
56 for (i
= 0; i
< hist
->n_key_data
; i
++) {
57 krb5_key_data
*key_data
= &hist
->key_data
[i
];
59 key_data
->key_data_ver
= 1;
61 if((cp
= nstrtok((char *) NULL
, "\t")) == NULL
) {
62 com_err(NULL
, IMPORT_BAD_RECORD
, "%s", current
);
66 key_data
->key_data_type
[0] = atoi(cp
);
68 if((cp
= nstrtok((char *) NULL
, "\t")) == NULL
) {
69 com_err(NULL
, IMPORT_BAD_RECORD
, "%s", current
);
73 key_data
->key_data_length
[0] = atoi(cp
);
75 if((cp
= nstrtok((char *) NULL
, "\t")) == NULL
) {
76 com_err(NULL
, IMPORT_BAD_RECORD
, "%s", current
);
80 if(!(key_data
->key_data_contents
[0] =
81 (krb5_octet
*) malloc(key_data
->key_data_length
[0]+1))) {
85 for(j
= 0; j
< key_data
->key_data_length
[0]; j
++) {
86 if(sscanf(cp
, "%02x", &tmp
) != 1) {
87 com_err(NULL
, IMPORT_BAD_RECORD
, "%s", current
);
91 key_data
->key_data_contents
[0][j
] = tmp
;
92 cp
= strchr(cp
, ' ') + 1;
101 * Function: parse_principal
103 * Purpose: parse principal line in db dump file
106 * <return value> 0 on success, error code on failure
109 * principal database to be opened.
110 * nstrtok(3) to have a valid buffer in memory.
119 int process_ov_principal(fname
, kcontext
, filep
, verbose
, linenop
)
121 krb5_context kcontext
;
129 krb5_tl_data tl_data
;
130 krb5_principal princ
;
138 if (fgets(line
, LINESIZE
, filep
) == (char *) NULL
) {
139 return IMPORT_BAD_FILE
;
141 if((cp
= nstrtok(line
, "\t")) == NULL
)
142 return IMPORT_BAD_FILE
;
143 if((rec
= (osa_princ_ent_t
) malloc(sizeof(osa_princ_ent_rec
))) == NULL
)
145 memset(rec
, 0, sizeof(osa_princ_ent_rec
));
146 if((ret
= krb5_parse_name(kcontext
, cp
, &princ
)))
148 krb5_unparse_name(kcontext
, princ
, ¤t
);
149 if((cp
= nstrtok((char *) NULL
, "\t")) == NULL
) {
150 com_err(NULL
, IMPORT_BAD_RECORD
, "%s", current
);
155 if((rec
->policy
= (char *) malloc(strlen(cp
)+1)) == NULL
) {
159 strcpy(rec
->policy
, cp
);
160 } else rec
->policy
= NULL
;
162 if((cp
= nstrtok((char *) NULL
, "\t")) == NULL
) {
163 com_err(NULL
, IMPORT_BAD_RECORD
, "%s", current
);
167 rec
->aux_attributes
= strtol(cp
, (char **)NULL
, 16);
168 if((cp
= nstrtok((char *) NULL
, "\t")) == NULL
) {
169 com_err(NULL
, IMPORT_BAD_RECORD
, "%s", current
);
173 rec
->old_key_len
= atoi(cp
);
174 if((cp
= nstrtok((char *) NULL
, "\t")) == NULL
) {
175 com_err(NULL
, IMPORT_BAD_RECORD
, "%s", current
);
179 rec
->old_key_next
= atoi(cp
);
180 if((cp
= nstrtok((char *) NULL
, "\t")) == NULL
) {
181 com_err(NULL
, IMPORT_BAD_RECORD
, "%s", current
);
185 rec
->admin_history_kvno
= atoi(cp
);
186 if (! rec
->old_key_len
) {
187 rec
->old_keys
= NULL
;
189 if(!(rec
->old_keys
= (osa_pw_hist_ent
*)
190 malloc(sizeof(osa_pw_hist_ent
) * rec
->old_key_len
))) {
194 memset(rec
->old_keys
,0,
195 sizeof(osa_pw_hist_ent
) * rec
->old_key_len
);
196 for(x
= 0; x
< rec
->old_key_len
; x
++)
197 parse_pw_hist_ent(current
, &rec
->old_keys
[x
]);
200 xdralloc_create(&xdrs
, XDR_ENCODE
);
201 if (! xdr_osa_princ_ent_rec(&xdrs
, rec
)) {
203 ret
= KADM5_XDR_FAILURE
;
207 tl_data
.tl_data_type
= KRB5_TL_KADM_DATA
;
208 tl_data
.tl_data_length
= xdr_getpos(&xdrs
);
209 tl_data
.tl_data_contents
= (krb5_octet
*) xdralloc_getdata(&xdrs
);
212 ret
= krb5_db_get_principal(kcontext
, princ
, &kdb
, &one
, &more
);
216 ret
= krb5_dbe_update_tl_data(kcontext
, &kdb
, &tl_data
);
220 ret
= krb5_db_put_principal(kcontext
, &kdb
, &one
);
230 krb5_free_principal(kcontext
, princ
);
231 osa_free_princ_ent(rec
);