summaryrefslogtreecommitdiffstats
path: root/contrib/amd/libamu
diff options
context:
space:
mode:
authorobrien <obrien@FreeBSD.org>2001-09-02 17:19:13 +0000
committerobrien <obrien@FreeBSD.org>2001-09-02 17:19:13 +0000
commitcc5c13afbaed26d39ba1178d68749c4cfb9449b2 (patch)
tree9a76e4a63e2f56518cb388d8d625df794665e066 /contrib/amd/libamu
parent0bff53b958d0a3310e138da1c240bcd089b68479 (diff)
parentac3e3d43d4bfa5d6b9dcc48360ec6bf36b03ed82 (diff)
downloadFreeBSD-src-cc5c13afbaed26d39ba1178d68749c4cfb9449b2.zip
FreeBSD-src-cc5c13afbaed26d39ba1178d68749c4cfb9449b2.tar.gz
This commit was generated by cvs2svn to compensate for changes in r82794,
which included commits to RCS files with non-trunk default branches.
Diffstat (limited to 'contrib/amd/libamu')
-rw-r--r--contrib/amd/libamu/amu.h4
-rw-r--r--contrib/amd/libamu/hasmntopt.c4
-rw-r--r--contrib/amd/libamu/misc_rpc.c40
-rw-r--r--contrib/amd/libamu/mtab.c72
-rw-r--r--contrib/amd/libamu/nfs_prot_xdr.c4
-rw-r--r--contrib/amd/libamu/util.c4
-rw-r--r--contrib/amd/libamu/wire.c29
-rw-r--r--contrib/amd/libamu/xdr_func.c115
-rw-r--r--contrib/amd/libamu/xutil.c103
9 files changed, 274 insertions, 101 deletions
diff --git a/contrib/amd/libamu/amu.h b/contrib/amd/libamu/amu.h
index a22371e..3769652 100644
--- a/contrib/amd/libamu/amu.h
+++ b/contrib/amd/libamu/amu.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997-1999 Erez Zadok
+ * Copyright (c) 1997-2001 Erez Zadok
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990 The Regents of the University of California.
@@ -38,7 +38,7 @@
*
* %W% (Berkeley) %G%
*
- * $Id: amu.h,v 1.2 1999/01/10 21:54:36 ezk Exp $
+ * $Id: amu.h,v 1.3.2.1 2001/01/10 03:23:38 ezk Exp $
*
*/
diff --git a/contrib/amd/libamu/hasmntopt.c b/contrib/amd/libamu/hasmntopt.c
index 5f19e71..9e76752 100644
--- a/contrib/amd/libamu/hasmntopt.c
+++ b/contrib/amd/libamu/hasmntopt.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997-1999 Erez Zadok
+ * Copyright (c) 1997-2001 Erez Zadok
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990 The Regents of the University of California.
@@ -38,7 +38,7 @@ n * modification, are permitted provided that the following conditions
*
* %W% (Berkeley) %G%
*
- * $Id: hasmntopt.c,v 1.2 1999/01/10 21:54:37 ezk Exp $
+ * $Id: hasmntopt.c,v 1.3.2.1 2001/01/10 03:23:39 ezk Exp $
*
*/
diff --git a/contrib/amd/libamu/misc_rpc.c b/contrib/amd/libamu/misc_rpc.c
index fa402c3..616ceed 100644
--- a/contrib/amd/libamu/misc_rpc.c
+++ b/contrib/amd/libamu/misc_rpc.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997-1999 Erez Zadok
+ * Copyright (c) 1997-2001 Erez Zadok
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990 The Regents of the University of California.
@@ -38,7 +38,7 @@
*
* %W% (Berkeley) %G%
*
- * $Id: misc_rpc.c,v 1.2 1999/01/10 21:54:37 ezk Exp $
+ * $Id: misc_rpc.c,v 1.4.2.1 2001/01/10 03:23:39 ezk Exp $
*
*/
@@ -166,3 +166,39 @@ make_rpc_packet(char *buf, int buflen, u_long proc, struct rpc_msg *mp, voidp ar
return len;
}
+
+
+/* get uid/gid from RPC credentials */
+int
+getcreds(struct svc_req *rp, uid_t *u, gid_t *g, SVCXPRT *nfsxprt)
+{
+ struct authunix_parms *aup = (struct authunix_parms *) NULL;
+#ifdef HAVE_RPC_AUTH_DES_H
+ struct authdes_cred *adp;
+#endif /* HAVE_RPC_AUTH_DES_H */
+
+ switch (rp->rq_cred.oa_flavor) {
+
+ case AUTH_UNIX:
+ aup = (struct authunix_parms *) rp->rq_clntcred;
+ *u = aup->aup_uid;
+ *g = aup->aup_gid;
+ break;
+
+#ifdef HAVE_RPC_AUTH_DES_H
+ case AUTH_DES:
+ adp = (struct authdes_cred *) rp->rq_clntcred;
+ *g = INVALIDID; /* some unknown group id */
+ if (sscanf(adp->adc_fullname.name, "unix.%lu@", (u_long *) u) == 1)
+ break;
+ /* fall through */
+#endif /* HAVE_RPC_AUTH_DES_H */
+
+ default:
+ *u = *g = INVALIDID; /* just in case */
+ svcerr_weakauth(nfsxprt);
+ return -1;
+ }
+
+ return 0; /* everything is ok */
+}
diff --git a/contrib/amd/libamu/mtab.c b/contrib/amd/libamu/mtab.c
index 3bcc38d..1fb3a33 100644
--- a/contrib/amd/libamu/mtab.c
+++ b/contrib/amd/libamu/mtab.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997-1999 Erez Zadok
+ * Copyright (c) 1997-2001 Erez Zadok
* Copyright (c) 1989 Jan-Simon Pendry
* Copyright (c) 1989 Imperial College of Science, Technology & Medicine
* Copyright (c) 1989 The Regents of the University of California.
@@ -38,7 +38,7 @@
*
* %W% (Berkeley) %G%
*
- * $Id: mtab.c,v 1.2 1999/01/10 21:54:37 ezk Exp $
+ * $Id: mtab.c,v 1.3.2.3 2001/04/14 21:08:25 ezk Exp $
*
*/
@@ -101,6 +101,43 @@ free_mntlist(mntlist *mp)
/*
+ * Utility routine which returns a pointer to whatever follows an = in a
+ * string. Returns null if = is not found in the string.
+ */
+char *
+haseq(char *instr)
+{
+ if (instr) {
+ char *eq = strchr(instr, '=');
+ if (eq) return ++eq;
+ }
+ return NULL;
+}
+
+
+/*
+ * Utility routine which returns a pointer to whatever
+ * follows an = in a mount option. Returns null if option
+ * doesn't exist or doesn't have an '='. Won't fall for opt,foo=.
+ */
+char *
+hasmnteq(mntent_t *mnt, char *opt)
+{
+ if (mnt && opt) { /* disallow null input pointers */
+ if ( *opt ) { /* disallow the null string as an opt */
+ char *str = hasmntopt(mnt, opt);
+ if ( str ) { /* option was there */
+ char *eq = str + strlen(opt); /* Look at char just after option */
+ if (*eq == '=') /* Is it '=' ? */
+ return ++eq; /* If so, return pointer to remaining str */
+ }
+ }
+ }
+ return NULL;
+}
+
+
+/*
* Utility routine which determines the value of a
* numeric option in the mount options (such as port=%d).
* Returns 0 if the option is not specified.
@@ -110,12 +147,31 @@ hasmntval(mntent_t *mnt, char *opt)
{
char *str = hasmntopt(mnt, opt);
- if (str) {
- char *eq = strchr(str, '=');
- if (eq)
- return atoi(eq + 1);
- else
- plog(XLOG_USER, "bad numeric option \"%s\" in \"%s\"", opt, str);
+ if (str) { /* The option was there */
+
+ char *eq = hasmnteq(mnt, opt);
+
+ if (eq) { /* and had an = after it */
+
+ char *endptr = NULL;
+ long int i = strtol(eq,&endptr,0); /* hex and octal allowed ;-) */
+
+ if ( (! endptr) || /* endptr == NULL means all chars valid */
+ /*
+ * endptr set means strtol saw a non-digit. If the
+ * non-digit is a comma, it's probably the start of the next
+ * option. If the comma is the first char though, complain about
+ * it (foo=,bar is made noticeable by this).
+ */
+ ((endptr == strchr(eq, ',')) && (endptr != eq))
+ )
+ return((int) i);
+ /* whatever was after = wasn't a number */
+ plog(XLOG_MAP, "invalid numeric option in \"%s\": \"%s\"", opt, str);
+ } else {
+ /* No argument to option (= was missing) */
+ plog(XLOG_MAP, "numeric option to \"%s\" missing", opt);
+ }
}
return 0;
}
diff --git a/contrib/amd/libamu/nfs_prot_xdr.c b/contrib/amd/libamu/nfs_prot_xdr.c
index 874f57a..c126471 100644
--- a/contrib/amd/libamu/nfs_prot_xdr.c
+++ b/contrib/amd/libamu/nfs_prot_xdr.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997-1999 Erez Zadok
+ * Copyright (c) 1997-2001 Erez Zadok
* Copyright (c) 1989 Jan-Simon Pendry
* Copyright (c) 1989 Imperial College of Science, Technology & Medicine
* Copyright (c) 1989 The Regents of the University of California.
@@ -38,7 +38,7 @@
*
* %W% (Berkeley) %G%
*
- * $Id: nfs_prot_xdr.c,v 1.2 1999/01/10 21:54:38 ezk Exp $
+ * $Id: nfs_prot_xdr.c,v 1.3.2.1 2001/01/10 03:23:40 ezk Exp $
*
*/
diff --git a/contrib/amd/libamu/util.c b/contrib/amd/libamu/util.c
index 72fcdad..ff84997 100644
--- a/contrib/amd/libamu/util.c
+++ b/contrib/amd/libamu/util.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997-1999 Erez Zadok
+ * Copyright (c) 1997-2001 Erez Zadok
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990 The Regents of the University of California.
@@ -38,7 +38,7 @@
*
* %W% (Berkeley) %G%
*
- * $Id: util.c,v 1.2 1999/01/10 21:54:39 ezk Exp $
+ * $Id: util.c,v 1.3.2.1 2001/01/10 03:23:41 ezk Exp $
*
*/
diff --git a/contrib/amd/libamu/wire.c b/contrib/amd/libamu/wire.c
index c8ed892..25a4427 100644
--- a/contrib/amd/libamu/wire.c
+++ b/contrib/amd/libamu/wire.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997-1999 Erez Zadok
+ * Copyright (c) 1997-2001 Erez Zadok
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990 The Regents of the University of California.
@@ -38,7 +38,7 @@
*
* %W% (Berkeley) %G%
*
- * $Id: wire.c,v 1.5 1999/09/08 23:36:52 ezk Exp $
+ * $Id: wire.c,v 1.8.2.5 2001/01/10 03:23:41 ezk Exp $
*
*/
@@ -60,7 +60,6 @@
#include <am_defs.h>
#include <amu.h>
-
#ifdef HAVE_IFADDRS_H
#include <ifaddrs.h>
#endif /* HAVE_IFADDRS_H */
@@ -169,7 +168,17 @@ getwire_lookup(u_long address, u_long netmask, int ishost)
u_char addr[4];
if (irs_gen == NULL)
+#ifdef irs_irp_acc
+ /*
+ * bsdi4 added another argument to this function, without changing
+ * its name. The irs_irp_acc is the one (hacky) distinguishing
+ * feature found in <irs.h> that can differentiate between bsdi3 and
+ * bsdi4.
+ */
+ irs_gen = irs_gen_acc("", NULL);
+#else /* not irs_irp_acc */
irs_gen = irs_gen_acc("");
+#endif /* not irs_irp_acc */
if (irs_gen && irs_nw == NULL)
irs_nw = (*irs_gen->nw_map)(irs_gen);
net = ntohl(address) & (mask = ntohl(netmask));
@@ -233,6 +242,12 @@ getwire_lookup(u_long address, u_long netmask, int ishost)
/* fill in network name (string) */
al->ip_net_name = strdup(s);
+ /* Let's be cautious here about buffer overflows -Ion */
+ if (strlen(s) > MAXHOSTNAMELEN) {
+ al->ip_net_name[MAXHOSTNAMELEN] = '\0';
+ plog(XLOG_WARNING, "Long hostname %s truncated to %d characters",
+ s, MAXHOSTNAMELEN);
+ }
return (al);
}
@@ -376,7 +391,7 @@ void
getwire(char **name1, char **number1)
{
struct ifconf ifc;
- struct ifreq *ifr;
+ struct ifreq *ifr, ifrpool;
caddr_t cp, cplim;
int fd = -1;
u_long address;
@@ -430,8 +445,10 @@ getwire(char **name1, char **number1)
/*
* Scan the list looking for a suitable interface
*/
- for (cp = buf; cp < cplim; cp += SIZE(ifr)) {
- ifr = (struct ifreq *) cp;
+ for (cp = buf; cp < cplim; /* increment in the loop body */) {
+ memcpy(&ifrpool, cp, sizeof(ifrpool));
+ ifr = &ifrpool;
+ cp += SIZE(ifr);
if (ifr->ifr_addr.sa_family != AF_INET)
continue;
diff --git a/contrib/amd/libamu/xdr_func.c b/contrib/amd/libamu/xdr_func.c
index deeb205..1e8085d 100644
--- a/contrib/amd/libamu/xdr_func.c
+++ b/contrib/amd/libamu/xdr_func.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997-1999 Erez Zadok
+ * Copyright (c) 1997-2001 Erez Zadok
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990 The Regents of the University of California.
@@ -38,7 +38,7 @@
*
* %W% (Berkeley) %G%
*
- * $Id: xdr_func.c,v 1.2 1999/01/10 21:54:39 ezk Exp $
+ * $Id: xdr_func.c,v 1.4.2.4 2001/02/02 18:28:27 ezk Exp $
*
*/
@@ -51,6 +51,7 @@
#include <am_defs.h>
#include <amu.h>
+
/*
* MACROS:
*/
@@ -77,7 +78,7 @@ bool_t
xdr_attrstat(XDR *xdrs, nfsattrstat *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_attrstat:");
#endif /* DEBUG */
@@ -103,7 +104,7 @@ bool_t
xdr_createargs(XDR *xdrs, nfscreateargs *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_createargs:");
#endif /* DEBUG */
@@ -123,7 +124,7 @@ bool_t
xdr_dirlist(XDR *xdrs, nfsdirlist *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_dirlist:");
#endif /* DEBUG */
@@ -143,7 +144,7 @@ bool_t
xdr_diropargs(XDR *xdrs, nfsdiropargs *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_diropargs:");
#endif /* DEBUG */
@@ -163,7 +164,7 @@ bool_t
xdr_diropokres(XDR *xdrs, nfsdiropokres *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_diropokres:");
#endif /* DEBUG */
@@ -183,7 +184,7 @@ bool_t
xdr_diropres(XDR *xdrs, nfsdiropres *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_diropres:");
#endif /* DEBUG */
@@ -209,7 +210,7 @@ bool_t
xdr_dirpath(XDR *xdrs, dirpath *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_dirpath:");
#endif /* DEBUG */
@@ -226,7 +227,7 @@ bool_t
xdr_entry(XDR *xdrs, nfsentry *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_entry:");
#endif /* DEBUG */
@@ -252,18 +253,14 @@ bool_t
xdr_exportnode(XDR *xdrs, exportnode *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_exportnode:");
#endif /* DEBUG */
if (!xdr_dirpath(xdrs, &objp->ex_dir)) {
return (FALSE);
}
- /*
- * This cast to (groups) is needed for Irix6. If you change it, it
- * may produce a warning/error on other systems.
- */
- if (!xdr_groups(xdrs, (groups) &objp->ex_groups)) {
+ if (!xdr_groups(xdrs, &objp->ex_groups)) {
return (FALSE);
}
if (!xdr_exports(xdrs, &objp->ex_next)) {
@@ -279,7 +276,7 @@ bool_t
xdr_exports(XDR *xdrs, exports *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_exports:");
#endif /* DEBUG */
@@ -296,7 +293,7 @@ bool_t
xdr_fattr(XDR *xdrs, nfsfattr *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_fattr:");
#endif /* DEBUG */
@@ -352,7 +349,7 @@ bool_t
xdr_fhandle(XDR *xdrs, fhandle objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_fhandle:");
#endif /* DEBUG */
@@ -369,7 +366,7 @@ bool_t
xdr_fhstatus(XDR *xdrs, fhstatus *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_fhstatus:");
#endif /* DEBUG */
@@ -389,7 +386,7 @@ bool_t
xdr_filename(XDR *xdrs, filename *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_filename:");
#endif /* DEBUG */
@@ -406,7 +403,7 @@ bool_t
xdr_ftype(XDR *xdrs, nfsftype *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_ftype:");
#endif /* DEBUG */
@@ -423,18 +420,14 @@ bool_t
xdr_groupnode(XDR *xdrs, groupnode *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_groupnode:");
#endif /* DEBUG */
if (!xdr_name(xdrs, &objp->gr_name)) {
return (FALSE);
}
- /*
- * This cast to (groups) is needed for Irix6. If you change it, it
- * may produce a warning/error on other systems.
- */
- if (!xdr_groups(xdrs, (groups) &objp->gr_next)) {
+ if (!xdr_groups(xdrs, &objp->gr_next)) {
return (FALSE);
}
return (TRUE);
@@ -444,10 +437,10 @@ xdr_groupnode(XDR *xdrs, groupnode *objp)
#ifndef HAVE_XDR_GROUPS
bool_t
-xdr_groups(XDR *xdrs, groups objp)
+xdr_groups(XDR *xdrs, groups *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_groups:");
#endif /* DEBUG */
@@ -464,7 +457,7 @@ bool_t
xdr_linkargs(XDR *xdrs, nfslinkargs *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_linkargs:");
#endif /* DEBUG */
@@ -484,7 +477,7 @@ bool_t
xdr_mountbody(XDR *xdrs, mountbody *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_mountbody:");
#endif /* DEBUG */
@@ -507,7 +500,7 @@ bool_t
xdr_mountlist(XDR *xdrs, mountlist *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_mountlist:");
#endif /* DEBUG */
@@ -531,7 +524,7 @@ bool_t
xdr_fhandle3(XDR *xdrs, fhandle3 *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_fhandle3:");
#endif /* DEBUG */
@@ -548,7 +541,7 @@ bool_t
xdr_mountstat3(XDR *xdrs, mountstat3 *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_mountstat3:");
#endif /* DEBUG */
@@ -562,7 +555,7 @@ bool_t
xdr_mountres3_ok(XDR *xdrs, mountres3_ok *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_mountres3_ok:");
#endif /* DEBUG */
@@ -583,7 +576,7 @@ bool_t
xdr_mountres3(XDR *xdrs, mountres3 *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_mountres3:");
#endif /* DEBUG */
@@ -604,7 +597,7 @@ bool_t
xdr_name(XDR *xdrs, name *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_name:");
#endif /* DEBUG */
@@ -621,7 +614,7 @@ bool_t
xdr_nfs_fh(XDR *xdrs, am_nfs_fh *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_nfs_fh:");
#endif /* DEBUG */
@@ -638,7 +631,7 @@ bool_t
xdr_nfscookie(XDR *xdrs, nfscookie objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_nfscookie:");
#endif /* DEBUG */
@@ -655,7 +648,7 @@ bool_t
xdr_nfspath(XDR *xdrs, nfspath *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_nfspath:");
#endif /* DEBUG */
@@ -672,7 +665,7 @@ bool_t
xdr_nfsstat(XDR *xdrs, nfsstat *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_nfsstat:");
#endif /* DEBUG */
@@ -689,7 +682,7 @@ bool_t
xdr_nfstime(XDR *xdrs, nfstime *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_nfstime:");
#endif /* DEBUG */
@@ -709,7 +702,7 @@ bool_t
xdr_pointer(register XDR *xdrs, char **objpp, u_int obj_size, XDRPROC_T_TYPE xdr_obj)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_pointer:");
#endif /* DEBUG */
@@ -735,7 +728,7 @@ bool_t
xdr_readargs(XDR *xdrs, nfsreadargs *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_readargs:");
#endif /* DEBUG */
@@ -761,7 +754,7 @@ bool_t
xdr_readdirargs(XDR *xdrs, nfsreaddirargs *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_readdirargs:");
#endif /* DEBUG */
@@ -784,7 +777,7 @@ bool_t
xdr_readdirres(XDR *xdrs, nfsreaddirres *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_readdirres:");
#endif /* DEBUG */
@@ -810,7 +803,7 @@ bool_t
xdr_readlinkres(XDR *xdrs, nfsreadlinkres *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_readlinkres:");
#endif /* DEBUG */
@@ -836,7 +829,7 @@ bool_t
xdr_readokres(XDR *xdrs, nfsreadokres *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_readokres:");
#endif /* DEBUG */
@@ -859,7 +852,7 @@ bool_t
xdr_readres(XDR *xdrs, nfsreadres *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_readres:");
#endif /* DEBUG */
@@ -885,7 +878,7 @@ bool_t
xdr_renameargs(XDR *xdrs, nfsrenameargs *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_renameargs:");
#endif /* DEBUG */
@@ -905,7 +898,7 @@ bool_t
xdr_sattr(XDR *xdrs, nfssattr *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_sattr:");
#endif /* DEBUG */
@@ -937,7 +930,7 @@ bool_t
xdr_sattrargs(XDR *xdrs, nfssattrargs *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_sattrargs:");
#endif /* DEBUG */
@@ -957,7 +950,7 @@ bool_t
xdr_statfsokres(XDR *xdrs, nfsstatfsokres *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_statfsokres:");
#endif /* DEBUG */
@@ -986,7 +979,7 @@ bool_t
xdr_statfsres(XDR *xdrs, nfsstatfsres *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_statfsres:");
#endif /* DEBUG */
@@ -1012,7 +1005,7 @@ bool_t
xdr_symlinkargs(XDR *xdrs, nfssymlinkargs *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_symlinkargs:");
#endif /* DEBUG */
@@ -1035,7 +1028,7 @@ bool_t
xdr_writeargs(XDR *xdrs, nfswriteargs *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_writeargs:");
#endif /* DEBUG */
@@ -1071,7 +1064,7 @@ bool_t
xdr_mntrequest(XDR *xdrs, mntrequest *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_mntrequest:");
#endif /* DEBUG */
@@ -1097,7 +1090,7 @@ bool_t
xdr_mntres(XDR *xdrs, mntres *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_mntres:");
#endif /* DEBUG */
@@ -1114,7 +1107,7 @@ bool_t
xdr_umntrequest(XDR *xdrs, umntrequest *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_umntrequest:");
#endif /* DEBUG */
@@ -1142,7 +1135,7 @@ bool_t
xdr_umntres(XDR *xdrs, umntres *objp)
{
#ifdef DEBUG
- amuDebug(D_TRACE)
+ amuDebug(D_XDRTRACE)
plog(XLOG_DEBUG, "xdr_mntres:");
#endif /* DEBUG */
diff --git a/contrib/amd/libamu/xutil.c b/contrib/amd/libamu/xutil.c
index a8b15bf..998d0d8 100644
--- a/contrib/amd/libamu/xutil.c
+++ b/contrib/amd/libamu/xutil.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997-1999 Erez Zadok
+ * Copyright (c) 1997-2001 Erez Zadok
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990 The Regents of the University of California.
@@ -38,7 +38,7 @@
*
* %W% (Berkeley) %G%
*
- * $Id: xutil.c,v 1.8 1999/09/30 21:01:42 ezk Exp $
+ * $Id: xutil.c,v 1.11.2.6 2001/01/10 03:23:41 ezk Exp $
*
*/
@@ -80,7 +80,11 @@ static int orig_mem_bytes;
#endif /* DEBUG_MEM */
/* forward definitions */
-static void real_plog(int lvl, char *fmt, va_list vargs);
+static void real_plog(int lvl, const char *fmt, va_list vargs)
+ __attribute__((__format__(__printf__, 2, 0)));
+/* for GCC format string auditing */
+static const char *expand_error(const char *f, char *e, int maxlen)
+ __attribute__((__format_arg__(1)));
#ifdef DEBUG
/*
@@ -93,15 +97,20 @@ struct opt_tab dbg_opt[] =
{"daemon", D_DAEMON}, /* Enter daemon mode */
{"fork", D_FORK}, /* Fork server (nofork = don't fork) */
{"full", D_FULL}, /* Program trace */
+#ifdef HAVE_CLOCK_GETTIME
+ {"hrtime", D_HRTIME}, /* Print high resolution time stamps */
+#endif /* HAVE_CLOCK_GETTIME */
/* info service specific debugging (hesiod, nis, etc) */
{"info", D_INFO},
# ifdef DEBUG_MEM
{"mem", D_MEM}, /* Trace memory allocations */
# endif /* DEBUG_MEM */
{"mtab", D_MTAB}, /* Use local mtab file */
+ {"readdir", D_READDIR}, /* check on browsable_dirs progress */
{"str", D_STR}, /* Debug string munging */
{"test", D_TEST}, /* Full debug - but no daemon */
{"trace", D_TRACE}, /* Protocol trace */
+ {"xdrtrace", D_XDRTRACE}, /* Trace xdr routines */
{0, 0}
};
#endif /* DEBUG */
@@ -280,18 +289,31 @@ checkup_mem(void)
* with the current error code taken from errno. Make sure
* 'e' never gets longer than maxlen characters.
*/
-static void
-expand_error(char *f, char *e, int maxlen)
+static const char *
+expand_error(const char *f, char *e, int maxlen)
{
+#ifndef HAVE_STRERROR
+ /*
+ * XXX: we are assuming that if a system doesn't has strerror,
+ * then it has sys_nerr. If this assumption turns out to be wrong on
+ * some systems, we'll have to write a separate test to detect if
+ * a system has sys_nerr. -Erez
+ */
extern int sys_nerr;
- char *p, *q;
+#endif /* not HAVE_STRERROR */
+ const char *p;
+ char *q;
int error = errno;
int len = 0;
for (p = f, q = e; (*q = *p) && len < maxlen; len++, q++, p++) {
if (p[0] == '%' && p[1] == 'm') {
const char *errstr;
+#ifdef HAVE_STRERROR
+ if (error < 0)
+#else /* not HAVE_STRERROR */
if (error < 0 || error >= sys_nerr)
+#endif /* not HAVE_STRERROR */
errstr = NULL;
else
#ifdef HAVE_STRERROR
@@ -309,6 +331,7 @@ expand_error(char *f, char *e, int maxlen)
}
}
e[maxlen-1] = '\0'; /* null terminate, to be sure */
+ return e;
}
@@ -320,13 +343,34 @@ show_time_host_and_name(int lvl)
{
static time_t last_t = 0;
static char *last_ctime = 0;
- time_t t = clocktime();
+ time_t t;
+#ifdef HAVE_CLOCK_GETTIME
+ struct timespec ts;
+#endif /* HAVE_CLOCK_GETTIME */
+ char nsecs[11] = ""; /* '.' + 9 digits + '\0' */
char *sev;
+#ifdef HAVE_CLOCK_GETTIME
+ /*
+ * Some systems (AIX 4.3) seem to implement clock_gettime() as stub
+ * returning ENOSYS.
+ */
+ if (clock_gettime(CLOCK_REALTIME, &ts) == 0) {
+ t = ts.tv_sec;
+#ifdef DEBUG
+ amuDebug(D_HRTIME)
+ sprintf(nsecs, ".%09ld", ts.tv_nsec);
+#endif /* DEBUG */
+ }
+ else
+#endif /* HAVE_CLOCK_GETTIME */
+ t = clocktime();
+
if (t != last_t) {
last_ctime = ctime(&t);
last_t = t;
}
+
switch (lvl) {
case XLOG_FATAL:
sev = "fatal:";
@@ -356,8 +400,8 @@ show_time_host_and_name(int lvl)
sev = "hmm: ";
break;
}
- fprintf(logfp, "%15.15s %s %s[%ld]/%s ",
- last_ctime + 4, am_get_hostname(),
+ fprintf(logfp, "%15.15s%s %s %s[%ld]/%s ",
+ last_ctime + 4, nsecs, am_get_hostname(),
am_get_progname(),
(long) am_mypid,
sev);
@@ -376,7 +420,7 @@ debug_option(char *opt)
void
-dplog(char *fmt, ...)
+dplog(const char *fmt, ...)
{
va_list ap;
@@ -391,7 +435,7 @@ dplog(char *fmt, ...)
void
-plog(int lvl, char *fmt, ...)
+plog(int lvl, const char *fmt, ...)
{
va_list ap;
@@ -405,7 +449,7 @@ plog(int lvl, char *fmt, ...)
static void
-real_plog(int lvl, char *fmt, va_list vargs)
+real_plog(int lvl, const char *fmt, va_list vargs)
{
char msg[1024];
char efmt[1024];
@@ -420,17 +464,21 @@ real_plog(int lvl, char *fmt, va_list vargs)
checkup_mem();
#endif /* DEBUG_MEM */
- expand_error(fmt, efmt, 1024);
-
#ifdef HAVE_VSNPRINTF
- vsnprintf(ptr, 1024, efmt, vargs);
+ /*
+ * XXX: ptr is 1024 bytes long, but we may write to ptr[strlen(ptr) + 2]
+ * (to add an '\n', see code below) so we have to limit the string copy
+ * to 1023 (including the '\0').
+ */
+ vsnprintf(ptr, 1023, expand_error(fmt, efmt, 1024), vargs);
+ msg[1022] = '\0'; /* null terminate, to be sure */
#else /* not HAVE_VSNPRINTF */
/*
* XXX: ptr is 1024 bytes long. It is possible to write into it
* more than 1024 bytes, if efmt is already large, and vargs expand
* as well. This is not as safe as using vsnprintf().
*/
- vsprintf(ptr, efmt, vargs);
+ vsprintf(ptr, expand_error(fmt, efmt, 1023), vargs);
msg[1023] = '\0'; /* null terminate, to be sure */
#endif /* not HAVE_VSNPRINTF */
@@ -873,6 +921,7 @@ amu_release_controlling_tty(void)
#ifdef TIOCNOTTY
int fd;
#endif /* TIOCNOTTY */
+ int tempfd;
#ifdef HAVE_SETSID
/* XXX: one day maybe use vhangup(2) */
@@ -884,6 +933,28 @@ amu_release_controlling_tty(void)
}
#endif /* HAVE_SETSID */
+ /*
+ * In daemon mode, leaving open file descriptors to terminals or pipes
+ * can be a really bad idea.
+ * Case in point: the redhat startup script calls us through their 'initlog'
+ * program, which exits as soon as the original amd process exits. If, at some
+ * point, a misbehaved library function decides to print something to the screen,
+ * we get a SIGPIPE and die.
+ * More precisely: NIS libc functions will attempt to print to stderr
+ * "YPBINDPROC_DOMAIN: Domain not bound" if ypbind is running but can't find
+ * a ypserver.
+ *
+ * So we close all of our "terminal" filedescriptors, i.e. 0, 1 and 2, then
+ * reopen them as /dev/null.
+ *
+ * XXX We should also probably set the SIGPIPE handler to SIG_IGN.
+ */
+ tempfd = open("/dev/null", O_RDWR);
+ fflush(stdin); close(0); dup2(tempfd, 0);
+ fflush(stdout); close(1); dup2(tempfd, 1);
+ fflush(stderr); close(2); dup2(tempfd, 2);
+ close(tempfd);
+
#ifdef TIOCNOTTY
fd = open("/dev/tty", O_RDWR);
if (fd < 0) {
OpenPOWER on IntegriCloud