X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=utils%2Fmountd%2Fcache.c;h=5612a9edf547ed626f35d27d50ffc3e22aa88612;hp=dcb5dac1369bc3621290f730fd3b3537d1115cd0;hb=e3f2d2262fed12f0f6b77c5ac1c4072d82f1e754;hpb=8fd9fad1ea4b25b8962d70133f476650ef0637b0 diff --git a/utils/mountd/cache.c b/utils/mountd/cache.c index dcb5dac..5612a9e 100644 --- a/utils/mountd/cache.c +++ b/utils/mountd/cache.c @@ -21,11 +21,28 @@ #include #include #include +#include +#include #include "misc.h" #include "nfslib.h" #include "exportfs.h" #include "mountd.h" #include "xmalloc.h" +#include "fsloc.h" + +#include "blkid/blkid.h" + + +enum nfsd_fsid { + FSID_DEV = 0, + FSID_NUM, + FSID_MAJOR_MINOR, + FSID_ENCODE_DEV, + FSID_UUID4_INUM, + FSID_UUID8, + FSID_UUID16, + FSID_UUID16_INUM, +}; /* * Support routines for text-based upcalls. @@ -87,6 +104,119 @@ void auth_unix_ip(FILE *f) } +void auth_unix_gid(FILE *f) +{ + /* Request are + * uid + * reply is + * uid expiry count list of group ids + */ + int uid; + struct passwd *pw; + gid_t glist[100], *groups = glist; + int ngroups = 100; + int rv, i; + char *cp; + + if (readline(fileno(f), &lbuf, &lbuflen) != 1) + return; + + cp = lbuf; + if (qword_get_int(&cp, &uid) != 0) + return; + + pw = getpwuid(uid); + if (!pw) + rv = -1; + else { + rv = getgrouplist(pw->pw_name, pw->pw_gid, groups, &ngroups); + if (rv == -1 && ngroups >= 100) { + groups = malloc(sizeof(gid_t)*ngroups); + if (!groups) + rv = -1; + else + rv = getgrouplist(pw->pw_name, pw->pw_gid, + groups, &ngroups); + } + } + qword_printint(f, uid); + qword_printint(f, time(0)+30*60); + if (rv >= 0) { + qword_printint(f, ngroups); + for (i=0; i 3) + if (fsidtype < 0 || fsidtype > 7) goto out; /* unknown type */ if ((fsidlen = qword_get(&cp, fsid, 32)) <= 0) goto out; switch(fsidtype) { - case 0: /* 4 bytes: 2 major, 2 minor, 4 inode */ + case FSID_DEV: /* 4 bytes: 2 major, 2 minor, 4 inode */ if (fsidlen != 8) goto out; memcpy(&dev, fsid, 4); @@ -133,13 +266,13 @@ void nfsd_fh(FILE *f) minor = ntohl(dev) & 0xFFFF; break; - case 1: /* 4 bytes - fsid */ + case FSID_NUM: /* 4 bytes - fsid */ if (fsidlen != 4) goto out; memcpy(&fsidnum, fsid, 4); break; - case 2: /* 12 bytes: 4 major, 4 minor, 4 inode + case FSID_MAJOR_MINOR: /* 12 bytes: 4 major, 4 minor, 4 inode * This format is never actually used but was * an historical accident */ @@ -150,7 +283,7 @@ void nfsd_fh(FILE *f) memcpy(&inode, fsid+8, 4); break; - case 3: /* 8 bytes: 4 byte packed device number, 4 inode */ + case FSID_ENCODE_DEV: /* 8 bytes: 4 byte packed device number, 4 inode */ /* This is *host* endian, not net-byte-order, because * no-one outside this host has any business interpreting it */ @@ -162,6 +295,33 @@ void nfsd_fh(FILE *f) minor = (dev & 0xff) | ((dev >> 12) & 0xfff00); break; + case FSID_UUID4_INUM: /* 4 byte inode number and 4 byte uuid */ + if (fsidlen != 8) + goto out; + memcpy(&inode, fsid, 4); + uuidlen = 4; + fhuuid = fsid+4; + break; + case FSID_UUID8: /* 8 byte uuid */ + if (fsidlen != 8) + goto out; + uuidlen = 8; + fhuuid = fsid; + break; + case FSID_UUID16: /* 16 byte uuid */ + if (fsidlen != 16) + goto out; + uuidlen = 16; + fhuuid = fsid; + break; + case FSID_UUID16_INUM: /* 8 byte inode number and 16 byte uuid */ + if (fsidlen != 24) + goto out; + memcpy(&inode64, fsid, 8); + inode = inode64; + uuidlen = 16; + fhuuid = fsid+8; + break; } auth_reload(); @@ -170,6 +330,7 @@ void nfsd_fh(FILE *f) for (i=0 ; i < MCL_MAXTYPES; i++) { for (exp = exportlist[i]; exp; exp = exp->m_next) { struct stat stb; + char u[16]; if (!client_member(dom, exp->m_client->m_hostname)) continue; @@ -180,16 +341,41 @@ void nfsd_fh(FILE *f) dev_missing ++; if (stat(exp->m_export.e_path, &stb) != 0) continue; - if (fsidtype == 1 && - ((exp->m_export.e_flags & NFSEXP_FSID) == 0 || - exp->m_export.e_fsid != fsidnum)) - continue; - if (fsidtype != 1) { + switch(fsidtype){ + case FSID_DEV: + case FSID_MAJOR_MINOR: + case FSID_ENCODE_DEV: if (stb.st_ino != inode) continue; if (major != major(stb.st_dev) || minor != minor(stb.st_dev)) continue; + break; + case FSID_NUM: + if (((exp->m_export.e_flags & NFSEXP_FSID) == 0 || + exp->m_export.e_fsid != fsidnum)) + continue; + break; + case FSID_UUID4_INUM: + case FSID_UUID16_INUM: + if (stb.st_ino != inode) + continue; + goto check_uuid; + case FSID_UUID8: + case FSID_UUID16: + if (!is_mountpoint(exp->m_export.e_path)) + continue; + check_uuid: + if (exp->m_export.e_uuid) + get_uuid(NULL, exp->m_export.e_uuid, + uuidlen, u); + else if (get_uuid(exp->m_export.e_path, NULL, + uuidlen, u) == 0) + continue; + + if (memcmp(u, fhuuid, uuidlen) != 0) + continue; + break; } /* It's a match !! */ if (!found) @@ -227,7 +413,15 @@ void nfsd_fh(FILE *f) qword_print(f, dom); qword_printint(f, fsidtype); qword_printhex(f, fsid, fsidlen); - qword_printint(f, time(0)+30*60); + /* The fsid -> path lookup can be quite expensive as it + * potentially stats and reads lots of devices, and some of those + * might have spun-down. The Answer is not likely to + * change underneath us, and an 'exportfs -f' can always + * remove this from the kernel, so use a really log + * timeout. Maybe this should be configurable on the command + * line. + */ + qword_printint(f, 0x7fffffff); if (found) qword_print(f, found->e_path); qword_eol(f); @@ -236,6 +430,54 @@ void nfsd_fh(FILE *f) return; } +static void write_fsloc(FILE *f, struct exportent *ep, char *path) +{ + struct servers *servers; + + if (ep->e_fslocmethod == FSLOC_NONE) + return; + + servers = replicas_lookup(ep->e_fslocmethod, ep->e_fslocdata, path); + if (!servers) + return; + qword_print(f, "fsloc"); + qword_printint(f, servers->h_num); + if (servers->h_num >= 0) { + int i; + for (i=0; ih_num; i++) { + qword_print(f, servers->h_mp[i]->h_host); + qword_print(f, servers->h_mp[i]->h_path); + } + } + qword_printint(f, servers->h_referral); + release_replicas(servers); +} + +static int dump_to_cache(FILE *f, char *domain, char *path, struct exportent *exp) +{ + qword_print(f, domain); + qword_print(f, path); + qword_printint(f, time(0)+30*60); + if (exp) { + qword_printint(f, exp->e_flags); + qword_printint(f, exp->e_anonuid); + qword_printint(f, exp->e_anongid); + qword_printint(f, exp->e_fsid); + write_fsloc(f, exp, path); + if (exp->e_uuid == NULL) { + char u[16]; + if (get_uuid(exp->e_path, NULL, 16, u)) { + qword_print(f, "uuid"); + qword_printhex(f, u, 16); + } + } else if (exp->e_uuid) { + qword_print(f, "uuid"); + qword_printhex(f, exp->e_uuid, 16); + } + } + return qword_eol(f); +} + void nfsd_export(FILE *f) { /* requests are: @@ -248,6 +490,7 @@ void nfsd_export(FILE *f) int i; char *dom, *path; nfs_export *exp, *found = NULL; + int found_type = 0; if (readline(fileno(f), &lbuf, &lbuflen) != 1) @@ -274,26 +517,25 @@ void nfsd_export(FILE *f) continue; if (strcmp(path, exp->m_export.e_path)) continue; - if (!found) + if (!found) { found = exp; - else { - xlog(L_WARNING, "%s exported to both %s and %s in %s", - path, exp->m_client->m_hostname, found->m_client->m_hostname, + found_type = i; + } else if (found_type == i && found->m_warned == 0) { + xlog(L_WARNING, "%s exported to both %s and %s, " + "arbitrarily choosing options from first", + path, found->m_client->m_hostname, exp->m_client->m_hostname, dom); + found->m_warned = 1; } } } - qword_print(f, dom); - qword_print(f, path); - qword_printint(f, time(0)+30*60); if (found) { - qword_printint(f, found->m_export.e_flags); - qword_printint(f, found->m_export.e_anonuid); - qword_printint(f, found->m_export.e_anongid); - qword_printint(f, found->m_export.e_fsid); + dump_to_cache(f, dom, path, &found->m_export); + mountlist_add(dom, path); + } else { + dump_to_cache(f, dom, path, NULL); } - qword_eol(f); out: if (dom) free(dom); if (path) free(path); @@ -306,16 +548,20 @@ struct { FILE *f; } cachelist[] = { { "auth.unix.ip", auth_unix_ip}, + { "auth.unix.gid", auth_unix_gid}, { "nfsd.export", nfsd_export}, { "nfsd.fh", nfsd_fh}, { NULL, NULL } }; +extern int manage_gids; void cache_open(void) { int i; - for (i=0; cachelist[i].cache_name; i++ ){ + for (i=0; cachelist[i].cache_name; i++ ) { char path[100]; + if (!manage_gids && cachelist[i].cache_handle == auth_unix_gid) + continue; sprintf(path, "/proc/net/rpc/%s/channel", cachelist[i].cache_name); cachelist[i].f = fopen(path, "r+"); } @@ -359,16 +605,9 @@ int cache_export_ent(char *domain, struct exportent *exp) if (!f) return -1; - qword_print(f, domain); - qword_print(f, exp->e_path); - qword_printint(f, time(0)+30*60); - qword_printint(f, exp->e_flags); - qword_printint(f, exp->e_anonuid); - qword_printint(f, exp->e_anongid); - qword_printint(f, exp->e_fsid); - err = qword_eol(f); - + err = dump_to_cache(f, domain, exp->e_path, exp); fclose(f); + mountlist_add(domain, exp->e_path); return err; }