|
|
1.1 ! root 1: /* whois.c - fred whois function */ ! 2: ! 3: #ifndef lint ! 4: static char *rcsid = "$Header: /f/osi/others/quipu/uips/fred/RCS/whois.c,v 7.14 90/07/27 08:45:10 mrose Exp $"; ! 5: #endif ! 6: ! 7: /* ! 8: * $Header: /f/osi/others/quipu/uips/fred/RCS/whois.c,v 7.14 90/07/27 08:45:10 mrose Exp $ ! 9: * ! 10: * ! 11: * $Log: whois.c,v $ ! 12: * Revision 7.14 90/07/27 08:45:10 mrose ! 13: * update ! 14: * ! 15: * Revision 7.13 90/07/09 14:41:21 mrose ! 16: * sync ! 17: * ! 18: * Revision 7.12 90/06/11 21:17:12 mrose ! 19: * touch-up ! 20: * ! 21: * Revision 7.11 90/06/11 10:55:38 mrose ! 22: * UFN ! 23: * ! 24: * Revision 7.10 90/03/23 02:39:29 mrose ! 25: * network ! 26: * ! 27: * Revision 7.9 90/03/15 11:20:45 mrose ! 28: * quipu-sync ! 29: * ! 30: * Revision 7.8 90/03/08 08:05:10 mrose ! 31: * phone ! 32: * ! 33: * Revision 7.7 90/01/16 20:43:45 mrose ! 34: * last check-out ! 35: * ! 36: * Revision 7.6 90/01/11 18:36:41 mrose ! 37: * real-sync ! 38: * ! 39: * Revision 7.5 89/12/18 08:44:23 mrose ! 40: * typo ! 41: * ! 42: * Revision 7.4 89/12/14 18:49:05 mrose ! 43: * KIS project ! 44: * ! 45: * Revision 7.3 89/12/01 10:45:11 mrose ! 46: * touch-up ! 47: * ! 48: * Revision 7.2 89/11/26 15:09:32 mrose ! 49: * sync ! 50: * ! 51: * Revision 7.1 89/11/26 14:25:22 mrose ! 52: * sync ! 53: * ! 54: * Revision 7.0 89/11/23 22:09:06 mrose ! 55: * Release 6.0 ! 56: * ! 57: */ ! 58: ! 59: /* ! 60: * NOTICE ! 61: * ! 62: * Acquisition, use, and distribution of this module and related ! 63: * materials are subject to the restrictions of a license agreement. ! 64: * Consult the Preface in the User's Manual for the full terms of ! 65: * this agreement. ! 66: * ! 67: */ ! 68: ! 69: ! 70: #include <ctype.h> ! 71: #include <signal.h> ! 72: #include "fred.h" ! 73: ! 74: /* DATA */ ! 75: ! 76: struct whois { ! 77: char *w_input; ! 78: int w_inputype; ! 79: #define W_NULL 0x00 ! 80: #define W_HANDLE 0x01 ! 81: #define W_MAILBOX 0x02 ! 82: #define W_NAME 0x03 ! 83: ! 84: int w_nametype; ! 85: #define W_COMMONAME 0x01 ! 86: #define W_SURNAME 0x02 ! 87: ! 88: int w_record; /* same values as ag_record */ ! 89: ! 90: char *w_title; ! 91: ! 92: char *w_area; ! 93: int w_areatype; ! 94: char *w_geography; ! 95: ! 96: int w_output; ! 97: #define W_EXPAND 0x01 ! 98: #define W_FULL 0x02 ! 99: #define W_SUMMARY 0x04 ! 100: #define W_SUBDISPLAY 0x08 ! 101: }; ! 102: ! 103: ! 104: char *eqstr (); ! 105: ! 106: /* */ ! 107: ! 108: char *whois_help[] = { ! 109: "whois input-field [record-type] [area-designator] [output-control]", ! 110: " input-field is one of:", ! 111: "\tname NAME\t\te.g., surname \"smith\", or fullname \"john smith\"", ! 112: "\thandle HANDLE\t\te.g., handle @c=US@cn=Manager", ! 113: "\tmailbox LOCAL@DOMAIN\te.g., mailbox [email protected]", ! 114: " record-type is one of:", ! 115: "\tperson or -title NAME\te.g., -title scientist", ! 116: "\torganization", ! 117: "\tunit (a division under an organization)", ! 118: "\trole (a role within an organization)", ! 119: "\tlocality", ! 120: "\tdsa (white pages server)", ! 121: " area-designator is one of:", ! 122: "\t-org NAME\t\te.g., -org nyser", ! 123: "\t-unit NAME\t\te.g., -unit engineering", ! 124: "\t-locality NAME\t\te.g., -locality rensselaer", ! 125: "\t-area HANDLE\t\te.g., -area \"@c=US@o=NYSERNet Inc.\"", ! 126: "\t and may be optionally followed by -geo HANDLE, e.g., -geo @c=GB", ! 127: " output-control is any of:", ! 128: "\texpand\t - give a detailed listing, followed by children", ! 129: "\tsubdisplay - give a one-listing listing, followed by children", ! 130: "\tfull\t - give a detailed listing, even on ambiguous matches", ! 131: "\tsummary\t - give a one-line listing, even on unique matches", ! 132: ! 133: NULL ! 134: }; ! 135: ! 136: /* */ ! 137: ! 138: static int seqno = 0; ! 139: static char fredseq[10]; ! 140: ! 141: ! 142: char *limits (); ! 143: FILE *capture (); ! 144: ! 145: /* WHOIS */ ! 146: ! 147: int f_whois (vec) ! 148: char **vec; ! 149: { ! 150: if (strcmp (*vec, "whois") == 0) ! 151: vec++; ! 152: ! 153: return (nametype > 1 ? f_ufn (vec) : f_whois_aux (vec)); ! 154: } ! 155: ! 156: /* */ ! 157: ! 158: static int f_whois_aux (vec) ! 159: char **vec; ! 160: { ! 161: int c, ! 162: didany, ! 163: multiple, ! 164: result; ! 165: register char *bp, ! 166: *cp, ! 167: *dp; ! 168: char buffer[BUFSIZ], ! 169: onehit[BUFSIZ], ! 170: orgname[BUFSIZ], ! 171: *args[NVEC + 1]; ! 172: register struct area_guide *ag; ! 173: struct whois ws; ! 174: register struct whois *w = &ws; ! 175: FILE *fp; ! 176: ! 177: bzero ((char *) w, sizeof *w); ! 178: ! 179: while (cp = *vec++) { ! 180: postscan: ; ! 181: ! 182: switch (*cp) { ! 183: case '.': ! 184: if (w -> w_inputype != W_NULL) { ! 185: too_many_fields: ; ! 186: advise (NULLCP, ! 187: "only one of NAME, HANDLE, or MAILBOX allowed"); ! 188: goto you_really_lose; ! 189: } ! 190: if (*++cp == NULL) { ! 191: advise (NULLCP, "expecting NAME after \".\""); ! 192: goto you_really_lose; ! 193: } ! 194: w -> w_inputype = W_NAME; ! 195: w -> w_input = cp; ! 196: break; ! 197: ! 198: case '!': ! 199: if (w -> w_inputype != W_NULL) ! 200: goto too_many_fields; ! 201: if (*++cp == NULL) { ! 202: advise (NULLCP, "expecting HANDLE after \"!\""); ! 203: goto you_really_lose; ! 204: } ! 205: goto got_handle; ! 206: ! 207: case '*': ! 208: if (cp[1] == '*') { ! 209: cp++; ! 210: goto name_or_something; ! 211: } ! 212: w -> w_output |= W_EXPAND; ! 213: if (*++cp) ! 214: goto postscan; ! 215: break; ! 216: ! 217: case '~': ! 218: w -> w_output &= ~W_EXPAND; ! 219: if (*++cp) ! 220: goto postscan; ! 221: break; ! 222: ! 223: case '|': ! 224: w -> w_output |= W_FULL; ! 225: if (*++cp) ! 226: goto postscan; ! 227: break; ! 228: ! 229: case '$': ! 230: w -> w_output |= W_SUMMARY; ! 231: if (*++cp) ! 232: goto postscan; ! 233: break; ! 234: ! 235: case '%': ! 236: w -> w_output |= W_SUBDISPLAY; ! 237: if (*++cp) ! 238: goto postscan; ! 239: break; ! 240: ! 241: case '-': ! 242: if (test_arg (cp, "-area", 4)) { ! 243: result = W_NULL; ! 244: ! 245: stuff_area: ; ! 246: if (w -> w_area != NULL) { ! 247: advise (NULLCP, "only one AREA specification allowed"); ! 248: goto you_really_lose; ! 249: } ! 250: if (*vec == NULL) { ! 251: advise (NULLCP, "expecting %s after \"%s\"", ! 252: result != W_NULL ? "NAME" : "HANDLE", cp); ! 253: goto you_really_lose; ! 254: } ! 255: if (*(dp = *vec) == '!') ! 256: result = W_NULL; ! 257: else { ! 258: for (; *dp; dp++) ! 259: if (!isdigit (*dp)) ! 260: break; ! 261: if (!*dp) ! 262: result = NULL; ! 263: } ! 264: w -> w_area = *vec++, w -> w_areatype = result; ! 265: break; ! 266: ! 267: } ! 268: if (test_arg (cp, "-expand", 4)) { ! 269: w -> w_output |= W_EXPAND; ! 270: break; ! 271: } ! 272: if (test_arg (cp, "-full", 4)) { ! 273: w -> w_output |= W_FULL; ! 274: break; ! 275: } ! 276: if (test_arg (cp, "-geography", 4)) { ! 277: if (*vec == NULL) { ! 278: advise (NULLCP, ! 279: "expecting location after \"-geography\""); ! 280: goto you_really_lose; ! 281: } ! 282: w -> w_geography = *vec++; ! 283: break; ! 284: } ! 285: if (test_arg (cp, "-help", 5)) ! 286: goto print_help; ! 287: if (test_arg (cp, "-locality", 4)) { ! 288: result = W_LOCALITY; ! 289: goto stuff_area; ! 290: } ! 291: if (test_arg (cp, "-organization", 4)) { ! 292: result = W_ORGANIZATION; ! 293: goto stuff_area; ! 294: } ! 295: if (test_arg (cp, "-summary", 4)) { ! 296: w -> w_output |= W_SUMMARY; ! 297: break; ! 298: } ! 299: if (test_arg (cp, "-subdisplay", 4)) { ! 300: w -> w_output |= W_SUBDISPLAY; ! 301: break; ! 302: } ! 303: if (test_arg (cp, "-title", 4)) { ! 304: if (*vec == NULL) { ! 305: advise (NULLCP, ! 306: "expecting something after \"-title\""); ! 307: goto you_really_lose; ! 308: } ! 309: w -> w_title = *vec++; ! 310: break; ! 311: } ! 312: if (test_arg (cp, "-unit", 4)) { ! 313: result = W_UNIT; ! 314: goto stuff_area; ! 315: } ! 316: ! 317: advise (NULLCP, "unknown switch: %s", cp); ! 318: you_really_lose: ; ! 319: if (mail) { ! 320: fprintf (stdfp, "\n\n"); ! 321: goto print_help; ! 322: } ! 323: return NOTOK; ! 324: ! 325: case 'd': ! 326: if (strcmp (cp, "dsa")) ! 327: goto name_or_something; ! 328: if (w -> w_record != W_NULL) ! 329: goto too_many_fields; ! 330: w -> w_record = W_DSA; ! 331: break; ! 332: ! 333: case 'e': ! 334: if (strcmp (cp, "expand")) ! 335: goto name_or_something; ! 336: w -> w_output |= W_EXPAND; ! 337: break; ! 338: ! 339: case 'f': ! 340: if (strcmp (cp, "full") == 0) { ! 341: w -> w_output |= W_FULL; ! 342: break; ! 343: } ! 344: if (strcmp (cp, "fullname") == 0) { ! 345: w -> w_nametype = W_COMMONAME; ! 346: goto name; ! 347: } ! 348: goto name_or_something; ! 349: ! 350: case 'h': ! 351: if (strcmp (cp, "handle")) ! 352: goto name_or_something; ! 353: if (w -> w_inputype != W_NULL) ! 354: goto too_many_fields; ! 355: if ((cp = *vec++) == NULL) { ! 356: advise (NULLCP, "expecting HANDLE after \"handle\""); ! 357: goto you_really_lose; ! 358: } ! 359: got_handle: ; ! 360: if (!mail && strcmp (cp, "me") == 0) { ! 361: if (mydn == NULL) { ! 362: advise (NULLCP, ! 363: "who are you? use the \"thisis\" command first..."); ! 364: return NOTOK; ! 365: } ! 366: cp = mydn; ! 367: } ! 368: w -> w_inputype = W_HANDLE; ! 369: w -> w_input = cp; ! 370: break; ! 371: ! 372: case 'l': ! 373: if (strcmp (cp, "locality")) ! 374: goto name_or_something; ! 375: if (w -> w_record != W_NULL) ! 376: goto too_many_fields; ! 377: w -> w_record = W_LOCALITY; ! 378: break; ! 379: ! 380: case 'm': ! 381: if (strcmp (cp, "mailbox")) ! 382: goto name_or_something; ! 383: if (w -> w_inputype != W_NULL) ! 384: goto too_many_fields; ! 385: if ((cp = *vec++) == NULL) { ! 386: advise (NULLCP, "expecting MAILBOX after \"mailbox\""); ! 387: goto you_really_lose; ! 388: } ! 389: w -> w_inputype = W_MAILBOX; ! 390: w -> w_input = cp; ! 391: break; ! 392: ! 393: case 'n': ! 394: if (strcmp (cp, "name")) ! 395: goto name_or_something; ! 396: name: ; ! 397: if (w -> w_inputype != W_NULL) ! 398: goto too_many_fields; ! 399: if ((cp = *vec++) == NULL) { ! 400: advise (NULLCP, "expecting NAME after \"%sname\"", ! 401: w -> w_nametype == W_COMMONAME ? "full" ! 402: : w -> w_nametype == W_SURNAME ? "sur" : ""); ! 403: goto you_really_lose; ! 404: } ! 405: w -> w_inputype = W_NAME; ! 406: w -> w_input = cp; ! 407: break; ! 408: ! 409: case 'o': ! 410: if (strcmp (cp, "organization") && strcmp (cp, "org")) ! 411: goto name_or_something; ! 412: if (w -> w_record != W_NULL) ! 413: goto too_many_fields; ! 414: w -> w_record = W_ORGANIZATION; ! 415: break; ! 416: ! 417: case 'p': ! 418: if (strcmp (cp, "person")) ! 419: goto name_or_something; ! 420: if (w -> w_record != W_NULL) ! 421: goto too_many_fields; ! 422: w -> w_record = W_PERSON; ! 423: break; ! 424: ! 425: case 'r': ! 426: if (strcmp (cp, "role")) ! 427: goto name_or_something; ! 428: if (w -> w_record != W_NULL) ! 429: goto too_many_fields; ! 430: w -> w_record = W_ROLE; ! 431: break; ! 432: ! 433: case 's': ! 434: if (strcmp (cp, "subdisplay") == 0) { ! 435: w -> w_output |= W_SUBDISPLAY; ! 436: break; ! 437: } ! 438: if (strcmp (cp, "summary") == 0) { ! 439: w -> w_output |= W_SUMMARY; ! 440: break; ! 441: } ! 442: if (strcmp (cp, "surname") == 0) { ! 443: w -> w_nametype = W_SURNAME; ! 444: goto name; ! 445: } ! 446: goto name_or_something; ! 447: ! 448: case 'u': ! 449: if (strcmp (cp, "unit")) ! 450: goto name_or_something; ! 451: if (w -> w_record != W_NULL) ! 452: goto too_many_fields; ! 453: w -> w_record = W_UNIT; ! 454: break; ! 455: ! 456: default: ! 457: name_or_something: ; ! 458: if (w -> w_inputype != W_NULL) ! 459: goto too_many_fields; ! 460: for (dp = cp; *dp; dp++) ! 461: if (!isdigit (*dp)) ! 462: break; ! 463: if (!*dp) ! 464: goto got_handle; ! 465: if ((dp = index (cp, '@')) == NULL) { ! 466: w -> w_inputype = W_NAME; ! 467: w -> w_input = cp; ! 468: break; ! 469: } ! 470: if (index (dp + 1, '@') || index (dp + 1, '=')) { ! 471: w -> w_inputype = W_HANDLE; ! 472: w -> w_input = cp; ! 473: break; ! 474: } ! 475: w -> w_inputype = W_MAILBOX; ! 476: w -> w_input = cp; ! 477: break; ! 478: } ! 479: } ! 480: ! 481: if (w -> w_nametype != W_NULL) ! 482: switch (w -> w_record) { ! 483: default: ! 484: advise (NULLCP, "record-type ignored with \"%sname\"", ! 485: w -> w_nametype == W_COMMONAME ? "full" : "sur"); ! 486: /* and fall... */ ! 487: ! 488: case W_NULL: ! 489: w -> w_record = W_PERSON; ! 490: /* and fall... */ ! 491: ! 492: case W_PERSON: ! 493: break; ! 494: } ! 495: ! 496: if (w -> w_input && strcmp (w -> w_input, "*") == 0) ! 497: w -> w_input = NULL, w -> w_inputype = W_NULL; ! 498: if (w -> w_title && strcmp (w -> w_title, "*") == 0) ! 499: w -> w_title = NULL; ! 500: if ((w -> w_input || w -> w_title) ! 501: && w -> w_area ! 502: && strcmp (w -> w_area, "*") == 0) ! 503: w -> w_area = NULL, w -> w_areatype = W_NULL; ! 504: ! 505: if (w -> w_title) { ! 506: if (w -> w_inputype == W_NULL) ! 507: w -> w_inputype = W_NAME; ! 508: if (w -> w_inputype != W_NAME) { ! 509: advise (NULLCP, "title specification ignored with %s", ! 510: w -> w_inputype == W_HANDLE ? "HANDLE" : "MAILBOX"); ! 511: w -> w_title = NULL; ! 512: } ! 513: else ! 514: if (w -> w_record == W_NULL) ! 515: w -> w_record = W_PERSON; ! 516: } ! 517: ! 518: if (w -> w_inputype == W_HANDLE && w -> w_geography) { ! 519: advise (NULLCP, "geography specification ignored with HANDLE"); ! 520: w -> w_geography = NULL; ! 521: } ! 522: if (w -> w_geography) ! 523: if (w -> w_area == NULL) { ! 524: w -> w_area = w -> w_geography, w -> w_areatype = W_LOCALITY; ! 525: w -> w_geography = NULL; ! 526: } ! 527: else ! 528: if (*w -> w_geography == '!') ! 529: w -> w_geography++; ! 530: ! 531: if (w -> w_inputype == W_HANDLE && w -> w_area) { ! 532: advise (NULLCP, "area specification ignored with HANDLE"); ! 533: w -> w_area = NULL, w -> w_areatype = W_NULL; ! 534: } ! 535: if (w -> w_area) ! 536: if (w -> w_inputype == W_NULL) { ! 537: if (*w -> w_area != '!') { ! 538: for (dp = w -> w_area; *dp; dp++) ! 539: if (!isdigit (*dp)) ! 540: break; ! 541: w -> w_inputype = *dp ? W_NAME : W_HANDLE, ! 542: w -> w_input = w -> w_area; ! 543: } ! 544: else ! 545: w -> w_inputype = W_HANDLE, w -> w_input = w -> w_area + 1; ! 546: w -> w_record = w -> w_areatype; ! 547: w -> w_area = NULL, w -> w_areatype = W_NULL; ! 548: } ! 549: else ! 550: if (*w -> w_area == '!') ! 551: w -> w_area++; ! 552: ! 553: if (w -> w_inputype == W_NULL) { ! 554: register char **ap; ! 555: ! 556: if (w -> w_record != W_NULL || w -> w_output != W_NULL) { ! 557: advise (NULLCP, "input-field missing"); ! 558: return NOTOK; ! 559: } ! 560: ! 561: print_help: ; ! 562: for (ap = whois_help; *ap; ap++) ! 563: fprintf (stdfp, "%s%s", *ap, EOLN); ! 564: ! 565: return OK; ! 566: } ! 567: else ! 568: if (w -> w_inputype == W_NAME && w -> w_nametype == W_NULL) ! 569: w -> w_nametype = nametype ? W_SURNAME : W_COMMONAME; ! 570: ! 571: (void) sprintf (fredseq, "fred%d", seqno++); ! 572: ! 573: bp = buffer; ! 574: ! 575: if (w -> w_areatype == W_NULL) { ! 576: if (w -> w_inputype == W_MAILBOX ! 577: && w -> w_area == NULL ! 578: && (cp = index (w -> w_input, '@')) ! 579: && !index (++cp, '*')) { ! 580: (void) sprintf (bp, "fred -dm2dn %s", cp); ! 581: bp += strlen (bp); ! 582: ! 583: goto multiple_searching; ! 584: } ! 585: ! 586: result = whois_aux (w); ! 587: if (ifd == NOTOK) ! 588: return result; ! 589: goto check_wp; ! 590: } ! 591: ! 592: (void) sprintf (bp, ! 593: "search %s -norelative -singlelevel -dontdereference -sequence default -types aliasedObjectName -value -nosearchalias ", ! 594: limits (-1)); ! 595: bp += strlen (bp); ! 596: ! 597: for (ag = areas; ag -> ag_record; ag++) ! 598: if (ag -> ag_record == w -> w_areatype) ! 599: break; ! 600: if (w -> w_geography) { ! 601: (void) sprintf (bp, "\"%s\" ", w -> w_geography); ! 602: bp += strlen (bp); ! 603: ! 604: w -> w_geography = NULL; ! 605: } ! 606: else ! 607: if (ag -> ag_area) { ! 608: (void) sprintf (bp, "\"%s\" ", ag -> ag_area); ! 609: bp += strlen (bp); ! 610: } ! 611: ! 612: (void) sprintf (bp, "-filter \"objectClass=%s & %s%s\"", ! 613: ag -> ag_class, ag -> ag_rdn, eqstr (w -> w_area, 0)); ! 614: bp += strlen (bp); ! 615: ! 616: multiple_searching: ; ! 617: if ((fp = capture (buffer)) == NULL) ! 618: return NOTOK; ! 619: ! 620: if (interrupted) { ! 621: you_lose: ; ! 622: (void) fclose (fp); ! 623: return NOTOK; ! 624: } ! 625: ! 626: w -> w_area = orgname, w -> w_areatype = W_NULL; ! 627: ! 628: multiple = 0; ! 629: while (fgets (buffer, sizeof buffer, fp) && !interrupted) { ! 630: if ((cp = index (buffer, '\n')) == NULL) { ! 631: advise (NULLCP, "internal error(1)"); ! 632: goto you_lose; ! 633: } ! 634: *cp = NULL; ! 635: ! 636: if (!isdigit (*buffer)) { ! 637: fprintf (stderr, "%s\n", buffer); ! 638: continue; ! 639: } ! 640: ! 641: if ((cp = index (buffer, ' ')) == NULL) { ! 642: advise (NULLCP, "internal error(2)"); ! 643: goto you_lose; ! 644: } ! 645: *cp++ = NULL; ! 646: while (*cp == ' ') ! 647: cp++; ! 648: ! 649: if (multiple == 0 && (c = getc (fp)) != EOF) { ! 650: (void) ungetc (c, fp); ! 651: multiple = 1; ! 652: } ! 653: ! 654: if (multiple && query && !network) ! 655: switch (ask ("try %s", cp)) { ! 656: case NOTOK: ! 657: continue; ! 658: ! 659: case OK: ! 660: default: ! 661: break; ! 662: ! 663: case DONE: ! 664: goto out; ! 665: } ! 666: else ! 667: if (verbose) { ! 668: fprintf (stdfp, "Trying @%s ...\n", cp); ! 669: (void) fflush (stdfp); ! 670: } ! 671: ! 672: (void) sprintf (orgname, "@%s", cp); ! 673: (void) whois_aux (w); ! 674: ! 675: fprintf (stdfp, EOLN); ! 676: (void) fflush (stdfp); ! 677: } ! 678: ! 679: out: ; ! 680: (void) fclose (fp); ! 681: ! 682: if (ifd == NOTOK) ! 683: return OK; ! 684: ! 685: check_wp: ; ! 686: (void) sprintf (buffer, "squid -sequence %s", fredseq); ! 687: ! 688: if ((fp = capture (buffer)) == NULL) ! 689: return NOTOK; ! 690: ! 691: didany = 0; ! 692: while (fgets (buffer, sizeof buffer, fp)) { ! 693: char disher[BUFSIZ]; ! 694: ! 695: if ((cp = index (buffer, '\n')) == NULL) { ! 696: advise (NULLCP, "internal error(3)"); ! 697: goto you_lose; ! 698: } ! 699: *cp = NULL; ! 700: ! 701: if (strncmp (buffer, "Sequence ", sizeof "Sequence " - 1) == 0) ! 702: continue; ! 703: ! 704: if ((cp = index (buffer, ' ')) == NULL) { ! 705: advise (NULLCP, "internal error(4)"); ! 706: goto you_lose; ! 707: } ! 708: *cp++ = NULL; ! 709: while (*cp == ' ') ! 710: cp++; ! 711: ! 712: if (!didany++) { ! 713: fprintf (stdfp, "-------\n\n"); ! 714: ! 715: if ((c = getc (fp)) != EOF) { ! 716: (void) ungetc (c, fp); ! 717: fprintf (stdfp, "Select one of:\n\n"); ! 718: } ! 719: else ! 720: fprintf (stdfp, "One entry matched:\n\n"); ! 721: ! 722: (void) strcpy (onehit, buffer); ! 723: } ! 724: ! 725: (void) sprintf (disher, ! 726: "showentry \"%s\" -fred -dontdereference -summary", ! 727: cp); ! 728: dontpage = 1; ! 729: (void) dish (disher, 0); ! 730: dontpage = 0; ! 731: ! 732: fprintf (stdfp, " %s\n\n", cp); ! 733: (void) fflush (stdfp); ! 734: } ! 735: (void) fclose (fp); ! 736: ! 737: if (!didany) { ! 738: fprintf (stdfp, ! 739: "\nenter new \"whois\" command to continue searching (or \"quit\" to abort)\n"); ! 740: return OK; ! 741: } ! 742: ! 743: if (didany == 1) { ! 744: if (getline ("enter RETURN to use this entry (or \"no\" to look some more): ", ! 745: buffer) == NOTOK ! 746: || (str2vec (buffer, args) > 0 && *args[0] != 'y')) ! 747: return OK; ! 748: args[0] = onehit; ! 749: } ! 750: else ! 751: if (getline ("enter number (or RETURN to look some more): ", buffer) ! 752: == NOTOK ! 753: || str2vec (buffer, args) < 1) ! 754: return OK; ! 755: ! 756: if (sscanf (args[0], "%d", &result) != 1) { ! 757: advise (NULLCP, "invalid number \"%s\"", args[0]); ! 758: return OK; ! 759: } ! 760: ! 761: (void) sprintf (buffer, "show -sequence %s %d -types rfc822Mailbox -value", ! 762: fredseq, result); ! 763: ! 764: if ((fp = capture (buffer)) == NULL) ! 765: return NOTOK; ! 766: ! 767: if (fgets (buffer, sizeof buffer, fp) == NULL ! 768: || (cp = index (buffer, '\n')) == NULL) { ! 769: advise (NULLCP, "internal error(5)"); ! 770: goto you_lose; ! 771: } ! 772: (void) fclose (fp); ! 773: ! 774: if (strncmp (buffer, "Invalid sequence number", ! 775: sizeof "Invalid sequence number" - 1) == 0) { ! 776: advise (NULLCP, "invalid selection \"%d\"", result); ! 777: return OK; ! 778: } ! 779: if (strncmp (buffer, "No attributes", sizeof "No attributes" - 1) == 0) { ! 780: advise (NULLCP, "no rfc822Mailbox attribute for this entry!"); ! 781: return OK; ! 782: } ! 783: if (strncmp (buffer, "rfc822Mailbox", sizeof "rfc822Mailbox" - 1) == 0) { ! 784: if ((cp = index (buffer, '-')) == NULL) { ! 785: advise (NULLCP, "internal error(6)"); ! 786: return NOTOK; ! 787: } ! 788: for (cp++; isspace (*cp); cp++) ! 789: continue; ! 790: if (verbose) ! 791: fprintf (stdfp, "using %s\n", cp); ! 792: result = strlen (cp); ! 793: ! 794: if (write (ofd, cp, result) != result) ! 795: adios ("failed", "write to UA"); ! 796: ! 797: istat = signal (SIGINT, SIG_IGN); ! 798: qstat = signal (SIGQUIT, SIG_IGN); ! 799: ! 800: if (watch) { ! 801: fprintf (stderr, "---> %s", cp); ! 802: (void) fflush (stderr); ! 803: } ! 804: ! 805: usetty = 0; ! 806: ! 807: return OK; ! 808: } ! 809: ! 810: advise (NULLCP, "internal error(7): \"%s\"", buffer); ! 811: return NOTOK; ! 812: } ! 813: ! 814: /* */ ! 815: ! 816: static whois_aux (w) ! 817: register struct whois *w; ! 818: { ! 819: register char *bp, ! 820: *cp; ! 821: char *handle, ! 822: buffer[BUFSIZ]; ! 823: register struct area_guide *ag; ! 824: ! 825: for (ag = areas; ag -> ag_record; ag++) ! 826: if (ag -> ag_record == w -> w_record) ! 827: break; ! 828: ! 829: bp = buffer; ! 830: switch (w -> w_inputype) { ! 831: case W_NULL: ! 832: default: ! 833: advise (NULLCP, "internal error(8)"); ! 834: return NOTOK; ! 835: ! 836: case W_HANDLE: ! 837: (void) sprintf (bp, "showentry \"%s\" %s -fred -dontdereference", ! 838: w -> w_input, limits (0)); ! 839: bp += strlen (bp); ! 840: goto options; ! 841: ! 842: case W_MAILBOX: ! 843: (void) sprintf (bp, "search %s -fred ", limits (1)); ! 844: bp += strlen (bp); ! 845: ! 846: if (w -> w_area) { ! 847: (void) sprintf (bp, "\"%s\" ", w -> w_area); ! 848: bp += strlen (bp); ! 849: } ! 850: ! 851: (void) sprintf (bp, "-subtree -filter \""); ! 852: bp += strlen (bp); ! 853: ! 854: cp = w -> w_input; ! 855: if (*cp == '@') ! 856: (void) sprintf (bp, "mail=*%s", cp); ! 857: else ! 858: if (*(cp + strlen (cp) - 1) == '@' || !index (cp, '@')) ! 859: (void) sprintf (bp, "mail=%s*", cp); ! 860: else ! 861: (void) sprintf (bp, "(mail=%s | otherMailbox=internet$%s)", ! 862: cp, cp); ! 863: bp += strlen (bp); ! 864: break; ! 865: ! 866: case W_NAME: ! 867: if (cp = w -> w_input) { ! 868: cp += strlen (cp) - 1; ! 869: if (*cp == '.') ! 870: *cp = '*'; ! 871: } ! 872: ! 873: (void) sprintf (bp, "search %s -%s ", limits (1), ! 874: kflag ? "show" : "fred"); ! 875: bp += strlen (bp); ! 876: ! 877: if (w -> w_area) { ! 878: (void) sprintf (bp, "\"%s\" -subtree ", w -> w_area); ! 879: bp += strlen (bp); ! 880: } ! 881: else ! 882: if (w -> w_geography) { ! 883: (void) sprintf (bp, "\"%s\" ", w -> w_geography); ! 884: bp += strlen (bp); ! 885: } ! 886: else ! 887: if (ag -> ag_area) { ! 888: (void) sprintf (bp, "\"%s\" %s ", ag -> ag_area, ! 889: ag -> ag_search); ! 890: bp += strlen (bp); ! 891: } ! 892: else { ! 893: (void) sprintf (bp, "-subtree "); ! 894: bp += strlen (bp); ! 895: } ! 896: (void) sprintf (bp, "-filter \""); ! 897: bp += strlen (bp); ! 898: ! 899: handle = eqstr (w -> w_input, 0); ! 900: switch (w -> w_record) { ! 901: case W_NULL: ! 902: case W_PERSON: ! 903: if (handle) { ! 904: if (w -> w_title ! 905: && (w -> w_record == W_NULL ! 906: || w -> w_nametype == W_SURNAME)) { ! 907: (void) sprintf (bp, "( "); ! 908: bp += strlen (bp); ! 909: } ! 910: if (w -> w_record == W_NULL) { ! 911: (void) sprintf (bp, "o%s | ou%s | l%s | ", ! 912: handle, handle, handle, handle); ! 913: bp += strlen (bp); ! 914: } ! 915: ! 916: if (w -> w_nametype == W_SURNAME) { ! 917: if (w -> w_record == W_PERSON && !w -> w_title) { ! 918: (void) sprintf (bp, "( "); ! 919: bp += strlen (bp); ! 920: } ! 921: (void) sprintf (bp, "surname%s | mail=%s@* ", ! 922: eqstr (w -> w_input, 1), ! 923: w -> w_input); ! 924: bp += strlen (bp); ! 925: if (w -> w_record == W_PERSON && !w -> w_title) { ! 926: (void) sprintf (bp, ") "); ! 927: bp += strlen (bp); ! 928: } ! 929: } ! 930: else { ! 931: (void) sprintf (bp, "cn%s ", handle); ! 932: bp += strlen (bp); ! 933: } ! 934: ! 935: if (w -> w_title ! 936: && (w -> w_record == W_NULL ! 937: || w -> w_nametype == W_SURNAME)) { ! 938: (void) sprintf (bp, ") "); ! 939: bp += strlen (bp); ! 940: } ! 941: } ! 942: if (w -> w_title) { ! 943: (void) sprintf (bp, "%stitle%s", ! 944: handle ? "& " : "", ! 945: eqstr (w -> w_title, 1)); ! 946: bp += strlen (bp); ! 947: } ! 948: break; ! 949: ! 950: default: ! 951: if (strcmp (handle, "=*")) { ! 952: (void) sprintf (bp, "%s%s", ag -> ag_rdn, handle); ! 953: bp += strlen (bp); ! 954: } ! 955: break; ! 956: } ! 957: break; ! 958: } ! 959: ! 960: if (w -> w_record == W_PERSON ! 961: || (w -> w_record != W_NULL && strcmp (handle, "=*"))) { ! 962: (void) sprintf (bp, " & "); ! 963: bp += strlen (bp); ! 964: } ! 965: ! 966: if (w -> w_record != W_NULL) { ! 967: (void) sprintf (bp, "objectClass=%s", ag -> ag_class); ! 968: bp += strlen (bp); ! 969: } ! 970: ! 971: (void) sprintf (bp, "\""); ! 972: bp += strlen (bp); ! 973: ! 974: options: ; ! 975: if (w -> w_output & W_EXPAND) { ! 976: (void) sprintf (bp, " -expand"); ! 977: bp += strlen (bp); ! 978: } ! 979: if (w -> w_output & W_FULL) { ! 980: (void) sprintf (bp, " -full"); ! 981: bp += strlen (bp); ! 982: } ! 983: if (w -> w_output & W_SUMMARY) { ! 984: (void) sprintf (bp, " -summary"); ! 985: bp += strlen (bp); ! 986: } ! 987: if (w -> w_output & W_SUBDISPLAY) { ! 988: (void) sprintf (bp, " -subdisplay"); ! 989: bp += strlen (bp); ! 990: } ! 991: ! 992: (void) sprintf (bp, " -sequence %s", ifd != NOTOK ? fredseq : "default"); ! 993: bp += strlen (bp); ! 994: ! 995: return dish (buffer, 0); ! 996: } ! 997: ! 998: /* */ ! 999: ! 1000: static int test_arg (user, full, minlen) ! 1001: char *user, ! 1002: *full; ! 1003: int minlen; ! 1004: { ! 1005: int i; ! 1006: ! 1007: if ((i = strlen (user)) < minlen ! 1008: || i > strlen (full) ! 1009: || strncmp (user, full, i)) ! 1010: return 0; ! 1011: ! 1012: return 1; ! 1013: } ! 1014: ! 1015: /* */ ! 1016: ! 1017: static char *eqstr (s, exact) ! 1018: char *s; ! 1019: int exact; ! 1020: { ! 1021: static char buffer[BUFSIZ]; ! 1022: ! 1023: if (s == NULL) ! 1024: return NULL; ! 1025: ! 1026: if (index (s, '*')) ! 1027: (void) sprintf (buffer, "=%s", s); ! 1028: else ! 1029: if (soundex) ! 1030: (void) sprintf (buffer, "~=%s", s); ! 1031: else ! 1032: if (exact) ! 1033: (void) sprintf (buffer, "=%s", s); ! 1034: else ! 1035: (void) sprintf (buffer, "=*%s*", s); ! 1036: ! 1037: return buffer; ! 1038: } ! 1039: ! 1040: /* */ ! 1041: ! 1042: static char *limits (isearch) ! 1043: int isearch; ! 1044: { ! 1045: register char *bp; ! 1046: static char buffer[100]; ! 1047: ! 1048: bp = buffer; ! 1049: ! 1050: if (phone) { ! 1051: (void) strcpy (bp, "-phone "); ! 1052: bp += strlen (bp); ! 1053: } ! 1054: ! 1055: #ifdef notdef /* don't do this! */ ! 1056: if (isearch) { ! 1057: (void) strcpy (bp, "-searchalias "); ! 1058: bp += strlen (bp); ! 1059: } ! 1060: #endif ! 1061: ! 1062: (void) strcpy (bp, "-nosizelimit "); ! 1063: bp += strlen (bp); ! 1064: ! 1065: if (timelimit > 0) ! 1066: (void) sprintf (bp, "-timelimit %d", timelimit); ! 1067: else ! 1068: (void) strcpy (bp, "-notimelimit"); ! 1069: bp += strlen (bp); ! 1070: ! 1071: if (isearch >= 0 && (network || oneshot)) { ! 1072: (void) strcpy (bp, " -nofredseq"); ! 1073: bp += strlen (bp); ! 1074: } ! 1075: ! 1076: return buffer; ! 1077: } ! 1078: ! 1079: /* */ ! 1080: ! 1081: static FILE *capture (command) ! 1082: char *command; ! 1083: { ! 1084: int savnet, ! 1085: savpage; ! 1086: char tmpfil[BUFSIZ]; ! 1087: FILE *fp, ! 1088: *savfp; ! 1089: ! 1090: (void) sprintf (tmpfil, "/tmp/fredXXXXXX"); ! 1091: (void) unlink (mktemp (tmpfil)); ! 1092: ! 1093: if ((fp = fopen (tmpfil, "w+")) == NULL) { ! 1094: advise (tmpfil, "unable to create"); ! 1095: return NULL; ! 1096: } ! 1097: (void) unlink (tmpfil); ! 1098: ! 1099: savfp = stdfp, stdfp = fp; ! 1100: savnet = network, network = 0; ! 1101: savpage = dontpage, dontpage = 1; ! 1102: ! 1103: (void) dish (command, 0); ! 1104: ! 1105: dontpage = savpage; ! 1106: network = savnet; ! 1107: stdfp = savfp; ! 1108: ! 1109: rewind (fp); ! 1110: ! 1111: return fp; ! 1112: } ! 1113: ! 1114: /* */ ! 1115: ! 1116: static int f_ufn (vec) ! 1117: char **vec; ! 1118: { ! 1119: register char *dp; ! 1120: char *cp, ! 1121: buffer[BUFSIZ]; ! 1122: static int lastq = -1; ! 1123: ! 1124: if ((cp = vec[0]) == NULL || strcmp (cp, "-help") == 0) { ! 1125: help: ; ! 1126: fprintf (stdfp, "whois name...\n"); ! 1127: fprintf (stdfp, " find something in the white pages\n"); ! 1128: ! 1129: return OK; ! 1130: } ! 1131: ! 1132: if (*(dp = cp) == '!') ! 1133: dp++; ! 1134: for (; *dp; dp++) ! 1135: if (!isdigit (*dp)) ! 1136: break; ! 1137: if (!*dp || *dp == '-') { /* a handle, or oldstyle */ ! 1138: oldstyle: ; ! 1139: (void) strcpy (buffer, cp); ! 1140: (void) str2vec (buffer, vec); ! 1141: return f_whois_aux (vec); ! 1142: } ! 1143: ! 1144: if (!index (dp = cp, ',')) ! 1145: while (dp = index (dp, ' ')) ! 1146: if (*++dp == '-') ! 1147: goto oldstyle; ! 1148: ! 1149: (void) sprintf (buffer, "fred -ufn %s", cp); ! 1150: ! 1151: if (lastq != area_quantum) { ! 1152: FILE *fp; ! 1153: ! 1154: if (fp = fopen (ufn_file, "w")) { ! 1155: register struct area_guide *ag; ! 1156: ! 1157: for (ag = areas; ag -> ag_record; ag++) ! 1158: if (ag -> ag_record == W_ORGANIZATION) ! 1159: break; ! 1160: ! 1161: fprintf (fp, "1:\t%s\n", myarea + 1); ! 1162: if (ag -> ag_record) ! 1163: fprintf (fp, "\t%s\n", ag -> ag_area + 1); ! 1164: fprintf (fp, "\t-\n"); ! 1165: ! 1166: fprintf (fp, "2:"); ! 1167: if (ag -> ag_record) ! 1168: fprintf (fp, "\t%s\n", ag -> ag_area + 1); ! 1169: fprintf (fp, "\t%s\n", myarea + 1); ! 1170: fprintf (fp, "\t-\n"); ! 1171: ! 1172: fprintf (fp, "3,+:\t-\n"); ! 1173: if (ag -> ag_record) ! 1174: fprintf (fp, "\t%s\n", ag -> ag_area + 1); ! 1175: fprintf (fp, "\t%s\n", myarea + 1); ! 1176: ! 1177: (void) fclose (fp); ! 1178: ! 1179: lastq = area_quantum; ! 1180: } ! 1181: } ! 1182: ! 1183: return dish (buffer, 0); ! 1184: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.