]> git.decadent.org.uk Git - nfs-utils.git/commitdiff
Error check messages sent to the kernel.
authorNeil Brown <neilb@suse.de>
Thu, 11 Jan 2007 01:45:48 +0000 (12:45 +1100)
committerNeil Brown <neilb@suse.de>
Thu, 11 Jan 2007 01:45:48 +0000 (12:45 +1100)
And make sure that if we fail to export a filesystem in mountd,
then we don't try to get a filehandle on it, or a deadlock
might occur.

support/include/nfslib.h
support/nfs/cacheio.c
support/nfs/nfsexport.c
utils/gssd/cacheio.c
utils/gssd/cacheio.h
utils/gssd/svcgssd_proc.c
utils/mountd/cache.c
utils/mountd/mountd.c

index 3e25761cef700c70e4f16700e38fb617ee013bea..aba37c2fced4e4ed7e42070b4c8c2461f7d19233 100644 (file)
@@ -132,7 +132,7 @@ struct nfs_fh_len * getfh_size(struct sockaddr *addr, const char *, int size);
 void qword_print(FILE *f, char *str);
 void qword_printhex(FILE *f, char *str, int slen);
 void qword_printint(FILE *f, int num);
 void qword_print(FILE *f, char *str);
 void qword_printhex(FILE *f, char *str, int slen);
 void qword_printint(FILE *f, int num);
-void qword_eol(FILE *f);
+int qword_eol(FILE *f);
 int readline(int fd, char **buf, int *lenp);
 int qword_get(char **bpp, char *dest, int bufsize);
 int qword_get_int(char **bpp, int *anint);
 int readline(int fd, char **buf, int *lenp);
 int qword_get(char **bpp, char *dest, int bufsize);
 int qword_get_int(char **bpp, int *anint);
index 3e868d8843e9c9153be7ee595eec4517ec5cd5b4..36473cf3b911beb1fa7670a2a57225b58c8130bc 100644 (file)
@@ -109,10 +109,10 @@ void qword_printint(FILE *f, int num)
        fprintf(f, "%d ", num);
 }
 
        fprintf(f, "%d ", num);
 }
 
-void qword_eol(FILE *f)
+int qword_eol(FILE *f)
 {
        fprintf(f,"\n");
 {
        fprintf(f,"\n");
-       fflush(f);
+       return fflush(f);
 }
 
 
 }
 
 
index aa0e49b8cfbff688c42fcd76f5faa77318bb8a52..f129fd2e088a6808200043fed007302c92577fdf 100644 (file)
@@ -38,6 +38,7 @@ exp_unexp(struct nfsctl_export *exp, int export)
        char fsidstr[8];
        __u16 dev;
        __u32 inode;
        char fsidstr[8];
        __u16 dev;
        __u32 inode;
+       int err;
 
 
        f = fopen("/proc/net/rpc/nfsd.export/channel", "w");
 
 
        f = fopen("/proc/net/rpc/nfsd.export/channel", "w");
@@ -53,7 +54,7 @@ exp_unexp(struct nfsctl_export *exp, int export)
        } else
                qword_printint(f, 1);
 
        } else
                qword_printint(f, 1);
 
-       qword_eol(f);
+       err = qword_eol(f);
        fclose(f);
 
        if (stat(exp->ex_path, &stb) != 0)
        fclose(f);
 
        if (stat(exp->ex_path, &stb) != 0)
@@ -71,7 +72,7 @@ exp_unexp(struct nfsctl_export *exp, int export)
                } else
                        qword_printint(f, 1);
 
                } else
                        qword_printint(f, 1);
 
-               qword_eol(f);
+               err = qword_eol(f) || err;
        }
        qword_print(f,exp->ex_client);
        qword_printint(f,0);
        }
        qword_print(f,exp->ex_client);
        qword_printint(f,0);
@@ -85,9 +86,9 @@ exp_unexp(struct nfsctl_export *exp, int export)
                qword_print(f, exp->ex_path);
        } else
                qword_printint(f, 1);
                qword_print(f, exp->ex_path);
        } else
                qword_printint(f, 1);
-       qword_eol(f);
+       err = qword_eol(f) || err;
        fclose(f);
        fclose(f);
-       return 0;
+       return err;
 }
 
 int
 }
 
 int
index 75c7a5d8e3b4a0d481d394db8a39257a4afe8bf3..f2f2960ca3491685d0285a60be457ed52b042ccc 100644 (file)
@@ -173,11 +173,13 @@ void qword_printint(FILE *f, int num)
        printerr(2, "%d ", num);
 }
 
        printerr(2, "%d ", num);
 }
 
-void qword_eol(FILE *f)
+int qword_eol(FILE *f)
 {
 {
+       int err;
        fprintf(f,"\n");
        fprintf(f,"\n");
-       fflush(f);
+       err = fflush(f);
        printerr(2, "\n");
        printerr(2, "\n");
+       return err;
 }
 
 
 }
 
 
index cc97b364fef040b6ca4bd6ff5a92c5b3fb67a0e3..dfff2586ae23ab8942296af35ab5d9b68f326ee4 100644 (file)
@@ -40,7 +40,7 @@ void qword_addeol(char **bpp, int *lp);
 void qword_print(FILE *f, char *str);
 void qword_printhex(FILE *f, char *str, int slen);
 void qword_printint(FILE *f, int num);
 void qword_print(FILE *f, char *str);
 void qword_printhex(FILE *f, char *str, int slen);
 void qword_printint(FILE *f, int num);
-void qword_eol(FILE *f);
+int qword_eol(FILE *f);
 int readline(int fd, char **buf, int *lenp);
 int qword_get(char **bpp, char *dest, int bufsize);
 int qword_get_int(char **bpp, int *anint);
 int readline(int fd, char **buf, int *lenp);
 int qword_get(char **bpp, char *dest, int bufsize);
 int qword_get_int(char **bpp, int *anint);
index 79813990c518c2dca579aaceded088e15ee08106..4037159b2ede2f737d0229728c15425ff9acdbd3 100644 (file)
@@ -72,6 +72,7 @@ do_svc_downcall(gss_buffer_desc *out_handle, struct svc_cred *cred,
        FILE *f;
        int i;
        char *fname = NULL;
        FILE *f;
        int i;
        char *fname = NULL;
+       int err;
 
        printerr(1, "doing downcall\n");
        if ((fname = mech2file(mech)) == NULL)
 
        printerr(1, "doing downcall\n");
        if ((fname = mech2file(mech)) == NULL)
@@ -93,9 +94,9 @@ do_svc_downcall(gss_buffer_desc *out_handle, struct svc_cred *cred,
                qword_printint(f, cred->cr_groups[i]);
        qword_print(f, fname);
        qword_printhex(f, context_token->value, context_token->length);
                qword_printint(f, cred->cr_groups[i]);
        qword_print(f, fname);
        qword_printhex(f, context_token->value, context_token->length);
-       qword_eol(f);
+       err = qword_eol(f);
        fclose(f);
        fclose(f);
-       return 0;
+       return err;
 out_err:
        printerr(0, "WARNING: downcall failed\n");
        return -1;
 out_err:
        printerr(0, "WARNING: downcall failed\n");
        return -1;
index 726b98fc9b2a35681e7a4c07d2c2412b068ca33b..dcb5dac1369bc3621290f730fd3b3537d1115cd0 100644 (file)
@@ -35,7 +35,7 @@
  * Record is terminated with newline.
  *
  */
  * Record is terminated with newline.
  *
  */
-void cache_export_ent(char *domain, struct exportent *exp);
+int cache_export_ent(char *domain, struct exportent *exp);
 
 
 char *lbuf  = NULL;
 
 
 char *lbuf  = NULL;
@@ -352,12 +352,12 @@ int cache_process_req(fd_set *readfds)
  * % echo $domain $path $[now+30*60] $options $anonuid $anongid $fsid > /proc/net/rpc/nfsd.export/channel
  */
 
  * % echo $domain $path $[now+30*60] $options $anonuid $anongid $fsid > /proc/net/rpc/nfsd.export/channel
  */
 
-void cache_export_ent(char *domain, struct exportent *exp)
+int cache_export_ent(char *domain, struct exportent *exp)
 {
 {
-
+       int err;
        FILE *f = fopen("/proc/net/rpc/nfsd.export/channel", "w");
        if (!f)
        FILE *f = fopen("/proc/net/rpc/nfsd.export/channel", "w");
        if (!f)
-               return;
+               return -1;
 
        qword_print(f, domain);
        qword_print(f, exp->e_path);
 
        qword_print(f, domain);
        qword_print(f, exp->e_path);
@@ -366,28 +366,32 @@ void cache_export_ent(char *domain, struct exportent *exp)
        qword_printint(f, exp->e_anonuid);
        qword_printint(f, exp->e_anongid);
        qword_printint(f, exp->e_fsid);
        qword_printint(f, exp->e_anonuid);
        qword_printint(f, exp->e_anongid);
        qword_printint(f, exp->e_fsid);
-       qword_eol(f);
+       err = qword_eol(f);
 
        fclose(f);
 
        fclose(f);
+       return err;
 }
 
 }
 
-void cache_export(nfs_export *exp)
+int cache_export(nfs_export *exp)
 {
 {
+       int err;
        FILE *f;
 
        f = fopen("/proc/net/rpc/auth.unix.ip/channel", "w");
        if (!f)
        FILE *f;
 
        f = fopen("/proc/net/rpc/auth.unix.ip/channel", "w");
        if (!f)
-               return;
+               return -1;
 
        qword_print(f, "nfsd");
        qword_print(f, inet_ntoa(exp->m_client->m_addrlist[0]));
        qword_printint(f, time(0)+30*60);
        qword_print(f, exp->m_client->m_hostname);
 
        qword_print(f, "nfsd");
        qword_print(f, inet_ntoa(exp->m_client->m_addrlist[0]));
        qword_printint(f, time(0)+30*60);
        qword_print(f, exp->m_client->m_hostname);
-       qword_eol(f);
+       err = qword_eol(f);
        
        fclose(f);
 
        
        fclose(f);
 
-       cache_export_ent(exp->m_client->m_hostname, &exp->m_export);
+       err = cache_export_ent(exp->m_client->m_hostname, &exp->m_export)
+               || err;
+       return err;
 }
 
 /* Get a filehandle.
 }
 
 /* Get a filehandle.
@@ -413,9 +417,10 @@ cache_get_filehandle(nfs_export *exp, int len, char *p)
        qword_print(f, exp->m_client->m_hostname);
        qword_print(f, p);
        qword_printint(f, len); 
        qword_print(f, exp->m_client->m_hostname);
        qword_print(f, p);
        qword_printint(f, len); 
-       qword_eol(f);
+       failed = qword_eol(f);
        
        
-       failed = (fgets(buf, sizeof(buf), f) == NULL);
+       if (!failed)
+               failed = (fgets(buf, sizeof(buf), f) == NULL);
        fclose(f);
        if (failed)
                return NULL;
        fclose(f);
        if (failed)
                return NULL;
index 08f294d95ac71488d2ec2b71ecb1db43670d8559..72332ce7772ad559519516293b5dedcec47b3349 100644 (file)
@@ -29,7 +29,7 @@
 
 extern void    cache_open(void);
 extern struct nfs_fh_len *cache_get_filehandle(nfs_export *exp, int len, char *p);
 
 extern void    cache_open(void);
 extern struct nfs_fh_len *cache_get_filehandle(nfs_export *exp, int len, char *p);
-extern void cache_export(nfs_export *exp);
+extern int cache_export(nfs_export *exp);
 
 extern void my_svc_run(void);
 
 
 extern void my_svc_run(void);
 
@@ -416,7 +416,10 @@ get_rootfh(struct svc_req *rqstp, dirpath *path, mountstat3 *error, int v3)
                 */
                struct nfs_fh_len  *fh;
 
                 */
                struct nfs_fh_len  *fh;
 
-               cache_export(exp);
+               if (cache_export(exp)) {
+                       *error = NFSERR_ACCES;
+                       return NULL;
+               }
                fh = cache_get_filehandle(exp, v3?64:32, p);
                if (fh == NULL) 
                        *error = NFSERR_ACCES;
                fh = cache_get_filehandle(exp, v3?64:32, p);
                if (fh == NULL) 
                        *error = NFSERR_ACCES;