Annotation of 43BSDReno/contrib/isode-beta/others/quipu/uips/manage/del_alias.c, revision 1.1.1.1

1.1       root        1: /* del_alias.c -  */
                      2: 
                      3: #ifndef        lint
                      4: static char *rcsid = "$Header: /f/osi/others/quipu/uips/manage/RCS/del_alias.c,v 7.1 90/07/27 08:47:19 mrose Exp $";
                      5: #endif
                      6: 
                      7: /* 
                      8:  * $Header: /f/osi/others/quipu/uips/manage/RCS/del_alias.c,v 7.1 90/07/27 08:47:19 mrose Exp $
                      9:  *
                     10:  *
                     11:  * $Log:       del_alias.c,v $
                     12:  * Revision 7.1  90/07/27  08:47:19  mrose
                     13:  * update
                     14:  * 
                     15:  * Revision 7.0  90/06/26  14:52:33  mrose
                     16:  * *** empty log message ***
                     17:  * 
                     18:  */
                     19: 
                     20: /*
                     21:  *                               NOTICE
                     22:  *
                     23:  *    Acquisition, use, and distribution of this module and related
                     24:  *    materials are subject to the restrictions of a license agreement.
                     25:  *    Consult the Preface in the User's Manual for the full terms of
                     26:  *    this agreement.
                     27:  *
                     28:  */
                     29: 
                     30: 
                     31: #include "quipu/util.h"
                     32: #include "quipu/entry.h"
                     33: #include "quipu/remove.h"
                     34: #include "quipu/compare.h"
                     35: #include "quipu/modify.h"
                     36: 
                     37: extern DN       dn;
                     38: extern  char    frompipe;
                     39: #define OPT     (!frompipe || rps -> ps_byteno == 0 ? opt : rps)
                     40: #define RPS     (!frompipe || opt -> ps_byteno == 0 ? rps : opt)
                     41: extern PS      opt;
                     42: extern PS      rps;
                     43: extern Entry   current_entry ;
                     44: 
                     45: call_del_alias (argc, argv)
                     46: int            argc;
                     47: char         **argv;
                     48: {
                     49:        DN              dnptr, aoj_dn, oj_dn, save_dn;
                     50:        DN              trail = NULLDN ;
                     51: extern DN              str2dn_aux() ;
                     52: extern DN              sequence_dn () ;
                     53:        PS              str_ps ;
                     54:        char           *str_buffer ;
                     55:        char            alias = FALSE ;
                     56:        int             mod_failed = 0 ;
                     57:        AV_Sequence     aliObjNameAVS ;
                     58:         struct          entrymod               *emnew ;
                     59:        struct          DSError                 compare_error;
                     60:        struct          ds_compare_result       compare_result;
                     61:        struct          ds_compare_arg          compare_arg;
                     62:        struct          ds_removeentry_arg      remove_arg;
                     63:        struct          ds_modifyentry_arg      mod_arg;
                     64:        struct          DSError                 mod_error;
                     65:        struct          DSError                 error;
                     66:        char            objectname[80] ;
                     67:        char           *contact_compare[6] ;
                     68:        char           *contact_showentry[6] ;
                     69:        char           *contact_modify[1] ;
                     70:        contact_compare[0] = "compare" ;
                     71:        contact_compare[1] = "";
                     72:        contact_compare[2] = "-attribute";
                     73:        contact_compare[4] = "-noprint";
                     74:        contact_compare[5] = "-dontdereferencealias" ;
                     75:        contact_showentry[0] = "showentry";
                     76:        contact_showentry[1] = "-noshow" ;
                     77:        contact_showentry[2] = "-all" ;
                     78:        contact_showentry[3] = "-nokey" ;
                     79:        contact_showentry[4] = "-dontdereferencealias";
                     80:        contact_modify[0] = "modify" ;
                     81: 
                     82:        emnew = em_alloc() ;
                     83:        str_buffer = (char *) malloc ((unsigned)1000) ;
                     84:        contact_showentry[5] = (char *) malloc ((unsigned)strlen(argv[1])) ;
                     85:        (void)strcpy(contact_showentry[5], argv[1]) ;
                     86: 
                     87:        contact_compare[3] = (char *) malloc ((unsigned)strlen("objectClass=alias.")) ;
                     88:        (void)strcpy(contact_compare[3], "objectClass=alias") ;
                     89: 
                     90:        if ((argc = service_control (OPT, argc, argv, &remove_arg.rma_common)) == -1)
                     91:                return ;
                     92: 
                     93:        if (argc > 2)
                     94:        {
                     95:                ps_printf (OPT,"Too many arguments. Aborting...\n");
                     96:                Usage (argv[0]);
                     97:                return ;
                     98:        }
                     99: 
                    100:        if (argc == 1)
                    101:        {
                    102:                ps_printf (OPT,"Delete what???\n") ;
                    103:                Usage (argv[0]) ;
                    104:                return ;
                    105:        }
                    106: 
                    107:        (void)strcpy(objectname,argv[1]) ;
                    108:        contact_compare[1] = argv[1] ;
                    109: 
                    110:        if (service_control (OPT, 6, contact_compare, &compare_arg.cma_common) == -1)
                    111:        {
                    112:                ps_print(OPT, "Problems with compare service control flags.\n") ;
                    113:                return ;
                    114:        }
                    115: 
                    116:        /* Turn a sequence number back into a DN */
                    117:        if (*objectname >= '0' && *objectname <= '9')
                    118:        {
                    119:                /* First convert the number into a dn */
                    120:                oj_dn = dn_cpy(sequence_dn(atoi(objectname))) ;
                    121:        }
                    122:        else
                    123:        {
                    124:                if (*objectname == '.')
                    125:                {
                    126:                        ps_print(OPT, "..@ gives me a headache. Ambiguous. Aborting.\n") ;
                    127:                        return ;
                    128:                }
                    129:                if (*objectname == '@')
                    130:                {
                    131:                        oj_dn = dn_cpy(str2dn(objectname + 1)) ;
                    132:                }
                    133:                else
                    134:                {
                    135:                        /*oj_dn = dn_cpy(dn) ;
                    136:                         *dn_append(oj_dn, dn_cpy(str2dn(objectname))) ;
                    137:                         */
                    138:                        save_dn = str2dn_aux(objectname,&alias) ;
                    139:                        if (save_dn != NULLDN)
                    140:                        {
                    141:                                if (alias)
                    142:                                {
                    143:                                        oj_dn = dn_cpy(save_dn);
                    144:                                } 
                    145:                                else
                    146:                                {
                    147:                                        if (dn == NULLDN)
                    148:                                        {
                    149:                                                oj_dn = dn_cpy(save_dn) ;
                    150:                                        }
                    151:                                        else
                    152:                                        {
                    153:                                                oj_dn = dn_cpy(dn) ;
                    154:                                                dn_append (oj_dn,save_dn);
                    155:                                        }
                    156:                                }
                    157:                        }
                    158:                        dn_free(save_dn) ;
                    159:                }
                    160:        }
                    161: 
                    162:        if (get_ava (&compare_arg.cma_purported, "objectClass", "alias") != OK)
                    163:        {
                    164:                ps_print(OPT, "Oops, 'objectClass=alias' is a bad attribute!\n") ;
                    165:                ps_print(OPT, "This is very bad...\n") ;
                    166:                return ;
                    167:        }
                    168: 
                    169:        save_dn = dn_cpy(dn) ;
                    170:        dn = dn_cpy(oj_dn) ;
                    171:        compare_arg.cma_object = oj_dn;
                    172: 
                    173:        if (rebind () != OK)
                    174:                return ;
                    175: 
                    176:        /* Strong authentication */
                    177:        if (compare_arg.cma_common.ca_security != (struct security_parms *) 0)
                    178:        {
                    179:        struct signature *sign_operation();
                    180:        int encode_DAS_CompareArgumentData();
                    181: 
                    182:        compare_arg.cma_common.ca_sig =
                    183:                sign_operation((caddr_t)&compare_arg, encode_DAS_CompareArgumentData) ;
                    184:        }
                    185: 
                    186:        while (ds_compare (&compare_arg, &compare_error, &compare_result) != DS_OK)
                    187:        {
                    188:                if (dish_error (OPT, &compare_error) == 0)
                    189:                {
                    190:                        return ;
                    191:                }
                    192:                compare_arg.cma_object = compare_error.ERR_REFERRAL.DSE_ref_candidates->cr_name;
                    193:        }
                    194: 
                    195:        if (compare_result.cmr_matched == FALSE)
                    196:        {
                    197:                ps_printf(OPT, "Sorry, object is not an alias. Aborting.\n") ;
                    198:                return ;
                    199:        }
                    200: 
                    201:        call_showentry(5, contact_showentry) ;
                    202: 
                    203:        if (current_entry == NULLENTRY)
                    204:        {
                    205:                (void)fprintf(stderr, "we have no current entry. No wonder!\n") ;
                    206:        }
                    207:        else
                    208:        {
                    209:                Attr_Sequence eptr ;
                    210:                AttributeType a_t = AttrT_new("aliasedObjectName") ;
                    211: 
                    212:                for (eptr = current_entry->e_attributes; eptr != NULLATTR; eptr = eptr->attr_link) 
                    213:                {
                    214:                        if ( AttrT_cmp (eptr->attr_type, a_t) == 0 )
                    215:                        {
                    216:                                aliObjNameAVS = avs_cpy(eptr->attr_value);
                    217:                        }
                    218:                }
                    219:        }
                    220:        if (aliObjNameAVS == NULLAV)
                    221:        {
                    222:                ps_print(OPT, "Can't find 'aliasedObjectName' attribute type.\n") ;
                    223:                ps_print(OPT, "Are you sure that this is an alias? Aborting.\n") ;
                    224:                return ;
                    225:        }
                    226: 
                    227:        /* Now we have the other end of the alias in AttrValue format,
                    228:         * convert it into a DN, so we can modify it.
                    229:         */
                    230: 
                    231:        if ((str_ps = ps_alloc(str_open)) == NULLPS)
                    232:        {
                    233:                ps_printf(OPT, "Ps alloc for your string failed.\n") ;
                    234:                return ;
                    235:        }
                    236:        if (str_setup (str_ps, str_buffer, 998, 1) == NOTOK)
                    237:        {
                    238:                ps_printf (OPT, "str_setup: %s", ps_error (str_ps -> ps_errno));
                    239:                ps_free (str_ps);
                    240:                return ;
                    241:        }
                    242: 
                    243:        avs_print(str_ps, aliObjNameAVS, EDBOUT) ;
                    244:        *str_ps->ps_ptr = 0 ;
                    245:        ps_free (str_ps) ;
                    246:        {
                    247:                char    *ptr_local = str_buffer ;
                    248:                while(*ptr_local !=0 && *ptr_local != '\n')
                    249:                        ptr_local++ ;
                    250:                *ptr_local = '\0' ;
                    251:        }
                    252:        aoj_dn = str2dn(str_buffer) ;
                    253: 
                    254:        /* We now have converted a string to DN and we now have to form the
                    255:         * attribute "seeAlso=<DN>", put it into the modify attributes
                    256:         * and delete that attribute from the other end of the alias.
                    257:         */
                    258: 
                    259:        if (service_control(OPT, 1, contact_modify, &mod_arg.mea_common) == -1)
                    260:        {
                    261:                ps_printf(OPT, "Del_alias: Badly wrong. Service controls for modify in error...\n") ;
                    262:                return ;
                    263:        }
                    264: 
                    265:        dn_free(dn) ;
                    266:        dn = dn_cpy(aoj_dn) ;
                    267:        contact_showentry[1] = ( char *) malloc ((unsigned)strlen("-noshow") + 1) ;
                    268:        (void)strcpy(contact_showentry[1], "-noshow") ;
                    269:        contact_showentry[2] = ( char *) malloc ((unsigned)strlen("-all") + 1) ;
                    270:        (void)strcpy(contact_showentry[2], "-all") ;
                    271:        contact_showentry[3] = ( char *) malloc ((unsigned)strlen("-nokey") + 1) ;
                    272:        (void)strcpy(contact_showentry[3], "-nokey") ;
                    273:        contact_showentry[4] = ( char *) malloc ((unsigned)strlen("-dontdereferencealias") + 1) ;
                    274:        (void)strcpy(contact_showentry[4], "-dontdereferencealias") ;
                    275: 
                    276:        call_showentry(5, contact_showentry) ;
                    277:        if (current_entry == NULLENTRY)
                    278:        {
                    279:                (void)fprintf(stderr, "we have no current entry. No wonder!\n") ;
                    280:        }
                    281:        else
                    282:        {
                    283:                Attr_Sequence eptr ;
                    284:                AttributeType a_t = AttrT_new("seeAlso") ;
                    285: 
                    286:                emnew->em_type = -1 ;
                    287:                for (eptr = current_entry->e_attributes; eptr != NULLATTR; eptr = eptr->attr_link) 
                    288:                {
                    289:                        if ( AttrT_cmp (eptr->attr_type, a_t) == 0 )
                    290:                        {
                    291:                                if (emnew->em_type == -1)
                    292:                                {
                    293:                                        emnew->em_type = EM_REMOVEATTRIBUTE ;
                    294:                                }
                    295:                                else
                    296:                                {
                    297:                                        emnew->em_type = EM_REMOVEVALUES ;
                    298:                                }
                    299:                        }
                    300:                }
                    301:                if (emnew->em_type == -1)
                    302:                {
                    303:                        ps_print(OPT, "INVALID set of entries for the alias object\n") ;
                    304:                        ps_print(OPT, "Aborting...\n") ;
                    305:                        return ;
                    306:                }
                    307:        }
                    308: 
                    309:        {
                    310:                AV_Sequence     new_avs = avs_comp_alloc() ;
                    311:                AttributeValue  new_AV = AttrV_alloc() ;
                    312: 
                    313:                str_buffer = (char *) malloc ((unsigned)1000) ;
                    314:                if ((str_ps = ps_alloc(str_open)) == NULLPS)
                    315:                {
                    316:                        ps_printf(OPT, "Ps alloc for your string failed.\n") ;
                    317:                        return ;
                    318:                }
                    319:                if (str_setup (str_ps, str_buffer, 998, 1) == NOTOK)
                    320:                {
                    321:                        ps_printf (OPT, "str_setup: %s", ps_error (str_ps -> ps_errno));
                    322:                        ps_free (str_ps);
                    323:                        return ;
                    324:                }
                    325: 
                    326:                dn_print(str_ps, oj_dn, EDBOUT) ;
                    327:                *str_ps->ps_ptr = 0 ;
                    328:                ps_free(str_ps) ;
                    329: 
                    330:                new_AV = AttrV_cpy(str2AttrV(str_buffer, str2syntax("DN"))) ;
                    331:                new_avs = avs_comp_new(AttrV_cpy(new_AV)) ;
                    332:                emnew->em_what = as_comp_new(AttrT_new("seeAlso"), new_avs, NULLACL_INFO) ;
                    333:        }
                    334:        emnew->em_next = NULLMOD ;
                    335:        mod_arg.mea_object = aoj_dn;
                    336:        mod_arg.mea_changes = emnew ;
                    337: 
                    338:        if (rebind () != OK)
                    339:                return ;
                    340:                        
                    341: /*
                    342:  * If this operation is time-stamped, it may have expired while the user
                    343:  * was editing the entry. Re-calculate the time-stamp. Modify is the only
                    344:  * dish command where this needs to be done.
                    345:  */
                    346: 
                    347:        if ((mod_arg.mea_common.ca_security != (struct security_parms *) 0)
                    348:                && (mod_arg.mea_common.ca_security->sp_time != NULLCP))
                    349:        {
                    350:                char *new_version();
                    351: 
                    352:                free(mod_arg.mea_common.ca_security->sp_time);
                    353:                mod_arg.mea_common.ca_security->sp_time = new_version();
                    354:        }
                    355: 
                    356: /* If security parameters are present, take this to mean that strong
                    357:  * authentication is required. This disallows 'parms + no signature'
                    358:  * (pointless) and 'signature + no parms' (security risk).
                    359:  */
                    360:        if (mod_arg.mea_common.ca_security != (struct security_parms *) 0)
                    361:        {
                    362:                int encode_DAS_ModifyEntryArgumentData();
                    363:                struct signature *sign_operation();
                    364:                mod_arg.mea_common.ca_sig = 
                    365:                        sign_operation((caddr_t)&mod_arg, 
                    366:                                encode_DAS_ModifyEntryArgumentData);
                    367:        }
                    368: 
                    369:        while (ds_modifyentry (&mod_arg, &mod_error) != DS_OK)
                    370:        {
                    371:                if (dish_error (OPT, &mod_error) == 0)
                    372:                {
                    373:                        ps_print(OPT, "Unable to modify ") ;
                    374:                        dn_print(OPT, aoj_dn, EDBOUT) ;
                    375:                        ps_print(OPT, "\nContinuing to delete alias...") ;
                    376:                        mod_failed = 1 ;
                    377:                }
                    378:                mod_arg.mea_object = mod_error.ERR_REFERRAL.DSE_ref_candidates->cr_name;
                    379:        }
                    380:        if (!mod_failed)
                    381:        {
                    382:                ps_print (RPS, "Modified ");
                    383:                dn_print (RPS, aoj_dn, EDBOUT);
                    384:                ps_print (RPS, "\n");
                    385:                delete_cache (aoj_dn);  /* re-cache when next read */
                    386:        }
                    387: 
                    388:        dn_free(dn) ;
                    389:        dn = dn_cpy(save_dn) ;
                    390: 
                    391:        if (move (objectname) == OK)
                    392:                argc--;
                    393: 
                    394:        remove_arg.rma_object = dn;
                    395: 
                    396:        if (rebind () != OK)
                    397:                return ;
                    398: 
                    399:        while (ds_removeentry (&remove_arg, &error) != DS_OK) 
                    400:        {
                    401:                if (dish_error (OPT, &error) == 0)
                    402:                        return ;
                    403:                remove_arg.rma_object = error.ERR_REFERRAL.DSE_ref_candidates->cr_name;
                    404:        } 
                    405:                
                    406:        ps_print (RPS, "Removed ");
                    407:        dn_print (RPS, dn, EDBOUT);
                    408:        delete_cache (dn);
                    409:        for (dnptr = dn; dnptr->dn_parent != NULLDN; dnptr = dnptr->dn_parent)
                    410:                trail = dnptr;
                    411: 
                    412:        if (trail != NULLDN) 
                    413:                trail->dn_parent = NULLDN;
                    414:        else
                    415:                dn = NULLDN;
                    416: 
                    417:        dn_comp_free (dnptr);
                    418:        ps_print (RPS, "\n");
                    419: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.