/* * Check whether host h is in our local domain, * defined as sharing the last two components of the domain part, * or the entire domain part if the local domain has only one component. * If either name is unqualified (contains no '.'), * assume that the host is local, as it will be * interpreted as such. */ int local_domain(char *h) { char localhost[MAXHOSTNAMELEN]; char *p1, *p2; localhost[0] = 0; (void) gethostname(localhost, sizeof(localhost)); p1 = topdomain(localhost); p2 = topdomain(h); if (p1 == NULL || p2 == NULL || !strcasecmp(p1, p2)) return (1); return (0); }
int in_local_domain (char *hostname) { char *p = topdomain (hostname, local_dot_count); return p && strcasecmp (p, local_domain_name) == 0; }
int main (int argc, char *argv[]) { int index; set_program_name (argv[0]); /* Parse command line */ iu_argp_init ("rlogind", program_authors); argp_parse (&argp, argc, argv, 0, &index, NULL); openlog ("rlogind", LOG_PID | LOG_CONS, LOG_AUTH); argc -= index; if (argc > 0) { syslog (LOG_ERR, "%d extra arguments", argc); exit (1); } signal (SIGHUP, SIG_IGN); if (!local_domain_name) { char *p = localhost (); if (!p) { syslog (LOG_ERR, "can't determine local hostname"); exit (1); } local_dot_count = 2; local_domain_name = topdomain (p, local_dot_count); } else { char *p; local_dot_count = 0; for (p = local_domain_name; *p; p++) if (*p == '.') local_dot_count++; } if (mode == MODE_DAEMON) rlogin_daemon (maxchildren, port); else exit (rlogind_mainloop (fileno (stdin), fileno (stdout))); return 0; }