|
|
1.1 ! root 1: /* ufn_main.c - stand-alone UFN user-interface */ ! 2: ! 3: #ifndef lint ! 4: static char *rcsid = "$Header: /f/osi/others/quipu/uips/ufn/RCS/ufn_main.c,v 7.1 90/07/09 14:42:35 mrose Exp $"; ! 5: #endif ! 6: ! 7: /* ! 8: * $Header: /f/osi/others/quipu/uips/ufn/RCS/ufn_main.c,v 7.1 90/07/09 14:42:35 mrose Exp $ ! 9: * ! 10: * ! 11: * $Log: ufn_main.c,v $ ! 12: * Revision 7.1 90/07/09 14:42:35 mrose ! 13: * sync ! 14: * ! 15: * Revision 7.0 90/06/13 18:52:43 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/ufn.h" ! 32: #include "quipu/bind.h" ! 33: #include "quipu/dsp.h" ! 34: #include "quipu/ds_error.h" ! 35: ! 36: extern char * dn2str(); ! 37: extern char * dn2ufn(); ! 38: static PS ps; ! 39: ! 40: DNS interact (dns,dn,s) ! 41: DNS dns; ! 42: DN dn; ! 43: char * s; ! 44: { ! 45: char buf[LINESIZE]; ! 46: DNS result = NULLDNS; ! 47: DNS newdns; ! 48: ! 49: if (dns == NULLDNS) ! 50: return NULLDNS; ! 51: ! 52: ps_printf (ps,"Please select from the following (matching '%s'):\n",s); ! 53: ! 54: while (dns != NULLDNS) { ! 55: ps_printf (ps," %s [y/n] ? ",dn2ufn(dns->dns_dn,FALSE)); ! 56: (void) ps_flush (ps); ! 57: ! 58: again:; ! 59: if (gets (buf) == NULL) { ! 60: clearerr (stdin); ! 61: ps_print (ps,"\n"); ! 62: return result; ! 63: } ! 64: ! 65: if ((buf[0] == NULL) ! 66: || (strlen(buf) != 1) ! 67: || ((buf[0] != 'y') && (buf[0] != 'n'))) { ! 68: ps_print (ps,"Please type 'y' or 'n': "); ! 69: (void) ps_flush (ps); ! 70: goto again; ! 71: } ! 72: ! 73: if (buf[0] == 'y') { ! 74: newdns = dn_seq_alloc(); ! 75: newdns->dns_next = result; ! 76: newdns->dns_dn = dn_cpy (dns->dns_dn); ! 77: result = newdns; ! 78: dns = dns->dns_next; ! 79: } else { ! 80: DNS tmp; ! 81: tmp = dns; ! 82: dns = dns->dns_next; ! 83: tmp->dns_next = NULLDNS; ! 84: dn_seq_free (tmp); ! 85: } ! 86: } ! 87: return result; ! 88: } ! 89: ! 90: bind_to_dsa () ! 91: { ! 92: struct ds_bind_arg bindarg; ! 93: struct ds_bind_arg bindresult; ! 94: struct ds_bind_error binderr; ! 95: ! 96: bindarg.dba_version = DBA_VERSION_V1988; ! 97: ! 98: bindarg.dba_passwd_len = 0; ! 99: bindarg.dba_passwd [0] = '\0'; ! 100: bindarg.dba_dn = NULLDN; ! 101: ! 102: if (ds_bind (&bindarg,&binderr,&bindresult) != DS_OK) ! 103: return FALSE; ! 104: else ! 105: return TRUE; ! 106: } ! 107: ! 108: ! 109: ! 110: main (argc,argv) ! 111: int argc; ! 112: char ** argv; ! 113: { ! 114: char buffer [1024]; ! 115: char use_dish = FALSE; ! 116: char full_dn = FALSE; ! 117: char got_arg = FALSE; ! 118: int n; ! 119: envlist el; ! 120: ! 121: buffer[0] = NULL; ! 122: ! 123: for (n=1; n<argc; n++) { ! 124: if (*argv[n] == '-') { ! 125: if ((strlen (argv[n]) != 2) ! 126: || ((buffer[0] != NULL) && (n != argc - 1)) ! 127: || got_arg) { ! 128: usage:; ! 129: (void) fprintf (stderr,"Usage: %s [-df] [name]\n",argv[0]); ! 130: (void) fprintf (stderr," -d: send results to dish for processing (assumes dish is running in the background)\n"); ! 131: (void) fprintf (stderr," -f: print the full DN in results\n"); ! 132: exit (-4); ! 133: } ! 134: ! 135: got_arg = TRUE; ! 136: if (argv[n][1] == 'd') ! 137: use_dish = TRUE; ! 138: else if (argv[n][1] == 'f') ! 139: full_dn = TRUE; ! 140: else ! 141: goto usage; ! 142: continue; ! 143: } ! 144: (void) strcat (buffer," "); ! 145: (void) strcat (buffer, argv[n]); ! 146: } ! 147: ! 148: ufn_notify = TRUE; ! 149: ! 150: if ((ps = ps_alloc (std_open)) == NULLPS) { ! 151: (void) fprintf (stderr,"Can't allocate output PS\n"); ! 152: exit (-1); ! 153: } ! 154: if (std_setup (ps, stdout) == NOTOK) { ! 155: (void) fprintf (stderr,"Can't set up output PS\n"); ! 156: exit (-2); ! 157: } ! 158: ! 159: isodetailor ("ufn",1); ! 160: ! 161: quipu_syntaxes (); ! 162: dsap_init ((int *)0,(char ***)0); ! 163: check_known_oids(); ! 164: (void) ufn_init (); ! 165: if ((el = read_envlist ()) == NULLEL) { ! 166: (void) fprintf (stderr, "%s\n", PY_pepy); ! 167: exit (-5); ! 168: } ! 169: ! 170: if (buffer[0] != NULL) ! 171: do_name (ps,buffer,use_dish,full_dn,el); ! 172: else ! 173: for (;;) { ! 174: ps_print (ps,"\nufn> "); ! 175: (void) ps_flush (ps); ! 176: if (gets (buffer) == NULL) ! 177: break; ! 178: if (buffer[0] != NULL) ! 179: do_name (ps,buffer,use_dish,full_dn,el); ! 180: } ! 181: ! 182: (void) ds_unbind(); ! 183: } ! 184: ! 185: do_name (opt,buffer,use_dish,full_dn,el) ! 186: PS opt; ! 187: char * buffer; ! 188: char use_dish; ! 189: char full_dn; ! 190: envlist el; ! 191: { ! 192: char command [1024]; ! 193: int n; ! 194: char * v[20]; ! 195: extern int print_parse_errors, parse_status; ! 196: extern char PY_pepy[]; ! 197: int old; ! 198: DNS dns = NULLDNS, tdns; ! 199: static char bound = FALSE; ! 200: DN marker; ! 201: extern char * local_dit; ! 202: ! 203: if ((n = sstr2arg (buffer,20,v,",")) == NOTOK) { ! 204: (void) fprintf (stderr, "Can't parse input !!!\n"); ! 205: return; ! 206: } ! 207: ! 208: if (n == 1) { ! 209: DN dn; ! 210: char * ptr; ! 211: ! 212: if (*v[0] == '@') ! 213: ptr = strdup (v[0]); ! 214: else if ((ptr = alias2name (v[0])) != NULLCP) ! 215: ptr = strdup (ptr); ! 216: else ! 217: goto use_ufn; ! 218: ! 219: old = print_parse_errors; ! 220: print_parse_errors = FALSE; ! 221: if ((dn = str2dn (ptr)) != NULLDN) { ! 222: if (use_dish) { ! 223: (void) sprintf (command,"showentry -fred \"@%s\"",dn2str(dn)); ! 224: dish (command); ! 225: } else { ! 226: ps_print (opt,"\nThat's an easy one:\n "); ! 227: if (full_dn) ! 228: dn_print (opt,dn,EDBOUT); ! 229: else ! 230: ufn_dn_print (opt,dn,TRUE); ! 231: } ! 232: ps_print (opt,"\n"); ! 233: return; ! 234: } ! 235: free (ptr); ! 236: parse_status--; /* ignore error */ ! 237: print_parse_errors = old; ! 238: } ! 239: ! 240: use_ufn:; ! 241: if (!bound) { ! 242: (void) fprintf (stderr,"Connecting to DSA...\n"); ! 243: if (! bind_to_dsa()) { ! 244: (void) fprintf (stderr,"Can't contact DSA\n"); ! 245: exit (-3); ! 246: } ! 247: bound = TRUE; ! 248: } ! 249: ! 250: if ( ! ufn_match (n,v,interact,&dns,el)) ! 251: (void) fprintf (stderr, "Try again later !!!\n"); ! 252: else { ! 253: if (dns == NULLDNS) { ! 254: ps_print (opt, "Nothing found\n"); ! 255: } else if (dns->dns_next == NULLDNS) { ! 256: if (use_dish) { ! 257: (void) sprintf (command,"showentry -fred \"@%s\"",dn2str(dns->dns_dn)); ! 258: dish (command); ! 259: } else { ! 260: ps_print (opt,"\nThe following name was matched:\n "); ! 261: if (full_dn) ! 262: dn_print (opt,dns->dns_dn,EDBOUT); ! 263: else ! 264: ufn_dn_print (opt,dns->dns_dn,TRUE); ! 265: } ! 266: ps_print (opt,"\n"); ! 267: return; ! 268: } else { ! 269: DN next, trail = NULLDN; ! 270: ! 271: (void) printf ("\nThe following names were matched...\n"); ! 272: ! 273: if (!full_dn) { ! 274: DN tdn; ! 275: marker = str2dn (local_dit); ! 276: for (tdns=dns; (tdns!= NULLDNS) && (marker != NULLDN); tdns=tdns->dns_next) { ! 277: tdn = tdns->dns_dn; ! 278: for (next=marker; ! 279: (tdn!= NULLDN) && (next != NULLDN); ! 280: next=next->dn_parent, tdn=tdn->dn_parent) { ! 281: if (dn_comp_cmp(tdn,next) != 0) { ! 282: if (trail == NULLDN) ! 283: marker = NULLDN; ! 284: else ! 285: trail->dn_parent = NULLDN; ! 286: dn_free (next); ! 287: break; ! 288: } ! 289: trail = next; ! 290: } ! 291: if (tdn == NULLDN) { ! 292: if (trail == NULLDN) ! 293: marker = NULLDN; ! 294: else ! 295: trail->dn_parent = NULLDN; ! 296: dn_free (next); ! 297: } ! 298: } ! 299: } ! 300: ! 301: for (; dns!= NULLDNS; dns=dns->dns_next) { ! 302: if (use_dish) { ! 303: (void) sprintf (command,"squid -alias \"@%s\"",dn2str(dns->dns_dn)); ! 304: dish (command); ! 305: } else { ! 306: ps_print (opt," "); ! 307: if (full_dn) ! 308: dn_print (opt,dns->dns_dn,EDBOUT); ! 309: else ! 310: ufn_dn_print_aux (opt,dns->dns_dn,marker,TRUE); ! 311: ps_print (opt,"\n"); ! 312: } ! 313: } ! 314: ps_print (opt,"\n"); ! 315: } ! 316: } ! 317: } ! 318: ! 319: #include <varargs.h> ! 320: ! 321: #ifndef lint ! 322: ! 323: void advise (va_alist) ! 324: va_dcl ! 325: { ! 326: int code; ! 327: va_list ap; ! 328: ! 329: va_start (ap); ! 330: ! 331: code = va_arg (ap, int); ! 332: ! 333: (void) fprintf (stderr, ap); ! 334: ! 335: va_end (ap); ! 336: } ! 337: ! 338: #else ! 339: /* VARARGS */ ! 340: ! 341: void advise (code, what, fmt) ! 342: char *what, ! 343: *fmt; ! 344: int code; ! 345: { ! 346: advise (code, what, fmt); ! 347: } ! 348: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.