spelling
[tprouty/samba.git] / source / smbd / service.c
index d475451e6bedbdfd6faf4615840e27f2d72dbc02..c9f5330551485407f808c631038a0ca665c040cf 100644 (file)
@@ -155,7 +155,7 @@ int find_service(fstring service)
          char *pszTemp;
 
          DEBUG(3,("checking whether %s is a valid printer name...\n", service));
-         pszTemp = PRINTCAP;
+         pszTemp = lp_printcapname();
          if ((pszTemp != NULL) && pcap_printername_ok(service, pszTemp))
          {
             DEBUG(3,("%s is a valid printer name\n", service));
@@ -218,7 +218,7 @@ int find_service(fstring service)
  do some basic sainity checks on the share.  
  This function modifies dev, ecode.
 ****************************************************************************/
-static NTSTATUS share_sanity_checks(int snum, pstring dev) 
+static NTSTATUS share_sanity_checks(int snum, fstring dev) 
 {
        
        if (!lp_snum_ok(snum) || 
@@ -227,28 +227,33 @@ static NTSTATUS share_sanity_checks(int snum, pstring dev)
                return NT_STATUS_ACCESS_DENIED;
        }
 
-       /* you can only connect to the IPC$ service as an ipc device */
-       if (strequal(lp_fstype(snum), "IPC"))
-               pstrcpy(dev,"IPC");
-       
        if (dev[0] == '?' || !dev[0]) {
                if (lp_print_ok(snum)) {
-                       pstrcpy(dev,"LPT1:");
+                       fstrcpy(dev,"LPT1:");
+               } else if (strequal(lp_fstype(snum), "IPC")) {
+                       fstrcpy(dev, "IPC");
                } else {
-                       pstrcpy(dev,"A:");
+                       fstrcpy(dev,"A:");
                }
        }
 
-       /* if the request is as a printer and you can't print then refuse */
        strupper(dev);
-       if (!lp_print_ok(snum) && (strncmp(dev,"LPT",3) == 0)) {
-               DEBUG(1,("Attempt to connect to non-printer as a printer\n"));
+
+       if (lp_print_ok(snum)) {
+               if (!strequal(dev, "LPT1:")) {
+                       return NT_STATUS_BAD_DEVICE_TYPE;
+               }
+       } else if (strequal(lp_fstype(snum), "IPC")) {
+               if (!strequal(dev, "IPC")) {
+                       return NT_STATUS_BAD_DEVICE_TYPE;
+               }
+       } else if (!strequal(dev, "A:")) {
                return NT_STATUS_BAD_DEVICE_TYPE;
        }
 
        /* Behave as a printer if we are supposed to */
        if (lp_print_ok(snum) && (strcmp(dev, "A:") == 0)) {
-               pstrcpy(dev, "LPT1:");
+               fstrcpy(dev, "LPT1:");
        }
 
        return NT_STATUS_OK;
@@ -258,7 +263,7 @@ static NTSTATUS share_sanity_checks(int snum, pstring dev)
 /****************************************************************************
  readonly share?
 ****************************************************************************/
-static void set_read_only(connection_struct *conn
+static void set_read_only(connection_struct *conn, gid_t *groups, size_t n_groups)
 {
        char **list;
        char *service = lp_servicename(conn->service);
@@ -271,7 +276,7 @@ static void set_read_only(connection_struct *conn)
                if (!str_list_substitute(list, "%S", service)) {
                        DEBUG(0, ("ERROR: read list substitution failed\n"));
                }
-               if (user_in_list(conn->user, list))
+               if (user_in_list(conn->user, (const char **)list, groups, n_groups))
                        conn->read_only = True;
                str_list_free(&list);
        }
@@ -281,7 +286,7 @@ static void set_read_only(connection_struct *conn)
                if (!str_list_substitute(list, "%S", service)) {
                        DEBUG(0, ("ERROR: write list substitution failed\n"));
                }
-               if (user_in_list(conn->user, list))
+               if (user_in_list(conn->user, (const char **)list, groups, n_groups))
                        conn->read_only = False;
                str_list_free(&list);
        }
@@ -291,7 +296,7 @@ static void set_read_only(connection_struct *conn)
 /****************************************************************************
   admin user check
 ****************************************************************************/
-static void set_admin_user(connection_struct *conn
+static void set_admin_user(connection_struct *conn, gid_t *groups, size_t n_groups)
 {
        /* admin user check */
        
@@ -299,7 +304,7 @@ static void set_admin_user(connection_struct *conn)
           marked read_only. Changed as I don't think this is needed,
           but old code left in case there is a problem here.
        */
-       if (user_in_list(conn->user,lp_admin_users(conn->service)) 
+       if (user_in_list(conn->user,lp_admin_users(conn->service), groups, n_groups
 #if 0
            && !conn->read_only
 #endif
@@ -326,14 +331,17 @@ static void set_admin_user(connection_struct *conn)
 
 static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                                               DATA_BLOB password, 
-                                              char *dev, NTSTATUS *status)
+                                              const char *pdev, NTSTATUS *status)
 {
        struct passwd *pass = NULL;
        BOOL guest = False;
        connection_struct *conn;
        struct stat st;
        fstring user;
+       fstring dev;
+
        *user = 0;
+       fstrcpy(dev, pdev);
 
        if (NT_STATUS_IS_ERR(*status = share_sanity_checks(snum, dev))) {
                return NULL;
@@ -364,14 +372,14 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
        } else if (vuser) {
                if (vuser->guest) {
                        if (!lp_guest_ok(snum)) {
-                               DEBUG(2, ("guest user (from session setup) not permitted to access this share (%s)", lp_servicename(snum)));
+                               DEBUG(2, ("guest user (from session setup) not permitted to access this share (%s)\n", lp_servicename(snum)));
                                      conn_free(conn);
                                      *status = NT_STATUS_ACCESS_DENIED;
                                      return NULL;
                        }
                } else {
-                       if (!user_ok(vuser->user.unix_name, snum)) {
-                               DEBUG(2, ("user '%s' (from session setup) not permitted to access this share (%s)", vuser->user.unix_name, lp_servicename(snum)));
+                       if (!user_ok(vuser->user.unix_name, snum, vuser->groups, vuser->n_groups)) {
+                               DEBUG(2, ("user '%s' (from session setup) not permitted to access this share (%s)\n", vuser->user.unix_name, lp_servicename(snum)));
                                conn_free(conn);
                                *status = NT_STATUS_ACCESS_DENIED;
                                return NULL;
@@ -427,9 +435,9 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
        string_set(&conn->user,user);
        conn->nt_user_token = NULL;
        
-       set_read_only(conn);
+       set_read_only(conn, vuser ? vuser->groups : NULL, vuser ? vuser->n_groups : 0);
        
-       set_admin_user(conn);
+       set_admin_user(conn, vuser ? vuser->groups : NULL, vuser ? vuser->n_groups : 0);
 
        /*
         * If force user is true, then store the
@@ -478,13 +486,14 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                pstring tmp_gname;
                BOOL user_must_be_member = False;
                
-               StrnCpy(tmp_gname,lp_force_group(snum),sizeof(pstring)-1);
+               pstrcpy(tmp_gname,lp_force_group(snum));
                
                if (tmp_gname[0] == '+') {
                        user_must_be_member = True;
-                       StrnCpy(gname,&tmp_gname[1],sizeof(pstring)-2);
+                       /* even now, tmp_gname is null terminated */
+                       pstrcpy(gname,&tmp_gname[1]);
                } else {
-                       StrnCpy(gname,tmp_gname,sizeof(pstring)-1);
+                       pstrcpy(gname,tmp_gname);
                }
                /* default service may be a group name          */
                pstring_sub(gname,"%S",lp_servicename(snum));
@@ -499,7 +508,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                         * Otherwise, the meaning of the '+' would be ignored.
                         */
                        if (conn->force_user && user_must_be_member) {
-                               if (user_in_group_list( user, gname )) {
+                               if (user_in_group_list( user, gname, NULL, 0)) {
                                                conn->gid = gid;
                                                DEBUG(3,("Forced group %s for member %s\n",gname,user));
                                }
@@ -569,7 +578,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
        if (!smbd_vfs_init(conn)) {
                DEBUG(0, ("vfs_init failed for service %s\n", lp_servicename(SNUM(conn))));
                conn_free(conn);
-               *status = NT_STATUS_UNSUCCESSFUL;
+               *status = NT_STATUS_BAD_NETWORK_NAME;
                return NULL;
        }
 
@@ -578,7 +587,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
        if (!claim_connection(conn,
                              lp_servicename(SNUM(conn)),
                              lp_max_connections(SNUM(conn)),
-                             False)) {
+                             False,0)) {
                DEBUG(1,("too many connections - rejected\n"));
                conn_free(conn);
                *status = NT_STATUS_INSUFFICIENT_RESOURCES;
@@ -598,7 +607,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                        DEBUG(1,("root preexec gave %d - failing connection\n", ret));
                        yield_connection(conn, lp_servicename(SNUM(conn)));
                        conn_free(conn);
-                       *status = NT_STATUS_UNSUCCESSFUL;
+                       *status = NT_STATUS_ACCESS_DENIED;
                        return NULL;
                }
        }
@@ -611,7 +620,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                *status = NT_STATUS_LOGON_FAILURE;
                return NULL;
        }
-       
+
        /* Remember that a different vuid can connect later without these checks... */
        
        /* Preexecs are done here as they might make the dir we are to ChDir to below */
@@ -627,7 +636,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                        change_to_root_user();
                        yield_connection(conn, lp_servicename(SNUM(conn)));
                        conn_free(conn);
-                       *status = NT_STATUS_UNSUCCESSFUL;
+                       *status = NT_STATUS_ACCESS_DENIED;
                        return NULL;
                }
        }
@@ -717,7 +726,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
  **************************************************************************************/
  
 connection_struct *make_connection_with_chdir(const char *service_in, DATA_BLOB password, 
-                                  char *dev, uint16 vuid, NTSTATUS *status)
+                                  const char *dev, uint16 vuid, NTSTATUS *status)
 {
        connection_struct *conn = NULL;
        
@@ -747,13 +756,16 @@ connection_struct *make_connection_with_chdir(const char *service_in, DATA_BLOB
 ****************************************************************************/
 
 connection_struct *make_connection(const char *service_in, DATA_BLOB password, 
-                                  char *dev, uint16 vuid, NTSTATUS *status)
+                                  const char *pdev, uint16 vuid, NTSTATUS *status)
 {
        uid_t euid;
        user_struct *vuser = NULL;
-       pstring service;
+       fstring service;
+       fstring dev;
        int snum = -1;
 
+       fstrcpy(dev, pdev);
+
        /* This must ONLY BE CALLED AS ROOT. As it exits this function as root. */
        if (!non_root_mode() && (euid = geteuid()) != 0) {
                DEBUG(0,("make_connection: PANIC ERROR. Called as nonroot (%u)\n", (unsigned int)euid ));
@@ -780,7 +792,7 @@ connection_struct *make_connection(const char *service_in, DATA_BLOB password,
                if(lp_security() != SEC_SHARE) {
                        DATA_BLOB no_pw = data_blob(NULL, 0);
                        if (vuser->homes_snum == -1) {
-                               DEBUG(2, ("[homes] share not available for this user becouse it was not found or created at session setup time\n"));
+                               DEBUG(2, ("[homes] share not available for this user because it was not found or created at session setup time\n"));
                                *status = NT_STATUS_BAD_NETWORK_NAME;
                                return NULL;
                        }
@@ -814,7 +826,7 @@ connection_struct *make_connection(const char *service_in, DATA_BLOB password,
                                            dev, status);
        }
        
-       pstrcpy(service, service_in);
+       fstrcpy(service, service_in);
 
        strlower(service);
 
@@ -833,6 +845,13 @@ connection_struct *make_connection(const char *service_in, DATA_BLOB password,
                return NULL;
        }
 
+       /* Handle non-Dfs clients attempting connections to msdfs proxy */
+       if (lp_host_msdfs() && (*lp_msdfs_proxy(snum) != '\0'))  {
+               DEBUG(3, ("refusing connection to dfs proxy '%s'\n", service));
+               *status = NT_STATUS_BAD_NETWORK_NAME;
+               return NULL;
+       }
+
        DEBUG(5, ("making a connection to 'normal' service %s\n", service));
 
        return make_connection_snum(snum, vuser,