1: /* $Header: registerhost.c,v 2.0a 85/11/21 07:22:36 jqj,sklower Exp $ */
   2: 
   3: /*
   4:  * This program enters a Unix host into the Clearinghouse as a server and
   5:  * workstation, hence eligible for gap telnet
   6:  */
   7: /*
   8:  * $Log:	registerhost.c,v $
   9:  * Revision 2.0  85/11/21  07:22:36  jqj
  10:  * 4.3BSD standard release
  11:  *
  12:  * Revision 1.1  85/11/20  13:54:08  jqj
  13:  * Initial revision
  14:  *
  15:  */
  16: 
  17: #include <stdio.h>
  18: #include <sys/types.h>
  19: #include <netns/ns.h>
  20: #include "Clearinghouse2_defs.h"
  21: #include <xnscourier/CHEntries.h>
  22: #include <xnscourier/CH.h>
  23: #include <xnscourier/except.h>
  24: 
  25: 
  26: 
  27: char *
  28: ItemToString(item)
  29:     Item item;
  30: {
  31:     char *strval;
  32: 
  33:     Unspecified buf[501], *bp;
  34:     Cardinal len;
  35: 
  36:     externalize_Item(&item, buf);
  37:     bp = buf;
  38:     bp += internalize_Cardinal(&len, bp);
  39:     bp += internalize_String(&strval, bp);
  40:     return(strval);
  41: }
  42: 
  43: Item
  44: StringToItem(strval)
  45:     String strval;
  46: {
  47:     Unspecified buf[501], *bp;
  48:     Item item;
  49:     Cardinal len;
  50: 
  51:     bp = buf + sizeof_Cardinal(len);
  52:     len = externalize_String(&strval, bp);
  53:     (void) externalize_Cardinal(&len, buf);
  54:     internalize_Item(&item, buf);
  55:     return(item);
  56: }
  57: 
  58: Item
  59: addrToItem(addr)
  60:     struct ns_addr *addr;
  61: {
  62:     Unspecified buf[501], *bp;
  63:     Item item;
  64:     Cardinal len;
  65:     NetworkAddressList nalist;
  66:     NetworkAddress naddr;
  67: 
  68:     nalist.length = 1;
  69:     nalist.sequence = &naddr;
  70:     naddr.network[0] = htons(addr->x_net.s_net[0]);
  71:     naddr.network[1] = htons(addr->x_net.s_net[1]);
  72:     naddr.host[0] = htons(addr->x_host.s_host[0]);
  73:     naddr.host[1] = htons(addr->x_host.s_host[1]);
  74:     naddr.host[2] = htons(addr->x_host.s_host[2]);
  75:     naddr.socket = 0;
  76: 
  77:     bp = buf + sizeof_Cardinal(len);
  78:     len = externalize_NetworkAddressList(&nalist, bp);
  79:     (void) externalize_Cardinal(&len, buf);
  80:     internalize_Item(&item, buf);
  81:     return(item);
  82: }
  83: 
  84: int
  85: isprop(prop, proplist)
  86:     Property prop;
  87:     Properties proplist;
  88: {
  89:     int i;
  90: 
  91:     prop = prop<<16;    /* correct for bug in Clearinghouse v 2 */
  92:     for (i=0; i < proplist.length; i++) {
  93:         if (proplist.sequence[i] == prop) return(1);
  94:     }
  95:     return(0);      /* not found */
  96: }
  97: 
  98: char *
  99: XNSaddrToString(addr)
 100:     struct ns_addr *addr;
 101: {
 102:     u_char *s;
 103:     static char buf[21];
 104: 
 105:     s = addr->x_host.c_host;
 106:     sprintf(buf,"%lx#%x.%x.%x.%x.%x.%x#%x",
 107:         ntohl(ns_netof(*addr)),
 108:         s[0], s[1], s[2], s[3], s[4], s[5],
 109:         ntohs(addr->x_port));
 110:     return(buf);
 111: }
 112: 
 113: 
 114: main(argc, argv)
 115:     int argc;
 116:     char *argv[];
 117: {
 118:     ObjectName myname, name, defname;
 119:     struct ns_addr *destaddr, *getXNSaddr(), *myaddr;
 120:     struct sockaddr_ns sns;
 121:     Authenticator agent;
 122:     CourierConnection *conn;
 123:     int i;
 124:     ListPropertiesResults LPresult;
 125:     RetrieveItemResults RIresult;
 126:     ChangeItemResults CIresult;
 127:     AddItemPropertyResults AIPresult;
 128:     char *pwd, *propval, *getXNSpass(), *malloc(), *gets(),
 129:         mystrname[200], addrstr[200], *myhostname;
 130:     String ItemToString();
 131:     Item item, StringToItem(), addrToItem();
 132:     Property propnum;
 133:     struct ns_addr *addr;
 134:     static Boolean authseq[2] = {1, 0}; /* simple, not strong */
 135: 
 136:     if (argc < 1 || argc >4) {
 137:         fprintf(stderr,"Usage: %s [hostname]\n",argv[0]);
 138:         exit(1);
 139:     }
 140:     CH_NameDefault(&defname);
 141:     if (argc == 1) {
 142:         gethostname(myhostname=malloc(100), 100);
 143:       name = CH_StringToName(myhostname, &defname);
 144:     } else
 145:       name = CH_StringToName(argv[1], &defname);
 146:     if (argc > 2)
 147:         name.domain = argv[2];
 148:     if (argc > 3)
 149:         name.organization = argv[3];
 150:     printf("Registering host %s:%s:%s\n",
 151:            name.object,name.domain,name.organization);
 152:     printf("XNS UserName: ");
 153:     gets(mystrname);
 154:     myname = CH_StringToName(mystrname, &name);
 155:     pwd = getXNSpass("Password:");
 156:     MakeSimpleCredsAndVerifier(&myname,pwd,
 157:             &agent.credentials, &agent.verifier);
 158:     conn = CH_GetFirstCH();
 159:     i = sizeof(sns); myaddr = &sns.sns_addr;
 160:     getsockname(*(int *)conn, &sns, &i); myaddr->x_port = 0;
 161:     DURING {
 162:         LPresult = ListProperties(conn,NULL,name,agent);
 163:     } HANDLER {
 164:         if (Exception.Code == ArgumentError) {
 165:           DURING CreateObject(conn,NULL,name,agent);
 166:           HANDLER {
 167:             fprintf(stderr,"Can't create object. Error %d\n",
 168:                 Exception.Code);
 169:             exit(1);
 170:           } END_HANDLER;
 171:           LPresult.properties.length = 0;
 172:         }
 173:         else {
 174:           fprintf(stderr,"ListProperties failed.  Error %d\n",
 175:             Exception.Code);
 176:           exit(1);
 177:         }
 178:     } END_HANDLER;
 179:     /* AddressList property */
 180:     if (isprop(4,LPresult.properties)) {
 181:         addr = CH_LookupAddr(name,4);
 182:         if (addr==0) {
 183:             fprintf(stderr,"NetworkAddress is in property list, but CH_LookupAddr failed\n");
 184:             exit(1);
 185:         }
 186:         printf("Old address: %s\n",XNSaddrToString(addr));
 187:         printf("New address: ");
 188:         gets(addrstr);
 189:         if (*addrstr==0 && addr->x_port!=0) {
 190:             printf("Warning:  port should be 0 for gaptelnet\n");
 191:             printf("New address: ");
 192:             gets(addrstr);
 193:         }
 194:         if (*addrstr!=0) {
 195:             addr = getXNSaddr(addrstr);
 196:         } else
 197:             addr = myaddr;
 198:         item = addrToItem(addr);
 199:         DURING CIresult = ChangeItem(conn,NULL, name,4,item,agent);
 200:         HANDLER {
 201:           fprintf(stderr,"Can't change address.  Error %d\n",
 202:              Exception.Code);
 203:           exit(1);
 204:         } END_HANDLER;
 205:     } else {
 206:         printf("NS address (e.g. 2-273#2-613-688-939-672): ");
 207:         gets(addrstr);
 208:         if (*addrstr==0) {
 209:             addr = myaddr;
 210:         } else
 211:             addr = getXNSaddr(addrstr);
 212:         item = addrToItem(addr);
 213:         DURING
 214:           AIPresult = AddItemProperty(conn,NULL,name,4,item,agent);
 215:         HANDLER {
 216:           fprintf(stderr,"Can't add address property.  Error %d\n",
 217:             Exception.Code);
 218:           exit(1);
 219:         } END_HANDLER;
 220:     }
 221:     /* AuthenticationLevel property */
 222:     if (!isprop(8,LPresult.properties)) {
 223:         item.length = 2;
 224:         item.sequence = (Unspecified *) authseq;
 225:         DURING
 226:           AIPresult = AddItemProperty(conn,NULL,name,8,item,agent);
 227:         HANDLER {
 228:           fprintf(stderr,"Can't add AuthenticationLevel property.\n");
 229:           exit(1);
 230:         } END_HANDLER;
 231:     }
 232:     /* description */
 233:     DURING {
 234:         if (isprop(10005,LPresult.properties)) {
 235:             propnum = 10005; /* 10005<<16; */
 236:             RIresult = RetrieveItem(conn, NULL,
 237:                     name,
 238:                     propnum, agent);
 239:             propval = ItemToString(RIresult.value);
 240:             printf("Workstation description (Property 10005) has value ``%s''\n",
 241:                    propval );
 242:             clear_RetrieveItemResults(&RIresult);
 243:         }
 244:         propnum = 10024; /* 10024<<16; */
 245:         if (isprop(10024,LPresult.properties)) {
 246:             RIresult = RetrieveItem(conn, NULL,
 247:                     name,
 248:                     propnum, agent);
 249:             propval = ItemToString(RIresult.value);
 250:             printf("Server description (Property 10024) has value ``%s''\nNew value: ",
 251:                    propval );
 252:             propval = gets(malloc(100));
 253:             item = StringToItem(propval);
 254:             CIresult = ChangeItem(conn, NULL,
 255:                     name,
 256:                     propnum, item, agent);
 257:         } else {
 258:             printf("Enter new description: ");
 259:             propval = gets(malloc(100));
 260:             item = StringToItem(propval);
 261:             AIPresult = AddItemProperty(conn, NULL,
 262:                     name,
 263:                     propnum, item, agent);
 264:         }
 265:     } HANDLER {
 266:         fprintf(stderr,
 267:             "Error during Property manipulations, %d (%d)\n",
 268:             Exception.Code,
 269:             CourierErrArgs(Clearinghouse2_CallErrorArgs,problem) );
 270:     } END_HANDLER;
 271: }

Defined functions

ItemToString defined in line 27; used 3 times
StringToItem defined in line 43; used 3 times
XNSaddrToString defined in line 98; used 1 times
addrToItem defined in line 58; used 3 times
isprop defined in line 84; used 4 times
main defined in line 114; never used
Last modified: 1986-03-13
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1446
Valid CSS Valid XHTML 1.0 Strict