1: #include <stdio.h>
   2: #include <sys/types.h>
   3: #include <netns/ns.h>
   4: #include "Clearinghouse2_defs.h"
   5: #include <xnscourier/except.h>
   6: 
   7: 
   8: #define MAXPACKS 5
   9: 
  10: static
  11: ProcessObjectName(obj)
  12:     ObjectName obj;
  13: {
  14:     printf("\t%s:%s:%s\n", obj.object, obj.domain, obj.organization);
  15: }
  16: 
  17: static
  18: GetData(conn)
  19:     CourierConnection *conn;
  20: {
  21:     int count, i;
  22:     Unspecified buffer[MAXWORDS*MAXPACKS], *bp, *bufend;
  23:     StreamOfObjectName obnames;
  24: 
  25:     bufend = buffer;
  26:     bp = buffer+((MAXWORDS-1)*MAXPACKS);    /* end of available space */
  27:     while (count = BDTread(conn, (char*)bufend,
  28:                 MAXWORDS*sizeof(Unspecified))
  29:         ) {
  30:         bufend += count/sizeof(Unspecified);
  31:         if (bufend > bp) {
  32:             fprintf(stderr,"BDT read too big to fit\n");
  33:             BDTabort(conn);
  34:             /* should clear out stuff here if we knew how much */
  35:         }
  36:     }
  37:     bp = buffer;
  38:     while (bp < bufend) {
  39:         bp += internalize_StreamOfObjectName(&obnames,bp);
  40:         if (0 == (int) obnames.designator)
  41:            for (i = 0; i < obnames.nextSegment_case.segment.length; i++)
  42:             ProcessObjectName(
  43:                 obnames.nextSegment_case.segment.sequence[i]);
  44:         else {
  45:            for (i = 0; i < obnames.lastSegment_case.length; i++)
  46:             ProcessObjectName(
  47:                 obnames.lastSegment_case.sequence[i]);
  48:            return;
  49:         }
  50:     }
  51: }
  52: 
  53: main(argc, argv)
  54:     int argc;
  55:     char *argv[];
  56: {
  57:     ListAliasesOfResults result;
  58:     CourierConnection *conn;
  59:     extern CourierConnection *CH_GetFirstCH();
  60:     extern ObjectName CH_StringToName();
  61:     ObjectNamePattern name;
  62:     extern char *getpass();
  63:     Authenticator agent;
  64:     static ObjectName defaults = {"Cornell-Univ","Computer Science",""};
  65: 
  66:     if (argc != 2) {
  67:         fprintf(stderr,"Usage: %s alias\n",argv[0]);
  68:         exit(1);
  69:     }
  70:     if ((conn = CH_GetFirstCH()) == NULL) {
  71:         fprintf(stderr,"Can't open connection to %s\n",argv[1]);
  72:         exit(1);
  73:     }
  74:     name.object = argv[1];
  75:     name = CH_StringToName(argv[1],&defaults);
  76:     /* use a null credentials&verifier */
  77:     MakeSimpleCredsAndVerifier(&defaults, "",
  78:         &agent.credentials, &agent.verifier );
  79:     printf("Aliases:\n");
  80: 
  81:     DURING
  82:         result = ListAliasesOf(conn, GetData, name,
  83:             BulkData1_immediateSink, agent);
  84:     HANDLER {
  85:         switch (Exception.Code) {
  86:         case CallError:
  87:             fprintf(stderr,"Call error, %d\n",
  88:                 CourierErrArgs(CallErrorArgs,problem));
  89:             break;
  90:         case ArgumentError:
  91:             switch (CourierErrArgs(ArgumentErrorArgs,problem)) {
  92:             case illegalOrganizationName:
  93:             case illegalDomainName:
  94:             case illegalObjectName:
  95:                 fprintf(stderr,
  96:                     "%s:%s:%s has bad format\n",
  97:                     name.object, name.domain,
  98:                     name.organization);
  99:                 break;
 100:             case noSuchOrganization:
 101:                 fprintf(stderr,
 102:                     "%s does not exist\n",
 103:                     name.organization);
 104:                 break;
 105:             case noSuchDomain:
 106:                 fprintf(stderr,
 107:                     "%s:%s does not exist\n",
 108:                     name.domain,
 109:                     name.organization);
 110:                 break;
 111:             case noSuchObject:
 112:                 fprintf(stderr,"No such object as %s:%s:%s\n",
 113:                     name.object, name.domain,
 114:                     name.organization);
 115:                 break;
 116:             default:
 117:                 fprintf(stderr,"Argument error (%d,%d)\n",
 118:                     CourierErrArgs(ArgumentErrorArgs,problem),
 119:                     CourierErrArgs(ArgumentErrorArgs,which) );
 120:                 break;
 121:             }
 122:             break;
 123:         case AuthenticationError:
 124:             fprintf(stderr,"Authentication error, %d\n",
 125:                 CourierErrArgs(AuthenticationErrorArgs,problem)
 126:                 );
 127:             break;
 128:         case WrongServer:
 129:             fprintf(stderr,"Wrong server.  Try %s:%s:%s\n",
 130:                 CourierErrArgs(WrongServerArgs,hint.object),
 131:                 CourierErrArgs(WrongServerArgs,hint.domain),
 132:                 CourierErrArgs(WrongServerArgs,hint.organization)
 133:                 );
 134:             break;
 135:         case PropertyError:
 136:             fprintf(stderr,"Property error %d in %s:%s:%s\n",
 137:                 CourierErrArgs(PropertyErrorArgs,problem),
 138:                 CourierErrArgs(PropertyErrorArgs,distinguishedObject.object),
 139:                 CourierErrArgs(PropertyErrorArgs,distinguishedObject.domain),
 140:                 CourierErrArgs(PropertyErrorArgs,distinguishedObject.organization)
 141:                 );
 142:             break;
 143:         default:
 144:             fprintf(stderr,"Some random error, code %d\n",
 145:                 Exception.Code);
 146:             break;
 147:         }
 148:     exit(1);
 149:     } END_HANDLER;
 150: 
 151:     printf("Distinguished name:\n\t%s:%s:%s\n",
 152:         result.distinguishedObject.object,
 153:         result.distinguishedObject.domain,
 154:         result.distinguishedObject.organization );
 155: }

Defined functions

GetData defined in line 17; used 1 times
  • in line 82
ProcessObjectName defined in line 10; used 2 times
main defined in line 53; never used

Defined macros

MAXPACKS defined in line 8; used 2 times
Last modified: 1986-03-13
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1107
Valid CSS Valid XHTML 1.0 Strict