1/* $NetBSD: timed.c,v 1.30 2023/08/08 06:31:58 mrg Exp $ */ 2 3/*- 4 * Copyright (c) 1985, 1993 The Regents of the University of California. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. Neither the name of the University nor the names of its contributors 16 * may be used to endorse or promote products derived from this software 17 * without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 */ 31 32#include <sys/cdefs.h> 33#ifndef lint 34__COPYRIGHT("@(#) Copyright (c) 1985, 1993\ 35 The Regents of the University of California. All rights reserved."); 36#endif /* not lint */ 37 38#ifndef lint 39#if 0 40static char sccsid[] = "@(#)timed.c 8.2 (Berkeley) 3/26/95"; 41#else 42__RCSID("$NetBSD: timed.c,v 1.30 2023/08/08 06:31:58 mrg Exp $"); 43#endif 44#endif /* not lint */ 45 46#define TSPTYPES 47#include "globals.h" 48#include <net/if.h> 49#include <sys/file.h> 50#include <sys/ioctl.h> 51#include <setjmp.h> 52#include "pathnames.h" 53#include <math.h> 54#include <sys/types.h> 55#include <sys/times.h> 56#include <util.h> 57#include <ifaddrs.h> 58#include <err.h> 59 60#ifdef HAVENIS 61#include <netgroup.h> 62#endif 63 64int trace = 0; 65int sock, sock_raw = -1; 66int status = 0; 67u_short sequence; /* sequence number */ 68long delay1; 69long delay2; 70 71int nslavenets; /* nets where I could be a slave */ 72int nmasternets; /* nets where I could be a master */ 73int nignorednets; /* ignored nets */ 74int nnets; /* nets I am connected to */ 75 76FILE *fd; /* trace file FD */ 77 78jmp_buf jmpenv; 79 80struct netinfo *nettab = 0; 81struct netinfo *slavenet; 82int Mflag; 83int justquit = 0; 84int debug; 85 86static struct nets { 87 char *name; 88 in_addr_t net; 89 struct nets *next; 90} *nets = 0; 91 92struct hosttbl hosttbl[NHOSTS+1]; /* known hosts */ 93 94static struct goodhost { /* hosts that we trust */ 95 char name[MAXHOSTNAMELEN+1]; 96 struct goodhost *next; 97 char perm; 98} *goodhosts; 99 100static char *goodgroup; /* net group of trusted hosts */ 101static void checkignorednets(void); 102static void pickslavenet(struct netinfo *); 103static void add_good_host(const char*,char); 104 105 106/* 107 * The timedaemons synchronize the clocks of hosts in a local area network. 108 * One daemon runs as master, all the others as slaves. The master 109 * performs the task of computing clock differences and sends correction 110 * values to the slaves. 111 * Slaves start an election to choose a new master when the latter disappears 112 * because of a machine crash, network partition, or when killed. 113 * A resolution protocol is used to kill all but one of the masters 114 * that happen to exist in segments of a partitioned network when the 115 * network partition is fixed. 116 * 117 * Authors: Riccardo Gusella & Stefano Zatti 118 */ 119 120int 121main(int argc, char *argv[]) 122{ 123 int on; 124 int ret; 125 int nflag, iflag; 126 struct timeval ntime; 127 struct servent *srvp; 128 struct netinfo *ntp; 129 struct netinfo *ntip; 130 struct netinfo *savefromnet; 131 struct netent *nentp; 132 struct nets *nt; 133 struct sockaddr_in server; 134 uint16_t port; 135 int c; 136 extern char *optarg; 137 extern int optind, opterr; 138 struct ifaddrs *ifap, *ifa; 139 140#define IN_MSG "-i and -n make no sense together\n" 141#ifdef HAVENIS 142#define USAGE "[-dtM] [-i net|-n net] [-F host1 host2 ...] [-G netgp]\n" 143#else 144#define USAGE "[-dtM] [-i net|-n net] [-F host1 host2 ...]\n" 145#endif /* HAVENIS */ 146 147 ntip = NULL; 148 149 on = 1; 150 nflag = OFF; 151 iflag = OFF; 152 153 opterr = 0; 154 while ((c = getopt(argc, argv, "Mtdn:i:F:G:")) != -1) { 155 switch (c) { 156 case 'M': 157 Mflag = 1; 158 break; 159 160 case 't': 161 trace = 1; 162 break; 163 164 case 'n': 165 if (iflag) 166 errx(EXIT_FAILURE, "%s", IN_MSG); 167 nflag = ON; 168 addnetname(optarg); 169 break; 170 171 case 'i': 172 if (nflag) 173 errx(EXIT_FAILURE, "%s", IN_MSG); 174 iflag = ON; 175 addnetname(optarg); 176 break; 177 178 case 'F': 179 add_good_host(optarg,1); 180 while (optind < argc && argv[optind][0] != '-') 181 add_good_host(argv[optind++], 1); 182 break; 183 184 case 'd': 185 debug = 1; 186 break; 187 case 'G': 188 if (goodgroup != 0) 189 errx(EXIT_FAILURE, "timed: only one net group"); 190 goodgroup = optarg; 191 break; 192 default: 193 errx(EXIT_FAILURE, "%s", USAGE); 194 break; 195 } 196 } 197 if (optind < argc) 198 errx(EXIT_FAILURE, "%s", USAGE); 199 200 /* If we care about which machine is the master, then we must 201 * be willing to be a master 202 */ 203 if (0 != goodgroup || 0 != goodhosts) 204 Mflag = 1; 205 206 if (gethostname(hostname, sizeof(hostname)) < 0) 207 err(EXIT_FAILURE, "gethostname"); 208 209 hostname[sizeof(hostname) - 1] = '\0'; 210 self.l_bak = &self; 211 self.l_fwd = &self; 212 self.h_bak = &self; 213 self.h_fwd = &self; 214 self.head = 1; 215 self.good = 1; 216 217 if (goodhosts != 0) /* trust ourself */ 218 add_good_host(hostname,1); 219 220 srvp = getservbyname("timed", "udp"); 221 if (srvp == NULL) 222 errx(EXIT_FAILURE, "unknown service 'timed/udp'"); 223 224 port = srvp->s_port; 225 (void)memset(&server, 0, sizeof(server)); 226 server.sin_port = srvp->s_port; 227 server.sin_family = AF_INET; 228 sock = socket(AF_INET, SOCK_DGRAM, 0); 229 if (sock < 0) 230 err(EXIT_FAILURE, "socket"); 231 232 if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)) < 0) 233 err(EXIT_FAILURE, "setsockopt"); 234 235 if (bind(sock, (struct sockaddr*)(void *)&server, sizeof(server))) { 236 if (errno == EADDRINUSE) 237 errx(EXIT_FAILURE, "time daemon already running"); 238 else 239 err(EXIT_FAILURE, "bind"); 240 } 241 242 /* initial seq number */ 243 sequence = (u_short)arc4random_uniform(UINT16_MAX); 244 245 /* rounds kernel variable time to multiple of 5 ms. */ 246 ntime.tv_sec = 0; 247 ntime.tv_usec = -((ntime.tv_usec/1000) % 5) * 1000; 248 (void)adjtime(&ntime, (struct timeval *)0); 249 250 for (nt = nets; nt; nt = nt->next) { 251 nentp = getnetbyname(nt->name); 252 if (nentp == 0) { 253 nt->net = inet_network(nt->name); 254 if (nt->net != INADDR_NONE) 255 nentp = getnetbyaddr(nt->net, AF_INET); 256 } 257 if (nentp != 0) 258 nt->net = nentp->n_net; 259 else if (nt->net == INADDR_NONE) 260 errx(EXIT_FAILURE, "unknown net %s", nt->name); 261 else if (nt->net == INADDR_ANY) 262 errx(EXIT_FAILURE, "bad net %s", nt->name); 263 else 264 warnx("warning: %s unknown in /etc/networks", 265 nt->name); 266 267 if (0 == (nt->net & 0xff000000)) 268 nt->net <<= 8; 269 if (0 == (nt->net & 0xff000000)) 270 nt->net <<= 8; 271 if (0 == (nt->net & 0xff000000)) 272 nt->net <<= 8; 273 } 274 if (getifaddrs(&ifap) != 0) 275 err(EXIT_FAILURE, "get interface configuration"); 276 277 ntp = NULL; 278 for (ifa = ifap; ifa; ifa = ifa->ifa_next) { 279 if (ifa->ifa_addr->sa_family != AF_INET) 280 continue; 281 if (!ntp) 282 ntp = malloc(sizeof(struct netinfo)); 283 (void)memset(ntp, 0, sizeof(*ntp)); 284 ntp->my_addr=((struct sockaddr_in *)(void *)ifa->ifa_addr)->sin_addr; 285 ntp->status = NOMASTER; 286 287 if ((ifa->ifa_flags & IFF_UP) == 0) 288 continue; 289 if ((ifa->ifa_flags & IFF_BROADCAST) == 0 && 290 (ifa->ifa_flags & IFF_POINTOPOINT) == 0) { 291 continue; 292 } 293 294 ntp->mask = ((struct sockaddr_in *)(void *) 295 ifa->ifa_netmask)->sin_addr.s_addr; 296 297 if (ifa->ifa_flags & IFF_BROADCAST) { 298 ntp->dest_addr = *(struct sockaddr_in *)(void *)ifa->ifa_broadaddr; 299 /* What if the broadcast address is all ones? 300 * So we cannot just mask ntp->dest_addr. */ 301 ntp->net = ntp->my_addr; 302 ntp->net.s_addr &= ntp->mask; 303 } else { 304 ntp->dest_addr = *(struct sockaddr_in *)(void *)ifa->ifa_dstaddr; 305 ntp->net = ntp->dest_addr.sin_addr; 306 } 307 308 ntp->dest_addr.sin_port = port; 309 310 for (nt = nets; nt; nt = nt->next) { 311 if (ntohl(ntp->net.s_addr) == nt->net) 312 break; 313 } 314 if ((nflag && !nt) || (iflag && nt)) 315 continue; 316 317 ntp->next = NULL; 318 if (nettab == NULL) { 319 nettab = ntp; 320 } else { 321 ntip->next = ntp; 322 } 323 ntip = ntp; 324 ntp = NULL; 325 } 326 freeifaddrs(ifap); 327 if (ntp) 328 (void) free(ntp); 329 if (nettab == NULL) 330 errx(EXIT_FAILURE, "no network usable"); 331 332 333 /* microseconds to delay before responding to a broadcast */ 334 delay1 = 1L + arc4random_uniform((100 * 1000L) - 1L); 335 336 /* election timer delay in secs. */ 337 delay2 = MINTOUT + arc4random_uniform(MAXTOUT - MINTOUT); 338 339 if (!debug) { 340 daemon(debug, 0); 341 pidfile(NULL); 342 } 343 344 if (trace) 345 traceon(); 346 openlog("timed", LOG_PID, LOG_DAEMON); 347 348 /* 349 * keep returning here 350 */ 351 ret = setjmp(jmpenv); 352 savefromnet = fromnet; 353 setstatus(); 354 355 if (Mflag) { 356 switch (ret) { 357 358 case 0: 359 checkignorednets(); 360 pickslavenet(0); 361 break; 362 case 1: 363 /* Just lost our master */ 364 if (slavenet != 0) 365 slavenet->status = election(slavenet); 366 if (!slavenet || slavenet->status == MASTER) { 367 checkignorednets(); 368 pickslavenet(0); 369 } else { 370 makeslave(slavenet); /* prune extras */ 371 } 372 break; 373 374 case 2: 375 /* Just been told to quit */ 376 justquit = 1; 377 pickslavenet(savefromnet); 378 break; 379 } 380 381 setstatus(); 382 if (!(status & MASTER) && sock_raw != -1) { 383 /* sock_raw is not being used now */ 384 (void)close(sock_raw); 385 sock_raw = -1; 386 } 387 388 if (status == MASTER) 389 master(); 390 else 391 slave(); 392 393 } else { 394 if (sock_raw != -1) { 395 (void)close(sock_raw); 396 sock_raw = -1; 397 } 398 399 if (ret) { 400 /* we just lost our master or were told to quit */ 401 justquit = 1; 402 } 403 for (ntp = nettab; ntp != NULL; ntp = ntp->next) { 404 if (ntp->status == MASTER) { 405 rmnetmachs(ntp); 406 ntp->status = NOMASTER; 407 } 408 } 409 checkignorednets(); 410 pickslavenet(0); 411 setstatus(); 412 413 slave(); 414 } 415 /* NOTREACHED */ 416 return(0); 417} 418 419 420/* suppress an upstart, untrustworthy, self-appointed master 421 */ 422void 423suppress(struct sockaddr_in *addr, char *name, struct netinfo *net) 424{ 425 struct sockaddr_in tgt; 426 char tname[MAXHOSTNAMELEN]; 427 struct tsp msg; 428 static struct timeval wait; 429 430 if (trace) 431 fprintf(fd, "suppress: %s\n", name); 432 tgt = *addr; 433 (void)strlcpy(tname, name, sizeof(tname)); 434 435 while (0 != readmsg(TSP_ANY, ANYADDR, &wait, net)) { 436 if (trace) 437 fprintf(fd, "suppress:\tdiscarded packet from %s\n", 438 name); 439 } 440 441 syslog(LOG_NOTICE, "suppressing false master %s", tname); 442 msg.tsp_type = TSP_QUIT; 443 set_tsp_name(&msg, hostname); 444 (void)acksend(&msg, &tgt, tname, TSP_ACK, 0, 1); 445} 446 447void 448lookformaster(struct netinfo *ntp) 449{ 450 struct tsp resp, conflict, *answer; 451 struct timeval ntime; 452 char mastername[MAXHOSTNAMELEN]; 453 struct sockaddr_in masteraddr; 454 455 get_goodgroup(0); 456 ntp->status = SLAVE; 457 458 /* look for master */ 459 resp.tsp_type = TSP_MASTERREQ; 460 set_tsp_name(&resp, hostname); 461 answer = acksend(&resp, &ntp->dest_addr, ANYADDR, 462 TSP_MASTERACK, ntp, 0); 463 if (answer != 0 && !good_host_name(answer->tsp_name)) { 464 suppress(&from, answer->tsp_name, ntp); 465 ntp->status = NOMASTER; 466 answer = 0; 467 } 468 if (answer == 0) { 469 /* 470 * Various conditions can cause conflict: races between 471 * two just started timedaemons when no master is 472 * present, or timedaemons started during an election. 473 * A conservative approach is taken. Give up and become a 474 * slave, postponing election of a master until first 475 * timer expires. 476 */ 477 ntime.tv_sec = ntime.tv_usec = 0; 478 answer = readmsg(TSP_MASTERREQ, ANYADDR, &ntime, ntp); 479 if (answer != 0) { 480 if (!good_host_name(answer->tsp_name)) { 481 suppress(&from, answer->tsp_name, ntp); 482 ntp->status = NOMASTER; 483 } 484 return; 485 } 486 487 ntime.tv_sec = ntime.tv_usec = 0; 488 answer = readmsg(TSP_MASTERUP, ANYADDR, &ntime, ntp); 489 if (answer != 0) { 490 if (!good_host_name(answer->tsp_name)) { 491 suppress(&from, answer->tsp_name, ntp); 492 ntp->status = NOMASTER; 493 } 494 return; 495 } 496 497 ntime.tv_sec = ntime.tv_usec = 0; 498 answer = readmsg(TSP_ELECTION, ANYADDR, &ntime, ntp); 499 if (answer != 0) { 500 if (!good_host_name(answer->tsp_name)) { 501 suppress(&from, answer->tsp_name, ntp); 502 ntp->status = NOMASTER; 503 } 504 return; 505 } 506 507 if (Mflag) 508 ntp->status = MASTER; 509 else 510 ntp->status = NOMASTER; 511 return; 512 } 513 514 ntp->status = SLAVE; 515 get_tsp_name(answer, mastername, sizeof(mastername)); 516 masteraddr = from; 517 518 /* 519 * If network has been partitioned, there might be other 520 * masters; tell the one we have just acknowledged that 521 * it has to gain control over the others. 522 */ 523 ntime.tv_sec = 0; 524 ntime.tv_usec = 300000; 525 answer = readmsg(TSP_MASTERACK, ANYADDR, &ntime, ntp); 526 /* 527 * checking also not to send CONFLICT to ack'ed master 528 * due to duplicated MASTERACKs 529 */ 530 if (answer != NULL && 531 strcmp(answer->tsp_name, mastername) != 0) { 532 conflict.tsp_type = TSP_CONFLICT; 533 set_tsp_name(&conflict, hostname); 534 if (!acksend(&conflict, &masteraddr, mastername, 535 TSP_ACK, 0, 0)) { 536 syslog(LOG_ERR, 537 "error on sending TSP_CONFLICT"); 538 } 539 } 540} 541 542/* 543 * based on the current network configuration, set the status, and count 544 * networks; 545 */ 546void 547setstatus(void) 548{ 549 struct netinfo *ntp; 550 551 status = 0; 552 nmasternets = nslavenets = nnets = nignorednets = 0; 553 if (trace) 554 fprintf(fd, "Net status:\n"); 555 for (ntp = nettab; ntp != NULL; ntp = ntp->next) { 556 switch ((int)ntp->status) { 557 case MASTER: 558 nmasternets++; 559 break; 560 case SLAVE: 561 nslavenets++; 562 break; 563 case NOMASTER: 564 case IGNORE: 565 nignorednets++; 566 break; 567 } 568 if (trace) { 569 fprintf(fd, "\t%-16s", inet_ntoa(ntp->net)); 570 switch ((int)ntp->status) { 571 case NOMASTER: 572 fprintf(fd, "NOMASTER\n"); 573 break; 574 case MASTER: 575 fprintf(fd, "MASTER\n"); 576 break; 577 case SLAVE: 578 fprintf(fd, "SLAVE\n"); 579 break; 580 case IGNORE: 581 fprintf(fd, "IGNORE\n"); 582 break; 583 default: 584 fprintf(fd, "invalid state %d\n", 585 (int)ntp->status); 586 break; 587 } 588 } 589 nnets++; 590 status |= ntp->status; 591 } 592 status &= ~IGNORE; 593 if (trace) 594 fprintf(fd, 595 "\tnets=%d masters=%d slaves=%d ignored=%d delay2=%ld\n", 596 nnets, nmasternets, nslavenets, nignorednets, (long)delay2); 597} 598 599void 600makeslave(struct netinfo *net) 601{ 602 struct netinfo *ntp; 603 604 for (ntp = nettab; ntp != NULL; ntp = ntp->next) { 605 if (ntp->status == SLAVE && ntp != net) 606 ntp->status = IGNORE; 607 } 608 slavenet = net; 609} 610 611/* 612 * Try to become master over ignored nets.. 613 */ 614static void 615checkignorednets(void) 616{ 617 struct netinfo *ntp; 618 619 for (ntp = nettab; ntp != NULL; ntp = ntp->next) { 620 if (!Mflag && ntp->status == SLAVE) 621 break; 622 623 if (ntp->status == IGNORE || ntp->status == NOMASTER) { 624 lookformaster(ntp); 625 if (!Mflag && ntp->status == SLAVE) 626 break; 627 } 628 } 629} 630 631/* 632 * choose a good network on which to be a slave 633 * The ignored networks must have already been checked. 634 * Take a hint about for a good network. 635 */ 636static void 637pickslavenet(struct netinfo *ntp) 638{ 639 if (slavenet != 0 && slavenet->status == SLAVE) { 640 makeslave(slavenet); /* prune extras */ 641 return; 642 } 643 644 if (ntp == 0 || ntp->status != SLAVE) { 645 for (ntp = nettab; ntp != 0; ntp = ntp->next) { 646 if (ntp->status == SLAVE) 647 break; 648 } 649 } 650 makeslave(ntp); 651} 652 653char * 654date(void) 655{ 656 struct timeval tv; 657 time_t t; 658 659 (void)gettimeofday(&tv, (struct timezone *)0); 660 t = tv.tv_sec; 661 return (ctime(&t)); 662} 663 664void 665addnetname(char *name) 666{ 667 struct nets **netlist = &nets; 668 669 while (*netlist) 670 netlist = &((*netlist)->next); 671 *netlist = calloc(1, sizeof **netlist); 672 if (*netlist == NULL) 673 err(EXIT_FAILURE, "malloc failed"); 674 (*netlist)->name = name; 675} 676 677/* note a host as trustworthy */ 678static void 679add_good_host(const char* name, 680 char perm) /* 1=not part of the netgroup */ 681{ 682 struct goodhost *ghp; 683 struct hostent *hentp; 684 685 ghp = calloc(1, sizeof(*ghp)); 686 if (!ghp) { 687 syslog(LOG_ERR, "malloc failed"); 688 exit(EXIT_FAILURE); 689 } 690 691 (void)strncpy(&ghp->name[0], name, sizeof(ghp->name) - 1); 692 ghp->name[sizeof(ghp->name) - 1] = 0; 693 ghp->next = goodhosts; 694 ghp->perm = perm; 695 goodhosts = ghp; 696 697 hentp = gethostbyname(name); 698 if (NULL == hentp && perm) 699 warnx("unknown host %s", name); 700} 701 702 703/* update our image of the net-group of trustworthy hosts 704 */ 705void 706get_goodgroup(int force) 707{ 708# define NG_DELAY (30*60*CLK_TCK) /* 30 minutes */ 709 static unsigned long last_update; 710 static int firsttime; 711 unsigned long new_update; 712 struct goodhost *ghp, **ghpp; 713#ifdef HAVENIS 714 struct hosttbl *htp; 715 const char *mach, *usr, *dom; 716#endif 717 struct tms tm; 718 719 if (firsttime == 0) { 720 last_update = -NG_DELAY; 721 firsttime++; 722 } 723 724 /* if no netgroup, then we are finished */ 725 if (goodgroup == 0 || !Mflag) 726 return; 727 728 /* Do not chatter with the netgroup master too often. 729 */ 730 new_update = times(&tm); 731 if (new_update < last_update + NG_DELAY 732 && !force) 733 return; 734 last_update = new_update; 735 736 /* forget the old temporary entries */ 737 ghpp = &goodhosts; 738 while (0 != (ghp = *ghpp)) { 739 if (!ghp->perm) { 740 *ghpp = ghp->next; 741 free(ghp); 742 } else { 743 ghpp = &ghp->next; 744 } 745 } 746 747#ifdef HAVENIS 748 /* quit now if we are not one of the trusted masters 749 */ 750 if (!innetgr(goodgroup, &hostname[0], 0,0)) { 751 if (trace) 752 (void)fprintf(fd, "get_goodgroup: %s not in %s\n", 753 &hostname[0], goodgroup); 754 return; 755 } 756 if (trace) 757 (void)fprintf(fd, "get_goodgroup: %s in %s\n", 758 &hostname[0], goodgroup); 759 760 /* mark the entire netgroup as trusted */ 761 (void)setnetgrent(goodgroup); 762 while (getnetgrent(&mach,&usr,&dom)) { 763 if (0 != mach) 764 add_good_host(mach,0); 765 } 766 (void)endnetgrent(); 767 768 /* update list of slaves */ 769 for (htp = self.l_fwd; htp != &self; htp = htp->l_fwd) { 770 htp->good = good_host_name(&htp->name[0]); 771 } 772#endif /* HAVENIS */ 773} 774 775 776/* see if a machine is trustworthy 777 */ 778int /* 1=trust hp to change our date */ 779good_host_name(char *name) 780{ 781 struct goodhost *ghp = goodhosts; 782 char c; 783 784 if (!ghp || !Mflag) /* trust everyone if no one named */ 785 return 1; 786 787 c = *name; 788 do { 789 if (c == ghp->name[0] 790 && !strcasecmp(name, ghp->name)) 791 return 1; /* found him, so say so */ 792 } while (0 != (ghp = ghp->next)); 793 794 if (!strcasecmp(name,hostname)) /* trust ourself */ 795 return 1; 796 797 return 0; /* did not find him */ 798} 799