1 /* 2 * Copyright (c) 1997, 1998, 1999 Kungliga Tekniska H�gskolan 3 * (Royal Institute of Technology, Stockholm, Sweden). 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * 3. Neither the name of the Institute nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34 #include "kadm5_locl.h" 35 36 RCSID("$Id: ent_setup.c,v 1.11 1999/12/02 17:05:06 joda Exp $"); 37 38 #define set_value(X, V) do { if((X) == NULL) (X) = malloc(sizeof(*(X))); *(X) = V; } while(0) 39 #define set_null(X) do { if((X) != NULL) free((X)); (X) = NULL; } while (0) 40 41 static void 42 attr_to_flags(unsigned attr, HDBFlags *flags) 43 { 44 flags->postdate = !(attr & KRB5_KDB_DISALLOW_POSTDATED); 45 flags->forwardable = !(attr & KRB5_KDB_DISALLOW_FORWARDABLE); 46 flags->initial = !!(attr & KRB5_KDB_DISALLOW_TGT_BASED); 47 flags->renewable = !(attr & KRB5_KDB_DISALLOW_RENEWABLE); 48 flags->proxiable = !(attr & KRB5_KDB_DISALLOW_PROXIABLE); 49 /* DUP_SKEY */ 50 flags->invalid = !!(attr & KRB5_KDB_DISALLOW_ALL_TIX); 51 flags->require_preauth = !!(attr & KRB5_KDB_REQUIRES_PRE_AUTH); 52 /* HW_AUTH */ 53 flags->server = !(attr & KRB5_KDB_DISALLOW_SVR); 54 flags->change_pw = !!(attr & KRB5_KDB_PWCHANGE_SERVICE); 55 flags->client = 1; /* XXX */ 56 } 57 58 /* 59 * Create the hdb entry `ent' based on data from `princ' with 60 * `princ_mask' specifying what fields to be gotten from there and 61 * `mask' specifying what fields we want filled in. 62 */ 63 64 kadm5_ret_t 65 _kadm5_setup_entry(hdb_entry *ent, 66 u_int32_t mask, 67 kadm5_principal_ent_t princ, 68 u_int32_t princ_mask, 69 kadm5_principal_ent_t def, 70 u_int32_t def_mask) 71 { 72 if(mask & KADM5_PRINC_EXPIRE_TIME 73 && princ_mask & KADM5_PRINC_EXPIRE_TIME) { 74 if (princ->princ_expire_time) 75 set_value(ent->valid_end, princ->princ_expire_time); 76 else 77 set_null(ent->valid_end); 78 } 79 if(mask & KADM5_PW_EXPIRATION 80 && princ_mask & KADM5_PW_EXPIRATION) { 81 if (princ->pw_expiration) 82 set_value(ent->pw_end, princ->pw_expiration); 83 else 84 set_null(ent->pw_end); 85 } 86 if(mask & KADM5_ATTRIBUTES) { 87 if (princ_mask & KADM5_ATTRIBUTES) { 88 attr_to_flags(princ->attributes, &ent->flags); 89 } else if(def_mask & KADM5_ATTRIBUTES) { 90 attr_to_flags(def->attributes, &ent->flags); 91 ent->flags.invalid = 0; 92 } else { 93 ent->flags.client = 1; 94 ent->flags.server = 1; 95 ent->flags.forwardable = 1; 96 ent->flags.proxiable = 1; 97 ent->flags.renewable = 1; 98 ent->flags.postdate = 1; 99 } 100 } 101 if(mask & KADM5_MAX_LIFE) { 102 if(princ_mask & KADM5_MAX_LIFE) { 103 if(princ->max_life) 104 set_value(ent->max_life, princ->max_life); 105 else 106 set_null(ent->max_life); 107 } else if(def_mask & KADM5_MAX_LIFE) { 108 if(def->max_life) 109 set_value(ent->max_life, def->max_life); 110 else 111 set_null(ent->max_life); 112 } 113 } 114 if(mask & KADM5_KVNO 115 && princ_mask & KADM5_KVNO) 116 ent->kvno = princ->kvno; 117 if(mask & KADM5_MAX_RLIFE) { 118 if(princ_mask & KADM5_MAX_RLIFE) { 119 if(princ->max_renewable_life) 120 set_value(ent->max_renew, princ->max_renewable_life); 121 else 122 set_null(ent->max_renew); 123 } else if(def_mask & KADM5_MAX_RLIFE) { 124 if(def->max_renewable_life) 125 set_value(ent->max_renew, def->max_renewable_life); 126 else 127 set_null(ent->max_renew); 128 } 129 } 130 if(mask & KADM5_KEY_DATA 131 && princ_mask & KADM5_KEY_DATA) { 132 _kadm5_set_keys2(ent, princ->n_key_data, princ->key_data); 133 } 134 if(mask & KADM5_TL_DATA) { 135 /* XXX */ 136 } 137 if(mask & KADM5_FAIL_AUTH_COUNT) { 138 /* XXX */ 139 } 140 return 0; 141 } 142