reconnection patch for smbmount

Bill Hawes (whawes@star.net)
Mon, 19 Jan 1998 21:53:06 -0500


This is a multi-part message in MIME format.
--------------7251C11909F0274FECBDAC9E
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi Volker,

There's a problem in the 1.9.18 smbmount utility with reconnecting after
a droppped connection. Since the old socket have been closed, the
smbmount daemon must reopen the sockets before it tries another logon.
The existing smbmount fails to get a new connection so that the smbfs
must be remounted.

The attached patch (cumulative against 1.9.18 with my prior changes)
adds a call to open the socket again. It works OK, but has a minor
problem in that it fails if the SMBFS_DEBUG flag isn't set (i.e. if all
of the files are closed.) Maybe you (or someone) can spot the problem,
but this at least works to reconnect after dropped connections.

Regards,
Bill
--------------7251C11909F0274FECBDAC9E
Content-Type: text/plain; charset=us-ascii; name="smbmnt-patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="smbmnt-patch"

--- samba-1.9.18/source/smbmount.c.old Mon Jan 5 19:13:44 1998
+++ samba-1.9.18/source/smbmount.c Sun Jan 18 15:14:34 1998
@@ -31,6 +31,9 @@
#define REGISTER 0
#endif

+/* Uncomment this to allow debug the smbmount daemon */
+#define SMBFS_DEBUG 1
+
pstring cur_dir = "\\";
pstring cd_path = "";
extern pstring service;
@@ -60,6 +63,7 @@
extern int name_type;

extern int max_protocol;
+int port = SMB_PORT;


time_t newer_than = 0;
@@ -178,9 +182,6 @@
return(CVAL(inbuf,smb_rcls) == 0);
}

-
-/* #define SMBFS_DEBUG 1 */
-
static void
daemonize(void)
{
@@ -222,11 +223,11 @@
*/
static BOOL mount_send_login(char *inbuf, char *outbuf)
{
- struct connection_options opt;
- int res = cli_send_login(inbuf, outbuf, True, True, &opt);
+ struct connection_options opt;
+ int res = cli_send_login(inbuf, outbuf, True, True, &opt);

- if (!res)
- return res;
+ if (!res)
+ return res;

conn_options.protocol = opt.protocol;
conn_options.case_handling = CASE_LOWER;
@@ -260,9 +261,7 @@
{
if ((fd = open(mount_point, O_RDONLY)) < 0)
{
-#ifdef SMBFS_DEBUG
- printf("smbclient: can't open %s\n", mount_point);
-#endif
+ DEBUG(0, ("smbmount: can't open %s\n", mount_point));
break;
}

@@ -276,9 +275,7 @@
res = ioctl(fd, SMB_IOC_NEWCONN, &conn_options);
if (res != 0)
{
-#ifdef SMBFS_DEBUG
- printf("smbclient: ioctl failed, res=%d\n",res);
-#endif
+ DEBUG(0, ("smbmount: ioctl failed, res=%d\n", res));
}

close_sockets();
@@ -299,21 +296,22 @@
*/
signal(SIGUSR1, &usr1_handler);
pause();
-#ifdef SMBFS_DEBUG
- printf("smbclient: got signal, getting new socket\n");
-#endif
+ DEBUG(0, ("smbmount: got signal, getting new socket\n"));

- res = mount_send_login(inbuf,outbuf);
+ res = cli_open_sockets(port);
if (!res)
{
-#ifdef SMBFS_DEBUG
- printf("smbclient: login failed\n");
-#endif
+ DEBUG(0, ("smbmount: can't open sockets\n"));
+ continue;
+ }
+
+ res = mount_send_login(inbuf, outbuf);
+ if (!res)
+ {
+ DEBUG(0, ("smbmount: login failed\n"));
}
}
-#ifdef SMBFS_DEBUG
- printf("smbclient: exit\n");
-#endif
+ DEBUG(0, ("smbmount: exit\n"));
exit(1);
}

@@ -323,10 +321,11 @@
static void cmd_mount(char *inbuf,char *outbuf)
{
pstring mpoint;
- char mount_point[MAXPATHLEN+1];
+ pstring share_name;
pstring mount_command;
fstring buf;
int retval;
+ char mount_point[MAXPATHLEN+1];

if (!next_token(NULL, mpoint, NULL))
{
@@ -342,7 +341,15 @@
return;
}

- sprintf(mount_command, "smbmnt %s", mount_point);
+ /*
+ * Build the service name to report on the Unix side,
+ * converting '\' to '/' and ' ' to '_'.
+ */
+ strcpy(share_name, service);
+ string_replace(share_name, '\\', '/');
+ string_replace(share_name, ' ', '_');
+
+ sprintf(mount_command, "smbmnt %s -s %s", mount_point, share_name);

while(next_token(NULL, buf, NULL))
{
@@ -350,7 +357,7 @@
strcat(mount_command, buf);
}

- DEBUG(3,("mount command: %s\n", mount_command));
+ DEBUG(3, ("mount command: %s\n", mount_command));

/*
* Create the background process before trying the mount.
@@ -368,9 +375,6 @@
}


-
-
-
/* This defines the commands supported by this client */
struct
{
@@ -667,7 +671,6 @@
{
fstring base_directory;
char *pname = argv[0];
- int port = SMB_PORT;
int opt;
extern FILE *dbf;
extern char *optarg;
@@ -739,7 +742,7 @@
if (*argv[1] != '-')
{

- strcpy(service,argv[1]);
+ strcpy(service, argv[1]);
/* Convert any '/' characters in the service name to '\' characters */
string_replace( service, '/','\\');
argc--;
@@ -751,15 +754,6 @@
printf("\n%s: Not enough '\\' characters in service\n",service);
exit(1);
}
-
-/*
- if (count_chars(service,'\\') > 3)
- {
- usage(pname);
- printf("\n%s: Too many '\\' characters in service\n",service);
- exit(1);
- }
- */

if (argc > 1 && (*argv[1] != '-'))
{
--- samba-1.9.18/source/smbmnt.c.old Mon Jan 5 17:56:29 1998
+++ samba-1.9.18/source/smbmnt.c Sat Jan 17 12:05:49 1998
@@ -53,18 +53,18 @@
"-f mode permission the files get (octal notation)\n"
"-d mode permission the dirs get (octal notation)\n"
"-P pid connection handler's pid\n\n"
+ "-s share share name on server\n\n"
"-h print this help text\n");
}

static int
-parse_args(int argc, char *argv[], struct smb_mount_data *data)
+parse_args(int argc, char *argv[], struct smb_mount_data *data, char **share)
{
int opt;
struct passwd *pwd;
struct group *grp;

- while ((opt = getopt (argc, argv, "u:g:f:d:"))
- != EOF)
+ while ((opt = getopt (argc, argv, "u:g:f:d:s:")) != EOF)
{
switch (opt)
{
@@ -108,6 +108,9 @@
case 'd':
data->dir_mode = strtol(optarg, NULL, 8);
break;
+ case 's':
+ *share = optarg;
+ break;
default:
return -1;
}
@@ -157,17 +160,13 @@
int
main(int argc, char *argv[])
{
- struct smb_mount_data data;
- struct stat st;
-
- int fd;
- int um;
+ char *mount_point, *share_name = NULL;
+ FILE *mtab;
+ int fd, um;
unsigned int flags;
-
- char *mount_point;
-
- struct mntent ment;
- FILE *mtab;
+ struct smb_mount_data data;
+ struct stat st;
+ struct mntent ment;

progname = argv[0];

@@ -222,7 +221,7 @@
data.file_mode = (S_IRWXU|S_IRWXG|S_IRWXO) & ~um;
data.dir_mode = 0;

- if (parse_args(argc, argv, &data) != 0) {
+ if (parse_args(argc, argv, &data, &share_name) != 0) {
usage();
return -1;
}
@@ -239,15 +238,14 @@

flags = MS_MGC_VAL;

- if (mount(NULL, mount_point, "smbfs",
- flags, (char *)&data) < 0) {
+ if (mount(share_name, mount_point, "smbfs", flags, (char *)&data) < 0)
+ {
perror("mount error");
- printf("Please look at smbmount's manual page for "
- "possible reasons\n");
+ printf("Please refer to the smbmnt(8) manual page\n");
return -1;
}

- ment.mnt_fsname = "none";
+ ment.mnt_fsname = share_name ? share_name : "none";
ment.mnt_dir = fullpath(mount_point);
ment.mnt_type = "smbfs";
ment.mnt_opts = "";

--------------7251C11909F0274FECBDAC9E--