RIP BOOL. Convert BOOL -> bool. I found a few interesting
[samba.git] / source3 / client / smbmount.c
index 343d4f267576b7b7cf2821f8d9016817763f38ea..95adc9a8f233c4b77413621ebbb5e1757a565cca 100644 (file)
@@ -5,7 +5,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#define NO_SYSLOG
-
 #include "includes.h"
 
 #include <mntent.h>
 #include <asm/types.h>
 #include <linux/smb_fs.h>
 
-extern BOOL in_client;
+extern bool in_client;
 extern pstring user_socket_options;
+extern char *optarg;
+extern int optind;
 
 static pstring credentials;
 static pstring my_netbios_name;
@@ -39,20 +38,20 @@ static pstring service;
 static pstring options;
 
 static struct in_addr dest_ip;
-static BOOL have_ip;
+static bool have_ip;
 static int smb_port = 0;
-static BOOL got_user;
-static BOOL got_pass;
+static bool got_user;
+static bool got_pass;
 static uid_t mount_uid;
 static gid_t mount_gid;
 static int mount_ro;
 static unsigned mount_fmask;
 static unsigned mount_dmask;
-static BOOL use_kerberos;
+static bool use_kerberos;
 /* TODO: Add code to detect smbfs version in kernel */
-static BOOL status32_smbfs = False;
-static BOOL smbfs_has_unicode = False;
-static BOOL smbfs_has_lfs = False;
+static bool status32_smbfs = False;
+static bool smbfs_has_unicode = False;
+static bool smbfs_has_lfs = False;
 
 static void usage(void);
 
@@ -147,12 +146,12 @@ static struct cli_state *do_connection(char *the_service)
        make_nmb_name(&called , server, 0x20);
 
  again:
-        zero_ip(&ip);
+        zero_ip_v4(&ip);
        if (have_ip) ip = dest_ip;
 
        /* have to open a new connection */
-       if (!(c=cli_initialise(NULL)) || (cli_set_port(c, smb_port) != smb_port) ||
-           !cli_connect(c, server_n, &ip)) {
+       if (!(c=cli_initialise()) || (cli_set_port(c, smb_port) != smb_port) ||
+           !NT_STATUS_IS_OK(cli_connect(c, server_n, &ip))) {
                DEBUG(0,("%d: Connection to %s failed\n", sys_getpid(), server_n));
                if (c) {
                        cli_shutdown(c);
@@ -213,14 +212,14 @@ static struct cli_state *do_connection(char *the_service)
                c->force_dos_errors = True;
        }
 
-       if (!cli_session_setup(c, username, 
-                              password, strlen(password),
-                              password, strlen(password),
-                              workgroup)) {
+       if (!NT_STATUS_IS_OK(cli_session_setup(c, username, 
+                                              password, strlen(password),
+                                              password, strlen(password),
+                                              workgroup))) {
                /* if a password was not supplied then try again with a
                        null username */
                if (password[0] || !username[0] ||
-                               !cli_session_setup(c, "", "", 0, "", 0, workgroup)) {
+                   !NT_STATUS_IS_OK(cli_session_setup(c, "", "", 0, "", 0, workgroup))) {
                        DEBUG(0,("%d: session setup failed: %s\n",
                                sys_getpid(), cli_errstr(c)));
                        cli_shutdown(c);
@@ -383,10 +382,14 @@ static void send_fs_socket(char *the_service, char *mount_point, struct cli_stat
 
                   If we don't do this we will "leak" sockets and memory on
                   each reconnection we have to make. */
+               c->smb_rw_error = DO_NOT_DO_TDIS;
                cli_shutdown(c);
                c = NULL;
 
                if (!closed) {
+                       /* close the name cache so that close_our_files() doesn't steal its FD */
+                       namecache_shutdown();
+
                        /* redirect stdout & stderr since we can't know that
                           the library functions we use are using DEBUG. */
                        if ( (fd = open("/dev/null", O_WRONLY)) < 0)
@@ -428,11 +431,11 @@ static void send_fs_socket(char *the_service, char *mount_point, struct cli_stat
  **/
 static void init_mount(void)
 {
-       char mount_point[MAXPATHLEN+1];
+       char mount_point[PATH_MAX+1];
        pstring tmp;
        pstring svc2;
        struct cli_state *c;
-       char *args[20];
+       const char *args[20];
        int i, status;
 
        if (realpath(mpoint, mount_point) == NULL) {
@@ -500,12 +503,12 @@ static void init_mount(void)
                asprintf(&smbmnt_path, "%s/smbmnt", dyn_BINDIR);
                
                if (file_exist(smbmnt_path, NULL)) {
-                       execv(smbmnt_path, args);
+                       execv(smbmnt_path, (char * const *)args);
                        fprintf(stderr,
                                "smbfs/init_mount: execv of %s failed. Error was %s.",
                                smbmnt_path, strerror(errno));
                } else {
-                       execvp("smbmnt", args);
+                       execvp("smbmnt", (char * const *)args);
                        fprintf(stderr,
                                "smbfs/init_mount: execv of %s failed. Error was %s.",
                                "smbmnt", strerror(errno));
@@ -546,7 +549,7 @@ static void get_password_file(void)
 {
        int fd = -1;
        char *p;
-       BOOL close_it = False;
+       bool close_it = False;
        pstring spec;
        char pass[128];
 
@@ -663,7 +666,10 @@ static void usage(void)
 {
        printf("Usage: mount.smbfs service mountpoint [-o options,...]\n");
 
-       printf("Version %s\n\n",VERSION);
+       printf("Version %s\n\n",SAMBA_VERSION_STRING);
+
+       printf("Please be aware that smbfs is deprecated in favor of "
+              "cifs\n\n");
 
        printf(
 "Options:\n\
@@ -710,7 +716,6 @@ static void parse_mount_smb(int argc, char **argv)
        int opt;
        char *opts;
        char *opteq;
-       extern char *optarg;
        int val;
        char *p;
 
@@ -794,7 +799,7 @@ static void parse_mount_smb(int argc, char **argv)
                                DEBUGLEVEL = val;
                        } else if(!strcmp(opts, "ip")) {
                                dest_ip = *interpret_addr2(opteq+1);
-                               if (is_zero_ip(dest_ip)) {
+                               if (is_zero_ip_v4(dest_ip)) {
                                        fprintf(stderr,"Can't resolve address %s\n", opteq+1);
                                        exit(1);
                                }
@@ -860,12 +865,12 @@ static void parse_mount_smb(int argc, char **argv)
 ****************************************************************************/
  int main(int argc,char *argv[])
 {
-       extern char *optarg;
-       extern int optind;
        char *p;
 
        DEBUGLEVEL = 1;
 
+       load_case_tables();
+
        /* here we are interactive, even if run from autofs */
        setup_logging("mount.smbfs",True);
 
@@ -908,7 +913,7 @@ static void parse_mount_smb(int argc, char **argv)
                pstrcpy(username,getenv("LOGNAME"));
        }
 
-       if (!lp_load(dyn_CONFIGFILE,True,False,False)) {
+       if (!lp_load(dyn_CONFIGFILE,True,False,False,True)) {
                fprintf(stderr, "Can't load %s - run testparm to debug it\n", 
                        dyn_CONFIGFILE);
        }
@@ -923,7 +928,7 @@ static void parse_mount_smb(int argc, char **argv)
                read_credentials_file(credentials);
        }
 
-       DEBUG(3,("mount.smbfs started (version %s)\n", VERSION));
+       DEBUG(3,("mount.smbfs started (version %s)\n", SAMBA_VERSION_STRING));
 
        if (*workgroup == 0) {
                pstrcpy(workgroup,lp_workgroup());