Annotation of 43BSDReno/contrib/isode-beta/quipu/dish/dishlib.c, revision 1.1.1.1

1.1       root        1: /* dish.c - */
                      2: 
                      3: #ifndef        lint
                      4: static char *rcsid = "$Header: /f/osi/quipu/dish/RCS/dishlib.c,v 7.3 90/07/09 14:47:06 mrose Exp $";
                      5: #endif
                      6: 
                      7: /* 
                      8:  * $Header: /f/osi/quipu/dish/RCS/dishlib.c,v 7.3 90/07/09 14:47:06 mrose Exp $
                      9:  *
                     10:  *
                     11:  * $Log:       dishlib.c,v $
                     12:  * Revision 7.3  90/07/09  14:47:06  mrose
                     13:  * sync
                     14:  * 
                     15:  * Revision 7.2  90/04/18  08:49:37  mrose
                     16:  * 6.2
                     17:  * 
                     18:  * Revision 7.1  90/03/15  11:18:23  mrose
                     19:  * quipu-sync
                     20:  * 
                     21:  * Revision 7.1  89/12/19  16:21:01  mrose
                     22:  * sync
                     23:  * 
                     24:  * Revision 7.0  89/11/23  22:20:01  mrose
                     25:  * Release 6.0
                     26:  * 
                     27:  */
                     28: 
                     29: /*
                     30:  *                               NOTICE
                     31:  *
                     32:  *    Acquisition, use, and distribution of this module and related
                     33:  *    materials are subject to the restrictions of a license agreement.
                     34:  *    Consult the Preface in the User's Manual for the full terms of
                     35:  *    this agreement.
                     36:  *
                     37:  */
                     38: 
                     39: 
                     40: #include <stdio.h>
                     41: #include <signal.h>
                     42: #include "quipu/util.h"
                     43: #include "quipu/name.h"
                     44: #include <varargs.h>
                     45: 
                     46: #ifdef SOCKETS
                     47: #include "internet.h"
                     48: extern int sd_current;
                     49: #endif
                     50: 
                     51: #define MAXARGS 50
                     52: 
                     53: extern LLog    *log_dsap;
                     54: DN              dn = NULLDN;   /* This actually stores the current position. */
                     55: 
                     56: #define        OPT     (!frompipe || rps -> ps_byteno == 0 ? opt : rps)
                     57: #define        RPS     (!frompipe || opt -> ps_byteno == 0 ? rps : opt)
                     58: char   frompipe;
                     59: PS     opt, rps;
                     60: 
                     61: DN              savename;
                     62: 
                     63: SFD             dish_quit ();
                     64: SFD             dish_intr ();
                     65: unsigned       cache_time = 3600;      /* time to keep process alive */
                     66: unsigned       connect_time = 120;     /* time to keep connection open */
                     67: 
                     68: char            inbuf[LINESIZE];
                     69: char           bound = FALSE;
                     70: char           remote_prob;
                     71: char           doneget;
                     72: char           *TidyString();
                     73: char           search_result;          /* another horrid global ! */
                     74: 
                     75: extern int call_list (), call_compare (), call_search (),
                     76:            call_add (), call_delete (), call_showentry (), call_showname (),
                     77:            call_showattribute (), call_unbind (), call_help (), call_ds (),
                     78:            unknown_cmd (), dsa_control (), call_modify (), call_modifyrdn (),
                     79:           call_quit (), call_bind (), call_moveto (), call_fred ();
                     80: 
                     81: static struct {
                     82:        char           *command;
                     83:        int             (*handler) ();
                     84:        int             unique;
                     85:        char            defaults [LINESIZE];
                     86: } Commands[MAXARGS];
                     87: static int num_cmd = 0;
                     88: 
                     89: add_dish_command (name,func,len)
                     90: char * name;
                     91: IFP func;
                     92: int len;
                     93: {
                     94:        Commands[num_cmd].command = name;
                     95:        Commands[num_cmd].handler = func;
                     96:        Commands[num_cmd].unique  = (len == 0 ? strlen(name) : len);
                     97:        bzero (Commands[num_cmd].defaults,LINESIZE);
                     98:        num_cmd++;
                     99: }
                    100: 
                    101: dish_cmd_init ()
                    102: {
                    103:        add_dish_command ("list",       call_list,              1);
                    104:        add_dish_command ("compare",    call_compare,           1);
                    105:        add_dish_command ("search",     call_search,            2);
                    106:        add_dish_command ("add",        call_add,               1);
                    107:        add_dish_command ("delete",     call_delete,            2);
                    108:        add_dish_command ("modify",     call_modify,            3);
                    109:        add_dish_command ("modifyrdn",  call_modifyrdn,         7);
                    110:        add_dish_command ("showentry",  call_showentry,         2);
                    111:        add_dish_command ("showname",   call_showname,          5);
                    112:        add_dish_command ("bind",       call_bind,              1);
                    113:        add_dish_command ("unbind",     call_unbind,            1);
                    114:        add_dish_command ("moveto",     call_moveto,            3);
                    115:        add_dish_command ("dsacontrol", dsa_control,            2);
                    116:        add_dish_command ("quit",       call_quit,              1); /* quick way out for interactive program */ 
                    117:        add_dish_command ("squid",      call_ds,                2);
                    118:        add_dish_command ("?",          call_help,              1);
                    119:        add_dish_command ("help",       call_help,              1);
                    120:        add_dish_command ("fred",       call_fred,              4);
                    121:        dish_help_init ();
                    122: };
                    123: 
                    124: jmp_buf  dish_env;
                    125: 
                    126: #ifndef IDLE
                    127: #define IDLE 0
                    128: #endif
                    129: #ifndef BUSY
                    130: #define BUSY 1
                    131: #endif
                    132: static char    dish_state;
                    133: 
                    134: #ifndef NO_STATS
                    135: extern LLog *log_stat;
                    136: #endif
                    137: extern LLog *log_dsap;
                    138: 
                    139: char no_rcfile;
                    140: 
                    141: dish_init (argc, argv)
                    142: int             argc;
                    143: char          **argv;
                    144: {
                    145:        int             i;
                    146:        char           *ttyname (), *getenv();
                    147:        char           *vec [1];
                    148:        char          **vecptr;
                    149:        extern char *  tailfile;
                    150: 
                    151:        dish_cmd_init ();
                    152: 
                    153:        (void) signal (SIGHUP,  dish_quit);
                    154:        (void) signal (SIGQUIT, dish_quit);
                    155:        (void) signal (SIGILL,  dish_quit);
                    156:        (void) signal (SIGBUS,  dish_quit);
                    157:        (void) signal (SIGSEGV, dish_quit);
                    158:        (void) signal (SIGSYS,  dish_quit);
                    159:        (void) signal (SIGTERM, dish_quit);
                    160: 
                    161:        no_rcfile = FALSE;
                    162:        for (i=1; i<argc; i++) {
                    163:            if (test_arg (argv[i],"-fast",1)) {
                    164:                no_rcfile = TRUE;
                    165:                shuffle_up (argc--, argv, i);
                    166:                continue;
                    167:            }
                    168:            if (test_arg (argv[i],"-help",1)) {
                    169:                if ((opt = ps_alloc (std_open)) == NULLPS)
                    170:                        fatal (-62, "ps_alloc failed");
                    171:                if (std_setup (opt, stderr) == NOTOK)
                    172:                        fatal (-63, "std_setup failed");
                    173: 
                    174:                if ((rps = ps_alloc (std_open)) == NULLPS)
                    175:                        fatal (-64, "ps_alloc 2 failed");
                    176:                if (std_setup (rps, stdout) == NOTOK)
                    177:                        fatal (-65, "std_setup 2 failed");
                    178: 
                    179:                help_arg ("dish");
                    180:                exit (0);
                    181:            }
                    182:            if (test_arg(argv[i],"-tailor",1)) {
                    183:                shuffle_up (argc--, argv, i);
                    184:                if (i == argc) 
                    185:                        fatal (-66,"Tailor file name missing");
                    186:                tailfile = argv[i];
                    187:                shuffle_up (argc--, argv, i);
                    188:            }
                    189:        }
                    190: 
                    191:        if ( (argc >1) && (test_arg (argv[1], "-pipe",3))) {
                    192:                if (init_pipe () != OK)
                    193:                        exit (-61);
                    194:                frompipe = TRUE;
                    195:                opt = rps = NULLPS;
                    196:        } else {
                    197:                frompipe = FALSE;
                    198: 
                    199:                if ((opt = ps_alloc (std_open)) == NULLPS)
                    200:                        fatal (-62, "ps_alloc failed");
                    201:                if (std_setup (opt, stderr) == NOTOK)
                    202:                        fatal (-63, "std_setup failed");
                    203: 
                    204:                if ((rps = ps_alloc (std_open)) == NULLPS)
                    205:                        fatal (-64, "ps_alloc 2 failed");
                    206:                if (std_setup (rps, stdout) == NOTOK)
                    207:                        fatal (-65, "std_setup 2 failed");
                    208: 
                    209:                (void) printf ("Welcome to Dish (DIrectory SHell)\n");
                    210:                (void) fflush (stdout);
                    211:        }
                    212: 
                    213:        i = 1;
                    214:        vec[0] = argv[0];
                    215:        vecptr = vec;
                    216: 
                    217:        want_oc_hierarchy ();   /* for add/modify ! */
                    218: 
                    219: #ifndef NO_STATS
                    220:        log_stat -> ll_file = "dish.log";
                    221:        log_stat -> ll_stat &= ~LLOGCRT;
                    222: #endif
                    223:        log_dsap -> ll_stat &= ~LLOGCRT;
                    224:        dsap_init (&i, &vecptr);
                    225: 
                    226: #ifndef NO_STATS
                    227:        ll_hdinit (log_stat,vec[0]);
                    228: #endif
                    229:        
                    230:        check_known_oids();
                    231: 
                    232:        if (user_tailor () != OK) {
                    233:                
                    234:                (void) fprintf (stderr, "Tailoring failed\n");
                    235:                
                    236:                if (frompipe)
                    237:                        exit_pipe ();
                    238: 
                    239:                exit (-66);
                    240:        }
                    241:        
                    242:        if (! frompipe) {
                    243:        
                    244: #ifndef NO_STATS
                    245:                char buf [LINESIZE];
                    246:                *buf = 0;
                    247: 
                    248:                for (i=0; i<argc; i++) {
                    249:                        (void) strcat (buf,argv[i]);
                    250:                        (void) strcat (buf," ");
                    251:                        if (test_arg (argv[i], "-password",2) && ++i < argc)
                    252:                            (void) strcat (buf, "????");
                    253:                }
                    254:                LLOG (log_stat,LLOG_NOTICE,("%s",buf)); 
                    255: #endif
                    256:                if (setjmp (dish_env)) 
                    257:                        exit (-66);
                    258: 
                    259:                if (call_bind (argc,argv) != OK)
                    260:                        exit (-67);
                    261:        }
                    262: }
                    263: 
                    264: unknown_cmd ()
                    265: {
                    266:        if (frompipe)
                    267:                ps_print (opt,"Serious dish error\n");
                    268:        else {
                    269:                if (print_arg_error (opt) != OK)
                    270:                        ps_print (opt,"Unknown command --- type '?' for help\n");
                    271:        }
                    272: }
                    273: 
                    274: do_dish ()
                    275: {
                    276:        char           *brkset;
                    277:        char           *command;
                    278:        char            cmd_buf [LINESIZE];
                    279:        char           *ptr;
                    280:        char           *vector[MAXARGS];
                    281:        int             no_of_args;
                    282:        int             x;
                    283:        char            noarg;
                    284:        extern int      parse_line;
                    285:        extern int      dsa_dead;
                    286:        extern int      errno;
                    287: 
                    288:        Commands[num_cmd].command = NULLCP;
                    289:        Commands[num_cmd].handler = unknown_cmd;
                    290:        Commands[num_cmd].unique  = 0;
                    291: 
                    292:        (void) signal (SIGINT, dish_intr);
                    293:        if (setjmp (dish_env) == 1)
                    294:                goto tidy_up;
                    295: 
                    296:        while (1) {
                    297:                dish_state = IDLE;
                    298:                if (dsa_dead) {
                    299:                        (void) ds_unbind ();
                    300:                        bound = FALSE;
                    301:                        dsa_dead = FALSE;
                    302:                }
                    303: 
                    304:                parse_line = 0;
                    305:                reset_arg ();
                    306:                set_current_pos();
                    307:                remote_prob = FALSE;
                    308:                doneget = FALSE;
                    309: 
                    310:                if (frompipe) {
                    311:                        set_alarm ();
                    312: 
                    313:                        if (read_pipe (inbuf,LINESIZE) == -1)
                    314:                                continue;
                    315: 
                    316:                        (void) signal (SIGALRM, SIG_IGN);       
                    317:                                /* unset alarm */
                    318: #ifdef SOCKETS
                    319:                        command = inbuf;
                    320: #else
                    321:                        command = index (inbuf, ':');
                    322:                        *command++ = 0;
                    323: #endif
                    324: 
                    325: #ifdef SOCKETS
                    326:                        if ((opt = ps_alloc (fdx_open)) == NULLPS) {
                    327:                                exit_pipe ();
                    328:                                fatal (-68, "ps_alloc failed");
                    329:                        }
                    330:                        if (fdx_setup (opt, sd_current) == NOTOK) {
                    331:                                exit_pipe ();
                    332:                                fatal (-69, "fdx_setup failed");
                    333:                        }
                    334:                        (void) (*opt -> ps_writeP) (opt, "2", 1, 0);
                    335: 
                    336:                        if ((rps = ps_alloc (fdx_open)) == NULLPS) {
                    337:                                exit_pipe ();
                    338:                                fatal (-70, "ps_alloc 2 failed");
                    339:                        }
                    340:                        if (fdx_setup (rps, sd_current) == NOTOK) {
                    341:                                exit_pipe ();
                    342:                                fatal (-71, "fdx_setup 2 failed");
                    343:                        }
                    344:                        (void) (*rps -> ps_writeP) (rps, "1", 1, 0);
                    345: #else
                    346:                        if ((opt = ps_alloc (str_open)) == NULLPS) {
                    347:                                exit_pipe ();
                    348:                                fatal (-68, "ps_alloc failed");
                    349:                        }
                    350:                        if (str_setup (opt, NULLCP, BUFSIZ, 0) == NOTOK) {
                    351:                                exit_pipe ();
                    352:                                fatal (-69, "str_setup failed");
                    353:                        }
                    354:                        opt->ps_ptr++, opt->ps_cnt--;
                    355: 
                    356:                        if ((rps = ps_alloc (str_open)) == NULLPS) {
                    357:                                exit_pipe ();
                    358:                                fatal (-70, "ps_alloc 2 failed");
                    359:                        }
                    360:                        if (str_setup (rps, NULLCP , BUFSIZ, 0) == NOTOK) {
                    361:                                exit_pipe ();
                    362:                                fatal (-71, "str_setup 2 failed");
                    363:                        }
                    364:                        rps->ps_ptr++, rps->ps_cnt--;
                    365: #endif
                    366:                        if (!no_rcfile)
                    367:                                test_rc_file (opt);
                    368:                } else {
                    369:                        do {
                    370:                            set_alarm ();
                    371:                            (void) printf ("Dish -> ");
                    372:                            if (fgets (inbuf, sizeof inbuf, stdin) == 0)
                    373:                                call_quit();
                    374:                            for (ptr = inbuf; isspace (*ptr); ptr++)
                    375:                                continue;
                    376:                        } while (*ptr == 0);
                    377:                        (void) signal (SIGALRM, SIG_IGN); /* unset alarm */
                    378:                        command = TidyString(inbuf);
                    379:                }
                    380:                savename = dn_cpy (dn);
                    381:                hide_picture();
                    382:                dish_state = BUSY;
                    383:                
                    384:                ptr = command;
                    385:                while (*ptr)
                    386:                        if (isspace (*ptr))
                    387:                                break;
                    388:                        else
                    389:                                ptr++;
                    390: 
                    391:                if (*ptr == 0) {
                    392:                        noarg = TRUE;
                    393:                } else {
                    394:                        *ptr = 0;       
                    395:                        noarg = FALSE;
                    396:                }
                    397:                for (x = 0; Commands[x].command != 0; x++)
                    398:                        if (test_arg (command, Commands[x].command, Commands[x].unique))
                    399:                                break;
                    400: 
                    401:                if (! noarg)    
                    402:                        *ptr++ = ' ';
                    403: 
                    404:                if (* Commands[x].defaults != 0) {
                    405:                        if (noarg) {
                    406:                                (void) sprintf (cmd_buf,"%s %s",Commands[x].command,Commands[x].defaults);
                    407:                        } else {
                    408:                                (void) sprintf (cmd_buf,"%s %s %s",Commands[x].command,Commands[x].defaults,ptr);
                    409:                        }
                    410:                        command = cmd_buf;
                    411:                }
                    412: 
                    413:                if (strncmp (command, "fred -ufn ", 9) == 0) {
                    414:                    command[4] = command[9] = ',';
                    415:                    brkset = ",";
                    416:                }
                    417:                else
                    418:                    brkset = " \t";
                    419:                if ((no_of_args = sstr2arg (command, MAXARGS, vector, brkset)) == NOTOK)
                    420:                        ps_printf (OPT, "Too many arguments... Can't cope.\n");
                    421:                else {
                    422:                        char help_flag = FALSE;
                    423:                        int y;
                    424: #ifndef NO_STATS
                    425:                        char buf [LINESIZE];
                    426: #endif
                    427: 
                    428:                        vector[0] = Commands[x].command;
                    429: 
                    430: #ifndef NO_STATS
                    431:                        if (vector[0] != NULLCP) {
                    432:                                (void) strcpy (buf,vector[0]);
                    433:                                (void) strcat (buf," ");
                    434:                        }
                    435: #endif
                    436:                        for (y=1; y<no_of_args; y++) {
                    437: 
                    438: #ifndef NO_STATS
                    439:                                (void) strcat (buf,vector[y]);
                    440:                                (void) strcat (buf," ");
                    441: 
                    442:                                if (test_arg (vector[y], "-password",2) && y+1 < no_of_args) {
                    443:                                    (void) strcat (buf, "????");
                    444:                                    y++;
                    445:                                    continue;
                    446:                                }
                    447: #endif
                    448:                                if (test_arg (vector[y],"-help",1)) {
                    449:                                        if (vector[0] != NULLCP)
                    450:                                                help_arg (vector[0]);
                    451:                                        else
                    452:                                                unknown_cmd();
                    453:                                        help_flag = TRUE;
                    454:                                }
                    455:                        }
                    456: #ifndef NO_STATS
                    457:                        LLOG (log_stat,LLOG_NOTICE,("%s",buf)); 
                    458: #endif
                    459:                        if ( ! help_flag)
                    460:                               (*Commands[x].handler) (no_of_args, vector);
                    461:                }
                    462: 
                    463:                /* if from pipe, return results */
                    464: tidy_up:;              
                    465: 
                    466:                if (frompipe && !remote_prob) {
                    467: #ifdef SOCKETS
                    468:                    if (rps -> ps_byteno > 0) {
                    469:                        (void) ps_flush (rps);
                    470:                    } else
                    471:                        if (opt -> ps_byteno > 0)
                    472:                            (void) ps_flush (opt);
                    473: #else
                    474:                        if (opt->ps_byteno == 0) {
                    475:                                *rps->ps_ptr = 0;
                    476:                                send_pipe (rps->ps_base);
                    477:                        } else {
                    478:                                *opt->ps_ptr = 0;
                    479:                                if (search_result == OK)
                    480:                                        *opt->ps_base = '2';
                    481:                                else
                    482:                                        *opt->ps_base = '3';    /* Signal search ok but >1 hit, with -hitone option */
                    483:                                send_pipe (opt->ps_base);
                    484:                        }
                    485: #endif
                    486:                        ps_free (opt);
                    487:                        ps_free (rps);
                    488: #ifdef SOCKETS
                    489:                        (void) close_tcp_socket (sd_current);
                    490:                        sd_current = NOTOK;
                    491: #endif
                    492:                } else {
                    493:                        (void) fflush (stdout);
                    494:                        (void) ps_flush (opt);
                    495:                        (void) ps_flush (rps);
                    496:                }
                    497:        }
                    498: }
                    499: 
                    500: call_quit ()
                    501: {
                    502:        /* can only get called if run interactively - dont worry about pipe */
                    503:        (void) signal (SIGINT, SIG_DFL);
                    504:        
                    505:        DLOG (log_dsap, LLOG_DEBUG, ("Dish:- Exiting Dish successfully..."));
                    506:        if (bound)
                    507:                (void) ds_unbind ();
                    508:        bound = FALSE;
                    509:        ps_free (opt);
                    510:        ps_free (rps);
                    511:        hide_picture();
                    512:        exit (0);
                    513: }
                    514: 
                    515: set_cmd_default (cmd, dflt)
                    516: char * cmd;
                    517: char * dflt;
                    518: {
                    519: int x;
                    520: 
                    521:        for (x = 0; Commands[x].command != 0; x++)
                    522:                if (strcmp (cmd, Commands[x].command) == 0) {
                    523:                        if (* Commands[x].defaults != 0)
                    524:                                (void) strcat (Commands[x].defaults, " ");
                    525:                        (void) strcat (Commands[x].defaults, dflt);
                    526:                        return (OK);
                    527:                }
                    528: 
                    529:        return (NOTOK);
                    530: 
                    531: }
                    532: 
                    533: SFD dish_intr ()
                    534: {
                    535: #ifndef BSDSIGS
                    536:        (void) signal (SIGINT, dish_intr);
                    537: #endif
                    538: 
                    539:        if (dish_state == IDLE)
                    540:                (void) fprintf (stderr,"\n");
                    541:        else {
                    542:                (void) fprintf (stderr,"(Interrupted)\n");
                    543:                dish_state = IDLE;
                    544:        }
                    545: 
                    546:        longjmp (dish_env,2);
                    547: }
                    548: 
                    549: void    advise (va_alist)
                    550: va_dcl
                    551: {
                    552:     int     code;
                    553:     va_list ap;
                    554:     extern LLog    *log_dsap;
                    555: 
                    556:     va_start (ap);
                    557: 
                    558:     code = va_arg (ap, int);
                    559: 
                    560:     (void) _ll_log (log_dsap, code, ap);
                    561: 
                    562:     va_end (ap);
                    563: }

unix.superglobalmegacorp.com

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