diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2004-09-16 08:25:06 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2004-09-16 08:25:06 +0000 |
commit | d39f4dbc575e1fb9d7cd9dc0534fd8e4bfe72ea1 (patch) | |
tree | 551317a57e856bff075eed5e64f5010daef1cc94 /libexec | |
parent | f8ab28e80b1f7bfb29f8ffcb3b9a895f30c5d96d (diff) |
i hate macros with 50 , :? and ())()()((()())); otto ok
Diffstat (limited to 'libexec')
-rw-r--r-- | libexec/identd/error.h | 37 | ||||
-rw-r--r-- | libexec/identd/identd.c | 60 | ||||
-rw-r--r-- | libexec/identd/identd.h | 3 | ||||
-rw-r--r-- | libexec/identd/openbsd.c | 4 | ||||
-rw-r--r-- | libexec/identd/parse.c | 4 |
5 files changed, 47 insertions, 61 deletions
diff --git a/libexec/identd/error.h b/libexec/identd/error.h deleted file mode 100644 index d05a418b719..00000000000 --- a/libexec/identd/error.h +++ /dev/null @@ -1,37 +0,0 @@ -/* $OpenBSD: error.h,v 1.6 2004/01/04 04:18:11 deraadt Exp $*/ - -/* -** -** error.h Error handling macros -** -** This program is in the public domain and may be used freely by anyone -** who wants to. -** -** Last update: 19 Aug 1992 -** -** Please send bug fixes/bug reports to: Peter Eriksson <pen@lysator.liu.se> -*/ - -#ifndef __ERROR_H__ -#define __ERROR_H__ - -#include <syslog.h> - -#define ERROR(msg) \ - ((syslog_flag ? (syslog(LOG_ERR, "%s", msg),0) : 0), \ - (debug_flag ? (fprintf(stderr, "%d , %d : ERROR : X-DBG : ", \ - lport, fport), \ - fprintf(stderr, "%s", msg), perror(": "), 0) : \ - (printf("%d , %d : ERROR : UNKNOWN-ERROR\r\n", lport, fport), 0)), \ - fflush(stdout), fflush(stderr), exit(1), 0) - - -#define ERROR1(fmt,v1) \ - ((syslog_flag ? (syslog(LOG_ERR, fmt, v1),0) : 0), \ - (debug_flag ? (fprintf(stderr, "%d , %d : ERROR : X-DBG : ", \ - lport, fport), \ - fprintf(stderr, fmt, v1), perror(": "), 0) : \ - (printf("%d , %d : ERROR : UNKNOWN-ERROR\r\n", lport, fport), 0)), \ - fflush(stdout), fflush(stderr), exit(1), 0) - -#endif diff --git a/libexec/identd/identd.c b/libexec/identd/identd.c index 59d50d50ab4..c3eda6381db 100644 --- a/libexec/identd/identd.c +++ b/libexec/identd/identd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: identd.c,v 1.39 2004/09/14 22:14:29 deraadt Exp $ */ +/* $OpenBSD: identd.c,v 1.40 2004/09/16 08:25:05 deraadt Exp $ */ /* * This program is in the public domain and may be used freely by anyone @@ -22,6 +22,7 @@ #include <stdlib.h> #include <poll.h> #include <string.h> +#include <stdarg.h> #include <ctype.h> #include <errno.h> #include <netdb.h> @@ -33,7 +34,6 @@ #include <grp.h> #include "identd.h" -#include "error.h" extern char *__progname; @@ -168,7 +168,7 @@ main(int argc, char *argv[]) if ((pwd = getpwnam(DEFAULT_UID)) == NULL) pwd = getpwnam("nobody"); if (pwd == NULL) - ERROR1("no such user: neither %s nor nobody", + error("no such user: neither %s nor nobody", DEFAULT_UID); set_uid = pwd->pw_uid; set_gid = pwd->pw_gid; @@ -211,7 +211,7 @@ main(int argc, char *argv[]) break; } if (pwd == NULL) - ERROR1("no such user (%s) for -u option", + error("no such user (%s) for -u option", optarg); else { set_uid = pwd->pw_uid; @@ -227,7 +227,7 @@ main(int argc, char *argv[]) } grp = getgrnam(optarg); if (!grp) - ERROR1("no such group (%s) for -g option", optarg); + error("no such group (%s) for -g option", optarg); else set_gid = grp->gr_gid; break; @@ -287,7 +287,7 @@ main(int argc, char *argv[]) fd = socket(AF_INET, SOCK_STREAM, 0); if (fd == -1) - ERROR("main: socket"); + error("main: socket"); if (fd != 0) dup2(fd, 0); @@ -304,7 +304,7 @@ main(int argc, char *argv[]) hp = gethostbyname(bind_address); if (!hp) - ERROR1("no such address (%s) for -a switch", + error("no such address (%s) for -a switch", bind_address); memcpy(&addr.sin_addr, hp->h_addr, sizeof(addr.sin_addr)); @@ -316,27 +316,27 @@ main(int argc, char *argv[]) else { sp = getservbyname(portno, "tcp"); if (sp == NULL) - ERROR1("main: getservbyname: %s", portno); + error("main: getservbyname: %s", portno); addr.sin_port = sp->s_port; } if (bind(0, (struct sockaddr *) &addr, sizeof(addr)) < 0) - ERROR("main: bind"); + error("main: bind"); if (listen(0, 3) < 0) - ERROR("main: listen"); + error("main: listen"); } if (set_gid) { if (setegid(set_gid) == -1) - ERROR("main: setgid"); + error("main: setgid"); if (setgid(set_gid) == -1) - ERROR("main: setgid"); + error("main: setgid"); } if (set_uid) { if (seteuid(set_uid) == -1) - ERROR("main: setuid"); + error("main: setuid"); if (setuid(set_uid) == -1) - ERROR("main: setuid"); + error("main: setuid"); } /* * Do some special handling if the "-b" or "-w" flags are used @@ -382,7 +382,7 @@ main(int argc, char *argv[]) * An error occurred in select? Just die */ if (nfds < 0) - ERROR("main: select"); + error("main: select"); /* * Timeout limit reached. Exit nicely @@ -400,7 +400,7 @@ main(int argc, char *argv[]) */ fd = accept(0, NULL, NULL); if (fd == -1) - ERROR1("main: accept. errno = %d", errno); + error("main: accept. errno = %d", errno); /* * And fork, then close the fd if we are the parent. @@ -414,13 +414,13 @@ main(int argc, char *argv[]) * We are now in child, the parent has returned to "do" above. */ if (dup2(fd, 0) == -1) - ERROR("main: dup2: failed fd 0"); + error("main: dup2: failed fd 0"); if (dup2(fd, 1) == -1) - ERROR("main: dup2: failed fd 1"); + error("main: dup2: failed fd 1"); if (dup2(fd, 2) == -1) - ERROR("main: dup2: failed fd 2"); + error("main: dup2: failed fd 2"); } /* * Get foreign internet address @@ -482,3 +482,25 @@ main(int argc, char *argv[]) exit(0); } + +void +error(char *fmt, ...) +{ + va_list ap, ap2; + + va_start(ap, fmt); + + if (syslog_flag) { + va_copy(ap2, ap); + syslog(LOG_ERR, fmt, ap2); + va_end(ap2); + } + if (debug_flag) { + fprintf(stderr, "%d , %d : ERROR : X-DBG : ", lport, fport); + fprintf(stderr, fmt, ap); + perror(": "); + } else + printf("%d , %d : ERROR : UNKNOWN-ERROR\r\n", lport, fport); + va_end(ap); + exit(1); +} diff --git a/libexec/identd/identd.h b/libexec/identd/identd.h index d94029e65fb..941ac4a7456 100644 --- a/libexec/identd/identd.h +++ b/libexec/identd/identd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: identd.h,v 1.16 2004/01/04 04:18:11 deraadt Exp $*/ +/* $OpenBSD: identd.h,v 1.17 2004/09/16 08:25:05 deraadt Exp $*/ /* ** @@ -43,5 +43,6 @@ char *gethost6(struct sockaddr_in6 *); int k_getuid(struct in_addr *, int, struct in_addr *, int, uid_t *); int k_getuid6(struct sockaddr_in6 *, int, struct sockaddr_in6 *, int, uid_t *); +void error(char *fmt, ...); #endif diff --git a/libexec/identd/openbsd.c b/libexec/identd/openbsd.c index 631a33370c8..46126aaec55 100644 --- a/libexec/identd/openbsd.c +++ b/libexec/identd/openbsd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: openbsd.c,v 1.18 2002/07/16 10:32:37 deraadt Exp $ */ +/* $OpenBSD: openbsd.c,v 1.19 2004/09/16 08:25:05 deraadt Exp $ */ /* * This program is in the public domain and may be used freely by anyone @@ -18,6 +18,7 @@ #include <stdio.h> #include <string.h> #include <errno.h> +#include <syslog.h> #include <netinet/in.h> #include <netinet/in_systm.h> @@ -29,7 +30,6 @@ #include <arpa/inet.h> #include "identd.h" -#include "error.h" /* * Return the user number for the connection owner diff --git a/libexec/identd/parse.c b/libexec/identd/parse.c index 9568b079487..81bb6ea19af 100644 --- a/libexec/identd/parse.c +++ b/libexec/identd/parse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.c,v 1.39 2004/08/08 19:32:45 deraadt Exp $ */ +/* $OpenBSD: parse.c,v 1.40 2004/09/16 08:25:05 deraadt Exp $ */ /* * This program is in the public domain and may be used freely by anyone @@ -18,6 +18,7 @@ #include <poll.h> #include <stdlib.h> #include <string.h> +#include <syslog.h> #include <errno.h> #include <ctype.h> #include <pwd.h> @@ -25,7 +26,6 @@ #include <unistd.h> #include "identd.h" -#include "error.h" #define IO_TIMEOUT 30 /* Timeout I/O operations after N seconds */ |