diff --git a/usr.sbin/bootparamd/Makefile.inc b/usr.sbin/bootparamd/Makefile.inc index 5c01215dd550..de7ed1c2f55c 100644 --- a/usr.sbin/bootparamd/Makefile.inc +++ b/usr.sbin/bootparamd/Makefile.inc @@ -1,6 +1,8 @@ # @(#)Makefile.inc 5.1 (Berkeley) 5/11/90 # $FreeBSD$ BINDIR?= /usr/sbin -WARNS?= 2 +NO_WCAST_ALIGN= +CWARNFLAGS.clang+= -Wno-incompatible-pointer-types-discards-qualifiers +CWARNFLAGS.gcc+= -Wno-error=discarded-qualifiers diff --git a/usr.sbin/bootparamd/bootparamd/bootparamd.c b/usr.sbin/bootparamd/bootparamd/bootparamd.c index 9c45cf8d0f38..7cc57d2427a4 100644 --- a/usr.sbin/bootparamd/bootparamd/bootparamd.c +++ b/usr.sbin/bootparamd/bootparamd/bootparamd.c @@ -1,365 +1,354 @@ /* This code is not copyright, and is placed in the public domain. Feel free to use and modify. Please send modifications and/or suggestions + bug fixes to Klas Heggemann */ -#ifndef lint -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ +#include +__FBSDID("$FreeBSD$"); #ifdef YP #include #include #include #endif #include "bootparam_prot.h" #include #include #include #include #include #include #include #include #include + extern int debug, dolog; extern in_addr_t route_addr; -extern char *bootpfile; +extern const char *bootpfile; #define MAXLEN 800 -struct hostent *he; +static struct hostent *he; static char buffer[MAXLEN]; static char hostname[MAX_MACHINE_NAME]; static char askname[MAX_MACHINE_NAME]; static char path[MAX_PATH_LEN]; static char domain_name[MAX_MACHINE_NAME]; -int getthefile(char *, char *, char *, int); -int checkhost(char *, char *, int); +static int getthefile(char *, char *, char *, int); +static int checkhost(char *, char *, int); bp_whoami_res * -bootparamproc_whoami_1_svc(whoami, req) -bp_whoami_arg *whoami; -struct svc_req *req; +bootparamproc_whoami_1_svc(bp_whoami_arg *whoami, struct svc_req *req __unused) { in_addr_t haddr; static bp_whoami_res res; if (debug) fprintf(stderr,"whoami got question for %d.%d.%d.%d\n", 255 & whoami->client_address.bp_address_u.ip_addr.net, 255 & whoami->client_address.bp_address_u.ip_addr.host, 255 & whoami->client_address.bp_address_u.ip_addr.lh, 255 & whoami->client_address.bp_address_u.ip_addr.impno); if (dolog) syslog(LOG_NOTICE, "whoami got question for %d.%d.%d.%d\n", 255 & whoami->client_address.bp_address_u.ip_addr.net, 255 & whoami->client_address.bp_address_u.ip_addr.host, 255 & whoami->client_address.bp_address_u.ip_addr.lh, 255 & whoami->client_address.bp_address_u.ip_addr.impno); bcopy((char *)&whoami->client_address.bp_address_u.ip_addr, (char *)&haddr, sizeof(haddr)); he = gethostbyaddr((char *)&haddr,sizeof(haddr),AF_INET); if ( ! he ) goto failed; if (debug) warnx("this is host %s", he->h_name); if (dolog) syslog(LOG_NOTICE,"This is host %s\n", he->h_name); strncpy(askname, he->h_name, sizeof(askname)); askname[sizeof(askname)-1] = 0; if (checkhost(askname, hostname, sizeof hostname) ) { res.client_name = hostname; getdomainname(domain_name, MAX_MACHINE_NAME); res.domain_name = domain_name; if ( res.router_address.address_type != IP_ADDR_TYPE ) { res.router_address.address_type = IP_ADDR_TYPE; bcopy( &route_addr, &res.router_address.bp_address_u.ip_addr, sizeof(in_addr_t)); } if (debug) fprintf(stderr, "Returning %s %s %d.%d.%d.%d\n", res.client_name, res.domain_name, 255 & res.router_address.bp_address_u.ip_addr.net, 255 & res.router_address.bp_address_u.ip_addr.host, 255 & res.router_address.bp_address_u.ip_addr.lh, 255 & res.router_address.bp_address_u.ip_addr.impno); if (dolog) syslog(LOG_NOTICE, "Returning %s %s %d.%d.%d.%d\n", res.client_name, res.domain_name, 255 & res.router_address.bp_address_u.ip_addr.net, 255 & res.router_address.bp_address_u.ip_addr.host, 255 & res.router_address.bp_address_u.ip_addr.lh, 255 & res.router_address.bp_address_u.ip_addr.impno); return(&res); } failed: if (debug) warnx("whoami failed"); if (dolog) syslog(LOG_NOTICE,"whoami failed\n"); return(NULL); } bp_getfile_res * - bootparamproc_getfile_1_svc(getfile, req) -bp_getfile_arg *getfile; -struct svc_req *req; +bootparamproc_getfile_1_svc(bp_getfile_arg *getfile, struct svc_req *req __unused) { char *where; static bp_getfile_res res; if (debug) warnx("getfile got question for \"%s\" and file \"%s\"", getfile->client_name, getfile->file_id); if (dolog) syslog(LOG_NOTICE,"getfile got question for \"%s\" and file \"%s\"\n", getfile->client_name, getfile->file_id); he = NULL; he = gethostbyname(getfile->client_name); if (! he ) goto failed; strncpy(askname, he->h_name, sizeof(askname)); askname[sizeof(askname)-1] = 0; if (getthefile(askname, getfile->file_id,buffer,sizeof(buffer))) { if ( (where = strchr(buffer,':')) ) { /* buffer is re-written to contain the name of the info of file */ strncpy(hostname, buffer, where - buffer); hostname[where - buffer] = '\0'; where++; strcpy(path, where); he = gethostbyname(hostname); if ( !he ) goto failed; bcopy( he->h_addr, &res.server_address.bp_address_u.ip_addr, 4); res.server_name = hostname; res.server_path = path; res.server_address.address_type = IP_ADDR_TYPE; } else { /* special for dump, answer with null strings */ if (!strcmp(getfile->file_id, "dump")) { res.server_name = ""; res.server_path = ""; res.server_address.address_type = IP_ADDR_TYPE; bzero(&res.server_address.bp_address_u.ip_addr,4); } else goto failed; } if (debug) fprintf(stderr, "returning server:%s path:%s address: %d.%d.%d.%d\n", res.server_name, res.server_path, 255 & res.server_address.bp_address_u.ip_addr.net, 255 & res.server_address.bp_address_u.ip_addr.host, 255 & res.server_address.bp_address_u.ip_addr.lh, 255 & res.server_address.bp_address_u.ip_addr.impno); if (dolog) syslog(LOG_NOTICE, "returning server:%s path:%s address: %d.%d.%d.%d\n", res.server_name, res.server_path, 255 & res.server_address.bp_address_u.ip_addr.net, 255 & res.server_address.bp_address_u.ip_addr.host, 255 & res.server_address.bp_address_u.ip_addr.lh, 255 & res.server_address.bp_address_u.ip_addr.impno); return(&res); } failed: if (debug) warnx("getfile failed for %s", getfile->client_name); if (dolog) syslog(LOG_NOTICE, "getfile failed for %s\n", getfile->client_name); return(NULL); } -/* getthefile return 1 and fills the buffer with the information +/* getthefile return 1 and fills the buf with the information of the file, e g "host:/export/root/client" if it can be found. - If the host is in the database, but the file is not, the buffer + If the host is in the database, but the file is not, the buf will be empty. (This makes it possible to give the special empty answer for the file "dump") */ -int -getthefile(askname,fileid,buffer,blen) -char *askname; -char *fileid, *buffer; -int blen; +static int +getthefile(char *l_askname, char *fileid, char *buf, int blen) { FILE *bpf; char *where; #ifdef YP static char *result; int resultlen; static char *yp_domain; #endif int ch, pch, fid_len, res = 0; int match = 0; #define INFOLEN 1343 _Static_assert(INFOLEN >= MAX_FILEID + MAX_PATH_LEN+MAX_MACHINE_NAME + 3, "INFOLEN isn't large enough"); char info[INFOLEN + 1]; bpf = fopen(bootpfile, "r"); if ( ! bpf ) errx(1, "no %s", bootpfile); /* XXX see comment below */ while ( fscanf(bpf, "%255s", hostname) > 0 && !match ) { if ( *hostname != '#' ) { /* comment */ - if ( ! strcmp(hostname, askname) ) { + if ( ! strcmp(hostname, l_askname) ) { match = 1; } else { he = gethostbyname(hostname); - if (he && !strcmp(he->h_name, askname)) match = 1; + if (he && !strcmp(he->h_name, l_askname)) match = 1; } } if (*hostname == '+' ) { /* NIS */ #ifdef YP if (yp_get_default_domain(&yp_domain)) { if (debug) warn("NIS"); return(0); } - if (yp_match(yp_domain, "bootparams", askname, strlen(askname), + if (yp_match(yp_domain, "bootparams", l_askname, strlen(l_askname), &result, &resultlen)) return (0); if (strstr(result, fileid) == NULL) { - buffer[0] = '\0'; + buf[0] = '\0'; } else { - snprintf(buffer, blen, + snprintf(buf, blen, "%s",strchr(strstr(result,fileid), '=') + 1); - if (strchr(buffer, ' ') != NULL) - *(char *)(strchr(buffer, ' ')) = '\0'; + if (strchr(buf, ' ') != NULL) + *(char *)(strchr(buf, ' ')) = '\0'; } if (fclose(bpf)) warnx("could not close %s", bootpfile); return(1); #else if (fclose(bpf)) warnx("could not close %s", bootpfile); return(0); /* ENOTSUP */ #endif } /* skip to next entry */ if ( match ) break; pch = ch = getc(bpf); while ( ! ( ch == '\n' && pch != '\\') && ch != EOF) { pch = ch; ch = getc(bpf); } } /* if match is true we read the rest of the line to get the info of the file */ if (match) { fid_len = strlen(fileid); #define AS_FORMAT(d) "%" #d "s" #define REXPAND(d) AS_FORMAT(d) /* Force another preprocessor expansion */ while ( ! res && (fscanf(bpf, REXPAND(INFOLEN), info)) > 0) { ch = getc(bpf); /* and a character */ if ( *info != '#' ) { /* Comment ? */ if (! strncmp(info, fileid, fid_len) && *(info + fid_len) == '=') { where = info + fid_len + 1; if ( isprint( *where )) { - strcpy(buffer, where); /* found file */ + strcpy(buf, where); /* found file */ res = 1; break; } } else { while (isspace(ch) && ch != '\n') ch = getc(bpf); /* read to end of line */ if ( ch == '\n' ) { /* didn't find it */ res = -1; break; /* but host is there */ } if ( ch == '\\' ) { /* more info */ ch = getc(bpf); /* maybe on next line */ if (ch == '\n') continue; /* read it in next loop */ ungetc(ch, bpf); ungetc('\\',bpf); /* push the character(s) back */ } else ungetc(ch, bpf); /* but who know what a `\` is */ } /* needed for. */ } else break; /* a commented rest-of-line */ } } if (fclose(bpf)) { warnx("could not close %s", bootpfile); } - if ( res == -1) buffer[0] = '\0'; /* host found, file not */ + if ( res == -1) buf[0] = '\0'; /* host found, file not */ return(match); } /* checkhost puts the hostname found in the database file in - the hostname-variable and returns 1, if askname is a valid + the l_hostname-variable and returns 1, if l_askname is a valid name for a host in the database */ -int -checkhost(askname, hostname, len) -char *askname; -char *hostname; -int len; +static int +checkhost(char *l_askname, char *l_hostname, int len) { int ch, pch; FILE *bpf; int res = 0; #ifdef YP static char *result; int resultlen; static char *yp_domain; #endif /* struct hostent *cmp_he;*/ bpf = fopen(bootpfile, "r"); if ( ! bpf ) errx(1, "no %s", bootpfile); /* XXX there is no way in ISO C to specify the maximal length for a conversion in a variable way */ - while ( fscanf(bpf, "%254s", hostname) > 0 ) { - if ( *hostname != '#' ) { /* comment */ - if ( ! strcmp(hostname, askname) ) { - /* return true for match of hostname */ + while ( fscanf(bpf, "%254s", l_hostname) > 0 ) { + if ( *l_hostname != '#' ) { /* comment */ + if ( ! strcmp(l_hostname, l_askname) ) { + /* return true for match of l_hostname */ res = 1; break; } else { /* check the alias list */ he = NULL; - he = gethostbyname(hostname); - if (he && !strcmp(askname, he->h_name)) { + he = gethostbyname(l_hostname); + if (he && !strcmp(l_askname, he->h_name)) { res = 1; break; } } } - if (*hostname == '+' ) { /* NIS */ + if (*l_hostname == '+' ) { /* NIS */ #ifdef YP if (yp_get_default_domain(&yp_domain)) { if (debug) warn("NIS"); return(0); } - if (!yp_match(yp_domain, "bootparams", askname, strlen(askname), + if (!yp_match(yp_domain, "bootparams", l_askname, strlen(l_askname), &result, &resultlen)) { /* return true for match of hostname */ he = NULL; - he = gethostbyname(askname); - if (he && !strcmp(askname, he->h_name)) { + he = gethostbyname(l_askname); + if (he && !strcmp(l_askname, he->h_name)) { res = 1; - snprintf(hostname, len, "%s", he->h_name); + snprintf(l_hostname, len, "%s", he->h_name); } } if (fclose(bpf)) warnx("could not close %s", bootpfile); return(res); #else return(0); /* ENOTSUP */ #endif } /* skip to next entry */ pch = ch = getc(bpf); while ( ! ( ch == '\n' && pch != '\\') && ch != EOF) { pch = ch; ch = getc(bpf); } } if (fclose(bpf)) { warnx("could not close %s", bootpfile); } return(res); } diff --git a/usr.sbin/bootparamd/bootparamd/main.c b/usr.sbin/bootparamd/bootparamd/main.c index 04f5ceffe36c..95b49f8f39a0 100644 --- a/usr.sbin/bootparamd/bootparamd/main.c +++ b/usr.sbin/bootparamd/bootparamd/main.c @@ -1,115 +1,118 @@ /* This code is not copyright, and is placed in the public domain. Feel free to use and modify. Please send modifications and/or suggestions + bug fixes to Klas Heggemann */ -#ifndef lint -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ +#include +__FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "bootparam_prot.h" +extern int debug, dolog; +extern in_addr_t route_addr; +extern const char *bootpfile; + int debug = 0; int dolog = 0; in_addr_t route_addr = -1; -struct sockaddr_in my_addr; -char *bootpfile = "/etc/bootparams"; +const char *bootpfile = "/etc/bootparams"; + +static struct sockaddr_in my_addr; static void usage(void); int main(int argc, char **argv) { SVCXPRT *transp; struct hostent *he; struct stat buf; int c; while ((c = getopt(argc, argv,"dsr:f:")) != -1) switch (c) { case 'd': debug = 1; break; case 'r': if (isdigit((unsigned char)*optarg)) { route_addr = inet_addr(optarg); break; } else { he = gethostbyname(optarg); if (he) { bcopy(he->h_addr, (char *)&route_addr, sizeof(route_addr)); break; } else { errx(1, "no such host %s", optarg); } } case 'f': bootpfile = optarg; break; case 's': dolog = 1; #ifndef LOG_DAEMON openlog("bootparamd", 0 , 0); #else openlog("bootparamd", 0 , LOG_DAEMON); setlogmask(LOG_UPTO(LOG_NOTICE)); #endif break; default: usage(); } if ( stat(bootpfile, &buf ) ) err(1, "%s", bootpfile); if (route_addr == INADDR_NONE) { get_myaddress(&my_addr); bcopy(&my_addr.sin_addr.s_addr, &route_addr, sizeof (route_addr)); } if (!debug) { if (daemon(0,0)) err(1, "fork"); } (void)pmap_unset(BOOTPARAMPROG, BOOTPARAMVERS); transp = svcudp_create(RPC_ANYSOCK); if (transp == NULL) errx(1, "cannot create udp service"); if (!svc_register(transp, BOOTPARAMPROG, BOOTPARAMVERS, bootparamprog_1, IPPROTO_UDP)) errx(1, "unable to register (BOOTPARAMPROG, BOOTPARAMVERS, udp)"); svc_run(); errx(1, "svc_run returned"); } static void usage(void) { fprintf(stderr, "usage: bootparamd [-d] [-s] [-r router] [-f bootparmsfile]\n"); exit(1); } diff --git a/usr.sbin/bootparamd/callbootd/callbootd.c b/usr.sbin/bootparamd/callbootd/callbootd.c index fe875093c5aa..ea1432c3140a 100644 --- a/usr.sbin/bootparamd/callbootd/callbootd.c +++ b/usr.sbin/bootparamd/callbootd/callbootd.c @@ -1,197 +1,193 @@ /* This code is not copyright, and is placed in the public domain. Feel free to use and modify. Please send modifications and/or suggestions + bug fixes to Klas Heggemann */ -#ifndef lint -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ +#include +__FBSDID("$FreeBSD$"); #include "bootparam_prot.h" #include #include #include #include #include #include #include #include /* #define bp_address_u bp_address */ #include #include -int broadcast; +static int broadcast; +static char cln[MAX_MACHINE_NAME+1]; +static char dmn[MAX_MACHINE_NAME+1]; +static char path[MAX_PATH_LEN+1]; -char cln[MAX_MACHINE_NAME+1]; -char dmn[MAX_MACHINE_NAME+1]; -char path[MAX_PATH_LEN+1]; static void usage(void); int printgetfile(bp_getfile_res *); int printwhoami(bp_whoami_res *); static bool_t eachres_whoami(bp_whoami_res *resultp, struct sockaddr_in *raddr) { struct hostent *he; he = gethostbyaddr((char *)&raddr->sin_addr.s_addr,4,AF_INET); printf("%s answered:\n", he ? he->h_name : inet_ntoa(raddr->sin_addr)); printwhoami(resultp); printf("\n"); return(0); } static bool_t eachres_getfile(bp_getfile_res *resultp, struct sockaddr_in *raddr) { struct hostent *he; he = gethostbyaddr((char *)&raddr->sin_addr.s_addr,4,AF_INET); printf("%s answered:\n", he ? he->h_name : inet_ntoa(raddr->sin_addr)); printgetfile(resultp); printf("\n"); return(0); } int main(int argc, char **argv) { char *server; bp_whoami_arg whoami_arg; bp_whoami_res *whoami_res, stat_whoami_res; bp_getfile_arg getfile_arg; bp_getfile_res *getfile_res, stat_getfile_res; - long the_inet_addr; - CLIENT *clnt; + in_addr_t the_inet_addr; + CLIENT *clnt = NULL; /* Silence warnings */ stat_whoami_res.client_name = cln; stat_whoami_res.domain_name = dmn; stat_getfile_res.server_name = cln; stat_getfile_res.server_path = path; if (argc < 3) usage(); server = argv[1]; if ( ! strcmp(server , "all") ) broadcast = 1; if ( ! broadcast ) { clnt = clnt_create(server,BOOTPARAMPROG, BOOTPARAMVERS, "udp"); if ( clnt == NULL ) errx(1, "could not contact bootparam server on host %s", server); } switch (argc) { case 3: whoami_arg.client_address.address_type = IP_ADDR_TYPE; the_inet_addr = inet_addr(argv[2]); if ( the_inet_addr == INADDR_NONE) errx(2, "bogus addr %s", argv[2]); bcopy(&the_inet_addr,&whoami_arg.client_address.bp_address_u.ip_addr,4); if (! broadcast ) { whoami_res = bootparamproc_whoami_1(&whoami_arg, clnt); printf("Whoami returning:\n"); if (printwhoami(whoami_res)) { errx(1, "bad answer returned from server %s", server); } else exit(0); } else { (void)clnt_broadcast(BOOTPARAMPROG, BOOTPARAMVERS, BOOTPARAMPROC_WHOAMI, (xdrproc_t)xdr_bp_whoami_arg, (char *)&whoami_arg, (xdrproc_t)xdr_bp_whoami_res, (char *)&stat_whoami_res, (resultproc_t)eachres_whoami); exit(0); } case 4: getfile_arg.client_name = argv[2]; getfile_arg.file_id = argv[3]; if (! broadcast ) { getfile_res = bootparamproc_getfile_1(&getfile_arg,clnt); printf("getfile returning:\n"); if (printgetfile(getfile_res)) { errx(1, "bad answer returned from server %s", server); } else exit(0); } else { (void)clnt_broadcast(BOOTPARAMPROG, BOOTPARAMVERS, BOOTPARAMPROC_GETFILE, (xdrproc_t)xdr_bp_getfile_arg, (char *)&getfile_arg, (xdrproc_t)xdr_bp_getfile_res, (char *)&stat_getfile_res, (resultproc_t)eachres_getfile); exit(0); } default: usage(); } } static void -usage() +usage(void) { fprintf(stderr, "usage: callbootd server procnum (IP-addr | host fileid)\n"); exit(1); } int -printwhoami(res) -bp_whoami_res *res; +printwhoami(bp_whoami_res *res) { if ( res) { printf("client_name:\t%s\ndomain_name:\t%s\n", res->client_name, res->domain_name); printf("router:\t%d.%d.%d.%d\n", 255 & res->router_address.bp_address_u.ip_addr.net, 255 & res->router_address.bp_address_u.ip_addr.host, 255 & res->router_address.bp_address_u.ip_addr.lh, 255 & res->router_address.bp_address_u.ip_addr.impno); return(0); } else { warnx("null answer!!!"); return(1); } } int -printgetfile(res) -bp_getfile_res *res; +printgetfile(bp_getfile_res *res) { if (res) { printf("server_name:\t%s\nserver_address:\t%s\npath:\t%s\n", res->server_name, inet_ntoa(*(struct in_addr *)&res->server_address.bp_address_u.ip_addr), res->server_path); return(0); } else { warnx("null answer!!!"); return(1); } }