Cleanups: (merge from HEAD)
authorAndrew Bartlett <abartlet@samba.org>
Mon, 10 Feb 2003 11:47:21 +0000 (11:47 +0000)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 10 Feb 2003 11:47:21 +0000 (11:47 +0000)
 - use safe_strcpy() instead of pstrcpy() for malloc()ed strings

 - CUPS: a failure in an attempt to automaticly add a printer is not level 0 stuff.

 - Fix up a possible Realloc() failure segfault

Andrew Bartlett
(This used to be commit c1cfc296c2efdb2b5972202146e80f0e3b6a3da4)

source3/auth/auth_ntlmssp.c
source3/auth/auth_unix.c
source3/auth/auth_util.c
source3/auth/pass_check.c
source3/locking/locking.c
source3/printing/print_cups.c
source3/smbd/dir.c
source3/smbd/statcache.c

index 3e650a7a2a7ec8b10db484e7f1df3e5c412fe01d..43542b24744660e117c28d5f0c3d8d54246a6dd4 100644 (file)
@@ -125,7 +125,6 @@ NTSTATUS auth_ntlmssp_end(AUTH_NTLMSSP_STATE **auth_ntlmssp_state)
        if ((*auth_ntlmssp_state)->server_info) {
                free_server_info(&(*auth_ntlmssp_state)->server_info);
        }
-
        talloc_destroy(mem_ctx);
        *auth_ntlmssp_state = NULL;
        return NT_STATUS_OK;
index 1251432b871462ebb187ea8991e54f85761fda10..4f44767a81aeb884ce199c186d82678bf2db2fc8 100644 (file)
@@ -106,7 +106,7 @@ static NTSTATUS check_unix_security(const struct auth_context *auth_context,
        
        unbecome_root();
 
-       if NT_STATUS_IS_OK(nt_status) {
+       if (NT_STATUS_IS_OK(nt_status)) {
                if (pass) {
                        make_server_info_pw(server_info, pass);
                } else {
index 5fdfd0694a1610c2f05c283bdfc33cc84663650f..bbe0c7cf43298c3c2171f292073213df43ba6ba3 100644 (file)
@@ -671,14 +671,22 @@ static NTSTATUS get_user_groups_from_local_sam(const DOM_SID *user_sid,
        };
        
        n_unix_groups = groups_max();
-       if ((*unix_groups = malloc( sizeof(gid_t) * groups_max() ) ) == NULL) {
+       if ((*unix_groups = malloc( sizeof(gid_t) * n_unix_groups ) ) == NULL) {
                DEBUG(0, ("get_user_groups_from_local_sam: Out of memory allocating unix group list\n"));
                passwd_free(&usr);
                return NT_STATUS_NO_MEMORY;
        }
        
        if (sys_getgrouplist(usr->pw_name, usr->pw_gid, *unix_groups, &n_unix_groups) == -1) {
-               *unix_groups = Realloc(*unix_groups, sizeof(gid_t) * n_unix_groups);
+               gid_t *groups_tmp;
+               groups_tmp = Realloc(*unix_groups, sizeof(gid_t) * n_unix_groups);
+               if (!groups_tmp) {
+                       SAFE_FREE(*unix_groups);
+                       passwd_free(&usr);
+                       return NT_STATUS_NO_MEMORY;
+               }
+               *unix_groups = groups_tmp;
+
                if (sys_getgrouplist(usr->pw_name, usr->pw_gid, *unix_groups, &n_unix_groups) == -1) {
                        DEBUG(0, ("get_user_groups_from_local_sam: failed to get the unix group list\n"));
                        SAFE_FREE(*unix_groups);
index e1783bfd1e2f72a7d57dcf58e50f70c3ddbd42a5..88b82e34746eba77a1204e18926b9a7c891aa15a 100644 (file)
@@ -579,7 +579,7 @@ static NTSTATUS password_check(const char *password)
        }
 #endif /* HAVE_CRYPT */
 #endif /* HAVE_BIGCRYPT && HAVE_CRYPT && USE_BOTH_CRYPT_CALLS */
-#endif /* WITH_PAM || KRB4_AUTH || KRB5_AUTH */
+#endif /* WITH_PAM */
 }
 
 
index e5a72d220859203ef121abe3b07557e130a57fb2..d4794560f60bf083b68ae8488c9f03d49d5debde 100644 (file)
@@ -611,6 +611,7 @@ BOOL set_share_mode(files_struct *fsp, uint16 port, uint16 op_type)
        /* read in the existing share modes if any */
        dbuf = tdb_fetch(tdb, locking_key_fsp(fsp));
        if (!dbuf.dptr) {
+               size_t offset;
                /* we'll need to create a new record */
                pstring fname;
 
@@ -628,7 +629,8 @@ BOOL set_share_mode(files_struct *fsp, uint16 port, uint16 op_type)
                DEBUG(10,("set_share_mode: creating entry for file %s. num_share_modes = 1\n",
                        fsp->fsp_name ));
 
-               pstrcpy(p + sizeof(*data) + sizeof(share_mode_entry), fname);
+               offset = sizeof(*data) + sizeof(share_mode_entry);
+               safe_strcpy(p + offset, fname, size - offset);
                fill_share_mode(p + sizeof(*data), fsp, port, op_type);
                dbuf.dptr = p;
                dbuf.dsize = size;
index c283937556653bf2bed77c14d941d042cc125651..7cf21c966e48bdd62f4ce92b49a7939036d52caa 100644 (file)
@@ -332,7 +332,7 @@ int cups_printername_ok(const char *name)
 
        if ((http = httpConnect(cupsServer(), ippPort())) == NULL)
        {
-               DEBUG(0,("Unable to connect to CUPS server %s - %s\n", 
+               DEBUG(3,("Unable to connect to CUPS server %s - %s\n", 
                         cupsServer(), strerror(errno)));
                return (0);
        }
@@ -374,7 +374,7 @@ int cups_printername_ok(const char *name)
 
        if ((response = cupsDoRequest(http, request, "/")) == NULL)
        {
-               DEBUG(0,("Unable to get printer status for %s - %s\n", name,
+               DEBUG(3,("Unable to get printer status for %s - %s\n", name,
                         ippErrorString(cupsLastError())));
                httpClose(http);
                return (0);
@@ -384,7 +384,7 @@ int cups_printername_ok(const char *name)
 
        if (response->request.status.status_code >= IPP_OK_CONFLICT)
        {
-               DEBUG(0,("Unable to get printer status for %s - %s\n", name,
+               DEBUG(3,("Unable to get printer status for %s - %s\n", name,
                         ippErrorString(response->request.status.status_code)));
                ippDelete(response);
                return (0);
index 9e8de2979b91b7e84d8acd930d6177a822ce2855..e022d26ea3c1943f7f57c56b5dabd59d2171ea91 100644 (file)
@@ -907,7 +907,7 @@ void *OpenDir(connection_struct *conn, const char *name, BOOL use_veto)
                        dirp->current = dirp->data;
                }
 
-               pstrcpy(dirp->data+used,n);
+               safe_strcpy(dirp->data+used,n, dirp->mallocsize - used - 1);
                used += l;
                dirp->numentries++;
        }
index 93782b9bb01109c75cb2b339b54a1f2c6bb466a3..f4b613428a223803976b2861f90da93e1df36263 100644 (file)
@@ -122,8 +122,8 @@ void stat_cache_add( char *full_orig_name, char *orig_translated_path)
       DEBUG(0,("stat_cache_add: Out of memory !\n"));
       return;
     }
-    pstrcpy(scp->names, orig_name);
-    pstrcpy(scp->names+namelen+1, translated_path);
+    safe_strcpy(scp->names, orig_name, namelen);
+    safe_strcpy(scp->names+namelen+1, translated_path, namelen);
     scp->name_len = namelen;
     hash_insert(&stat_cache, (char *)scp, orig_name);
   }