head 1.22; access; symbols; locks shettich:1.22; strict; comment @ * @; 1.22 date 95.12.06.22.15.26; author jromine; state Exp; branches; next 1.21; 1.21 date 93.08.25.17.32.58; author jromine; state Exp; branches; next 1.20; 1.20 date 93.08.20.15.55.35; author jromine; state Exp; branches; next 1.19; 1.19 date 92.12.15.00.20.22; author jromine; state Exp; branches; next 1.18; 1.18 date 92.12.03.16.50.12; author jromine; state Exp; branches; next 1.17; 1.17 date 92.12.03.16.28.56; author jromine; state Exp; branches; next 1.16; 1.16 date 92.11.12.19.32.01; author jromine; state Exp; branches; next 1.15; 1.15 date 92.11.12.19.29.42; author jromine; state Exp; branches; next 1.14; 1.14 date 92.11.12.01.04.54; author jromine; state Exp; branches; next 1.13; 1.13 date 92.11.11.20.56.03; author jromine; state Exp; branches; next 1.12; 1.12 date 92.11.06.03.21.30; author jromine; state Exp; branches; next 1.11; 1.11 date 92.05.19.21.22.20; author jromine; state Exp; branches; next 1.10; 1.10 date 92.02.11.17.39.48; author jromine; state Exp; branches; next 1.9; 1.9 date 92.02.11.16.36.00; author jromine; state Exp; branches; next 1.8; 1.8 date 92.02.09.23.07.47; author jromine; state Exp; branches; next 1.7; 1.7 date 92.01.31.22.33.33; author jromine; state Exp; branches; next 1.6; 1.6 date 90.04.05.15.04.36; author sources; state Exp; branches; next 1.5; 1.5 date 90.02.06.13.41.10; author sources; state Exp; branches; next 1.4; 1.4 date 90.02.05.14.58.39; author sources; state Exp; branches; next 1.3; 1.3 date 90.02.05.14.03.32; author sources; state Exp; branches; next 1.2; 1.2 date 90.02.01.14.34.57; author sources; state Exp; branches; next 1.1; 1.1 date 90.02.01.14.33.28; author sources; state Exp; branches; next ; desc @@ 1.22 log @64bit fix @ text @/* client.c - connect to a server */ #ifndef lint static char ident[] = "@@(#)$Id: client.c,v 1.21 1993/08/25 17:32:58 jromine Exp jromine $"; #endif /* lint */ #if defined(SYS5) && defined(AUX) #define u_short ushort #define u_long ulong #endif #if defined(BSD42) || defined(SOCKETS) #include "../h/strings.h" #include #include "mts.h" #include #include #include #include #include #ifndef hpux #include #endif #ifdef HESIOD #include #endif #ifdef KPOP #include #include static CREDENTIALS cred; static MSG_DAT msg_data; static KTEXT ticket = (KTEXT)NULL; static Key_schedule schedule; #endif /* KPOP */ #define NOTOK (-1) #define OK 0 #define DONE 1 #define TRUE 1 #define FALSE 0 #define OOPS1 (-2) #define OOPS2 (-3) #define MAXARGS 1000 #define MAXNETS 5 #define MAXHOSTS 25 /* */ extern int errno; #ifndef BSD44 extern int sys_nerr; extern char *sys_errlist[]; #endif struct addrent { int a_addrtype; /* assumes AF_INET for inet_netof () */ union { int un_net; char un_addr[14]; } un; #define a_net un.un_net #define a_addr un.un_addr }; static struct addrent *ne, *nz; static struct addrent nets[MAXNETS]; static struct addrent *he, *hz; static struct addrent hosts[MAXHOSTS]; #ifdef KPOP char krb_realm[REALM_SZ]; char *PrincipalHostname(); static char *kservice; /* "pop" if using kpop */ #endif /* KPOP */ #ifdef __STDC__ static int rcaux (struct servent *, struct hostent *, int, char *); static int getport (int, int, char *); static int inet (struct hostent *, int); #else static int rcaux (), getport (), inet (); #endif #if defined(BIND) && !defined(h_addr) #define h_addr h_addr_list[0] #endif #define inaddr_copy(hp,sin) \ bcopy ((hp) -> h_addr, (char *) &((sin) -> sin_addr), (hp) -> h_length) struct hostent *gethostbystring (); static int brkany (); static char *getcpy (), **copyip (), **brkstring (); /* */ int client (args, protocol, service, rproto, response) char *args, *protocol, *service, /* "pop" or "pop/kpop" */ *response; int rproto; { int sd; register char **ap; char *arguments[MAXARGS]; register struct hostent *hp; #ifndef BIND register struct netent *np; #endif register struct servent *sp; #ifdef KPOP char *cp; if (cp = index (kservice = service, '/')) { /* "pop/kpop" */ *cp++ = '\0'; /* kservice = "pop" */ service = cp; /* service = "kpop" */ } else kservice = NULL; /* not using KERBEROS */ #endif /* KPOP */ if ((sp = getservbyname (service, protocol)) == NULL) { #ifdef HESIOD if ((sp = hes_getservbyname (service, protocol)) == NULL) { (void) sprintf (response, "%s/%s: unknown service", protocol, service); return NOTOK; } #else (void) sprintf (response, "%s/%s: unknown service", protocol, service); return NOTOK; #endif } ap = arguments; if (args != NULL && *args != 0) ap = copyip (brkstring (getcpy (args), " ", "\n"), ap); else if (servers != NULL && *servers != 0) ap = copyip (brkstring (getcpy (servers), " ", "\n"), ap); if (ap == arguments) { *ap++ = getcpy ("localhost"); *ap = NULL; } nz = (ne = nets) + sizeof nets / sizeof nets[0]; hz = (he = hosts) + sizeof hosts / sizeof hosts[0]; for (ap = arguments; *ap; ap++) { if (**ap == '\01') { #ifndef BIND if (np = getnetbyname (*ap + 1)) { sethostent (1); while (hp = gethostent ()) if (np -> n_addrtype == hp -> h_addrtype && inet (hp, np -> n_net)) { switch (sd = rcaux (sp, hp, rproto, response)) { case NOTOK: continue; case OOPS1: break; case OOPS2: return NOTOK; default: return sd; } break; } } #endif continue; } if (hp = gethostbystring (*ap)) { switch (sd = rcaux (sp, hp, rproto, response)) { case NOTOK: case OOPS1: break; case OOPS2: return NOTOK; default: return sd; } continue; } } (void) strcpy (response, "no servers available"); return NOTOK; } /* */ static int rcaux (sp, hp, rproto, response) register struct servent *sp; register struct hostent *hp; int rproto; register char *response; { int sd; struct in_addr in; register struct addrent *ap; struct sockaddr_in in_socket; register struct sockaddr_in *isock = &in_socket; #ifdef KPOP int rem; #endif /* KPOP */ for (ap = nets; ap < ne; ap++) if (ap -> a_addrtype == hp -> h_addrtype && inet (hp, ap -> a_net)) return NOTOK; for (ap = hosts; ap < he; ap++) if (ap -> a_addrtype == hp -> h_addrtype && bcmp (ap -> a_addr, hp -> h_addr, hp -> h_length) == 0) return NOTOK; if ((sd = getport (rproto, hp -> h_addrtype, response)) == NOTOK) return OOPS2; bzero ((char *) isock, sizeof *isock); isock -> sin_family = hp -> h_addrtype; inaddr_copy (hp, isock); isock -> sin_port = sp -> s_port; if (connect (sd, (struct sockaddr *) isock, sizeof *isock) == NOTOK) switch (errno) { case ENETDOWN: case ENETUNREACH: (void) close (sd); if (ne < nz) { ne -> a_addrtype = hp -> h_addrtype; bcopy (hp -> h_addr, (char *) &in, sizeof in); ne -> a_net = inet_netof (in); ne++; } return OOPS1; case ETIMEDOUT: case ECONNREFUSED: default: (void) close (sd); if (he < hz) { he -> a_addrtype = hp -> h_addrtype; bcopy (hp -> h_addr, he -> a_addr, hp -> h_length); he++; } return NOTOK; } #ifdef KPOP if (kservice) { /* "pop" */ ticket = (KTEXT)malloc( sizeof(KTEXT_ST) ); rem = krb_sendauth(0L, sd, ticket, kservice, hp->h_name, (char *) krb_realmofhost(hp->h_name), (unsigned long)0, &msg_data, &cred, schedule, (struct sockaddr_in *)NULL, (struct sockaddr_in *)NULL, "KPOPV0.1"); if (rem != KSUCCESS) { close(sd); (void) strcpy(response, "Post office refused connection: "); (void) strcat(response, krb_err_txt[rem]); return OOPS2; } } #endif /* KPOP */ return sd; } /* */ static int getport (rproto, addrtype, response) int rproto, addrtype; register char *response; { int sd, port; struct sockaddr_in in_socket, *isock = &in_socket; if (rproto && addrtype != AF_INET) { (void) sprintf (response, "reserved ports not supported for af=%d", addrtype); errno = ENOPROTOOPT; return NOTOK; } if ((sd = socket (AF_INET, SOCK_STREAM, 0)) == NOTOK) { (void) sprintf (response, "unable to create socket: %s", errno > 0 && errno < sys_nerr ? sys_errlist[errno] : "unknown error"); return NOTOK; } #ifdef KPOP if (kservice) /* "pop" */ return(sd); #endif /* KPOP */ if (!rproto) return sd; bzero ((char *) isock, sizeof *isock); isock -> sin_family = addrtype; for (port = IPPORT_RESERVED - 1;;) { isock -> sin_port = htons ((u_short) port); if (bind (sd, (struct sockaddr *) isock, sizeof *isock) != NOTOK) return sd; switch (errno) { case EADDRINUSE: case EADDRNOTAVAIL: if (--port <= IPPORT_RESERVED / 2) { (void) strcpy (response, "ports available"); return NOTOK; } break; default: (void) sprintf (response, "unable to bind socket: %s", errno > 0 && errno < sys_nerr ? sys_errlist[errno] : "unknown error"); return NOTOK; } } } /* */ static int inet (hp, net) register struct hostent *hp; int net; { struct in_addr in; bcopy (hp -> h_addr, (char *) &in, sizeof in); return (inet_netof (in) == net); } /* */ /* taken from ISODE's compat/internet.c */ #ifndef OSF1 #ifndef DG u_long inet_addr (); #else struct in_addr inet_addr (); #endif #endif static char *empty = NULL; #ifdef h_addr static char *addrs[2] = { NULL }; #endif struct hostent *gethostbystring (s) char *s; { register struct hostent *h; #ifndef DG static u_long iaddr; #else static struct in_addr iaddr; #endif static struct hostent hs; iaddr = inet_addr (s); #ifndef DG if ((int)iaddr == NOTOK && strcmp (s, "255.255.255.255")) #else if (iaddr.s_addr == NOTOK && strcmp (s, "255.255.255.255")) #endif return gethostbyname (s); h = &hs; h -> h_name = s; h -> h_aliases = ∅ h -> h_addrtype = AF_INET; h -> h_length = sizeof (iaddr); #ifdef h_addr h -> h_addr_list = addrs; bzero ((char *) addrs, sizeof addrs); #endif h -> h_addr = (char *) &iaddr; return h; } /* */ /* static copies of three MH subroutines... (sigh) */ static char *broken[MAXARGS + 1]; static char **brkstring (strg, brksep, brkterm) register char *strg; register char *brksep, *brkterm; { register int bi; register char c, *sp; sp = strg; for (bi = 0; bi < MAXARGS; bi++) { while (brkany (c = *sp, brksep)) *sp++ = 0; if (!c || brkany (c, brkterm)) { *sp = 0; broken[bi] = 0; return broken; } broken[bi] = sp; while ((c = *++sp) && !brkany (c, brksep) && !brkany (c, brkterm)) continue; } broken[MAXARGS] = 0; return broken; } static brkany (chr, strg) register char chr, *strg; { register char *sp; if (strg) for (sp = strg; *sp; sp++) if (chr == *sp) return 1; return 0; } static char **copyip (p, q) register char **p, **q; { while (*p) *q++ = *p++; *q = 0; return q; } static char *getcpy (str) register char *str; { register char *cp; if ((cp = malloc ((unsigned) (strlen (str) + 1))) == NULL) return NULL; (void) strcpy (cp, str); return cp; } #endif /* BSD42 or SOCKETS */ @ 1.21 log @off_t fixes for BSD44 @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: client.c,v 1.20 1993/08/20 15:55:35 jromine Exp jromine $"; d362 1 d368 1 a369 1 d388 1 a388 1 if (iaddr == NOTOK && strcmp (s, "255.255.255.255")) @ 1.20 log @added gethostbystring() @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: client.c,v 1.19 1992/12/15 00:20:22 jromine Exp jromine $"; d56 1 d59 1 @ 1.19 log @endif sugar @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: client.c,v 1.18 1992/12/03 16:50:12 jromine Exp jromine $"; d91 12 d188 1 a188 1 if (hp = gethostbyname (*ap)) { d238 1 a239 1 bcopy (hp -> h_addr, (char *) &isock -> sin_addr, hp -> h_length); d354 49 @ 1.18 log @put u_short ifdef undef #if AUX @ text @d3 2 a4 2 static char ident[] = "@@(#)$Id: client.c,v 1.17 1992/12/03 16:28:56 jromine Exp jromine $"; #endif lint d418 1 a418 1 #endif BSD42 or SOCKETS @ 1.17 log @u_short AUX changes from Jim Guyton @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: client.c,v 1.16 1992/11/12 19:32:01 jromine Exp jromine $"; d6 1 a6 1 #ifdef SYS5 @ 1.16 log @try to fixup u_short without U_SHORT option @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: client.c,v 1.15 1992/11/12 19:29:42 jromine Exp jromine $"; d6 6 a22 5 #endif #ifdef SYS5 #define u_short ushort #define u_long ulong @ 1.15 log @add U_SHORT @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: client.c,v 1.14 1992/11/12 01:04:54 jromine Exp jromine $"; a5 5 #if defined(SYS5) && !defined(U_SHORT) #define u_short ushort #define u_long ulong #endif d17 5 @ 1.14 log @SVR4 (u_short) @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: client.c,v 1.13 1992/11/11 20:56:03 jromine Exp jromine $"; d6 1 a6 1 #if defined(SYS5) && !defined(_AIX) && !defined(SVR4) @ 1.13 log @don't define u_short if aix @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: client.c,v 1.12 1992/11/06 03:21:30 jromine Exp jromine $"; d6 1 a6 1 #if defined(SYS5) && !defined(_AIX) @ 1.12 log @fixup u_short define for AUX @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: client.c,v 1.11 1992/05/19 21:22:20 jromine Exp jromine $"; d6 1 a6 1 #ifdef SYS5 @ 1.11 log @AIX, HESIOD @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: client.c,v 1.10 1992/02/11 17:39:48 jromine Exp jromine $"; d6 5 a25 3 #endif #ifdef SYS5 #define u_short ushort @ 1.10 log @make KPOP changes clean @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: client.c,v 1.9 1992/02/11 16:36:00 jromine Exp $"; d19 3 d121 7 d130 1 a343 4 #ifndef __STDC__ char *malloc (); #endif @ 1.9 log @merge KPOP changes @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: client.c,v 1.8 1992/02/09 23:07:47 jromine Exp jromine $"; a8 3 #ifdef KPOP #include "../zotnet/mts/mts.h" #else a9 1 #endif d71 1 a71 5 #ifndef KPOP #define realservice service #else /* KPOP */ char realservice[] = "kpop"; d74 2 a76 4 /* redefine routine names for kerberos to make the loader happy */ #define client kclient #define rcaux krcaux d78 1 a78 1 static int rcaux (struct servent *, struct hostent *, int, char *, char *); d83 2 a84 1 #endif /* STDC */ a85 3 #endif /* KPOP */ a86 2 static brkany(); static int rcaux(), getport(), inet(); d93 1 a93 1 *service, d105 2 d108 11 a118 2 if ((sp = getservbyname (realservice, protocol)) == NULL) { (void) sprintf (response, "%s/%s: unknown service", realservice, protocol); d144 1 a144 1 switch (sd = rcaux (sp, hp, rproto, response, service)) { d163 1 a163 1 switch (sd = rcaux (sp, hp, rproto, response, service)) { d183 1 a183 1 static int rcaux (sp, hp, rproto, response, service) a187 1 char *service; /* what they really want to talk to */ d196 1 a196 1 #endif d241 14 a254 12 ticket = (KTEXT)malloc( sizeof(KTEXT_ST) ); rem = krb_sendauth(0L, sd, ticket, service, hp->h_name, (char *) krb_realmofhost(hp->h_name), (unsigned long)0, &msg_data, &cred, schedule, (struct sockaddr_in *)NULL, (struct sockaddr_in *)NULL, "KPOPV0.1"); if (rem != KSUCCESS) { close(sd); (void) strcpy(response, "Post office refused connection: "); (void) strcat(response, krb_err_txt[rem]); return OOPS2; d256 1 a256 1 #endif d287 3 a289 2 return(sd); #else a315 1 #endif @ 1.8 log @ANSI C @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: client.c,v 1.7 1992/01/31 22:33:33 jromine Exp jromine $"; d9 3 d13 1 d19 1 a19 1 # ifndef hpux /* Doesn't exist on HP-UX (SYS V?) */ d21 1 a21 1 # endif hpux a22 1 d25 1 a25 1 #endif SYS5 d27 10 d75 4 d80 18 d117 1 a117 1 #endif BIND d120 2 a121 2 if ((sp = getservbyname (service, protocol)) == NULL) { (void) sprintf (response, "%s/%s: unknown service", protocol, service); d147 1 a147 1 switch (sd = rcaux (sp, hp, rproto, response)) { d166 1 a166 1 switch (sd = rcaux (sp, hp, rproto, response)) { d186 1 a186 1 static int rcaux (sp, hp, rproto, response) d191 1 d198 3 d244 16 d288 3 d317 1 @ 1.7 log @kerberos @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: client.c,v 1.6 1990/04/05 15:04:36 sources Exp jromine $"; d277 1 d279 1 a279 1 @ 1.6 log @add ID @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id:$"; d91 1 a91 1 if (args != NULL && *args != NULL) d94 1 a94 1 if (servers != NULL && *servers != NULL) d126 1 a126 1 #endif not BIND @ 1.5 log @ANSI Compilance @ text @d2 3 @ 1.4 log @SOCKETS @ text @d60 3 a62 1 char *getcpy (), **brkstring (), **copyip (); @ 1.3 log @SYS5 fix @ text @d3 1 a3 1 #if defined (BSD42) || (defined (hpux) && !defined(hp9000s500)) d345 1 a345 1 #endif BSD42 || hpux @ 1.2 log @hpux changes @ text @d17 4 @ 1.1 log @Initial revision @ text @d3 1 a3 1 #ifdef BSD42 d12 1 d14 1 d341 1 a341 1 #endif BSD42 @