summaryrefslogtreecommitdiff
path: root/libexec/identd
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1997-08-09 22:59:11 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1997-08-09 22:59:11 +0000
commitb980b74f83a52e777efcf8f5bfefc61d0e42c56c (patch)
treef3e495d3e645e0d343274934c1b5454a234c877d /libexec/identd
parenta065e364ab922f838f31c8f0f37884ec53df8e4d (diff)
Using stdio on sockets is gross so don't do it. Also some -Wall.
Diffstat (limited to 'libexec/identd')
-rw-r--r--libexec/identd/identd.c10
-rw-r--r--libexec/identd/openbsd.c6
-rw-r--r--libexec/identd/parse.c82
3 files changed, 72 insertions, 26 deletions
diff --git a/libexec/identd/identd.c b/libexec/identd/identd.c
index 67332176087..708888db449 100644
--- a/libexec/identd/identd.c
+++ b/libexec/identd/identd.c
@@ -6,12 +6,14 @@
*/
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <netdb.h>
#include <signal.h>
#include <fcntl.h>
+#include <unistd.h>
#include <sys/types.h>
#include <sys/param.h>
@@ -264,7 +266,7 @@ main(argc, argv)
addr.sin_port = sp->s_port;
}
- if (bind(0, (struct sockaddr *) & addr, sizeof(addr)) < 0)
+ if (bind(0, (struct sockaddr *) &addr, sizeof(addr)) < 0)
ERROR("main: bind");
if (listen(0, 3) < 0)
@@ -364,7 +366,7 @@ main(argc, argv)
* Get foreign internet address
*/
len = sizeof(sin);
- if (getpeername(0, (struct sockaddr *) & sin, &len) == -1) {
+ if (getpeername(0, (struct sockaddr *) &sin, &len) == -1) {
/*
* A user has tried to start us from the command line or
* the network link died, in which case this message won't
@@ -391,7 +393,7 @@ main(argc, argv)
* Get local internet address
*/
len = sizeof(sin);
- if (getsockname(0, (struct sockaddr *) & sin, &len) == -1) {
+ if (getsockname(0, (struct sockaddr *) &sin, &len) == -1) {
/*
* We can just die here, because if this fails then the
* network has died and we haven't got anyone to return
@@ -404,6 +406,6 @@ main(argc, argv)
/*
* Get the local/foreign port pair from the luser
*/
- parse(stdin, &laddr, &faddr);
+ parse(STDIN_FILENO, &laddr, &faddr);
exit(0);
}
diff --git a/libexec/identd/openbsd.c b/libexec/identd/openbsd.c
index 520bba13ed4..7f38e5e5e58 100644
--- a/libexec/identd/openbsd.c
+++ b/libexec/identd/openbsd.c
@@ -88,7 +88,7 @@ getbuf(addr, buf, len, what)
{
if (kvm_read(kd, addr, buf, len) < 0) {
if (syslog_flag)
- syslog(LOG_ERR, "getbuf: kvm_read(%08x, %d) - %s : %m",
+ syslog(LOG_ERR, "getbuf: kvm_read(%08lx, %d) - %s : %m",
addr, len, what);
return 0;
@@ -138,10 +138,6 @@ k_getuid(faddr, fport, laddr, lport, uid)
int *uid;
{
struct socket *sockp, sock;
- int i, mib[2];
- struct ucred ucb;
- size_t siz;
- int rv;
if (!getbuf(nl[N_TCBTABLE].n_value, &tcbtable, sizeof(tcbtable), "tcbtable"))
return -1;
diff --git a/libexec/identd/parse.c b/libexec/identd/parse.c
index 811433dd7e3..fd83aa51f29 100644
--- a/libexec/identd/parse.c
+++ b/libexec/identd/parse.c
@@ -12,12 +12,14 @@
#include <netinet/in.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <pwd.h>
#include <nlist.h>
#include <kvm.h>
+#include <unistd.h>
#include "identd.h"
#include "error.h"
@@ -43,14 +45,14 @@ check_noident(homedir)
}
int
-parse(fp, laddr, faddr)
- FILE *fp;
+parse(fd, laddr, faddr)
+ int fd;
struct in_addr *laddr, *faddr;
{
- char lhostaddr[16], fhostaddr[16], password[33];
+ char buf[BUFSIZ], *p;
struct in_addr laddr2, faddr2;
struct passwd *pw;
- int try, rcode;
+ int try, n;
uid_t uid;
if (debug_flag && syslog_flag)
@@ -61,19 +63,42 @@ parse(fp, laddr, faddr)
faddr2 = *faddr;
laddr2 = *laddr;
lport = fport = 0;
- lhostaddr[0] = fhostaddr[0] = password[0] = '\0';
/* Read query from client */
- rcode = fscanf(fp, " %d , %d", &lport, &fport);
+ if ((n = read(fd, buf, sizeof(buf) - 1)) <= 0) {
+ if (syslog_flag)
+ syslog(LOG_NOTICE, "read from %s: %m", gethost(faddr));
+ n = snprintf(buf, sizeof(buf),
+ "%d , %d : ERROR : UNKNOWN-ERROR\r\n", lport, fport);
+ if (write(fd, buf, n) != n && syslog_flag) {
+ syslog(LOG_NOTICE, "write to %s: %m", gethost(faddr));
+ return 1;
+ }
+ return 0;
+ }
+ buf[n] = '\0';
+
+ /* Pull out local and remote ports */
+ p = buf;
+ while (*p != '\0' && isspace(*p))
+ p++;
+ if ((p = strtok(p, " \t,"))) {
+ lport = atoi(p);
+ if ((p = strtok(NULL, " \t,")))
+ fport = atoi(p);
+ }
- if (rcode < 2 || lport < 1 || lport > 65535 ||
- fport < 1 || fport > 65535) {
- if (syslog_flag && rcode > 0)
+ if (lport < 1 || lport > 65535 || fport < 1 || fport > 65535) {
+ if (syslog_flag)
syslog(LOG_NOTICE,
"scanf: invalid-port(s): %d , %d from %s",
lport, fport, gethost(faddr));
- printf("%d , %d : ERROR : %s\r\n", lport, fport,
- unknown_flag ? "UNKNOWN-ERROR" : "INVALID-PORT");
+ n = snprintf(buf, sizeof(buf), "%d , %d : ERROR : %s\r\n",
+ lport, fport, unknown_flag ? "UNKNOWN-ERROR" : "INVALID-PORT");
+ if (write(fd, buf, n) != n && syslog_flag) {
+ syslog(LOG_NOTICE, "write to %s: %m", gethost(faddr));
+ return 1;
+ }
return 0;
}
if (syslog_flag && verbose_flag)
@@ -100,8 +125,12 @@ parse(fp, laddr, faddr)
if (syslog_flag)
syslog(LOG_DEBUG, "Returned: %d , %d : NO-USER",
lport, fport);
- printf("%d , %d : ERROR : %s\r\n", lport, fport,
- unknown_flag ? "UNKNOWN-ERROR" : "NO-USER");
+ n = snprintf(buf, sizeof(buf), "%d , %d : ERROR : %s\r\n",
+ lport, fport, unknown_flag ? "UNKNOWN-ERROR" : "NO-USER");
+ if (write(fd, buf, n) != n && syslog_flag) {
+ syslog(LOG_NOTICE, "write to %s: %m", gethost(faddr));
+ return 1;
+ }
return 0;
}
if (try > 0 && syslog_flag)
@@ -116,9 +145,14 @@ parse(fp, laddr, faddr)
syslog(LOG_WARNING,
"getpwuid() could not map uid (%d) to name",
uid);
- printf("%d , %d : USERID : OTHER%s%s :%d\r\n",
+ n = snprintf(buf, sizeof(buf),
+ "%d , %d : USERID : OTHER%s%s :%d\r\n",
lport, fport, charset_name ? " , " : "",
charset_name ? charset_name : "", uid);
+ if (write(fd, buf, n) != n && syslog_flag) {
+ syslog(LOG_NOTICE, "write to %s: %m", gethost(faddr));
+ return 1;
+ }
return 0;
}
@@ -131,19 +165,33 @@ parse(fp, laddr, faddr)
syslog(LOG_NOTICE,
"user %s requested HIDDEN-USER for host %s: %d, %d",
pw->pw_name, gethost(faddr), lport, fport);
- printf("%d , %d : ERROR : HIDDEN-USER\r\n", lport, fport);
+ n = snprintf(buf, sizeof(buf),
+ "%d , %d : ERROR : HIDDEN-USER\r\n", lport, fport);
+ if (write(fd, buf, n) != n && syslog_flag) {
+ syslog(LOG_NOTICE, "write to %s: %m", gethost(faddr));
+ return 1;
+ }
return 0;
}
if (number_flag) {
- printf("%d , %d : USERID : OTHER%s%s :%d\r\n",
+ n = snprintf(buf, sizeof(buf),
+ "%d , %d : USERID : OTHER%s%s :%d\r\n",
lport, fport, charset_name ? " , " : "",
charset_name ? charset_name : "", uid);
+ if (write(fd, buf, n) != n && syslog_flag) {
+ syslog(LOG_NOTICE, "write to %s: %m", gethost(faddr));
+ return 1;
+ }
return 0;
}
- printf("%d , %d : USERID : %s%s%s :%s\r\n",
+ n = snprintf(buf, sizeof(buf), "%d , %d : USERID : %s%s%s :%s\r\n",
lport, fport, other_flag ? "OTHER" : "UNIX",
charset_name ? " , " : "",
charset_name ? charset_name : "", pw->pw_name);
+ if (write(fd, buf, n) != n && syslog_flag) {
+ syslog(LOG_NOTICE, "write to %s: %m", gethost(faddr));
+ return 1;
+ }
return 0;
}