2011-02-11 10:29:39

by Jan Engelhardt

[permalink] [raw]
Subject: domainless lookups


Hi,


here are two patches. The first one is pretty simple, simply
reducing the requirement.

Second one is more of a suggestion, and its implementation being
limited to nss.c makes it more of a temporary hack than a
full solution. Anyway, I'll just sit back and wait for input :)

-

The following changes since commit 8752edac80a250095dc920a5a5c3bedc4cbeeb4b:

Cleaned up some warnings (2011-01-14 10:43:53 -0500)

are available in the git repository at:
git://dev.medozas.de/libnfsidmap master

Jan Engelhardt (2):
configure: reduce minimum autoconf version to 2.65
nss: allow domainless lookups

configure.in | 2 +-
nss.c | 21 +++++++++++++++++++++
2 files changed, 22 insertions(+), 1 deletions(-)


2011-02-11 10:29:41

by Jan Engelhardt

[permalink] [raw]
Subject: [PATCH 2/2] nss: allow domainless lookups

When the Solaris NFS server itself has no name mapping for a given UID,
it will export plain UIDs without a domain part. I would still like to
be able to have these resolved locally somehow.

One reason for plain UIDs to be exported is that the file server just
has no name for them because the admin did not link it with the LDAP
tree. A second case would be when a file server stores files for
multiple domains with colliding UIDs, in which case the wrong name would
be exported for at least one user's files.

Signed-off-by: Jan Engelhardt <[email protected]>
---
nss.c | 21 +++++++++++++++++++++
1 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/nss.c b/nss.c
index 04aff19..095794c 100644
--- a/nss.c
+++ b/nss.c
@@ -37,7 +37,9 @@
#include <sys/types.h>
#include <errno.h>
#include <unistd.h>
+#include <stdbool.h>
#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
#include <pwd.h>
#include <grp.h>
@@ -160,6 +162,14 @@ struct pwbuf {
char buf[1];
};

+static bool only_digits(const char *s)
+{
+ for (; *s != '\0'; ++s)
+ if (!isdigit(*s))
+ return false;
+ return true;
+}
+
static struct passwd *nss_getpwnam(const char *name, const char *domain, int *err_p)
{
struct passwd *pw;
@@ -172,6 +182,16 @@ static struct passwd *nss_getpwnam(const char *name, const char *domain, int *er
if (buf == NULL)
goto err;

+ if (strchr(name, '@') == NULL && only_digits(name)) {
+ char *end;
+ long uid = strtoul(name, &end, 10);
+ err = getpwuid_r(uid, &buf->pwbuf, buf->buf, buflen, &pw);
+ IDMAP_LOG(0, ("%s: pure UID %ld lookup (result=%d,errno=%s)\n",
+ __func__, uid, err, strerror(errno)));
+ if (err == 0)
+ goto done;
+ }
+
err = EINVAL;
localname = strip_domain(name, domain);
IDMAP_LOG(4, ("nss_getpwnam: name '%s' domain '%s': "
@@ -189,6 +209,7 @@ static struct passwd *nss_getpwnam(const char *name, const char *domain, int *er
("nss_getpwnam: name '%s' not found in domain '%s'\n",
localname, domain));
free(localname);
+done:
if (err == 0 && pw != NULL) {
*err_p = 0;
return pw;
--
1.7.1


2011-02-11 10:29:40

by Jan Engelhardt

[permalink] [raw]
Subject: [PATCH 1/2] configure: reduce minimum autoconf version to 2.65

Bumping AC_PREREQ to 2.66 in commit
fac889e58e61a8547f2de07e764eb1031b47d9a0 seems unwarranted; the
constructs also work with 2.65.

Signed-off-by: Jan Engelhardt <[email protected]>
---
configure.in | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/configure.in b/configure.in
index 7ad3e5f..9341db1 100644
--- a/configure.in
+++ b/configure.in
@@ -1,7 +1,7 @@
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

-AC_PREREQ([2.66])
+AC_PREREQ([2.65])
AC_INIT([libnfsidmap],[0.24],[[email protected]])
AC_CONFIG_SRCDIR([nfsidmap.h])
AC_CONFIG_MACRO_DIR([m4])
--
1.7.1