|
|
1.1 ! root 1: /* ds_init.c - initialise the DSA */ ! 2: ! 3: #ifndef lint ! 4: static char *rcsid = "$Header: /f/osi/quipu/RCS/ds_init.c,v 7.2 90/07/09 14:45:42 mrose Exp $"; ! 5: #endif ! 6: ! 7: /* ! 8: * $Header: /f/osi/quipu/RCS/ds_init.c,v 7.2 90/07/09 14:45:42 mrose Exp $ ! 9: * ! 10: * ! 11: * $Log: ds_init.c,v $ ! 12: * Revision 7.2 90/07/09 14:45:42 mrose ! 13: * sync ! 14: * ! 15: * Revision 7.1 90/03/15 11:18:49 mrose ! 16: * quipu-sync ! 17: * ! 18: * Revision 7.0 89/11/23 22:17:08 mrose ! 19: * Release 6.0 ! 20: * ! 21: */ ! 22: ! 23: /* ! 24: * NOTICE ! 25: * ! 26: * Acquisition, use, and distribution of this module and related ! 27: * materials are subject to the restrictions of a license agreement. ! 28: * Consult the Preface in the User's Manual for the full terms of ! 29: * this agreement. ! 30: * ! 31: */ ! 32: ! 33: ! 34: #include "quipu/config.h" ! 35: #include "quipu/util.h" ! 36: #include "quipu/read.h" ! 37: #include "quipu/dua.h" ! 38: #include "quipu/connection.h" ! 39: #include "quipu/entry.h" ! 40: ! 41: AV_Sequence super_user; ! 42: Entry subtree_load (); ! 43: Entry make_path (); ! 44: extern LLog * log_dsap; ! 45: extern DN mydsadn; ! 46: extern Entry database_root; ! 47: static Entry load_dsa_cache_entry(), load_dsa_remote_entry(); ! 48: ! 49: dsa_init () ! 50: { ! 51: Attr_Sequence as; ! 52: AttributeType manager; ! 53: extern char * mydsaname; ! 54: DN str2dn(); ! 55: extern char * treedir; ! 56: extern char * get_entry_passwd(); ! 57: struct edb_info * dsainfo; ! 58: AV_Sequence avs; ! 59: Entry newentry; ! 60: extern char * new_version(); ! 61: extern char * quipuversion, * TidyString(); ! 62: extern int parse_status; ! 63: Entry my_entry, rem_entry; ! 64: extern IFP unrav_fn; ! 65: extern IFP schema_fn; ! 66: int real_unravel_attribute (); ! 67: int real_check_schema (); ! 68: char loadstate = TRUE; ! 69: ! 70: check_dsa_known_oids (); ! 71: ! 72: unrav_fn = (IFP) real_unravel_attribute; ! 73: schema_fn = (IFP) real_check_schema; ! 74: ! 75: if (( manager = AttrT_new (MANAGER_OID)) == NULLAttrT) ! 76: fatal (-1,"Manager - unknown attribute - check oid tables"); ! 77: ! 78: LLOG (log_dsap,LLOG_NOTICE,("dsa name %s",mydsaname)); ! 79: ! 80: if ((mydsadn = str2dn (mydsaname)) == NULLDN) { ! 81: fatal (-2,"Invalid dsa name"); ! 82: } ! 83: ! 84: if ((my_entry = load_dsa_cache_entry (mydsadn)) == NULLENTRY) { ! 85: if (parse_status != 0) ! 86: fatal (-3,"can't load my entry"); ! 87: ! 88: LLOG (log_dsap,LLOG_NOTICE,("Can't find my own entry - trying another DSA")); ! 89: if ((my_entry = load_dsa_remote_entry (mydsadn)) == NULLENTRY) ! 90: fatal (-4,"can't get my own entry!"); ! 91: else { ! 92: #ifdef TURBO_DISK ! 93: if (turbo_writeall(my_entry) != OK) ! 94: fatal (-4,"Can't write my entry"); ! 95: #else ! 96: if (journal (my_entry) != OK) ! 97: fatal (-4,"Can't write my entry"); ! 98: #endif ! 99: } ! 100: } else if (my_entry->e_data == E_TYPE_CACHE_FROM_MASTER) ! 101: if ((rem_entry = load_dsa_remote_entry (mydsadn)) != NULLENTRY) { ! 102: if (rem_entry->e_parent != NULLENTRY) ! 103: rem_entry->e_parent->e_edbversion = new_version(); ! 104: #ifdef TURBO_DISK ! 105: if (turbo_writeall(rem_entry) != OK) ! 106: fatal (-4,"Can't re-write my entry"); ! 107: #else ! 108: if (journal (rem_entry) != OK) ! 109: fatal (-4,"Can't re-write my entry"); ! 110: #endif ! 111: my_entry = rem_entry; ! 112: } ! 113: ! 114: if (get_entry_passwd (my_entry->e_attributes) == NULLCP) ! 115: /* This is not a fatal error, but some remote operations may fail */ ! 116: LLOG(log_dsap,LLOG_EXCEPTIONS,("Can't find my own PASSWORD")); ! 117: ! 118: if (my_entry->e_dsainfo != NULLDSA) { ! 119: /* get manager attribute */ ! 120: if ((as = as_find_type(my_entry->e_attributes,manager)) == NULLATTR ) ! 121: fatal (-5,"Manager attribute missing in my own entry"); ! 122: AttrT_free (manager); ! 123: super_user = avs_cpy ((AV_Sequence)as->attr_value); ! 124: if (strcmp(my_entry->e_dsainfo->dsa_version,TidyString (strdup (quipuversion))) != 0) ! 125: LLOG(log_dsap,LLOG_EXCEPTIONS,("WARNING: version number wrong (expecting '%s', got '%s') !!",quipuversion,my_entry->e_dsainfo->dsa_version)); ! 126: if (quipu_ctx_supported(my_entry) != 2) ! 127: LLOG(log_dsap,LLOG_EXCEPTIONS,("WARNING: I don't appear to support the QUIPU Context !!!")); ! 128: } else ! 129: fatal (-6,"No edbinfo attribute in my own entry"); ! 130: ! 131: if (parse_status != 0) ! 132: loadstate = FALSE; ! 133: ! 134: for (avs = my_entry->e_dsainfo->dsa_attr ; avs != NULLAV; avs=avs->avseq_next) { ! 135: if (avs->avseq_av.av_struct == NULL) ! 136: continue; ! 137: dsainfo = (struct edb_info *) avs->avseq_av.av_struct; ! 138: newentry = make_path (dsainfo->edb_name); ! 139: (void) subtree_load (newentry,dsainfo->edb_name); ! 140: if (parse_status != 0) ! 141: loadstate = FALSE; ! 142: } ! 143: ! 144: if (loadstate == FALSE) ! 145: fatal (-7,"DSA Halted"); ! 146: ! 147: if (database_root->e_child != NULLENTRY) ! 148: database_root->e_data = database_root->e_child->e_data; ! 149: ! 150: return (OK); ! 151: ! 152: } ! 153: ! 154: static Entry load_dsa_cache_entry(dn) ! 155: DN dn; ! 156: { ! 157: DN ptr,trail = NULLDN; ! 158: Entry newentry; ! 159: ! 160: for (ptr=dn; ptr->dn_parent != NULLDN; ptr=ptr->dn_parent) ! 161: trail = ptr; ! 162: ! 163: if (trail == NULLDN) { ! 164: database_root = subtree_load (NULLENTRY,NULLDN); ! 165: return (local_find_entry (dn,TRUE)); ! 166: } ! 167: ! 168: trail->dn_parent = NULLDN; ! 169: newentry = make_path (dn); ! 170: (void) subtree_load (newentry,dn); ! 171: trail->dn_parent = ptr; ! 172: ! 173: return (local_find_entry (dn,TRUE)); ! 174: } ! 175: ! 176: static Entry load_dsa_remote_entry(dn) ! 177: DN dn; ! 178: { ! 179: static struct ds_read_arg read_arg = ! 180: { ! 181: default_common_args, ! 182: NULLDN, ! 183: { /* entry info selection */ ! 184: TRUE, ! 185: NULLATTR, ! 186: EIS_ATTRIBUTESANDVALUES ! 187: } ! 188: }; ! 189: struct ds_read_result result; ! 190: struct DSError error; ! 191: extern Entry current_entry; ! 192: static struct ds_bind_arg bindarg; ! 193: static struct ds_bind_arg bindresult; ! 194: static struct ds_bind_error binderr; ! 195: int ad, id; ! 196: extern struct PSAPaddr *parent_psap(); ! 197: struct PSAPaddr * addr; ! 198: ! 199: #ifndef NO_STATS ! 200: extern LLog * log_stat; ! 201: extern dn_print (); ! 202: ! 203: pslog (log_stat,LLOG_NOTICE,"SYNC DAP remote entry lookup",dn_print,(caddr_t)dn); ! 204: #endif ! 205: ! 206: /* read from of remote DSA */ ! 207: /* Do synchronus read for now */ ! 208: /* Async read eventually */ ! 209: ! 210: make_dsa_bind_arg (&bindarg); ! 211: ! 212: if ((addr = parent_psap ()) == NULLPA) { ! 213: LLOG (log_dsap,LLOG_EXCEPTIONS,("No parent or quipu-db defined - check quiputailor")); ! 214: return (NULLENTRY); ! 215: } ! 216: ! 217: if (dap_bind (&ad, &bindarg, &binderr, &bindresult,addr) != OK) { ! 218: LLOG (log_dsap,LLOG_EXCEPTIONS,("Can't bind to remote DSA thus can't read my own entry")); ! 219: bind_arg_free (&bindarg); ! 220: return (NULLENTRY); ! 221: } ! 222: ! 223: bind_arg_free (&bindarg); ! 224: bind_arg_free (&bindresult); ! 225: ! 226: read_arg.rda_object = dn; ! 227: ! 228: id = 1; ! 229: if (dap_read (ad, &id,&read_arg, &error, &result) != DS_OK) { ! 230: log_ds_error (&error); ! 231: LLOG (log_dsap,LLOG_EXCEPTIONS,("Remote DSA failed on lookup of my address")); ! 232: (void) dap_unbind (ad); ! 233: return (NULLENTRY); ! 234: } ! 235: ! 236: cache_entry (&(result.rdr_entry), TRUE, EIS_ATTRIBUTESANDVALUES); ! 237: ! 238: if (unravel_attribute (current_entry,&error) != OK) { ! 239: log_ds_error (&error); ! 240: LLOG (log_dsap, LLOG_EXCEPTIONS, ("Remote copy of my entry is wrong!")); ! 241: return (NULLENTRY); ! 242: } ! 243: ! 244: (void) dap_unbind (ad); ! 245: ! 246: return (current_entry); ! 247: } ! 248: ! 249:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.