head 1.4; access; symbols OPENPKG_E1_MP_HEAD:1.4 OPENPKG_E1_MP:1.4 OPENPKG_E1_MP_2_STABLE:1.4 OPENPKG_E1_FP:1.4 OPENPKG_2_STABLE_MP:1.4 OPENPKG_2_STABLE_20061018:1.4 OPENPKG_2_STABLE_20060622:1.4 OPENPKG_2_STABLE:1.4.0.2 OPENPKG_2_STABLE_BP:1.4 OPENPKG_2_5_RELEASE:1.3.4.1 OPENPKG_2_5_SOLID:1.3.0.4 OPENPKG_2_5_SOLID_BP:1.3 OPENPKG_2_4_RELEASE:1.3 OPENPKG_2_4_SOLID:1.3.0.2 OPENPKG_2_4_SOLID_BP:1.3; locks; strict; comment @# @; 1.4 date 2005.10.15.08.17.06; author rse; state Exp; branches; next 1.3; 1.3 date 2005.06.10.20.36.59; author rse; state Exp; branches 1.3.4.1; next 1.2; 1.2 date 2005.03.31.16.04.05; author rse; state Exp; branches; next 1.1; 1.1 date 2005.03.31.14.37.37; author rse; state Exp; branches; next ; 1.3.4.1 date 2005.10.15.08.17.42; author rse; state Exp; branches; next ; desc @@ 1.4 log @avoid a snvprintf to be mapped to libintl_snvprintf by the gettext libintl.h header and this way cause a symbol conflict @ text @Index: src/in.swhoisd.h --- src/in.swhoisd.h.orig 2001-07-10 18:17:55 +0200 +++ src/in.swhoisd.h 2005-03-31 16:31:13 +0200 @@@@ -33,12 +33,14 @@@@ #endif #define MAXLINE 1024 /* for buffering purposes */ -#define MYNAME "in.swhoisd" +#define MYNAME "swhoisd" #define NLS_DOMAIN "swhoisd" /* for GNU gettext */ #define SYSCONFDIR "/etc" #define SYSLOGDIR "/var/log" +#define SYSPIDDIR "/var/run" #define DAEMON_LOG_FILENAME SYSLOGDIR "/swhoisd.log" +#define DAEMON_PID_FILENAME SYSLOGDIR "/swhoisd.pid" /* We use the HTTPD "Common Logfile Format"'s time stamp format: */ #define TIMESTAMP_FORMAT "%d/%b/%Y:%H:%M:%M" @@@@ -110,6 +112,8 @@@@ extern int standalone_mode; /* -s flag (-i disables) */ extern uid_t desired_uid; /* -u flag */ extern gid_t desired_gid; /* -u flag */ +extern char * desired_host; /* -h flag */ +extern char * desired_port; /* -p flag */ /* Perform the requested whois operation: */ int do_whois(FILE *in_fd, FILE *out_fd, char *ident); Index: src/main.c --- src/main.c.orig 2001-07-04 08:15:04 +0200 +++ src/main.c 2005-03-31 16:30:41 +0200 @@@@ -38,6 +38,8 @@@@ #endif uid_t desired_uid; /* -u flag */ gid_t desired_gid; /* -u flag */ +char * desired_host; /* -H flag */ +char * desired_port; /* -P flag */ /* @@@@ -95,6 +97,8 @@@@ /* Set default values for various options */ desired_uid = get_nobody_uid(); desired_gid = get_nogroup_gid(); + desired_host = ""; + desired_port = "43"; #ifndef INET_ONLY /* If stdin is a socket, default to inetd mode: */ @@@@ -104,7 +108,7 @@@@ #endif /* Parse command line options, if any */ - while ((c = getopt(argc, argv, "d:g:hlnsu:")) != EOF) { + while ((c = getopt(argc, argv, "d:g:hlnsu:H:P:")) != EOF) { switch (c) { case 'd': delay_time = atoi(optarg); @@@@ -132,6 +136,12 @@@@ case 'u': desired_uid = atoi(optarg); break; + case 'H': + desired_host = optarg; + break; + case 'P': + desired_port = optarg; + break; case 'h': /*FALLTHROUGH*/ case '?': /*FALLTHROUGH*/ default: Index: src/sysutils.c --- src/sysutils.c.orig 2004-01-04 06:38:16 +0100 +++ src/sysutils.c 2005-03-31 18:02:25 +0200 @@@@ -31,6 +31,40 @@@@ #include /* getgrnam_r() */ #include /* getpwnam_r() */ +#ifdef __FreeBSD__ +#include +#endif +#if !((defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__linux__) || defined(__sun__)) +int my_getpwnam_r(const char *name, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result) +{ + int rv = 0; + struct passwd *lpwd; + + if ((lpwd = getpwnam(name)) != NULL) + memcpy(pwd, lpwd, sizeof(struct passwd)); + else + rv = errno; + if (result != NULL) + *result = (rv == 0 ? pwd : NULL); + return rv; +} +int my_getgrnam_r(const char *name, struct group *grp, char *buffer, size_t bufsize, struct group **result) +{ + int rv = 0; + struct group *lgrp; + + if ((lgrp = getgrnam(name)) != NULL) + memcpy(grp, lgrp, sizeof(struct group)); + else + rv = errno; + if (result != NULL) + *result = (rv == 0 ? grp : NULL); + return rv; +} +#define getpwnam_r my_getpwnam_r +#define getgrnam_r my_getgrnam_r +#endif + /* * Socket stuff */ @@@@ -77,7 +111,7 @@@@ } -#if __sun +#ifndef __linux__ /* * Return 1 if the fd is of the specified type, 0 if not, -1 on error. * Present in Linux (sys/socket.h), but not Solaris. @@@@ -171,6 +205,19 @@@@ (void) dup(0); (void) dup(0); + /* write a daemon pidfile */ + { + pid_t pid; + FILE *fp; + pid = getpid(); + if ((fp = fopen(DAEMON_PID_FILENAME, "w")) == NULL) { + fprintf(stderr, "swhoisd: Can't write pidfile '%s'", DAEMON_PID_FILENAME); + exit(1); + } + fprintf(fp, "%ld\n", (long)pid); + fclose(fp); + } + return (0); /* OK */ } @@@@ -187,7 +234,7 @@@@ time_t curtime = 0L; struct tm *loctime = NULL; struct tm tm_buf; - extern time_t timezone; /* not set until AFTER localtime_r called */ + time_t timezone; time_t timezone_minutes; if ((buffer == NULL) || (buffer_size <= 0)) { @@@@ -201,6 +248,9 @@@@ (void) memset(&tm_buf, 0, sizeof (tm_buf)); loctime = localtime_r(&curtime, &tm_buf); + /* Determine timezone offset */ + timezone = (time_t)((long)mktime(gmtime(&curtime)) - (long)curtime); + /* Immediately save global variable and adjust seconds to minutes: */ timezone_minutes = timezone / 60; @@@@ -941,6 +991,7 @@@@ /* Startup message: */ print_syslog(LOG_NOTICE, MYNAME " initialized\n"); +#if 0 listenfd = tcp_listen(NULL, WHOIS_SERVICE, &addrlen); if (listenfd < 0) { /* Try port number instead of service name */ listenfd = tcp_listen(NULL, WHOIS_PORT, &addrlen); @@@@ -948,6 +999,11 @@@@ return (-1); /* error */ } } +#else + listenfd = tcp_listen(desired_host, desired_port, &addrlen); + if (listenfd < 0) + return (-1); +#endif /* Must call AFTER privledged whois port has been opened as root: */ (void) initialize2(); Index: src/snprintf.c --- src/snprintf.c.orig 2001-07-04 08:15:04 +0200 +++ src/snprintf.c 2005-10-15 10:15:23 +0200 @@@@ -37,7 +37,6 @@@@ */ #include "config.h" -#include "in.swhoisd.h" #include /* ANSI C header file */ #include /* exit() */ #include /* strlen() */ @ 1.3 log @fix building under Solaris 8 by using the more portable combination of gmtime/mktime instead of timegm @ text @d184 11 @ 1.3.4.1 log @MFC: avoid a snvprintf to be mapped to libintl_snvprintf by the gettext libintl.h header and this way cause a symbol conflict @ text @a183 11 Index: src/snprintf.c --- src/snprintf.c.orig 2001-07-04 08:15:04 +0200 +++ src/snprintf.c 2005-10-15 10:15:23 +0200 @@@@ -37,7 +37,6 @@@@ */ #include "config.h" -#include "in.swhoisd.h" #include /* ANSI C header file */ #include /* exit() */ #include /* strlen() */ @ 1.2 log @try to get it running under FreeBSD 4.x and similar old platforms, too @ text @d159 1 a159 1 + timezone = (time_t)((long)timegm(loctime) - (long)curtime); @ 1.1 log @new package: swhoisd 3.0.5 (Simple WHOIS Daemon) @ text @d74 43 a116 2 +++ src/sysutils.c 2005-03-31 16:30:41 +0200 @@@@ -77,7 +77,7 @@@@ d125 1 a125 1 @@@@ -171,6 +171,19 @@@@ d145 1 a145 1 @@@@ -187,7 +200,7 @@@@ d154 1 a154 1 @@@@ -201,6 +214,9 @@@@ d164 1 a164 1 @@@@ -941,6 +957,7 @@@@ d172 1 a172 1 @@@@ -948,6 +965,11 @@@@ @