Date: Tue, 12 Jun 2001 23:15:49 -0700 From: Dima Dorfman <dima@unixfreak.org> To: audit@freebsd.org Subject: mountd/showmount/mountdtab patch Message-ID: <20010613061550.049B13E28@bazooka.unixfreak.org>
index | next in thread | raw e-mail
The attached patch makes mountd write the numeric IP address instead
of the hostname of the connecting machine to /var/db/mountdtab, and
updates showmount to do the DNS lookup itself. It also adds an -n
option to the latter which disables the DNS lookup. That's the real
motivation behind this; it's very nice to be able to find the IP
address of the connecting machine without having to do a lookup.
Please review.
Thanks in advance,
Dima Dorfman
dima@unixfreak.org
Index: sbin/mountd/mountd.c
===================================================================
RCS file: /stl/src/FreeBSD/src/sbin/mountd/mountd.c,v
retrieving revision 1.55
diff -u -r1.55 mountd.c
--- sbin/mountd/mountd.c 2001/06/01 10:57:24 1.55
+++ sbin/mountd/mountd.c 2001/06/13 05:53:29
@@ -522,8 +522,7 @@
struct stat stb;
struct statfs fsb;
struct addrinfo *ai;
- char host[NI_MAXHOST], numerichost[NI_MAXHOST];
- int lookup_failed = 1;
+ char numerichost[NI_MAXHOST];
struct sockaddr *saddr;
u_short sport;
char rpcpath[RPCMNT_PATHLEN + 1], dirpath[MAXPATHLEN];
@@ -544,8 +543,6 @@
syslog(LOG_ERR, "request from unknown address family");
return;
}
- lookup_failed = getnameinfo(saddr, saddr->sa_len, host, sizeof host,
- NULL, 0, 0);
getnameinfo(saddr, saddr->sa_len, numerichost,
sizeof numerichost, NULL, 0, NI_NUMERICHOST);
ai = NULL;
@@ -622,10 +619,7 @@
}
if (!svc_sendreply(transp, xdr_fhs, (caddr_t)&fhr))
syslog(LOG_ERR, "can't send reply");
- if (!lookup_failed)
- add_mlist(host, dirpath);
- else
- add_mlist(numerichost, dirpath);
+ add_mlist(numerichost, dirpath);
if (debug)
warnx("mount successful");
if (log)
@@ -672,8 +666,6 @@
}
if (!svc_sendreply(transp, xdr_void, (caddr_t)NULL))
syslog(LOG_ERR, "can't send reply");
- if (!lookup_failed)
- del_mlist(host, dirpath);
del_mlist(numerichost, dirpath);
if (log)
syslog(LOG_NOTICE,
@@ -690,8 +682,6 @@
}
if (!svc_sendreply(transp, xdr_void, (caddr_t)NULL))
syslog(LOG_ERR, "can't send reply");
- if (!lookup_failed)
- del_mlist(host, NULL);
del_mlist(numerichost, NULL);
if (log)
syslog(LOG_NOTICE,
Index: usr.bin/showmount/showmount.c
===================================================================
RCS file: /stl/src/FreeBSD/src/usr.bin/showmount/showmount.c,v
retrieving revision 1.10
diff -u -r1.10 showmount.c
--- usr.bin/showmount/showmount.c 2001/06/12 03:44:35 1.10
+++ usr.bin/showmount/showmount.c 2001/06/13 05:53:29
@@ -94,7 +94,9 @@
static struct mountlist *mntdump;
static struct exportslist *exports;
static int type = 0;
+static int do_dns = 1;
+void normalize_host __P((const char *, char **));
void print_dump __P((struct mountlist *));
static void usage __P((void));
int xdr_mntdump __P((XDR *, struct mountlist **));
@@ -123,7 +125,7 @@
char *host;
int estat;
- while ((ch = getopt(argc, argv, "ade3")) != -1)
+ while ((ch = getopt(argc, argv, "aden3")) != -1)
switch((char)ch) {
case 'a':
if (type == 0) {
@@ -142,6 +144,9 @@
case 'e':
rpcs |= DOEXPORTS;
break;
+ case 'n':
+ do_dns = 0;
+ break;
case '3':
mntvers = 3;
break;
@@ -375,7 +380,7 @@
static void
usage()
{
- fprintf(stderr, "usage: showmount [-ade3] host\n");
+ fprintf(stderr, "usage: showmount [-aden3] host\n");
exit(1);
}
@@ -386,22 +391,60 @@
print_dump(mp)
struct mountlist *mp;
{
+ char *host;
if (mp == NULL)
return;
if (mp->ml_left)
print_dump(mp->ml_left);
+ normalize_host(mp->ml_host, &host);
switch (type) {
case ALL:
- printf("%s:%s\n", mp->ml_host, mp->ml_dirp);
+ printf("%s:%s\n", host, mp->ml_dirp);
break;
case DIRS:
printf("%s\n", mp->ml_dirp);
break;
default:
- printf("%s\n", mp->ml_host);
+ printf("%s\n", host);
break;
};
+ free(host);
if (mp->ml_right)
print_dump(mp->ml_right);
+}
+
+void
+normalize_host(old, new)
+ const char *old;
+ char **new;
+{
+ struct addrinfo *ai;
+ char *newval;
+ int error, flags;
+
+ if (!do_dns)
+ flags = NI_NUMERICHOST;
+ else
+ flags = 0;
+ error = getaddrinfo(old, NULL, NULL, &ai);
+ if (error != 0) {
+ *new = strdup(old);
+ return;
+ }
+ newval = malloc(NI_MAXHOST);
+ if (newval == NULL) {
+ freeaddrinfo(ai);
+ err(1, "malloc");
+ }
+ error = getnameinfo(ai->ai_addr, ai->ai_addrlen, newval, NI_MAXHOST,
+ NULL, 0, flags);
+ if (error != 0) {
+ freeaddrinfo(ai);
+ free(newval);
+ *new = strdup(old);
+ return;
+ }
+ freeaddrinfo(ai);
+ *new = newval;
}
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message
home |
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010613061550.049B13E28>
