10 date 95.12.06.22.15.26; author jromine; state Exp;
15 date 93.08.25.17.32.58; author jromine; state Exp;
20 date 93.08.20.15.55.35; author jromine; state Exp;
25 date 92.12.15.00.20.22; author jromine; state Exp;
30 date 92.12.03.16.50.12; author jromine; state Exp;
35 date 92.12.03.16.28.56; author jromine; state Exp;
40 date 92.11.12.19.32.01; author jromine; state Exp;
45 date 92.11.12.19.29.42; author jromine; state Exp;
50 date 92.11.12.01.04.54; author jromine; state Exp;
55 date 92.11.11.20.56.03; author jromine; state Exp;
60 date 92.11.06.03.21.30; author jromine; state Exp;
65 date 92.05.19.21.22.20; author jromine; state Exp;
70 date 92.02.11.17.39.48; author jromine; state Exp;
75 date 92.02.11.16.36.00; author jromine; state Exp;
80 date 92.02.09.23.07.47; author jromine; state Exp;
85 date 92.01.31.22.33.33; author jromine; state Exp;
90 date 90.04.05.15.04.36; author sources; state Exp;
95 date 90.02.06.13.41.10; author sources; state Exp;
100 date 90.02.05.14.58.39; author sources; state Exp;
105 date 90.02.05.14.03.32; author sources; state Exp;
110 date 90.02.01.14.34.57; author sources; state Exp;
115 date 90.02.01.14.33.28; author sources; state Exp;
129 @/* client.c - connect to a server */
131 static char ident[] = "@@(#)$Id: client.c,v 1.21 1993/08/25 17:32:58 jromine Exp jromine $";
134 #if defined(SYS5) && defined(AUX)
135 #define u_short ushort
140 #if defined(BSD42) || defined(SOCKETS)
141 #include "../h/strings.h"
145 #include <sys/types.h>
146 #include <sys/socket.h>
147 #include <netinet/in.h>
150 #include <arpa/inet.h>
161 static CREDENTIALS cred;
162 static MSG_DAT msg_data;
163 static KTEXT ticket = (KTEXT)NULL;
164 static Key_schedule schedule;
186 extern char *sys_errlist[];
191 int a_addrtype; /* assumes AF_INET for inet_netof () */
197 #define a_net un.un_net
198 #define a_addr un.un_addr
201 static struct addrent *ne, *nz;
202 static struct addrent nets[MAXNETS];
204 static struct addrent *he, *hz;
205 static struct addrent hosts[MAXHOSTS];
208 char krb_realm[REALM_SZ];
209 char *PrincipalHostname();
210 static char *kservice; /* "pop" if using kpop */
214 static int rcaux (struct servent *, struct hostent *, int, char *);
215 static int getport (int, int, char *);
216 static int inet (struct hostent *, int);
218 static int rcaux (), getport (), inet ();
222 #if defined(BIND) && !defined(h_addr)
223 #define h_addr h_addr_list[0]
226 #define inaddr_copy(hp,sin) \
227 bcopy ((hp) -> h_addr, (char *) &((sin) -> sin_addr), (hp) -> h_length)
230 struct hostent *gethostbystring ();
233 static int brkany ();
234 static char *getcpy (), **copyip (), **brkstring ();
238 int client (args, protocol, service, rproto, response)
241 *service, /* "pop" or "pop/kpop" */
247 char *arguments[MAXARGS];
248 register struct hostent *hp;
250 register struct netent *np;
252 register struct servent *sp;
256 if (cp = index (kservice = service, '/')) { /* "pop/kpop" */
257 *cp++ = '\0'; /* kservice = "pop" */
258 service = cp; /* service = "kpop" */
261 kservice = NULL; /* not using KERBEROS */
265 if ((sp = getservbyname (service, protocol)) == NULL) {
267 if ((sp = hes_getservbyname (service, protocol)) == NULL) {
268 (void) sprintf (response, "%s/%s: unknown service",
273 (void) sprintf (response, "%s/%s: unknown service", protocol, service);
279 if (args != NULL && *args != 0)
280 ap = copyip (brkstring (getcpy (args), " ", "\n"), ap);
282 if (servers != NULL && *servers != 0)
283 ap = copyip (brkstring (getcpy (servers), " ", "\n"), ap);
284 if (ap == arguments) {
285 *ap++ = getcpy ("localhost");
289 nz = (ne = nets) + sizeof nets / sizeof nets[0];
290 hz = (he = hosts) + sizeof hosts / sizeof hosts[0];
292 for (ap = arguments; *ap; ap++) {
295 if (np = getnetbyname (*ap + 1)) {
297 while (hp = gethostent ())
298 if (np -> n_addrtype == hp -> h_addrtype
299 && inet (hp, np -> n_net)) {
300 switch (sd = rcaux (sp, hp, rproto, response)) {
318 if (hp = gethostbystring (*ap)) {
319 switch (sd = rcaux (sp, hp, rproto, response)) {
333 (void) strcpy (response, "no servers available");
339 static int rcaux (sp, hp, rproto, response)
340 register struct servent *sp;
341 register struct hostent *hp;
343 register char *response;
347 register struct addrent *ap;
348 struct sockaddr_in in_socket;
349 register struct sockaddr_in *isock = &in_socket;
354 for (ap = nets; ap < ne; ap++)
355 if (ap -> a_addrtype == hp -> h_addrtype && inet (hp, ap -> a_net))
358 for (ap = hosts; ap < he; ap++)
359 if (ap -> a_addrtype == hp -> h_addrtype
360 && bcmp (ap -> a_addr, hp -> h_addr, hp -> h_length) == 0)
363 if ((sd = getport (rproto, hp -> h_addrtype, response)) == NOTOK)
366 bzero ((char *) isock, sizeof *isock);
367 isock -> sin_family = hp -> h_addrtype;
368 inaddr_copy (hp, isock);
369 isock -> sin_port = sp -> s_port;
371 if (connect (sd, (struct sockaddr *) isock, sizeof *isock) == NOTOK)
377 ne -> a_addrtype = hp -> h_addrtype;
378 bcopy (hp -> h_addr, (char *) &in, sizeof in);
379 ne -> a_net = inet_netof (in);
389 he -> a_addrtype = hp -> h_addrtype;
390 bcopy (hp -> h_addr, he -> a_addr, hp -> h_length);
397 if (kservice) { /* "pop" */
398 ticket = (KTEXT)malloc( sizeof(KTEXT_ST) );
399 rem = krb_sendauth(0L, sd, ticket, kservice, hp->h_name,
400 (char *) krb_realmofhost(hp->h_name),
401 (unsigned long)0, &msg_data, &cred, schedule,
402 (struct sockaddr_in *)NULL,
403 (struct sockaddr_in *)NULL,
405 if (rem != KSUCCESS) {
407 (void) strcpy(response, "Post office refused connection: ");
408 (void) strcat(response, krb_err_txt[rem]);
419 static int getport (rproto, addrtype, response)
422 register char *response;
426 struct sockaddr_in in_socket,
429 if (rproto && addrtype != AF_INET) {
430 (void) sprintf (response, "reserved ports not supported for af=%d",
436 if ((sd = socket (AF_INET, SOCK_STREAM, 0)) == NOTOK) {
437 (void) sprintf (response, "unable to create socket: %s",
438 errno > 0 && errno < sys_nerr ? sys_errlist[errno]
443 if (kservice) /* "pop" */
449 bzero ((char *) isock, sizeof *isock);
450 isock -> sin_family = addrtype;
451 for (port = IPPORT_RESERVED - 1;;) {
452 isock -> sin_port = htons ((u_short) port);
453 if (bind (sd, (struct sockaddr *) isock, sizeof *isock) != NOTOK)
459 if (--port <= IPPORT_RESERVED / 2) {
460 (void) strcpy (response, "ports available");
466 (void) sprintf (response, "unable to bind socket: %s",
467 errno > 0 && errno < sys_nerr ? sys_errlist[errno]
476 static int inet (hp, net)
477 register struct hostent *hp;
482 bcopy (hp -> h_addr, (char *) &in, sizeof in);
483 return (inet_netof (in) == net);
488 /* taken from ISODE's compat/internet.c */
494 struct in_addr inet_addr ();
498 static char *empty = NULL;
500 static char *addrs[2] = { NULL };
503 struct hostent *gethostbystring (s)
506 register struct hostent *h;
510 static struct in_addr iaddr;
512 static struct hostent hs;
514 iaddr = inet_addr (s);
516 if ((int)iaddr == NOTOK && strcmp (s, "255.255.255.255"))
518 if (iaddr.s_addr == NOTOK && strcmp (s, "255.255.255.255"))
520 return gethostbyname (s);
524 h -> h_aliases = ∅
525 h -> h_addrtype = AF_INET;
526 h -> h_length = sizeof (iaddr);
528 h -> h_addr_list = addrs;
529 bzero ((char *) addrs, sizeof addrs);
531 h -> h_addr = (char *) &iaddr;
538 /* static copies of three MH subroutines... (sigh) */
540 static char *broken[MAXARGS + 1];
543 static char **brkstring (strg, brksep, brkterm)
545 register char *brksep,
554 for (bi = 0; bi < MAXARGS; bi++) {
555 while (brkany (c = *sp, brksep))
557 if (!c || brkany (c, brkterm)) {
564 while ((c = *++sp) && !brkany (c, brksep) && !brkany (c, brkterm))
573 static brkany (chr, strg)
580 for (sp = strg; *sp; sp++)
587 static char **copyip (p, q)
599 static char *getcpy (str)
604 if ((cp = malloc ((unsigned) (strlen (str) + 1))) == NULL)
607 (void) strcpy (cp, str);
610 #endif /* BSD42 or SOCKETS */
616 @off_t fixes for BSD44
621 static char ident[] = "@@(#)$Id: client.c,v 1.20 1993/08/20 15:55:35 jromine Exp jromine $";
628 if (iaddr == NOTOK && strcmp (s, "255.255.255.255"))
634 @added gethostbystring()
639 static char ident[] = "@@(#)$Id: client.c,v 1.19 1992/12/15 00:20:22 jromine Exp jromine $";
652 static char ident[] = "@@(#)$Id: client.c,v 1.18 1992/12/03 16:50:12 jromine Exp jromine $";
656 if (hp = gethostbyname (*ap)) {
659 bcopy (hp -> h_addr, (char *) &isock -> sin_addr, hp -> h_length);
666 @put u_short ifdef undef #if AUX
671 static char ident[] = "@@(#)$Id: client.c,v 1.17 1992/12/03 16:28:56 jromine Exp jromine $";
675 #endif BSD42 or SOCKETS
681 @u_short AUX changes from Jim Guyton
686 static char ident[] = "@@(#)$Id: client.c,v 1.16 1992/11/12 19:32:01 jromine Exp jromine $";
695 @try to fixup u_short without U_SHORT option
700 static char ident[] = "@@(#)$Id: client.c,v 1.15 1992/11/12 19:29:42 jromine Exp jromine $";
706 #define u_short ushort
718 static char ident[] = "@@(#)$Id: client.c,v 1.14 1992/11/12 01:04:54 jromine Exp jromine $";
720 #if defined(SYS5) && !defined(U_SHORT)
721 #define u_short ushort
736 static char ident[] = "@@(#)$Id: client.c,v 1.13 1992/11/11 20:56:03 jromine Exp jromine $";
739 #if defined(SYS5) && !defined(_AIX) && !defined(SVR4)
745 @don't define u_short if aix
750 static char ident[] = "@@(#)$Id: client.c,v 1.12 1992/11/06 03:21:30 jromine Exp jromine $";
753 #if defined(SYS5) && !defined(_AIX)
759 @fixup u_short define for AUX
764 static char ident[] = "@@(#)$Id: client.c,v 1.11 1992/05/19 21:22:20 jromine Exp jromine $";
778 static char ident[] = "@@(#)$Id: client.c,v 1.10 1992/02/11 17:39:48 jromine Exp jromine $";
783 #define u_short ushort
789 @make KPOP changes clean
794 static char ident[] = "@@(#)$Id: client.c,v 1.9 1992/02/11 16:36:00 jromine Exp $";
813 static char ident[] = "@@(#)$Id: client.c,v 1.8 1992/02/09 23:07:47 jromine Exp jromine $";
816 #include "../zotnet/mts/mts.h"
823 #define realservice service
825 char realservice[] = "kpop";
829 /* redefine routine names for kerberos to make the loader happy */
830 #define client kclient
835 static int rcaux (struct servent *, struct hostent *, int, char *, char *);
845 static int rcaux(), getport(), inet();
852 if ((sp = getservbyname (realservice, protocol)) == NULL) {
853 (void) sprintf (response, "%s/%s: unknown service", realservice, protocol);
856 switch (sd = rcaux (sp, hp, rproto, response, service)) {
859 switch (sd = rcaux (sp, hp, rproto, response, service)) {
862 static int rcaux (sp, hp, rproto, response, service)
864 char *service; /* what they really want to talk to */
870 ticket = (KTEXT)malloc( sizeof(KTEXT_ST) );
871 rem = krb_sendauth(0L, sd, ticket, service, hp->h_name,
872 (char *) krb_realmofhost(hp->h_name),
873 (unsigned long)0, &msg_data, &cred, schedule,
874 (struct sockaddr_in *)NULL,
875 (struct sockaddr_in *)NULL,
877 if (rem != KSUCCESS) {
879 (void) strcpy(response, "Post office refused connection: ");
880 (void) strcat(response, krb_err_txt[rem]);
901 static char ident[] = "@@(#)$Id: client.c,v 1.7 1992/01/31 22:33:33 jromine Exp jromine $";
906 # ifndef hpux /* Doesn't exist on HP-UX (SYS V?) */
923 if ((sp = getservbyname (service, protocol)) == NULL) {
924 (void) sprintf (response, "%s/%s: unknown service", protocol, service);
927 switch (sd = rcaux (sp, hp, rproto, response)) {
930 switch (sd = rcaux (sp, hp, rproto, response)) {
933 static int rcaux (sp, hp, rproto, response)
949 static char ident[] = "@@(#)$Id: client.c,v 1.6 1990/04/05 15:04:36 sources Exp jromine $";
964 static char ident[] = "@@(#)$Id:$";
967 if (args != NULL && *args != NULL)
970 if (servers != NULL && *servers != NULL)
993 char *getcpy (), **brkstring (), **copyip ();
1004 #if defined (BSD42) || (defined (hpux) && !defined(hp9000s500))
1007 #endif BSD42 || hpux