kdb_convert.c revision ebd1706e95186ddae1d4c0d63c47544cf33832ee
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* This file contains api's for conversion of the kdb_incr_update_t
* struct(s) into krb5_db_entry struct(s) and vice-versa.
*/
#include <com_err.h>
#include <locale.h>
#include <errno.h>
#include <iprop_hdr.h>
#include "iprop.h"
#include <k5-int.h>
/* BEGIN CSTYLED */
#define ULOG_ENTRY_KEYVAL(upd, i, j) ((kdb_incr_update_t *)upd)->kdb_update.kdbe_t_val[i].kdbe_val_t_u.av_keydata.av_keydata_val[j]
#define ULOG_ENTRY_PRINC(upd, i, j) ((kdb_incr_update_t *)upd)->kdb_update.kdbe_t_val[i].kdbe_val_t_u.av_princ.k_components.k_components_val[j]
#define ULOG_ENTRY_MOD_PRINC(upd, i, j) ((kdb_incr_update_t *)upd)->kdb_update.kdbe_t_val[i].kdbe_val_t_u.av_mod_princ.k_components.k_components_val[j]
/* END CSTYLED */
typedef enum {
REG_PRINC = 0,
MOD_PRINC = 1
} princ_type;
/*
* This routine tracks the krb5_db_entry fields that have been modified
* (by comparing it to the db_entry currently present in principal.db)
* in the update.
*/
void
int i = 0, j = 0;
attrs[i++] = AT_ATTRFLAGS;
attrs[i++] = AT_MAX_LIFE;
attrs[i++] = AT_MAX_RENEW_LIFE;
attrs[i++] = AT_LAST_SUCCESS;
attrs[i++] = AT_LAST_FAILED;
attrs[i++] = AT_FAIL_AUTH_COUNT;
break;
}
}
} else {
}
} else {
}
/* Assuming key ordering is the same in new & current */
for (j = 0; j < new->n_key_data; j++) {
attrs[i++] = AT_KEYDATA;
break;
}
}
} else {
attrs[i++] = AT_KEYDATA;
}
/* Assuming we preserve the TL_DATA ordering between updates */
(char *)second->tl_data_contents,
first->tl_data_length)) != 0) {
attrs[i++] = AT_TL_DATA;
break;
}
} else {
attrs[i++] = AT_TL_DATA;
break;
}
}
} else {
attrs[i++] = AT_TL_DATA;
}
/*
* Store the no. of (possibly :)) changed attributes
*/
*nattrs = i;
}
/*
* Converts the krb5_principal struct from db2 to ulog format.
*/
int i = 0;
return (KRB5KRB_ERR_GENERIC);
switch (tp) {
case REG_PRINC:
== NULL)
return (ENOMEM);
}
break;
case MOD_PRINC:
if (ULOG_ENTRY(upd,
return (ENOMEM);
}
break;
default:
break;
}
return (0);
}
/*
* Converts the krb5_principal struct from ulog to db2 format.
*/
int princ_exists) {
int i;
return (KRB5KRB_ERR_GENERIC);
if (princ_exists == 0) {
return (ENOMEM);
}
} else {
}
switch (tp) {
case REG_PRINC:
if (princ_exists == 0)
goto error;
if (princ_exists == 0)
goto error;
if (princ_exists == 0)
goto error;
}
break;
case MOD_PRINC:
if (princ_exists == 0)
goto error;
if (princ_exists == 0)
goto error;
if (princ_exists == 0)
goto error;
(char *)ULOG_ENTRY_MOD_PRINC(upd,
}
break;
default:
break;
}
return (0);
return (ENOMEM);
}
/*
* This routine converts one or more krb5 db2 records into update
* log (ulog) entry format. Space for the update log entries should
* be allocated prior to invocation of this routine.
*/
int nentries) {
unsigned int more;
return (KRB5KRB_ERR_GENERIC);
for (k = 0; k < nentries; k++) {
final = -1;
attr_types = NULL;
return (ENOMEM);
}
/*
* Find out which attrs have been modified
*/
sizeof (kdbe_attr_type_t) * MAXATTRS_SIZE))
== NULL) {
return (ENOMEM);
}
return (ret);
if (nprincs == 0) {
/*
* This is a new entry to the database, hence will
* include all the attribute-value pairs
*
* We leave out the TL_DATA types which we model as
* attrs in kdbe_attr_type_t, since listing AT_TL_DATA
* encompasses these other types-turned-attributes
*
* So, we do *NOT* consider AT_MOD_PRINC, AT_MOD_TIME,
* AT_MOD_WHERE, AT_PW_LAST_CHANGE, AT_PW_POLICY,
* AT_PW_POLICY_SWITCH, AT_PW_HIST_KVNO and AT_PW_HIST,
* totalling 8 attrs.
*/
nattrs++;
}
} else {
}
for (i = 0; i < nattrs; i++) {
switch (attr_types[i]) {
case AT_ATTRFLAGS:
if (ent->attributes >= 0) {
}
break;
case AT_MAX_LIFE:
}
break;
case AT_MAX_RENEW_LIFE:
if (ent->max_renewable_life >= 0) {
}
break;
case AT_EXP:
if (ent->expiration >= 0) {
}
break;
case AT_PW_EXP:
if (ent->pw_expiration >= 0) {
}
break;
case AT_LAST_SUCCESS:
if (ent->last_success >= 0) {
}
break;
case AT_LAST_FAILED:
if (ent->last_failed >= 0) {
}
break;
case AT_FAIL_AUTH_COUNT:
}
break;
case AT_PRINC:
return (ret);
}
break;
case AT_KEYDATA:
/* BEGIN CSTYLED */
if (ent->n_key_data >= 0) {
return (ENOMEM);
for (j = 0; j < ent->n_key_data; j++) {
ULOG_ENTRY_KEYVAL(upd, final, j).k_enctype.k_enctype_val = malloc(ent->key_data[j].key_data_ver * sizeof(int32_t));
return (ENOMEM);
ULOG_ENTRY_KEYVAL(upd, final, j).k_contents.k_contents_val = malloc(ent->key_data[j].key_data_ver * sizeof(utf8str_t));
return (ENOMEM);
ULOG_ENTRY_KEYVAL(upd, final, j).k_enctype.k_enctype_val[cnt] = ent->key_data[j].key_data_type[cnt];
ULOG_ENTRY_KEYVAL(upd, final, j).k_contents.k_contents_val[cnt].utf8str_t_len = ent->key_data[j].key_data_length[cnt];
ULOG_ENTRY_KEYVAL(upd, final, j).k_contents.k_contents_val[cnt].utf8str_t_val = malloc(ent->key_data[j].key_data_length[cnt] * sizeof (char));
return (ENOMEM);
(void) memcpy(ULOG_ENTRY_KEYVAL(upd, final, j).k_contents.k_contents_val[cnt].utf8str_t_val, ent->key_data[j].key_data_contents[cnt], ent->key_data[j].key_data_length[cnt]);
}
}
}
break;
case AT_TL_DATA:
if (ret == 0) {
}
tmpint = 0;
if(!(ret = krb5_dbe_lookup_mod_princ_data(
if (ret)
return (ret);
}
while (newtl) {
switch (newtl->tl_data_type) {
case KRB5_TL_LAST_PWD_CHANGE:
case KRB5_TL_MOD_PRINC:
break;
case KRB5_TL_KADM_DATA:
default:
if (kadm_data_yes == B_FALSE) {
return (ENOMEM);
}
ULOG_ENTRY(upd, final).av_tldata.av_tldata_val[tmpint].tl_data.tl_data_val = malloc(newtl->tl_data_length * sizeof (char));
return (ENOMEM);
(void) memcpy(ULOG_ENTRY(upd, final).av_tldata.av_tldata_val[tmpint].tl_data.tl_data_val, newtl->tl_data_contents, newtl->tl_data_length);
break;
}
}
break;
/* END CSTYLED */
case AT_LEN:
break;
default:
break;
}
}
if (attr_types)
/*
* Update len field in kdb_update
*/
/*
* Bump up to next struct
*/
upd++;
ent++;
}
return (0);
}
/*
* This routine converts one or more update log (ulog) entries into
* kerberos db2 records. Required memory should be allocated
* for the db2 records (pointed to by krb5_db_entry *ent), prior
* to calling this routine.
*/
int nentries) {
char *dbprincstr = NULL;
unsigned int more;
unsigned int prev_n_keys = 0;
return (KRB5KRB_ERR_GENERIC);
for (k = 0; k < nentries; k++) {
/*
* If the ulog entry represents a DELETE update,
* just skip to the next entry.
*/
goto next;
/*
* Store the no. of changed attributes in nattrs
*/
* sizeof (char));
if (dbprincstr == NULL)
return (ENOMEM);
if (ret)
return (ret);
&more);
if (ret)
return (ret);
/*
* Set ent->n_tl_data = 0 initially, if this is an ADD update
*/
if (nprincs == 0)
for (i = 0; i < nattrs; i++) {
case AT_ATTRFLAGS:
break;
case AT_MAX_LIFE:
break;
case AT_MAX_RENEW_LIFE:
break;
case AT_EXP:
break;
case AT_PW_EXP:
break;
case AT_LAST_SUCCESS:
break;
case AT_LAST_FAILED:
break;
case AT_FAIL_AUTH_COUNT:
break;
case AT_PRINC:
return (ret);
break;
case AT_KEYDATA:
if (nprincs != 0)
if (nprincs == 0)
(ent->n_key_data *
sizeof (krb5_key_data)));
return (ENOMEM);
/* BEGIN CSTYLED */
for (j = 0; j < ent->n_key_data; j++) {
ent->key_data[j].key_data_type[cnt] = (krb5_int16)ULOG_ENTRY_KEYVAL(upd, i, j).k_enctype.k_enctype_val[cnt];
ent->key_data[j].key_data_length[cnt] = (krb5_int16)ULOG_ENTRY_KEYVAL(upd, i, j).k_contents.k_contents_val[cnt].utf8str_t_len;
if ((nprincs == 0) || (j >= prev_n_keys))
ent->key_data[j].key_data_contents[cnt] = (krb5_octet *)realloc(ent->key_data[j].key_data_contents[cnt], ent->key_data[j].key_data_length[cnt]);
return (ENOMEM);
(void) memset(ent->key_data[j].key_data_contents[cnt], 0, (ent->key_data[j].key_data_length[cnt] * sizeof (krb5_octet)));
(void) memcpy(ent->key_data[j].key_data_contents[cnt], ULOG_ENTRY_KEYVAL(upd, i, j).k_contents.k_contents_val[cnt].utf8str_t_val, ent->key_data[j].key_data_length[cnt]);
}
}
break;
case AT_TL_DATA:
return (ENOMEM);
for (j = 0; j < cnt; j++){
newtl[j].tl_data_length = (krb5_int16)ULOG_ENTRY(upd, i).av_tldata.av_tldata_val[j].tl_data.tl_data_len;
return (ENOMEM);
(void) memcpy(newtl[j].tl_data_contents, ULOG_ENTRY(upd, i).av_tldata.av_tldata_val[j].tl_data.tl_data_val, newtl[j].tl_data_length);
if (j > 0)
&newtl[j];
}
return (ret);
for (j = 0; j < cnt; j++)
if (newtl[j].tl_data_contents) {
}
if (newtl) {
}
break;
/* END CSTYLED */
case AT_PW_LAST_CHANGE:
if ((ret = krb5_dbe_update_last_pwd_change(
return (ret);
break;
case AT_MOD_PRINC:
i, MOD_PRINC, 0)))
return (ret);
break;
case AT_MOD_TIME:
break;
case AT_LEN:
break;
default:
break;
}
}
/*
* process mod_princ_data request
*/
if (ret)
return (ret);
}
next:
/*
* Bump up to next struct
*/
upd++;
ent++;
}
return (0);
}
/*
* This routine frees up memory associated with the bunched ulog entries.
*/
void
int i, j, k, cnt;
return;
/*
* Loop thru each ulog entry
*/
/*
* ulog entry - kdb_princ_name
*/
/* BEGIN CSTYLED */
/*
* ulog entry - kdb_kdcs_seen_by
*/
}
}
/*
* ulog entry - kdb_futures
*/
/*
* ulog entry - kdb_update
*/
/*
* Loop thru all the attributes and free up stuff
*/
/*
* Free av_key_data
*/
if ((ULOG_ENTRY_TYPE(upd, i).av_type == AT_KEYDATA) && ULOG_ENTRY(upd, i).av_keydata.av_keydata_val) {
}
}
}
}
/*
* Free av_tl_data
*/
if ((ULOG_ENTRY_TYPE(upd, i).av_type == AT_TL_DATA) && ULOG_ENTRY(upd, i).av_tldata.av_tldata_val) {
}
}
/*
* Free av_princ
*/
}
}
}
/*
* Free av_mod_princ
*/
}
}
}
/*
* Free av_mod_where
*/
if ((ULOG_ENTRY_TYPE(upd, i).av_type == AT_MOD_WHERE) && ULOG_ENTRY(upd, i).av_mod_where.utf8str_t_val)
/*
* Free av_pw_policy
*/
if ((ULOG_ENTRY_TYPE(upd, i).av_type == AT_PW_POLICY) && ULOG_ENTRY(upd, i).av_pw_policy.utf8str_t_val)
/*
* XXX: Free av_pw_hist
*
* For now, we just free the pointer
* to av_pw_hist_val, since we arent
* populating this union member in
* the conv api function(s) anyways.
*/
if ((ULOG_ENTRY_TYPE(upd, i).av_type == AT_PW_HIST) && ULOG_ENTRY(upd, i).av_pw_hist.av_pw_hist_val)
}
/*
* Free up the pointer to kdbe_t_val
*/
}
/* END CSTYLED */
/*
* Bump up to next struct
*/
upd++;
}
/*
* Finally, free up the pointer to the bunched ulog entries
*/
if (updates)
}