This patch was sent to me by Urban Widmark <urban@teststation.com>
(thanks Urban!).
It allows me to mount remote Win shares to my Linux box
automatically. I'm using kernel automounter.
The problem was that I have a ro root fs
and my /etc/mtab isn't writable (symlinked to /proc/mounts).
Patch adds -n and -o nomtab options for smbmount.
-o nomtab was particularly useful for me.
I don't see it applied in Samba 2.2.2.
I rediffed it for 2.2.2, compiled, and so far it is working fine.
I'd like to see it merged into mainline code.
Please CC any comments, I'm not on the list.
--
vda
diff --recursive -u samba-2.2.2/source/client/smbmnt.c
samba-2.2.2-nomtab/source/client/smbmnt.c
--- samba-2.2.2/source/client/smbmnt.c Sun Apr 8 20:22:51 2001
+++ samba-2.2.2-nomtab/source/client/smbmnt.c Tue Nov 6 13:01:19 2001
@@ -28,6 +28,7 @@
static uid_t mount_uid;
static gid_t mount_gid;
static int mount_ro;
+static int no_mtab;
static unsigned mount_fmask;
static unsigned mount_dmask;
static int user_mount;
@@ -40,6 +41,7 @@
printf("Usage: smbmnt mount-point [options]\n");
printf("Version %s\n\n",VERSION);
printf("-s share share name on server\n"
+ "-n don't update /etc/mtab\n"
"-r mount read-only\n"
"-u uid mount as uid\n"
"-g gid mount as gid\n"
@@ -54,7 +56,7 @@
{
int opt;
- while ((opt = getopt (argc, argv, "s:u:g:rf:d:o:")) != EOF)
+ while ((opt = getopt (argc, argv, "s:u:g:nrf:d:o:")) != EOF)
{
switch (opt)
{
@@ -71,6 +73,9 @@
mount_gid = strtol(optarg, NULL, 0);
}
break;
+ case 'n':
+ no_mtab = 1;
+ break;
case 'r':
mount_ro = 1;
break;
@@ -271,36 +276,33 @@
return -1;
}
- if ((fd = open(MOUNTED"~", O_RDWR|O_CREAT|O_EXCL, 0600)) ==
-1)
- {
- fprintf(stderr, "Can't get "MOUNTED"~ lock
file");
- return 1;
- }
- close(fd);
-
- if ((mtab = setmntent(MOUNTED, "a+")) == NULL)
- {
- fprintf(stderr, "Can't open " MOUNTED);
- return 1;
- }
+ if (!no_mtab) {
+ if ((fd = open(MOUNTED"~", O_RDWR|O_CREAT|O_EXCL, 0600)) == -1){
+ fprintf(stderr, "Can't get "MOUNTED"~ lock file");
+ return 1;
+ }
+ close(fd);
- if (addmntent(mtab, &ment) == 1)
- {
- fprintf(stderr, "Can't write mount entry");
- return 1;
- }
- if (fchmod(fileno(mtab), 0644) == -1)
- {
- fprintf(stderr, "Can't set perms on "MOUNTED);
- return 1;
- }
- endmntent(mtab);
+ if ((mtab = setmntent(MOUNTED, "a+")) == NULL) {
+ fprintf(stderr, "Can't open " MOUNTED);
+ return 1;
+ }
- if (unlink(MOUNTED"~") == -1)
- {
- fprintf(stderr, "Can't remove
"MOUNTED"~");
- return 1;
- }
+ if (addmntent(mtab, &ment) == 1) {
+ fprintf(stderr, "Can't write mount entry");
+ return 1;
+ }
+ if (fchmod(fileno(mtab), 0644) == -1) {
+ fprintf(stderr, "Can't set perms on "MOUNTED);
+ return 1;
+ }
+ endmntent(mtab);
+
+ if (unlink(MOUNTED"~") == -1) {
+ fprintf(stderr, "Can't remove "MOUNTED"~");
+ return 1;
+ }
+ }
return 0;
}
diff --recursive -u samba-2.2.2/source/client/smbmount.c
samba-2.2.2-nomtab/source/client/smbmount.c
--- samba-2.2.2/source/client/smbmount.c Sat Oct 13 21:09:19 2001
+++ samba-2.2.2-nomtab/source/client/smbmount.c Tue Nov 6 13:01:19 2001
@@ -53,6 +53,7 @@
static int mount_ro;
static unsigned mount_fmask;
static unsigned mount_dmask;
+static BOOL no_mtab = False;
static void usage(void);
@@ -253,6 +254,9 @@
return;
}
+ if (no_mtab)
+ return;
+
if ((fd = open(MOUNTED"~", O_RDWR|O_CREAT|O_EXCL, 0600)) ==
-1) {
DEBUG(0,("%d: Can't get "MOUNTED"~ lock
file", getpid()));
return;
@@ -461,6 +465,9 @@
args[i++] = "-s";
args[i++] = svc2;
+ if (no_mtab) {
+ args[i++] = "-n";
+ }
if (mount_ro) {
args[i++] = "-r";
}
@@ -708,8 +715,13 @@
argc -= 2;
argv += 2;
- opt = getopt(argc, argv, "o:");
- if(opt != 'o') {
+ opt = getopt(argc, argv, "no:");
+ if (opt == 'n') {
+ DEBUG(0,("No mtab!\n"));
+ no_mtab = True;
+ opt = getopt(argc, argv, "o:");
+ }
+ if (opt != 'o') {
return;
}
@@ -782,6 +794,8 @@
if(!strcmp(opts, "nocaps")) {
fprintf(stderr, "Unhandled option: %s\n", opteq+1);
exit(1);
+ } else if(!strcmp(opts, "nomtab")) {
+ no_mtab = True;
} else if(!strcmp(opts, "guest")) {
*password = '\0';
got_pass = True;