From: neilbrown Date: Mon, 4 Aug 2003 03:14:23 +0000 (+0000) Subject: Open channel files O_WRONLY, and improve mountlist support. X-Git-Tag: nfs-utils-1-0-5-post1^0 X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=18fc7a86a2a1213762cc4107565903127efadafc;p=nfs-utils.git Open channel files O_WRONLY, and improve mountlist support. --- diff --git a/ChangeLog b/ChangeLog index bf1adc1..9f1d85a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2003-08-04 NeilBrown + * support/nfs/nfsexport.c: open channel file O_WRONLY when + only writing. + * utils/mountd/cache.c: maintain mountlist when new_cache is + active. Also use O_WRONLY for channel files. + * utils/mountd/mountd.h: mountlist_{del,add} now take a host name + rather than an nfs_export. + * utils/mountd/rmtab.c: ditto. + 2003-07-24 Chip Salzenberg * support/nfs/xlog.c (xlog): Revise buffer-overflow fix to diff --git a/support/nfs/nfsexport.c b/support/nfs/nfsexport.c index 0e8b52b..782cc50 100644 --- a/support/nfs/nfsexport.c +++ b/support/nfs/nfsexport.c @@ -93,7 +93,7 @@ nfsexport(struct nfsctl_export *exp) { struct nfsctl_arg arg; int fd; - if ((fd=open("/proc/net/rpc/nfsd.fh/channel", O_RDWR))>= 0) { + if ((fd=open("/proc/net/rpc/nfsd.fh/channel", O_WRONLY))>= 0) { close(fd); return exp_unexp(exp, 1); } @@ -108,7 +108,7 @@ nfsunexport(struct nfsctl_export *exp) struct nfsctl_arg arg; int fd; - if ((fd=open("/proc/net/rpc/nfsd.fh/channel", O_RDWR))>= 0) { + if ((fd=open("/proc/net/rpc/nfsd.fh/channel", O_WRONLY))>= 0) { close(fd); return exp_unexp(exp, 0); } diff --git a/utils/mountd/cache.c b/utils/mountd/cache.c index 3402d12..2e35b17 100644 --- a/utils/mountd/cache.c +++ b/utils/mountd/cache.c @@ -78,6 +78,9 @@ void auth_unix_ip(FILE *f) qword_print(f, *client?client:"DEFAULT"); qword_eol(f); + if (client && strcmp(ipaddr, client)) + mountlist_add(ipaddr, *client?client:"DEFAULT"); + if (client) free(client); } @@ -258,6 +261,7 @@ void nfsd_export(FILE *f) qword_printint(f, found->m_export.e_anonuid); qword_printint(f, found->m_export.e_anongid); qword_printint(f, found->m_export.e_fsid); + mountlist_add(dom, path); } qword_eol(f); out: @@ -320,7 +324,7 @@ int cache_process_req(fd_set *readfds) void cache_export_ent(char *domain, struct exportent *exp) { - FILE *f = fopen("/proc/net/rpc/nfsd.export/channel", "r+"); + FILE *f = fopen("/proc/net/rpc/nfsd.export/channel", "w"); if (!f) return; @@ -334,13 +338,15 @@ void cache_export_ent(char *domain, struct exportent *exp) qword_eol(f); fclose(f); + + mountlist_add(domain, exp->e_path); } void cache_export(nfs_export *exp) { FILE *f; - f = fopen("/proc/net/rpc/auth.unix.ip/channel", "r+"); + f = fopen("/proc/net/rpc/auth.unix.ip/channel", "w"); if (!f) return; @@ -352,6 +358,9 @@ void cache_export(nfs_export *exp) fclose(f); + if (strcmp(inet_ntoa(exp->m_client->m_addrlist[0]), exp->m_client->m_hostname)) + mountlist_add(inet_ntoa(exp->m_client->m_addrlist[0]), exp->m_client->m_hostname); + cache_export_ent(exp->m_client->m_hostname, &exp->m_export); } diff --git a/utils/mountd/mountd.c b/utils/mountd/mountd.c index d0d8103..6dbd224 100644 --- a/utils/mountd/mountd.c +++ b/utils/mountd/mountd.c @@ -117,8 +117,14 @@ mount_umnt_1_svc(struct svc_req *rqstp, dirpath *argp, void *resp) if (!(exp = auth_authenticate("unmount", sin, p))) { return 1; } - mountlist_del(exp, p); - export_reset (exp); + if (new_cache) { + if (strcmp(inet_ntoa(exp->m_client->m_addrlist[0]), exp->m_client->m_hostname)) + mountlist_del(inet_ntoa(exp->m_client->m_addrlist[0]), exp->m_client->m_hostname); + mountlist_del(exp->m_client->m_hostname, p); + } else { + mountlist_del(exp->m_client->m_hostname, p); + export_reset (exp); + } return 1; } @@ -322,7 +328,7 @@ get_rootfh(struct svc_req *rqstp, dirpath *path, int *error, int v3) stb.st_dev, stb.st_ino); } if (fh != NULL) { - mountlist_add(exp, p); + mountlist_add(exp->m_client->m_hostname, p); *error = NFS_OK; export_reset (exp); return fh; diff --git a/utils/mountd/mountd.h b/utils/mountd/mountd.h index 9f9bc1f..d64c171 100644 --- a/utils/mountd/mountd.h +++ b/utils/mountd/mountd.h @@ -45,8 +45,8 @@ nfs_export * auth_authenticate(char *what, struct sockaddr_in *sin, char *path); void auth_export(nfs_export *exp); -void mountlist_add(nfs_export *exp, const char *path); -void mountlist_del(nfs_export *exp, const char *path); +void mountlist_add(char *host, const char *path); +void mountlist_del(char *host, const char *path); void mountlist_del_all(struct sockaddr_in *sin); mountlist mountlist_list(void); diff --git a/utils/mountd/rmtab.c b/utils/mountd/rmtab.c index 8c4a5a9..844de51 100644 --- a/utils/mountd/rmtab.c +++ b/utils/mountd/rmtab.c @@ -46,7 +46,7 @@ slink_safe_rename(const char * oldpath, const char * newpath) } void -mountlist_add(nfs_export *exp, const char *path) +mountlist_add(char *host, const char *path) { struct rmtabent xe; struct rmtabent *rep; @@ -58,7 +58,7 @@ mountlist_add(nfs_export *exp, const char *path) setrmtabent("r+"); while ((rep = getrmtabent(1, &pos)) != NULL) { if (strcmp (rep->r_client, - exp->m_client->m_hostname) == 0 + host) == 0 && strcmp(rep->r_path, path) == 0) { rep->r_count++; putrmtabent(rep, &pos); @@ -68,7 +68,7 @@ mountlist_add(nfs_export *exp, const char *path) } } endrmtabent(); - strncpy(xe.r_client, exp->m_client->m_hostname, + strncpy(xe.r_client, host, sizeof (xe.r_client) - 1); xe.r_client [sizeof (xe.r_client) - 1] = '\0'; strncpy(xe.r_path, path, sizeof (xe.r_path) - 1); @@ -82,11 +82,10 @@ mountlist_add(nfs_export *exp, const char *path) } void -mountlist_del(nfs_export *exp, const char *path) +mountlist_del(char *hname, const char *path) { struct rmtabent *rep; FILE *fp; - char *hname = exp->m_client->m_hostname; int lockid; int match;