From def9f9a0706a18cb1bc0f44b39d55e4e81c788ff Mon Sep 17 00:00:00 2001 From: Karl Ramm Date: Tue, 24 Aug 2010 07:08:36 +0000 Subject: stop using MAXHOSTNAMELEN in a variety of places. Also nuke-trailing-whitespace. --- clients/zctl/zctl.c | 147 ++++++++++++++-------------- clients/zshutdown_notify/zshutdown_notify.c | 13 +-- clients/zstat/zstat.c | 37 +++---- h/internal.h | 2 +- lib/ZExpnRlm.c | 2 +- lib/ZInit.c | 40 ++++---- lib/ZLocations.c | 16 +-- server/main.c | 48 ++++----- server/realm.c | 6 +- server/server.c | 8 +- zhm/zhm.c | 52 +++++----- zhm/zhm_server.c | 36 +++---- zwgc/main.c | 47 +++++---- zwgc/subscriptions.c | 15 +-- 14 files changed, 234 insertions(+), 235 deletions(-) diff --git a/clients/zctl/zctl.c b/clients/zctl/zctl.c index 47d7628..7f420c5 100644 --- a/clients/zctl/zctl.c +++ b/clients/zctl/zctl.c @@ -7,7 +7,7 @@ * * Copyright (c) 1987,1988 by the Massachusetts Institute of Technology. * For copying and distribution information, see the file - * "mit-copyright.h". + * "mit-copyright.h". */ #include @@ -15,6 +15,7 @@ #include #include #include +#include #ifndef lint static const char rcsid_zctl_c[] = "$Id$"; #endif @@ -42,7 +43,7 @@ static const char rcsid_zctl_c[] = "$Id$"; int sci_idx; char subsname[BUFSIZ]; -char ourhost[MAXHOSTNAMELEN],ourhostcanon[MAXHOSTNAMELEN]; +char ourhost[NS_MAXDNAME], ourhostcanon[NS_MAXDNAME]; extern ss_request_table zctl_cmds; @@ -76,7 +77,7 @@ main(int argc, * DISPLAY environment variable for the tty name. */ #ifndef X_DISPLAY_MISSING tty = getenv("DISPLAY"); -#endif +#endif if ((retval = ZInitLocationInfo(NULL, tty)) != ZERR_NONE) com_err(argv[0], retval, "initializing location information"); @@ -110,7 +111,7 @@ main(int argc, uname(&name); strcpy(ourhost, name.nodename); #else - if (gethostname(ourhost,MAXHOSTNAMELEN) == -1) { + if (gethostname(ourhost, sizeof(ourhost)) == -1) { com_err(argv[0],errno,"while getting host name"); exit (1); } @@ -140,12 +141,12 @@ main(int argc, fprintf (stderr, "%s: %s: %s\n", argv[0], error_message (code), ssline); exit((code != 0)); - } + } printf("ZCTL $Revision$ (Protocol %s%d.%d) - Type '?' for a list of commands.\n\n", ZVERSIONHDR, ZVERSIONMAJOR,ZVERSIONMINOR); - + ss_listen(sci_idx); exit(0); } @@ -170,7 +171,7 @@ flush_locations(int argc, char *argv[]) { int retval; - + if (argc > 1) { fprintf(stderr,"Usage: %s\n",argv[0]); return; @@ -195,7 +196,7 @@ wgc_control(int argc, fprintf(stderr,"Usage: %s\n",argv[0]); return; } - + if ((newport = ZGetWGPort()) == -1) { com_err(whoami, errno, "while getting WindowGram port"); return; @@ -238,7 +239,7 @@ wgc_control(int argc, if ((retval = ZInitialize()) != ZERR_NONE) com_err(whoami, retval, "while reinitializing"); -} +} void hm_control(int argc, @@ -251,7 +252,7 @@ hm_control(int argc, fprintf(stderr,"Usage: %s\n",argv[0]); return; } - + (void) memset((char *)¬ice, 0, sizeof(notice)); notice.z_kind = HMCTL; notice.z_port = 0; @@ -282,7 +283,7 @@ show_var(int argc, { int i; char *value; - + if (argc < 2) { fprintf(stderr,"Usage: %s ...\n",argv[0]); return; @@ -304,7 +305,7 @@ set_var(int argc, char *argv[]) char *exp_level = NULL; char *newargv[1]; char varcat[BUFSIZ]; - + if (argc < 2) { fprintf(stderr,"Usage: %s [value]\n", argv[0]); @@ -343,7 +344,7 @@ set_var(int argc, char *argv[]) EXPOSE_NETANN); return; } - } + } if (argc == 2) retval = ZSetVariable(argv[1],""); else { @@ -351,9 +352,9 @@ set_var(int argc, char *argv[]) for (i=3;i [ ... ]\n", argv[0]); @@ -424,12 +425,12 @@ cancel_subs(int argc, if (argc != 1) { fprintf(stderr,"Usage: %s\n",argv[0]); return; - } + } if ((wgport = ZGetWGPort()) == -1) { com_err(whoami, errno, "while finding WindowGram port"); return; - } + } if ((retval = ZCancelSubscriptions((u_short)wgport)) != ZERR_NONE) com_err(whoami, retval, "while cancelling subscriptions"); } @@ -441,27 +442,27 @@ subscribe(int argc, int retval; short wgport; ZSubscription_t sub,sub2; - + if (argc > 4 || argc < 3) { fprintf(stderr,"Usage: %s class instance [*]\n",argv[0]); return; } - + sub.zsub_class = argv[1]; sub.zsub_classinst = argv[2]; sub.zsub_recipient = (argc == 3)?ZGetSender():argv[3]; fix_macros(&sub,&sub2,1); - + if ((wgport = ZGetWGPort()) == -1) { com_err(whoami, errno, "while finding WindowGram port"); return; - } + } retval = (*argv[0] == 's') ? ZSubscribeToSansDefaults(&sub2,1,(u_short)wgport) : ZUnsubscribeTo(&sub2,1,(u_short)wgport); - + if (retval != ZERR_NONE) com_err(whoami, retval, "while subscribing"); } @@ -497,7 +498,7 @@ sub_file(int argc, if ((wgport = ZGetWGPort()) == -1) { com_err(whoami, errno, "while finding WindowGram port"); return; - } + } if (!strcmp(argv[0],"add")) add_file(wgport,&sub,0); @@ -531,7 +532,7 @@ add_file(short wgport, (void) sprintf(errbuf,"while opening %s for append",subsname); com_err(whoami, errno, errbuf); return; - } + } fprintf(fp,"%s%s,%s,%s\n", unsub ? "!" : "", subs->zsub_class, subs->zsub_classinst, subs->zsub_recipient); @@ -558,7 +559,7 @@ del_file(short wgport, { ZSubscription_t sub2; int retval; - + retval = purge_subs(subs, unsub ? UNSUBONLY : SUBONLY); if (retval == ERR) return; @@ -604,7 +605,7 @@ purge_subs(register ZSubscription_t *subs, (void) sprintf(errbuf,"while opening %s for read",subsname); com_err(whoami, errno, errbuf); return(ERR); - } + } (void) strcpy(backup, subsname); (void) strcat(backup, ".temp"); (void) unlink(backup); @@ -613,7 +614,7 @@ purge_subs(register ZSubscription_t *subs, com_err(whoami, errno, errbuf); (void) fclose(fp); return(ERR); - } + } for (;;) { if (!fgets(subline,sizeof subline,fp)) break; @@ -684,15 +685,15 @@ load_subs(int argc, else type = SUB; - if (type != LIST) + if (type != LIST) if ((wgport = ZGetWGPort()) == -1) { com_err(whoami, errno, "while finding WindowGram port"); return; - } + } file = (argc == 1) ? subsname : argv[1]; - + fp = fopen(file,"r"); if (fp == NULL) { @@ -700,13 +701,13 @@ load_subs(int argc, "while loading subscription file"); return; } - + #ifdef CMU_ZCTL_PUNT pind = #endif ind = unind = 0; lineno = 1; - + for (;;lineno++) { if (!fgets(subline,sizeof subline,fp)) break; @@ -727,7 +728,7 @@ load_subs(int argc, *comma = '\0'; *comma2 = '\0'; if (type == LIST) { - if (*subline == '!') + if (*subline == '!') printf("(Un-subscription) Class %s instance %s recipient %s\n", subline+1, comma+1, comma2+1); #ifdef CMU_ZCTL_PUNT @@ -780,7 +781,7 @@ load_subs(int argc, pind++; } else #endif - { + { subs[ind].zsub_class = (char *)malloc((unsigned)(strlen(subline)+1)); /* XXX check malloc return */ @@ -828,7 +829,7 @@ load_subs(int argc, free(subs[i].zsub_class); free(subs[i].zsub_classinst); free(subs[i].zsub_recipient); - } + } ind = 0; } if (unind == SUBSATONCE) { @@ -842,11 +843,11 @@ load_subs(int argc, free(unsubs[i].zsub_class); free(unsubs[i].zsub_classinst); free(unsubs[i].zsub_recipient); - } + } unind = 0; } } - + if (type != LIST) { /* even if we have no subscriptions, be sure to send an empty packet to trigger the default subscriptions */ @@ -885,12 +886,12 @@ cleanup: free(subs[i].zsub_class); free(subs[i].zsub_classinst); free(subs[i].zsub_recipient); - } + } for (i=0;i\n", punt ? "Punting" : "Unpunting", class, inst, *recip ? recip : "*"); - + memset((char *) ¬ice, 0, sizeof(ZNotice_t)); notice.z_kind = UNSAFE; notice.z_class = WG_CTL_CLASS; @@ -1134,12 +1135,12 @@ do_punt(int argc, char **argv) notice.z_port = 0; notice.z_message = msg; notice.z_message_len = strlen(class)+strlen(inst)+strlen(recip)+3; - + if ((retval = ZSendNotice(¬ice,ZNOAUTH)) != ZERR_NONE) fprintf(stderr,"%s: while sending notice\n",whoami); - + free(msg); - + ZClosePort(); #endif return 0; @@ -1155,26 +1156,26 @@ list_punts(int argc, char **argv) u_short ourport, zwgcport; char *msg; - ourport=0; + ourport=0; retval = ZOpenPort(&ourport); if(retval != ZERR_NONE) { com_err("zctl", retval, "while opening Zephyr port."); return 1; } - + old = ZGetDestAddr(); to = old; if ((zwgcport = ZGetWGPort()) == (u_short)-1) { fprintf(stderr, "zctl: Can't find windowgram port\n"); return 1; } - + to.sin_port = (u_short) zwgcport; if ((retval = ZSetDestAddr(&to)) != ZERR_NONE) { com_err("zctl",retval,"while setting destination address"); return 1; } - + memset((char *) ¬ice, 0, sizeof(ZNotice_t)); notice.z_kind = UNSAFE; notice.z_class = WG_CTL_CLASS; @@ -1185,25 +1186,25 @@ list_punts(int argc, char **argv) notice.z_port = ourport; notice.z_message = NULL; notice.z_message_len = 0; - + if ((retval = ZSendNotice(¬ice,ZNOAUTH)) != ZERR_NONE) com_err("zctl",retval,"while sending notice"); - + if ((retval = ZReceiveNotice(¬ice,&from)) != ZERR_NONE) com_err("zctl",retval,"while receiving ack"); - + (void) ZFreeNotice(¬ice); - + if ((retval = ZReceiveNotice(¬ice,&from)) != ZERR_NONE) com_err("zctl",retval,"while receiving notice"); - + notice.z_auth = ZCheckAuthentication(¬ice, &from); - + if ((retval = ZSetDestAddr(&old)) != ZERR_NONE) { com_err("zctl",retval,"while resetting destination address"); return 1; } - + msg = (char *) malloc((notice.z_message_len+1) * sizeof(char)); (void) strncpy(msg,notice.z_message, notice.z_message_len); msg[notice.z_message_len]=(char)0; @@ -1211,7 +1212,7 @@ list_punts(int argc, char **argv) (void) free(msg); (void) ZFreeNotice(¬ice); (void) ZClosePort(); - + #endif /* CMU_ZCTL_PUNT */ return 0; } diff --git a/clients/zshutdown_notify/zshutdown_notify.c b/clients/zshutdown_notify/zshutdown_notify.c index 067a813..a682abf 100644 --- a/clients/zshutdown_notify/zshutdown_notify.c +++ b/clients/zshutdown_notify/zshutdown_notify.c @@ -8,7 +8,7 @@ * * Copyright (c) 1987, 1993 by the Massachusetts Institute of Technology. * For copying and distribution information, see the file - * "mit-copyright.h". + * "mit-copyright.h". */ #include @@ -17,6 +17,7 @@ #include #include +#include #ifndef lint static const char rcsid_zshutdown_notify_c[] = @@ -48,18 +49,18 @@ main(int argc, ZNotice_t notice; struct hostent *hp; int retval; - char hostname[MAXHOSTNAMELEN]; + char hostname[NS_MAXDNAME]; char msgbuff[BUFSIZ], message[Z_MAXPKTLEN], *ptr; char scratch[BUFSIZ]; char *msg[N_FIELD_CNT]; #ifdef HAVE_KRB4 char tkt_filename[MAXPATHLEN]; char rlm[REALM_SZ]; - char hn2[MAXHOSTNAMELEN]; + char hn2[NS_MAXDNAME]; char *cp; #endif - if (gethostname(hostname, MAXHOSTNAMELEN) < 0) { + if (gethostname(hostname, sizeof(hostname)) < 0) { com_err(argv[0], errno, "while finding hostname"); exit(1); } @@ -102,7 +103,7 @@ main(int argc, if ((retval = ZInitialize()) != ZERR_NONE) { com_err(argv[0], retval, "while initializing"); exit(1); - } + } ptr = message; @@ -137,6 +138,6 @@ main(int argc, if (retval != ZERR_NONE) { com_err(argv[0], retval, "while sending notice"); exit(1); - } + } return 0; } diff --git a/clients/zstat/zstat.c b/clients/zstat/zstat.c index 944c4fc..c18bb60 100644 --- a/clients/zstat/zstat.c +++ b/clients/zstat/zstat.c @@ -7,7 +7,7 @@ * * Copyright (c) 1987,1988 by the Massachusetts Institute of Technology. * For copying and distribution information, see the file - * "mit-copyright.h". + * "mit-copyright.h". */ /* There should be library interfaces for the operations in zstat; for now, @@ -17,6 +17,7 @@ #include #include #include +#include #include "zserver.h" #if !defined(lint) && !defined(SABER) @@ -36,7 +37,7 @@ const char *hm_head[] = { "Machine type:" }; #define HM_SIZE (sizeof(hm_head) / sizeof (char *)) -const char *srv_head[] = { +const char *srv_head[] = { "Current server version =", "Packets handled:", "Uptime:", @@ -65,7 +66,7 @@ main(int argc, char *argv[]) { Code_t ret; - char hostname[MAXHOSTNAMELEN]; + char hostname[NS_MAXDNAME]; int optchar; struct servent *sp; extern char *optarg; @@ -105,7 +106,7 @@ main(int argc, srv_port = (sp) ? sp->s_port : SERVER_SVC_FALLBACK; if (optind == argc) { - if (gethostname(hostname, MAXHOSTNAMELEN) < 0) { + if (gethostname(hostname, sizeof(hostname)) < 0) { com_err("zstat",errno,"while finding hostname"); exit(-1); } @@ -122,8 +123,8 @@ main(int argc, void do_stat(char *host) { - char srv_host[MAXHOSTNAMELEN]; - + char srv_host[NS_MAXDNAME]; + if (serveronly) { (void) srv_stat(host); return; @@ -149,7 +150,7 @@ hm_stat(char *host, time_t runtime; struct tm *tim; ZNotice_t notice; - + if ((inaddr.s_addr = inet_addr(host)) == (unsigned)(-1)) { if ((hp = gethostbyname(host)) == NULL) { fprintf(stderr,"Unknown host: %s\n",host); @@ -161,12 +162,12 @@ hm_stat(char *host, } else { printf("Hostmanager stats: %s\n", host); } - + if ((code = ZhmStat(&inaddr, ¬ice)) != ZERR_NONE) { com_err("zstat", code, "getting hostmanager status"); exit(-1); } - + mp = notice.z_message; for (nf=0;mp #ifdef HAVE_ARPA_NAMESER_COMPAT_H #include #endif +#ifndef REALM_SZ /* XXX */ #define REALM_SZ NS_MAXDNAME #endif #define MAX_PRINCIPAL_SIZE 1024 diff --git a/lib/ZExpnRlm.c b/lib/ZExpnRlm.c index 1b752a9..54c2fdb 100644 --- a/lib/ZExpnRlm.c +++ b/lib/ZExpnRlm.c @@ -48,7 +48,7 @@ char *realm; #else int retval; FILE *rlm_file; - char krb_host[MAXHOSTNAMELEN+1]; + char krb_host[NS_MAXDNAME + 1]; static char krb_realm[REALM_SZ+1]; char linebuf[BUFSIZ]; char scratch[64]; diff --git a/lib/ZInit.c b/lib/ZInit.c index f6ec6de..8339cf3 100644 --- a/lib/ZInit.c +++ b/lib/ZInit.c @@ -7,7 +7,7 @@ * * Copyright (c) 1987, 1991 by the Massachusetts Institute of Technology. * For copying and distribution information, see the file - * "mit-copyright.h". + * "mit-copyright.h". */ #ifndef lint @@ -51,7 +51,7 @@ ZInitialize(void) { struct servent *hmserv; struct hostent *hostent; - char addr[4], hostname[MAXHOSTNAMELEN]; + char addr[4], hostname[NS_MAXDNAME]; struct in_addr servaddr; struct sockaddr_in sin; unsigned int s, sinsize = sizeof(sin); @@ -67,8 +67,8 @@ ZInitialize(void) #endif #endif - /* On OS X you don't need to initialize the Kerberos error tables - as long as you link with -framework Kerberos */ + /* On OS X you don't need to initialize the Kerberos error tables + as long as you link with -framework Kerberos */ #if !(defined(__APPLE__) && defined(__MACH__)) #ifdef HAVE_KRB4 initialize_krb_error_table(); @@ -78,12 +78,12 @@ ZInitialize(void) #endif #endif -#if defined(__APPLE__) && defined(__MACH__) - add_error_table(&et_zeph_error_table); -#else +#if defined(__APPLE__) && defined(__MACH__) + add_error_table(&et_zeph_error_table); +#else initialize_zeph_error_table(); #endif - + (void) memset((char *)&__HM_addr, 0, sizeof(__HM_addr)); __HM_addr.sin_family = AF_INET; @@ -104,7 +104,7 @@ ZInitialize(void) /* Initialize the input queue */ __Q_Tail = NULL; __Q_Head = NULL; - + #ifdef HAVE_KRB5 if ((code = krb5_init_context(&Z_krb5_ctx))) return(code); @@ -239,10 +239,6 @@ struct sockaddr_in ZGetDestAddr (void) { #if defined(HAVE_KRB5) && defined(KRB5_REFERRAL_REALM) #include #include -#include -#ifdef HAVE_ARPA_NAMESER_COMPAT_H -#include -#endif #include static int txt_lookup(char *qname, char **result) { @@ -250,7 +246,7 @@ static int txt_lookup(char *qname, char **result) { void *buf = NULL; HEADER *hdr; unsigned char *p; - char dname[MAXDNAME]; + char dname[NS_MAXDNAME]; int queries, answers, stored; ret = res_init(); @@ -261,7 +257,7 @@ static int txt_lookup(char *qname, char **result) { do { buflen = buflen ? buflen * 2 : 2048; buf = (buf == NULL) ? malloc(buflen) : realloc(buf, buflen); - + ret = res_search(qname, C_IN, T_TXT, buf, buflen); } while (ret > buflen); @@ -292,7 +288,7 @@ static int txt_lookup(char *qname, char **result) { stored = 0; while (answers--) { int class, type; - + ret = dn_expand(buf, buf + buflen, p, dname, sizeof dname); if (ret < 0 || ret > left) return -1; @@ -324,7 +320,7 @@ static int txt_lookup(char *qname, char **result) { p += ret; } return -1; -} +} static int z_get_host_realm_replacement(char *inhost, char ***krealms) { @@ -335,7 +331,7 @@ z_get_host_realm_replacement(char *inhost, char ***krealms) { char *qname; profile_t prof; int ret; - + host = strdup(inhost); for (p = host; *p; p++) @@ -397,9 +393,9 @@ z_get_host_realm_replacement(char *inhost, char ***krealms) { sprintf(qname, "_kerberos.%s.", p); ret = txt_lookup(qname, &realm); free(qname); - + p = strchr(p,'.'); - if (p) + if (p) p++; } while (ret && p && p[0]); } @@ -411,7 +407,7 @@ z_get_host_realm_replacement(char *inhost, char ***krealms) { free(host); return errno; } - + for (p = realm; *p; p++) if (islower(*p)) *p = toupper(*p); @@ -423,7 +419,7 @@ z_get_host_realm_replacement(char *inhost, char ***krealms) { } } } - + free(host); if ((*krealms = calloc(2, sizeof(*krealms))) == NULL) { diff --git a/lib/ZLocations.c b/lib/ZLocations.c index db6daa6..b0c197c 100644 --- a/lib/ZLocations.c +++ b/lib/ZLocations.c @@ -8,7 +8,7 @@ * * Copyright (c) 1987,1988,1991 by the Massachusetts Institute of Technology. * For copying and distribution information, see the file - * "mit-copyright.h". + * "mit-copyright.h". */ #ifndef lint @@ -20,7 +20,7 @@ static const char rcsid_ZLocations_c[] = #include -static char host[MAXHOSTNAMELEN], mytty[MAXPATHLEN]; +static char host[NS_MAXDNAME], mytty[MAXPATHLEN]; static int location_info_set = 0; Code_t @@ -33,7 +33,7 @@ ZInitLocationInfo(char *hostname, if (hostname) { strcpy(host, hostname); } else { - if (gethostname(host, MAXHOSTNAMELEN) < 0) + if (gethostname(host, sizeof(host)) < 0) return (errno); hent = gethostbyname(host); if (hent) { @@ -59,14 +59,14 @@ ZInitLocationInfo(char *hostname, Code_t ZSetLocation(char *exposure) { - return (Z_SendLocation(LOGIN_CLASS, exposure, ZAUTH, + return (Z_SendLocation(LOGIN_CLASS, exposure, ZAUTH, "$sender logged in to $1 on $3 at $2")); } Code_t ZUnsetLocation(void) { - return (Z_SendLocation(LOGIN_CLASS, LOGIN_USER_LOGOUT, ZNOAUTH, + return (Z_SendLocation(LOGIN_CLASS, LOGIN_USER_LOGOUT, ZNOAUTH, "$sender logged out of $1 on $3 at $2")); } @@ -158,8 +158,8 @@ Z_SendLocation(char *class, } ZFreeNotice(&retnotice); return (ZERR_SERVNAK); - } - + } + if (retnotice.z_kind != SERVACK) { ZFreeNotice(&retnotice); return (ZERR_INTERNAL); @@ -177,6 +177,6 @@ Z_SendLocation(char *class, } ZFreeNotice(&retnotice); - + return (ZERR_NONE); } diff --git a/server/main.c b/server/main.c index 0086923..c519f16 100644 --- a/server/main.c +++ b/server/main.c @@ -8,7 +8,7 @@ * * Copyright (c) 1987,1988,1991 by the Massachusetts Institute of Technology. * For copying and distribution information, see the file - * "mit-copyright.h". + * "mit-copyright.h". */ #include @@ -88,7 +88,7 @@ unsigned short hm_port; /* host manager receiver port */ unsigned short hm_srv_port; /* host manager server sending port */ char *programname; /* set to the basename of argv[0] */ -char myname[MAXHOSTNAMELEN]; /* my host name */ +char myname[NS_MAXDNAME]; /* my host name */ char list_file[128]; #ifdef HAVE_KRB5 @@ -217,7 +217,7 @@ main(int argc, is no possible way we can succeed, so we exit */ if (access(srvtab_file, R_OK) -#ifdef DEBUG +#ifdef DEBUG && !zalone #endif /* DEBUG */ ) { @@ -249,7 +249,7 @@ main(int argc, if (zdebug) syslog(LOG_DEBUG, "debugging on"); - /* set up sockets & my_addr and myname, + /* set up sockets & my_addr and myname, find other servers and set up server table, initialize queues for retransmits, initialize error tables, set up restricted classes */ @@ -341,7 +341,7 @@ main(int argc, /* Initialize t_local for other uses */ gettimeofday(&t_local, (struct timezone *)0); - + /* don't flame about EINTR, since a SIGUSR1 or SIGUSR2 can generate it by interrupting the select */ if (nfound < 0) { @@ -395,7 +395,7 @@ initialize(void) krb_set_tkt_string(tkt_file); #endif realm_init(); - + ZSetServerState(1); ZInitialize(); /* set up the library */ #ifdef HAVE_KRB5 @@ -414,16 +414,16 @@ initialize(void) #endif #if defined(HAVE_KRB4) || defined(HAVE_KRB5) /* Override what Zinitialize set for ZGetRealm() */ - if (*my_realm) + if (*my_realm) strcpy(__Zephyr_realm, my_realm); #endif /* set up err table */ -#if defined(__APPLE__) && defined(__MACH__) - add_error_table(&et_zsrv_error_table); -#else - init_zsrv_err_tbl(); -#endif +#if defined(__APPLE__) && defined(__MACH__) + add_error_table(&et_zsrv_error_table); +#else + init_zsrv_err_tbl(); +#endif ZSetFD(srv_socket); /* set up the socket as the input fildes */ @@ -442,7 +442,7 @@ initialize(void) return 0; } -/* +/* * Set up the server and client sockets, and initialize my_addr and myname */ @@ -451,20 +451,20 @@ do_net_setup(void) { struct servent *sp; struct hostent *hp; - char hostname[MAXHOSTNAMELEN+1]; + char hostname[NS_MAXDNAME]; int flags; - if (gethostname(hostname, MAXHOSTNAMELEN + 1)) { + if (gethostname(hostname, sizeof(hostname))) { syslog(LOG_ERR, "no hostname: %m"); return 1; } hp = gethostbyname(hostname); if (!hp || hp->h_addrtype != AF_INET) { syslog(LOG_ERR, "no gethostbyname repsonse"); - strncpy(myname, hostname, MAXHOSTNAMELEN); + strncpy(myname, hostname, sizeof(myname)); return 1; } - strncpy(myname, hp->h_name, MAXHOSTNAMELEN); + strncpy(myname, hp->h_name, sizeof(myname)); memcpy(&my_addr, hp->h_addr_list[0], hp->h_length); setservent(1); /* keep file/connection open */ @@ -476,15 +476,15 @@ do_net_setup(void) sp = getservbyname(HM_SVCNAME, "udp"); hm_port = (sp) ? sp->s_port : HM_SVC_FALLBACK; - + sp = getservbyname(HM_SRV_SVCNAME, "udp"); hm_srv_port = (sp) ? sp->s_port : HM_SRV_SVC_FALLBACK; - + srv_socket = socket(AF_INET, SOCK_DGRAM, 0); if (srv_socket < 0) { syslog(LOG_ERR, "client_sock failed: %m"); return 1; - } + } if (bind(srv_socket, (struct sockaddr *) &srv_addr, sizeof(srv_addr)) < 0) { syslog(LOG_ERR, "client bind failed: %m"); @@ -502,7 +502,7 @@ do_net_setup(void) #endif return 0; -} +} /* @@ -665,15 +665,15 @@ reap(int sig) zdbug((LOG_DEBUG,"reap()")); #ifdef _POSIX_VERSION - while ((pid = waitpid(-1, &waitb, WNOHANG)) == 0) + while ((pid = waitpid(-1, &waitb, WNOHANG)) == 0) { i++; if (i > 10) break; } #else - while ((pid = wait3 (&waitb, WNOHANG, (struct rusage*) 0)) == 0) + while ((pid = wait3 (&waitb, WNOHANG, (struct rusage*) 0)) == 0) { i++; if (i > 10) break; } #endif errno = oerrno; - + if (pid) { if (WIFSIGNALED(waitb) == 0) { if (WIFEXITED(waitb) != 0) { diff --git a/server/realm.c b/server/realm.c index 5de5d7e..b842a2d 100644 --- a/server/realm.c +++ b/server/realm.c @@ -150,8 +150,8 @@ get_realm_lists(char *file) ZRealmname *rlm_list, *rlm; int ii, nused, ntotal; FILE *fp; - char buf[REALM_SZ + MAXHOSTNAMELEN + 1]; /* one for newline */ - char realm[REALM_SZ], server[MAXHOSTNAMELEN + 1]; + char buf[REALM_SZ + NS_MAXDNAME + 1]; /* one for newline */ + char realm[REALM_SZ], server[NS_MAXDNAME + 1]; nused = 0; if (!(fp = fopen(file, "r"))) @@ -165,7 +165,7 @@ get_realm_lists(char *file) abort(); } - while (fgets(buf, REALM_SZ + MAXHOSTNAMELEN + 1, fp)) { + while (fgets(buf, sizeof(buf), fp)) { if (sscanf(buf, "%s %s", realm, server) != 2) { syslog(LOG_CRIT, "bad format in %s", file); abort(); diff --git a/server/server.c b/server/server.c index 37eaa3e..eab6ab1 100644 --- a/server/server.c +++ b/server/server.c @@ -893,7 +893,7 @@ static char ** get_server_list(char *file) { FILE *fp; - char buf[MAXHOSTNAMELEN]; + char buf[NS_MAXDNAME]; char **ret_list; int nused = 0; char *newline; @@ -907,10 +907,10 @@ get_server_list(char *file) if (!ret_list) return NULL; - while (fgets(buf, MAXHOSTNAMELEN, fp)) { + while (fgets(buf, sizeof(buf), fp)) { /* nuke the newline, being careful not to overrun the buffer searching for it with strlen() */ - buf[MAXHOSTNAMELEN - 1] = '\0'; + buf[sizeof(buf) - 1] = '\0'; newline = strchr(buf, '\n'); if (newline) *newline = '\0'; @@ -935,7 +935,7 @@ get_server_list(char *file) static char ** get_single_server(void) { - char buf[MAXHOSTNAMELEN]; + char buf[NS_MAXDNAME]; char **ret_list; int nused = 0; nhosts = 2; diff --git a/zhm/zhm.c b/zhm/zhm.c index 8e1303d..ce9f74a 100644 --- a/zhm/zhm.c +++ b/zhm/zhm.c @@ -7,7 +7,7 @@ * * Copyright (c) 1987,1991 by the Massachusetts Institute of Technology. * For copying and distribution information, see the file - * "mit-copyright.h". + * "mit-copyright.h". */ #include "zhm.h" @@ -34,12 +34,12 @@ u_short cli_port; struct sockaddr_in cli_sin, serv_sin, from; int numserv; char **serv_list = NULL; -char prim_serv[MAXHOSTNAMELEN], cur_serv[MAXHOSTNAMELEN]; +char prim_serv[NS_MAXDNAME], cur_serv[NS_MAXDNAME]; char *zcluster; int deactivating = 0; int terminating = 0; struct hostent *hp; -char hostname[MAXHOSTNAMELEN], loopback[4]; +char hostname[NS_MAXDNAME], loopback[4]; char PidFile[128]; static RETSIGTYPE deactivate(int); @@ -81,7 +81,7 @@ main(int argc, sprintf(PidFile, "%szhm.pid", PIDDIR); - if (gethostname(hostname, MAXHOSTNAMELEN) < 0) { + if (gethostname(hostname, sizeof(hostname)) < 0) { printf("Can't find my hostname?!\n"); exit(-1); } @@ -120,8 +120,8 @@ main(int argc, break; } if (errflg) { - fprintf(stderr, "Usage: %s [-d] [-h] [-r] [-n] [-f] [server]\n", - argv[0]); + fprintf(stderr, "Usage: %s [-d] [-h] [-r] [-n] [-f] [server]\n", + argv[0]); exit(2); } @@ -167,7 +167,7 @@ main(int argc, DPR2("zephyr server port: %u\n", ntohs(serv_sin.sin_port)); DPR2("zephyr client port: %u\n", ntohs(cli_port)); - + /* Main loop */ for ever { /* Wait for incoming packets or queue timeouts. */ @@ -246,7 +246,7 @@ main(int argc, "Unknown notice type: %d", notice.z_kind); } - } + } } } } @@ -264,16 +264,16 @@ choose_server(void) if (use_hesiod) { /* Free up any previously used resources */ - if (prim_serv[0]) + if (prim_serv[0]) i = 1; while (i < numserv) free(serv_list[i++]); if (serv_list) free(serv_list); - + numserv = 0; prim_serv[0] = '\0'; - + if ((clust_info = hes_resolve(hostname, "CLUSTER")) == NULL) { zcluster = NULL; } else { @@ -284,7 +284,7 @@ choose_server(void) */ if (!strncasecmp("ZEPHYR", *cpp, 6)) { register char *c; - + if ((c = strchr(*cpp, ' ')) == 0) { printf("Hesiod error getting primary server info.\n"); } else { @@ -295,7 +295,7 @@ choose_server(void) } if (!strncasecmp("ZCLUSTER", *cpp, 9)) { register char *c; - + if ((c = strchr(*cpp, ' ')) == 0) { printf("Hesiod error getting zcluster info.\n"); } else { @@ -354,7 +354,7 @@ choose_server(void) serv_list = cpp; } #endif - + if (!prim_serv[0] && numserv) { srandom(time(NULL)); strncpy(prim_serv, serv_list[random() % numserv], sizeof(prim_serv)); @@ -374,7 +374,7 @@ init_hm(void) starttime = time((time_t *)0); OPENLOG("hm", LOG_PID, LOG_DAEMON); - + ZSetServerState(1); /* Aargh!!! */ if ((ret = ZInitialize()) != ZERR_NONE) { Zperr(ret); @@ -388,19 +388,19 @@ init_hm(void) strncpy(prim_serv, *serv_list, sizeof(prim_serv)); prim_serv[sizeof(prim_serv) - 1] = '\0'; } - + loopback[0] = 127; loopback[1] = 0; loopback[2] = 0; loopback[3] = 1; - + if (inetd) { ZSetFD(0); /* fd 0 is on the socket, thanks to inetd */ } else { /* Open client socket, for receiving client and server notices */ sp = getservbyname(HM_SVCNAME, "udp"); cli_port = (sp) ? sp->s_port : HM_SVC_FALLBACK; - + if ((ret = ZOpenPort(&cli_port)) != ZERR_NONE) { Zperr(ret); com_err("hm", ret, "opening port"); @@ -412,11 +412,11 @@ init_hm(void) sp = getservbyname(SERVER_SVCNAME, "udp"); memset(&serv_sin, 0, sizeof(struct sockaddr_in)); serv_sin.sin_port = (sp) ? sp->s_port : SERVER_SVC_FALLBACK; - + #ifndef DEBUG if (!inetd && !nofork) detach(); - + /* Write pid to file */ fp = fopen(PidFile, "w"); if (fp != NULL) { @@ -433,7 +433,7 @@ init_hm(void) /* target is SERVER_SVCNAME port on server machine */ serv_sin.sin_family = AF_INET; - + /* who to talk to */ if ((hp = gethostbyname(prim_serv)) == NULL) { DPR("gethostbyname failed\n"); @@ -441,7 +441,7 @@ init_hm(void) } else { DPR2("Server = %s\n", prim_serv); strncpy(cur_serv, prim_serv, sizeof(cur_serv)); - cur_serv[sizeof(cur_serv) - 1] = '\0'; + cur_serv[sizeof(cur_serv) - 1] = '\0'; memcpy(&serv_sin.sin_addr, hp->h_addr, 4); } @@ -456,7 +456,7 @@ init_hm(void) sa.sa_flags = 0; sa.sa_handler = deactivate; sigaction(SIGHUP, &sa, (struct sigaction *)0); - sa.sa_handler = terminate; + sa.sa_handler = terminate; sigaction(SIGTERM, &sa, (struct sigaction *)0); #else signal(SIGHUP, deactivate); @@ -518,14 +518,14 @@ send_stats(ZNotice_t *notice, unsigned long size; newnotice = *notice; - + if ((ret = ZSetDestAddr(sin)) != ZERR_NONE) { Zperr(ret); com_err("hm", ret, "setting destination"); } newnotice.z_kind = HMACK; - list[0] = (char *) malloc(MAXHOSTNAMELEN); + list[0] = (char *) malloc(NS_MAXDNAME); if (list[0] == NULL) { printf("Out of memory.\n"); exit(-5); @@ -562,7 +562,7 @@ send_stats(ZNotice_t *notice, } strncpy(list[5], rcsid_hm_c, 64); list[5][63] = '\0'; - + list[6] = (char *) malloc(64); if (list[6] == NULL) { printf("Out of memory.\n"); diff --git a/zhm/zhm_server.c b/zhm/zhm_server.c index 9d8157f..ecfa5f3 100644 --- a/zhm/zhm_server.c +++ b/zhm/zhm_server.c @@ -7,7 +7,7 @@ * * Copyright (c) 1987 by the Massachusetts Institute of Technology. * For copying and distribution information, see the file - * "mit-copyright.h". + * "mit-copyright.h". */ #include "zhm.h" @@ -46,7 +46,7 @@ send_boot_notice(char *op) { ZNotice_t notice; Code_t ret; - + /* Set up server notice */ notice.z_kind = HMCTL; notice.z_port = cli_port; @@ -58,7 +58,7 @@ send_boot_notice(char *op) notice.z_default_format = ""; notice.z_num_other_fields = 0; notice.z_message_len = 0; - + /* Notify server that this host is here */ if ((ret = ZSetDestAddr(&serv_sin)) != ZERR_NONE) { Zperr(ret); @@ -77,7 +77,7 @@ send_flush_notice(char *op) { ZNotice_t notice; Code_t ret; - + /* Set up server notice */ notice.z_kind = HMCTL; notice.z_port = cli_port; @@ -108,7 +108,7 @@ find_next_server(char *sugg_serv) int done = 0; char **parse = serv_list; char *new_serv; - + if (sugg_serv) { do { if (!strcmp(*parse, sugg_serv)) @@ -117,13 +117,13 @@ find_next_server(char *sugg_serv) } if (done) { if ((hp = gethostbyname(sugg_serv)) != NULL) { - DPR2 ("Server = %s\n", sugg_serv); - (void)strncpy(cur_serv, sugg_serv, MAXHOSTNAMELEN); - cur_serv[MAXHOSTNAMELEN - 1] = '\0'; + DPR2 ("Server = %s\n", sugg_serv); + (void)strncpy(cur_serv, sugg_serv, NS_MAXDNAME); + cur_serv[NS_MAXDNAME - 1] = '\0'; if (hmdebug) syslog(LOG_DEBUG, "Suggested server: %s\n", sugg_serv); } else { - done = 0; + done = 0; } } while (!done) { @@ -131,8 +131,8 @@ find_next_server(char *sugg_serv) serv_loop = 0; if ((hp = gethostbyname(prim_serv)) != NULL) { DPR2 ("Server = %s\n", prim_serv); - (void)strncpy(cur_serv, prim_serv, MAXHOSTNAMELEN); - cur_serv[MAXHOSTNAMELEN - 1] = '\0'; + (void)strncpy(cur_serv, prim_serv, NS_MAXDNAME); + cur_serv[NS_MAXDNAME - 1] = '\0'; done = 1; break; } @@ -142,8 +142,8 @@ find_next_server(char *sugg_serv) case 1: if ((hp = gethostbyname(*serv_list)) != NULL) { DPR2 ("Server = %s\n", *serv_list); - (void)strncpy(cur_serv, *serv_list, MAXHOSTNAMELEN); - cur_serv[MAXHOSTNAMELEN - 1] = '\0'; + (void)strncpy(cur_serv, *serv_list, NS_MAXDNAME); + cur_serv[NS_MAXDNAME - 1] = '\0'; done = 1; break; } @@ -161,8 +161,8 @@ find_next_server(char *sugg_serv) if ((hp = gethostbyname(new_serv)) != NULL) { DPR2 ("Server = %s\n", new_serv); - (void)strncpy(cur_serv, new_serv, MAXHOSTNAMELEN); - cur_serv[MAXHOSTNAMELEN - 1] = '\0'; + (void)strncpy(cur_serv, new_serv, NS_MAXDNAME); + cur_serv[NS_MAXDNAME - 1] = '\0'; done = 1; } else sleep(1); @@ -210,9 +210,9 @@ hm_control(ZNotice_t *notice) { Code_t ret; struct hostent *hp; - char suggested_server[MAXHOSTNAMELEN]; + char suggested_server[NS_MAXDNAME]; unsigned long addr; - + DPR("Control message!\n"); if (!strcmp(notice->z_opcode, SERVER_SHUTDOWN)) { if (notice->z_message_len) { @@ -253,7 +253,7 @@ send_back(ZNotice_t *notice) ZNotice_Kind_t kind; struct sockaddr_in repl; Code_t ret; - + if (!strcmp(notice->z_opcode, HM_BOOT) || !strcmp(notice->z_opcode, HM_ATTACH)) { /* ignore message, just an ack from boot, but exit if we diff --git a/zwgc/main.c b/zwgc/main.c index 2979d73..5335678 100644 --- a/zwgc/main.c +++ b/zwgc/main.c @@ -148,7 +148,7 @@ fake_startup_packet(void) zwgc_version_string); notice->z_message = msgbuf; notice->z_message_len = strlen(notice->z_message)+1; - + #ifdef CMU_ZWGCPLUS list_add_notice(notice); set_notice_fake(notice, 1); @@ -175,7 +175,7 @@ read_in_description_file(void) program = parse_file(input_file); else program = NULL; - + fake_startup_packet(); } @@ -224,10 +224,10 @@ run_initprogs(void) int status; char *progname = ZGetVariable("initprogs"); - + if (!progname) return; - + status = system(progname); if (status == 127) { perror("zwgc initprog exec"); @@ -365,19 +365,19 @@ create_punt_reply(int_dictionary_binding *punt) string binding; int key_len = strlen(punt->key); char *tmp; - + if (!punt_reply.z_message) { punt_reply.z_message = (char *)malloc(PUNT_INC); punt_reply.z_message[0] = 0; } - - if ((punt_reply.z_message_len + key_len + 1) / PUNT_INC > + + if ((punt_reply.z_message_len + key_len + 1) / PUNT_INC > (punt_reply.z_message_len + PUNT_INC - 1) / PUNT_INC) { char *new_message = (char *)malloc((punt_reply.z_message_len / PUNT_INC + 1) * PUNT_INC); - + strcpy(new_message, punt_reply.z_message); - + free(punt_reply.z_message); punt_reply.z_message = new_message; } @@ -385,7 +385,7 @@ create_punt_reply(int_dictionary_binding *punt) strcat (punt_reply.z_message, punt->key); strcat (punt_reply.z_message, "\n"); punt_reply.z_message_len += key_len + 1; - + while (*tmp != '\001') tmp++; *tmp = ','; while (*tmp != '\001') tmp++; @@ -398,7 +398,7 @@ notice_handler(ZNotice_t *notice) { #ifndef HAVE_ARES int ret; - char node[MAXDNAME]; + char node[NS_MAXDNAME]; #endif #if defined(CMU_ZWGCPLUS) @@ -414,7 +414,6 @@ notice_handler(ZNotice_t *notice) sizeof(struct sockaddr_in6) : sizeof(notice->z_sender_sockaddr), ARES_NI_LOOKUPHOST, notice_callback, notice); - #else ret = getnameinfo((const struct sockaddr *)&(notice->z_sender_sockaddr), sizeof(notice->z_sender_sockaddr), @@ -511,7 +510,7 @@ process_notice(ZNotice_t *notice, } else if (!strcasecmp(control_opcode, USER_LIST_SUPPRESSED)) { struct sockaddr_in old, to; int retval; - + if (!notice->z_port) { printf("zwgc: can't reply to LIST-SUPPRESSED request\n"); return; @@ -527,28 +526,28 @@ process_notice(ZNotice_t *notice, punt_reply.z_port = notice->z_port; punt_reply.z_message = NULL; punt_reply.z_message_len = 0; - + if (puntable_addresses_dict) { int_dictionary_Enumerate(puntable_addresses_dict, create_punt_reply); } - + old = ZGetDestAddr(); to = old; - + to.sin_port = notice->z_port; if ((retval = ZSetDestAddr(&to)) != ZERR_NONE) { com_err("zwgc",retval,"while setting destination address"); exit(1); } - + ZSendNotice(&punt_reply, ZNOAUTH); - + if ((retval = ZSetDestAddr(&old)) != ZERR_NONE) { com_err("zwgc",retval,"while resetting destination address"); exit(1); } - + if (punt_reply.z_message) { free(punt_reply.z_message); punt_reply.z_message = NULL; @@ -567,9 +566,9 @@ process_notice(ZNotice_t *notice, if (zwgc_debug) printf("NON-ACTIVE: PUNTED <%s>!!!!\n", notice->z_class_inst); #endif - goto cleanup; + goto cleanup; } - + if (puntable_address_p(notice->z_class, notice->z_class_inst, notice->z_recipient)) { @@ -644,7 +643,7 @@ setup_signals(int dofork) sigemptyset(&sa.sa_mask); sa.sa_flags = 0; - + if (dofork) { sa.sa_handler = SIG_IGN; sigaction(SIGINT, &sa, (struct sigaction *)0); @@ -682,7 +681,7 @@ setup_signals(int dofork) /* clean up on SIGINT; exiting on logout is the user's problem, now. */ signal(SIGINT, signal_exit); } - + /* behavior never changes */ signal(SIGTERM, signal_exit); signal(SIGHUP, signal_exit); @@ -725,4 +724,4 @@ detach(void) } exit(0); } -} +} diff --git a/zwgc/subscriptions.c b/zwgc/subscriptions.c index 33ff801..e146554 100644 --- a/zwgc/subscriptions.c +++ b/zwgc/subscriptions.c @@ -24,6 +24,7 @@ static const char rcsid_subscriptions_c[] = "$Id$"; #include #include #include +#include #include "new_memory.h" #include "new_string.h" #include "int_dictionary.h" @@ -231,7 +232,7 @@ unsubscribe(string class, #define TOKEN_ME "%me%" #define TOKEN_WILD "*" -char ourhost[MAXHOSTNAMELEN],ourhostcanon[MAXHOSTNAMELEN]; +char ourhost[NS_MAXDNAME], ourhostcanon[NS_MAXDNAME]; static void inithosts(void) @@ -263,7 +264,7 @@ macro_sub(char *str) if (string_Eq(str, TOKEN_ME)) strcpy(str, ZGetSender()); else if (string_Eq(str, TOKEN_HOSTNAME)) - strcpy(str, ourhost); + strcpy(str, ourhost); else if (string_Eq(str, TOKEN_CANONNAME)) strcpy(str, ourhostcanon); } @@ -278,7 +279,7 @@ load_subscriptions_from_file(FILE *file) char class_buffer[BUFSIZ], instance[BUFSIZ], recipient[BUFSIZ]; char *class, *temp; char c; - + while ((!feof(file)) && (!ferror(file))) { if (fgets(line, BUFSIZ, file)) { class = class_buffer; @@ -299,12 +300,12 @@ load_subscriptions_from_file(FILE *file) c = class[0]; if (c==UNSUBSCRIBE_CHARACTER || c==PUNT_CHARACTER) class++; - + /* perform macro substitutions */ macro_sub(class); macro_sub(instance); macro_sub(recipient); - + /* do the right thing with it */ switch (c) { case UNSUBSCRIBE_CHARACTER: @@ -321,7 +322,7 @@ load_subscriptions_from_file(FILE *file) break; } } - + if (ferror(file)) { com_err("zwgc", errno, "while reading from subscription file"); exit(1); @@ -329,7 +330,7 @@ load_subscriptions_from_file(FILE *file) flush_subscriptions(); flush_unsubscriptions(); - + fclose(file); } -- cgit v1.2.3