spelling
[tprouty/samba.git] / source / smbd / service.c
index a47e6c1bbc82353a3ecee2efe41b5796996fca2a..c9f5330551485407f808c631038a0ca665c040cf 100644 (file)
@@ -227,22 +227,27 @@ static NTSTATUS share_sanity_checks(int snum, fstring 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)) {
                        fstrcpy(dev,"LPT1:");
+               } else if (strequal(lp_fstype(snum), "IPC")) {
+                       fstrcpy(dev, "IPC");
                } else {
                        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;
        }
 
@@ -326,14 +331,17 @@ static void set_admin_user(connection_struct *conn, gid_t *groups, size_t n_grou
 
 static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                                               DATA_BLOB password, 
-                                              fstring 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;
@@ -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));
@@ -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, 
-                                  fstring dev, uint16 vuid, NTSTATUS *status)
+                                  const char *pdev, uint16 vuid, NTSTATUS *status)
 {
        uid_t euid;
        user_struct *vuser = NULL;
        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;
                        }