1
Description: fix mtab corruption via resource limits
2
Origin: backport, http://git.samba.org/?p=cifs-utils.git;a=commitdiff;h=f6eae44a3d05b6515a59651e6bed8b6dde689aec
4
Index: samba-3.4.7~dfsg/source3/client/mount.cifs.c
5
===================================================================
6
--- samba-3.4.7~dfsg.orig/source3/client/mount.cifs.c 2011-09-29 09:27:30.269335212 -0400
7
+++ samba-3.4.7~dfsg/source3/client/mount.cifs.c 2011-09-29 09:31:01.057340608 -0400
13
size_t options_size = 0;
15
int retry = 0; /* set when we have to retry mount with uppercase */
16
@@ -1578,6 +1580,23 @@
21
+ fd = fileno(pmntfile);
23
+ fprintf(stderr, "mntent does not appear to be valid\n");
28
+ rc = fstat(fd, &statbuf);
30
+ fprintf(stderr, "unable to fstat open mtab\n");
31
+ endmntent(pmntfile);
37
mountent.mnt_fsname = dev_name;
38
mountent.mnt_dir = mountpoint;
39
mountent.mnt_type = CONST_DISCARD(char *,"cifs");
40
@@ -1609,8 +1628,17 @@
42
mountent.mnt_freq = 0;
43
mountent.mnt_passno = 0;
44
- rc = addmntent(pmntfile,&mountent);
45
- endmntent(pmntfile);
46
+ rc = addmntent(pmntfile, &mountent);
48
+ fprintf(stderr, "unable to add mount entry to mtab\n");
49
+ ftruncate(fd, statbuf.st_size);
52
+ tmprc = my_endmntent(pmntfile, statbuf.st_size);
54
+ fprintf(stderr, "error %d detected on close of mtab\n", tmprc);
58
SAFE_FREE(mountent.mnt_opts);
60
Index: samba-3.4.7~dfsg/source3/client/mount.h
61
===================================================================
62
--- samba-3.4.7~dfsg.orig/source3/client/mount.h 2011-09-29 09:27:32.797335278 -0400
63
+++ samba-3.4.7~dfsg/source3/client/mount.h 2011-09-29 09:31:09.457340826 -0400
66
extern int lock_mtab(void);
67
extern void unlock_mtab(void);
68
+extern int my_endmntent(FILE *stream, off_t size);
70
#endif /* ! _MOUNT_H_ */
71
Index: samba-3.4.7~dfsg/source3/client/mtab.c
72
===================================================================
73
--- samba-3.4.7~dfsg.orig/source3/client/mtab.c 2011-09-29 09:27:36.725335379 -0400
74
+++ samba-3.4.7~dfsg/source3/client/mtab.c 2011-09-29 09:31:31.637341388 -0400
80
+ * Call fflush and fsync on the mtab, and then endmntent. If either fflush
81
+ * or fsync fails, then truncate the file back to "size". endmntent is called
82
+ * unconditionally, and the errno (if any) from fflush and fsync are returned.
85
+my_endmntent(FILE *stream, off_t size)
89
+ fd = fileno(stream);
93
+ rc = fflush(stream);
97
+ /* truncate file back to "size" -- best effort here */
100
+ ftruncate(fd, size);