summaryrefslogtreecommitdiff
path: root/libexec/identd/parse.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2001-04-13 20:16:54 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2001-04-13 20:16:54 +0000
commit0eaa5a30b1120a648055bfc7b64551d95c8f1181 (patch)
treedae3a8921943ba89314d2f8f36cb957aa270c5e8 /libexec/identd/parse.c
parente0b9aee7172725208c5f363db42f56a50ef27fa4 (diff)
Add support for user specified tokens to identd. Based on a patch
from rjmooney@wall.st w/ minor tweakage by Theo and myself.
Diffstat (limited to 'libexec/identd/parse.c')
-rw-r--r--libexec/identd/parse.c85
1 files changed, 81 insertions, 4 deletions
diff --git a/libexec/identd/parse.c b/libexec/identd/parse.c
index 1e9e45d8317..61756c4ced8 100644
--- a/libexec/identd/parse.c
+++ b/libexec/identd/parse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.c,v 1.20 2001/01/28 19:34:29 niklas Exp $ */
+/* $OpenBSD: parse.c,v 1.21 2001/04/13 20:16:53 millert Exp $ */
/*
* This program is in the public domain and may be used freely by anyone
@@ -36,7 +36,7 @@ ssize_t timed_write __P((int, const void *, size_t, time_t));
void gentoken __P((char *, int));
/*
- * A small routine to check for the existance of the ".noident"
+ * A small routine to check for the existence of the ".noident"
* file in a users home directory.
*/
int
@@ -55,6 +55,45 @@ check_noident(homedir)
return 0;
}
+/*
+ * A small routine to check for the existence of the ".ident"
+ * file in a users home directory, and return its contents.
+ */
+int
+getuserident(homedir, buf, len)
+ char *homedir, *buf;
+ int len;
+{
+ char path[MAXPATHLEN];
+ struct stat st;
+ int fd, nread;
+ char *p;
+
+ if (len == 0)
+ return 0;
+ if (!homedir)
+ return 0;
+ if (snprintf(path, sizeof path, "%s/.ident", homedir) >= sizeof(path))
+ return 0;
+ if ((fd = open(path, O_RDONLY|O_NONBLOCK|O_NOFOLLOW, 0)) < 0)
+ return 0;
+ if (fstat(fd, &st) != 0 || !S_ISREG(st.st_mode))
+ return 0;
+
+ if ((nread = read(fd, buf, len - 1)) <= 0) {
+ close(fd);
+ return 0;
+ }
+ buf[nread] = '\0';
+
+ /* remove illegal characters */
+ if ((p = strpbrk(buf, "\r\n")))
+ *p = '\0';
+
+ close(fd);
+ return 1;
+}
+
static char token0cnv[] = "abcdefghijklmnopqrstuvwxyz";
static char tokencnv[] = "abcdefghijklmnopqrstuvwxyz0123456789";
@@ -215,7 +254,6 @@ parse(fd, laddr, faddr)
/*
* Next - get the specific TCP connection and return the
* uid - user number.
- *
*/
if (k_getuid(&faddr2, htons(fport), laddr,
htons(lport), &uid) == -1) {
@@ -268,6 +306,26 @@ parse(fd, laddr, faddr)
return 0;
}
+ if (userident_flag) {
+ char token[21];
+
+ if (getuserident(pw->pw_dir, token, sizeof token)) {
+ syslog(LOG_NOTICE, "token \"%s\" == uid %u (%s)",
+ token, uid, pw->pw_name);
+ n = snprintf(buf, sizeof(buf),
+ "%d , %d : USERID : OTHER%s%s :%s\r\n",
+ lport, fport, charset_name ? " , " : "",
+ charset_name ? charset_name : "", token);
+ if (timed_write(fd, buf, n, IO_TIMEOUT) != n &&
+ syslog_flag) {
+ syslog(LOG_NOTICE, "write to %s: %m",
+ gethost(faddr));
+ return 1;
+ }
+ return 0;
+ }
+ }
+
if (token_flag) {
char token[21];
@@ -376,7 +434,6 @@ parse6(fd, laddr, faddr)
/*
* Next - get the specific TCP connection and return the
* uid - user number.
- *
*/
if (k_getuid6(&faddr2, htons(fport), laddr,
htons(lport), &uid) == -1) {
@@ -429,6 +486,26 @@ parse6(fd, laddr, faddr)
return 0;
}
+ if (userident_flag) {
+ char token[21];
+
+ if (getuserident(pw->pw_dir, token, sizeof(token))) {
+ syslog(LOG_NOTICE, "token \"%s\" == uid %u (%s)",
+ token, uid, pw->pw_name);
+ n = snprintf(buf, sizeof(buf),
+ "%d , %d : USERID : OTHER%s%s :%s\r\n",
+ lport, fport, charset_name ? " , " : "",
+ charset_name ? charset_name : "", token);
+ if (timed_write(fd, buf, n, IO_TIMEOUT) != n &&
+ syslog_flag) {
+ syslog(LOG_NOTICE, "write to %s: %m",
+ gethost6(faddr));
+ return 1;
+ }
+ return 0;
+ }
+ }
+
if (token_flag) {
char token[21];