r16418: Pull in more Klocwork fixes (up to r16415)
authorGerald Carter <jerry@samba.org>
Tue, 20 Jun 2006 16:59:48 +0000 (16:59 +0000)
committerGerald Carter <jerry@samba.org>
Tue, 20 Jun 2006 16:59:48 +0000 (16:59 +0000)
55 files changed:
WHATSNEW.txt
source/Makefile.in
source/client/mount.cifs.c
source/lib/debug.c
source/lib/messages.c
source/lib/privileges.c
source/lib/util.c
source/lib/util_sid.c
source/lib/util_str.c
source/libsmb/clidfs.c
source/libsmb/clientgen.c
source/libsmb/libsmb_compat.c
source/libsmb/libsmbclient.c
source/libsmb/trusts_util.c
source/modules/vfs_afsacl.c
source/nsswitch/winbindd_ads.c
source/nsswitch/winbindd_cache.c
source/nsswitch/winbindd_cm.c
source/nsswitch/winbindd_misc.c
source/nsswitch/winbindd_rpc.c
source/passdb/login_cache.c
source/passdb/pdb_get_set.c
source/passdb/pdb_interface.c
source/passdb/pdb_ldap.c
source/printing/nt_printing.c
source/printing/print_generic.c
source/printing/printing_db.c
source/registry/reg_perfcount.c
source/registry/regfio.c
source/rpc_parse/parse_lsa.c
source/rpc_parse/parse_misc.c
source/rpc_parse/parse_ntsvcs.c
source/rpc_parse/parse_prs.c
source/rpc_parse/parse_samr.c
source/rpc_parse/parse_spoolss.c
source/rpc_server/srv_eventlog_nt.c
source/rpc_server/srv_lsa_nt.c
source/rpc_server/srv_netlog_nt.c
source/rpc_server/srv_samr_nt.c
source/smbd/message.c
source/smbd/negprot.c
source/smbd/nttrans.c
source/smbd/process.c
source/smbd/reply.c
source/smbd/sesssetup.c
source/utils/net_rpc.c
source/utils/net_rpc_audit.c
source/utils/net_rpc_join.c
source/utils/net_rpc_registry.c
source/utils/net_rpc_samsync.c
source/utils/net_sam.c
source/utils/net_usershare.c
source/utils/ntlm_auth_diagnostics.c
source/utils/profiles.c
source/utils/smbcacls.c

index 2143a8868ed4ddcdd403cdf38104ca5fb6816dcf..82efca45e388d9a0677c4f7e49ea7c1e6a6c9098 100644 (file)
@@ -1,6 +1,6 @@
                    =================================
                    Release Notes for Samba 3.0.23rc3
-                              Jun 19, 2006
+                              Jun XX, 2006
                    =================================
 
 This is the third release candidate of the 3.0.23 code base and is 
@@ -57,6 +57,7 @@ o   Guenther Deschner <gd@samba.org>
     * BUG 3843: Allow to set passwords directly when creating users 
       via "net rpc user add" 
     * Add "rpc shell" to the usage text for the net command.
+    * Winbindd user aliases lookup fixes for large domains.
 
 
 o   Bjoern Jacke <samba@j3e.de>.
@@ -69,6 +70,13 @@ o   Volker Lendecke <vl@samba.org>
     * Fixes for various Coverity defect reports.
 
 
+
+o   Derrell Lipman <derrell@samba.org>
+    [libsmbclient]
+    * BUG 3814: Only set the DFS capability flag in client requests
+      if the share is a DFS root.
+
+
 o   Jason Mader <jason@ncac.gwu.edu>
     * Compiler warning fixes.
 
index f1cf71406f9488718bc2f3e95396b8cd772d628d..bba2945613352af86428fbfa83d7769f0eb91a23 100644 (file)
@@ -1600,7 +1600,7 @@ clean: delheaders python_clean
                $(TOPFILES) $(BIN_PROGS) $(SBIN_PROGS) $(ROOT_SBIN_PROGS) \
                $(MODULES) $(TORTURE_PROGS) $(LIBSMBCLIENT) \
                $(LIBSMBSHAREMODES) $(EVERYTHING_PROGS) $(LIBMSRPC) \
-               .headers.stamp 
+               .headers.stamp */src/*.o */src/*.@PICSUFFIX@
        -rm -rf t_dir
 
 # Making this target will just make sure that the prototype files
index 23a74d34fad2fe5398be2c93e621b5716db6a7fd..ac98b992bb2187f7deb6ba01f4d2849b5fab24ea 100755 (executable)
@@ -259,6 +259,11 @@ static int get_password_from_file(int file_descript, char * filename)
        else 
                memset(mountpassword, 0, 64);
 
+       if (mountpassword == NULL) {
+               printf("malloc failed\n");
+               exit(1);
+       }
+
        if(filename != NULL) {
                file_descript = open(filename, O_RDONLY);
                if(file_descript < 0) {
index b8c42686cdb0f5465e806a3099a093623553d11c..2b6c42b8eb04484c52d78df3fccbb684a31b608c 100644 (file)
@@ -513,6 +513,11 @@ static void debuglevel_message(int msg_type, struct process_id src,
 {
        char *message = debug_list_class_names_and_levels();
 
+       if (!message) {
+               DEBUG(0,("debuglevel_message - debug_list_class_names_and_levels returned NULL\n"));
+               return;
+       }
+
        DEBUG(1,("INFO: Received REQ_DEBUGLEVEL message from PID %u\n",
                 (unsigned int)procid_to_pid(&src)));
        message_send_pid(src, MSG_DEBUGLEVEL, message, strlen(message) + 1, True);
index cd2a3b36b6e2402d4bc48b244f80d82276e7036c..dd6d4137d7b4dcf6558af7d0023b2bbb264d4bef 100644 (file)
@@ -105,6 +105,7 @@ static void ping_message(int msg_type, struct process_id src,
                         void *buf, size_t len)
 {
        const char *msg = buf ? buf : "none";
+
        DEBUG(1,("INFO: Received PING message from PID %s [%s]\n",
                 procid_str_static(&src), msg));
        message_send_pid(src, MSG_PONG, buf, len, True);
@@ -198,6 +199,11 @@ static BOOL message_send_pid_internal(struct process_id pid, int msg_type,
        char *ptr;
        struct message_rec prec;
 
+       /* NULL pointer means implicit length zero. */
+       if (!buf) {
+               SMB_ASSERT(len == 0);
+       }
+
        /*
         * Doing kill with a non-positive pid causes messages to be
         * sent to places we don't want.
@@ -209,7 +215,7 @@ static BOOL message_send_pid_internal(struct process_id pid, int msg_type,
        rec.msg_type = msg_type;
        rec.dest = pid;
        rec.src = procid_self();
-       rec.len = len;
+       rec.len = buf ? len : 0;
 
        kbuf = message_key_pid(pid);
 
@@ -218,7 +224,7 @@ static BOOL message_send_pid_internal(struct process_id pid, int msg_type,
                return False;
 
        memcpy(dbuf.dptr, &rec, sizeof(rec));
-       if (len > 0)
+       if (len > 0 && buf)
                memcpy((void *)((char*)dbuf.dptr+sizeof(rec)), buf, len);
 
        dbuf.dsize = len + sizeof(rec);
index d77d7857d72e71831945221052de6aa6e57ce107..d19592e58269b9e5a7ab0bd774b80804d172803c 100644 (file)
@@ -530,6 +530,10 @@ NTSTATUS privilege_enumerate_accounts(DOM_SID **sids, int *num_sids)
        TDB_CONTEXT *tdb = get_account_pol_tdb();
        PRIV_SID_LIST priv;
        
+       if (!tdb) {
+               return NT_STATUS_ACCESS_DENIED;
+       }
+
        ZERO_STRUCT(priv);
 
        se_priv_copy( &priv.privilege, &se_priv_none );
index d705901244ac3750e35c9a29e70c95f9856a0ff0..a1efecfbbbaac04681474e49731cf1f51b62bb5a 100644 (file)
@@ -2845,9 +2845,6 @@ void *talloc_check_name_abort(const void *ptr, const char *name)
 {
        void *result;
 
-       if (ptr == NULL)
-               return NULL;
-
        result = talloc_check_name(ptr, name);
        if (result != NULL)
                return result;
index 307f3e3415d05081273c72d8e89cc8512a7a56fb..09fe30f81bbd0a2f1119135357e7cdc0dcf34f47 100644 (file)
@@ -647,6 +647,25 @@ void del_sid_from_array(const DOM_SID *sid, DOM_SID **sids, size_t *num)
        return;
 }
 
+void add_rid_to_array_unique(TALLOC_CTX *mem_ctx,
+                                   uint32 rid, uint32 **pp_rids, size_t *p_num)
+{
+       size_t i;
+
+       for (i=0; i<*p_num; i++) {
+               if ((*pp_rids)[i] == rid)
+                       return;
+       }
+       
+       *pp_rids = TALLOC_REALLOC_ARRAY(mem_ctx, *pp_rids, uint32, *p_num+1);
+
+       if (*pp_rids == NULL)
+               return;
+
+       (*pp_rids)[*p_num] = rid;
+       *p_num += 1;
+}
+
 BOOL is_null_sid(const DOM_SID *sid)
 {
        static const DOM_SID null_sid = {0};
index df84fa90a565ee560adb6176e7da164e88f12273..6fe1668e880998c596120a9682321f65d676c0d2 100644 (file)
@@ -2250,15 +2250,21 @@ SMB_BIG_UINT STR_TO_SMB_BIG_UINT(const char *nptr, const char **entptr)
        SMB_BIG_UINT val = -1;
        const char *p = nptr;
        
-       while (p && *p && isspace(*p))
+       if (!p) {
+               *entptr = p;
+               return val;
+       }
+
+       while (*p && isspace(*p))
                p++;
+
 #ifdef LARGE_SMB_OFF_T
        sscanf(p,"%llu",&val);  
 #else /* LARGE_SMB_OFF_T */
        sscanf(p,"%lu",&val);
 #endif /* LARGE_SMB_OFF_T */
        if (entptr) {
-               while (p && *p && isdigit(*p))
+               while (*p && isdigit(*p))
                        p++;
                *entptr = p;
        }
index 298f4d1b548d108a89543fb984a5ab7d43fe989c..e564bc429573f57059e4db334eadedf95e6d62d3 100644 (file)
@@ -652,9 +652,12 @@ BOOL cli_resolve_path( const char *mountpt, struct cli_state *rootcli, const cha
 
        fullpath[consumed/2] = '\0';
        dos_clean_name( fullpath );
-       ppath = strchr_m( fullpath, '\\' );
-       ppath = strchr_m( ppath+1, '\\' );
-       ppath = strchr_m( ppath+1, '\\' );
+       if ((ppath = strchr_m( fullpath, '\\' )) == NULL)
+               return False;
+       if ((ppath = strchr_m( ppath+1, '\\' )) == NULL)
+               return False;
+       if ((ppath = strchr_m( ppath+1, '\\' )) == NULL)
+               return False;
        ppath++;
        
        pstr_sprintf( newmount, "%s\\%s", mountpt, ppath );
index 83664b0b328d13a6be4eeb16a3486c19f1fb8713..f5116234c8396f8e0ea14476fa7f6679c97e7784 100644 (file)
@@ -198,7 +198,7 @@ void cli_setup_packet(struct cli_state *cli)
                flags2 = FLAGS2_LONG_PATH_COMPONENTS;
                if (cli->capabilities & CAP_UNICODE)
                        flags2 |= FLAGS2_UNICODE_STRINGS;
-               if (cli->capabilities & CAP_DFS)
+               if ((cli->capabilities & CAP_DFS) && cli->dfsroot)
                        flags2 |= FLAGS2_DFS_PATHNAMES;
                if (cli->capabilities & CAP_STATUS32)
                        flags2 |= FLAGS2_32_BIT_ERROR_CODES;
index 5699e153bbd2c59ba092e4cfaa687a169062b5f5..cfd5948e269dfffaf87a139cd60c612f9601793a 100644 (file)
@@ -341,6 +341,10 @@ int smbc_fsetxattr(int fd,
                    int flags)
 {
        SMBCFILE * file = find_fd(fd);
+       if (file == NULL) {
+               errno = EBADF;
+               return -1;
+       }
         return statcont->setxattr(statcont, file->fname,
                                   name, value, size, flags);
 }
@@ -367,6 +371,10 @@ int smbc_fgetxattr(int fd,
                    size_t size)
 {
        SMBCFILE * file = find_fd(fd);
+       if (file == NULL) {
+               errno = EBADF;
+               return -1;
+       }
         return statcont->getxattr(statcont, file->fname, name, value, size);
 }
 
@@ -386,6 +394,10 @@ int smbc_fremovexattr(int fd,
                       const char *name)
 {
        SMBCFILE * file = find_fd(fd);
+       if (file == NULL) {
+               errno = EBADF;
+               return -1;
+       }
         return statcont->removexattr(statcont, file->fname, name);
 }
 
@@ -408,6 +420,10 @@ int smbc_flistxattr(int fd,
                     size_t size)
 {
        SMBCFILE * file = find_fd(fd);
+       if (file == NULL) {
+               errno = EBADF;
+               return -1;
+       }
         return statcont->listxattr(statcont, file->fname, list, size);
 }
 
index 4ea0ab6eb63682c91f48401487f04636b5c157e5..98264dfa862e75ed9875742585a1a7ad8067df45 100644 (file)
@@ -3932,7 +3932,9 @@ add_ace(SEC_ACL **the_acl,
                return True;
        }
 
-       aces = SMB_CALLOC_ARRAY(SEC_ACE, 1+(*the_acl)->num_aces);
+       if ((aces = SMB_CALLOC_ARRAY(SEC_ACE, 1+(*the_acl)->num_aces)) == NULL) {
+               return False;
+       }
        memcpy(aces, (*the_acl)->ace, (*the_acl)->num_aces * sizeof(SEC_ACE));
        memcpy(aces+(*the_acl)->num_aces, ace, sizeof(SEC_ACE));
        newacl = make_sec_acl(ctx, (*the_acl)->revision,
index 9d94c1d00a1e813fa5a4795d6be77647f5366076..55108bf72f2c0fa6827654cbd96060aed966e3e5 100644 (file)
@@ -86,7 +86,11 @@ NTSTATUS trust_pw_change_and_store_it(struct rpc_pipe_client *cli, TALLOC_CTX *m
                
        /* Create a random machine account password */
        str = generate_random_str(DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH);
-       new_trust_passwd = talloc_strdup(mem_ctx, str);
+
+       if ((new_trust_passwd = talloc_strdup(mem_ctx, str)) == NULL) {
+               DEBUG(0, ("talloc_strdup failed\n"));
+               return NT_STATUS_NO_MEMORY;
+       }
        
        E_md4hash(new_trust_passwd, new_trust_passwd_hash);
 
index 3794299b9a02ba50931bfb93c85d350102924c36..53272ca06fe374fa7fa6b2901a6fa4c1afd6f05c 100644 (file)
@@ -140,23 +140,24 @@ static struct afs_ace *new_afs_ace(TALLOC_CTX *mem_ctx,
                type = SID_NAME_UNKNOWN;
 
                if (string_to_sid(&sid, name)) {
-                       fstring user, domain;
+                       const char *user, *domain;
                        /* We have to find the type, look up the SID */
-                       lookup_sid(&sid, domain, user, &type);
+                       lookup_sid(tmp_talloc_ctx(), &sid,
+                                  &domain, &user, &type);
                }
 
        } else {
 
-               fstring domain, uname;
+               const char *domain, *uname;
                char *p;
 
-               p = strchr_m(name, lp_winbind_separator());
+               p = strchr_m(name, *lp_winbind_separator());
                if (p != NULL) {
                        *p = '\\';
                }
 
-               if (!lookup_name(name, LOOKUP_NAME_FULL,
-                                domain, uname, &sid, &type)) {
+               if (!lookup_name(tmp_talloc_ctx(), name, LOOKUP_NAME_ALL,
+                                &domain, &uname, &sid, &type)) {
                        DEBUG(10, ("Could not find AFS user %s\n", name));
 
                        sid_copy(&sid, &global_sid_NULL);
@@ -711,8 +712,7 @@ static BOOL nt_to_afs_acl(const char *filename,
 
        for (i = 0; i < dacl->num_aces; i++) {
                SEC_ACE *ace = &(dacl->ace[i]);
-               fstring dom_name;
-               fstring name;
+               const char *dom_name, *name;
                enum SID_NAME_USE name_type;
                char *p;
 
@@ -730,28 +730,28 @@ static BOOL nt_to_afs_acl(const char *filename,
                if (sid_compare(&ace->trustee,
                                &global_sid_Builtin_Administrators) == 0) {
 
-                       fstrcpy(name, "system:administrators");
+                       name = "system:administrators";
 
                } else if (sid_compare(&ace->trustee,
                                       &global_sid_World) == 0) {
 
-                       fstrcpy(name, "system:anyuser");
+                       name = "system:anyuser";
 
                } else if (sid_compare(&ace->trustee,
                                       &global_sid_Authenticated_Users) == 0) {
 
-                       fstrcpy(name, "system:authuser");
+                       name = "system:authuser";
 
                } else if (sid_compare(&ace->trustee,
                                       &global_sid_Builtin_Backup_Operators)
                           == 0) {
 
-                       fstrcpy(name, "system:backup");
+                       name = "system:backup";
 
                } else {
 
-                       if (!lookup_sid(&ace->trustee,
-                                       dom_name, name, &name_type)) {
+                       if (!lookup_sid(tmp_talloc_ctx(), &ace->trustee,
+                                       &dom_name, &name, &name_type)) {
                                DEBUG(1, ("AFSACL: Could not lookup SID %s on file %s\n",
                                          sid_string_static(&ace->trustee), filename));
                                continue;
@@ -759,18 +759,26 @@ static BOOL nt_to_afs_acl(const char *filename,
 
                        if ( (name_type == SID_NAME_USER) ||
                             (name_type == SID_NAME_DOM_GRP) ||
-                            (name_type == SID_NAME_ALIAS) ) { 
-                               fstring only_username;
-                               fstrcpy(only_username, name);
-                               fstr_sprintf(name, "%s%s%s",
-                                            dom_name, lp_winbind_separator(),
-                                            only_username);
-                               strlower_m(name);
+                            (name_type == SID_NAME_ALIAS) ) {
+                               char *tmp;
+                               tmp = talloc_asprintf(tmp_talloc_ctx(), "%s%s%s",
+                                                      dom_name, lp_winbind_separator(),
+                                                      name);
+                               if (tmp == NULL) {
+                                       return False;
+                               }
+                               strlower_m(tmp);
+                               name = tmp;
                        }
 
                        if (sidpts) {
                                /* Expect all users/groups in pts as SIDs */
-                               sid_to_string(name, &ace->trustee);
+                               name = talloc_strdup(
+                                       tmp_talloc_ctx(),
+                                       sid_string_static(&ace->trustee));
+                               if (name == NULL) {
+                                       return False;
+                               }
                        }
                }
 
@@ -1007,7 +1015,7 @@ static int afsacl_connect(vfs_handle_struct *handle,
                          const char *service, 
                          const char *user)
 {
-       char *spc;
+       const char *spc;
 
        spc = lp_parm_const_string(SNUM(handle->conn), "afsacl", "space", "%");
 
index 3ed651f8cdcffe82a75dea028897439b1ff63852..250b5f3b8c2784bdb462e39e886b408e6f0d7968 100644 (file)
@@ -904,7 +904,11 @@ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain,
        members = NULL;
        num_members = 0;
 
-       attrs = TALLOC_ARRAY(mem_ctx, const char *, 3);
+       if ((attrs = TALLOC_ARRAY(mem_ctx, const char *, 3)) == NULL) {
+               status = NT_STATUS_NO_MEMORY;
+               goto done;
+       }
+               
        attrs[1] = talloc_strdup(mem_ctx, "usnChanged");
        attrs[2] = NULL;
                
index ba69d41392e577228806e5836c8381be7a64a0a6..e078c295e172bc2296a16b70ab6649b96e3d547b 100644 (file)
@@ -276,7 +276,7 @@ static BOOL centry_sid(struct cache_entry *centry, TALLOC_CTX *mem_ctx, DOM_SID
 {
        char *sid_string;
        sid_string = centry_string(centry, mem_ctx);
-       if (!string_to_sid(sid, sid_string)) {
+       if ((sid_string == NULL) || (!string_to_sid(sid, sid_string))) {
                return False;
        }
        return True;
@@ -2136,6 +2136,7 @@ void wcache_flush_cache(void)
 
        if (!wcache->tdb) {
                DEBUG(0,("Failed to open winbindd_cache.tdb!\n"));
+               return;
        }
 
        tdb_traverse(wcache->tdb, traverse_fn_cleanup, NULL);
index b24ed842de3bf745e9a10d1dce81fa59d6d6bc36..ea4d8503c1b15e957cd86e4daedc35681deb1c29 100644 (file)
@@ -723,6 +723,9 @@ static BOOL find_new_dc(TALLOC_CTX *mem_ctx,
        if ((num_dcnames == 0) || (num_dcnames != num_addrs))
                return False;
 
+       if ((addrs == NULL) || (dcnames == NULL))
+               return False;
+
        if ( !open_any_socket_out(addrs, num_addrs, 10000, &fd_index, fd) ) 
        {
                for (i=0; i<num_dcs; i++) {
index 9413a79abaa5bf7846031956a896d9f808098964..6c6dc5b7651cc60bfc8fbb13128f09c1950b0e26 100644 (file)
@@ -158,7 +158,10 @@ enum winbindd_result winbindd_dual_list_trusted_domains(struct winbindd_domain *
        /* This is a bit excessive, but the extra data sooner or later will be
           talloc'ed */
 
-       extra_data_len = strlen(extra_data);
+       extra_data_len = 0;
+       if (extra_data != NULL) {
+               extra_data_len = strlen(extra_data);
+       }
 
        if (extra_data_len > 0) {
                state->response.extra_data.data = SMB_STRDUP(extra_data);
index de4dbc9a79bed6915b9a31ffc4d46d6ea148a1e1..984c5cd8415f74835ec83b93cf297f0007107d25 100644 (file)
@@ -473,9 +473,14 @@ NTSTATUS msrpc_lookup_useraliases(struct winbindd_domain *domain,
 {
        NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
        POLICY_HND dom_pol;
-       DOM_SID2 *sid2;
+       DOM_SID2 *query_sids;
+       uint32 num_query_sids = 0;
        int i;
        struct rpc_pipe_client *cli;
+       uint32 *alias_rids_query, num_aliases_query;
+       int rangesize = MAX_SAM_ENTRIES_W2K;
+       uint32 total_sids = 0;
+       int num_queries = 1;
 
        *num_aliases = 0;
        *alias_rids = NULL;
@@ -486,19 +491,57 @@ NTSTATUS msrpc_lookup_useraliases(struct winbindd_domain *domain,
        if (!NT_STATUS_IS_OK(result))
                return result;
 
-       sid2 = TALLOC_ARRAY(mem_ctx, DOM_SID2, num_sids);
+       do {
+               /* prepare query */
 
-       if (sid2 == NULL)
-               return NT_STATUS_NO_MEMORY;
+               num_query_sids = MIN(num_sids - total_sids, rangesize);
 
-       for (i=0; i<num_sids; i++) {
-               sid_copy(&sid2[i].sid, &sids[i]);
-               sid2[i].num_auths = sid2[i].sid.num_auths;
-       }
+               DEBUG(10,("rpc: lookup_useraliases: entering query %d for %d sids\n", 
+                       num_queries, num_query_sids));  
+
+
+               query_sids = TALLOC_ARRAY(mem_ctx, DOM_SID2, num_query_sids);
+               if (query_sids == NULL) {
+                       return NT_STATUS_NO_MEMORY;
+               }
+
+               for (i=0; i<num_query_sids; i++) {
+                       sid_copy(&query_sids[i].sid, &sids[total_sids++]);
+                       query_sids[i].num_auths = query_sids[i].sid.num_auths;
+               }
+
+               /* do request */
+
+               result = rpccli_samr_query_useraliases(cli, mem_ctx, &dom_pol,
+                                                      num_query_sids, query_sids,
+                                                      &num_aliases_query, 
+                                                      &alias_rids_query);
+
+               if (!NT_STATUS_IS_OK(result)) {
+                       *num_aliases = 0;
+                       *alias_rids = NULL;
+                       TALLOC_FREE(query_sids);
+                       goto done;
+               }
+
+               /* process output */
+
+               for (i=0; i<num_aliases_query; i++) {
+                       size_t na = *num_aliases;
+                       add_rid_to_array_unique(mem_ctx, alias_rids_query[i], 
+                                               alias_rids, &na);
+                       *num_aliases = na;
+               }
+
+               TALLOC_FREE(query_sids);
+
+               num_queries++;
+
+       } while (total_sids < num_sids);
 
-       result = rpccli_samr_query_useraliases(cli, mem_ctx, &dom_pol,
-                                              num_sids, sid2,
-                                              num_aliases, alias_rids);
+ done:
+       DEBUG(10,("rpc: lookup_useraliases: got %d aliases in %d queries "
+               "(rangesize: %d)\n", *num_aliases, num_queries, rangesize));
 
        return result;
 }
index fba5990d8118bef1fb395065a5e897b67c831ac1..9a19dcf437ac250ee3624fccead5e28ac63a65aa 100644 (file)
@@ -72,6 +72,10 @@ LOGIN_CACHE * login_cache_read(struct samu *sampass)
        if (!login_cache_init())
                return NULL;
 
+       if (pdb_get_nt_username(sampass) == NULL) {
+               return NULL;
+       }
+
        keybuf.dptr = SMB_STRDUP(pdb_get_nt_username(sampass));
        if (!keybuf.dptr || !strlen(keybuf.dptr)) {
                SAFE_FREE(keybuf.dptr);
@@ -117,6 +121,10 @@ BOOL login_cache_write(const struct samu *sampass, LOGIN_CACHE entry)
        if (!login_cache_init())
                return False;
 
+       if (pdb_get_nt_username(sampass) == NULL) {
+               return False;
+       }
+
        keybuf.dptr = SMB_STRDUP(pdb_get_nt_username(sampass));
        if (!keybuf.dptr || !strlen(keybuf.dptr)) {
                SAFE_FREE(keybuf.dptr);
@@ -163,6 +171,10 @@ BOOL login_cache_delentry(const struct samu *sampass)
        if (!login_cache_init()) 
                return False;   
 
+       if (pdb_get_nt_username(sampass) == NULL) {
+               return False;
+       }
+
        keybuf.dptr = SMB_STRDUP(pdb_get_nt_username(sampass));
        if (!keybuf.dptr || !strlen(keybuf.dptr)) {
                SAFE_FREE(keybuf.dptr);
index 831ddefa13c528c12582252b2e5c7a20312f01b3..2e69240b1afbefd143982e4fedb17f50a6a37476 100644 (file)
@@ -328,101 +328,61 @@ void *pdb_get_backend_private_data(const struct samu *sampass, const struct pdb_
 
 BOOL pdb_set_acct_ctrl(struct samu *sampass, uint32 acct_ctrl, enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
-               
        sampass->acct_ctrl = acct_ctrl;
-
        return pdb_set_init_flags(sampass, PDB_ACCTCTRL, flag);
 }
 
 BOOL pdb_set_logon_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
-
        sampass->logon_time = mytime;
-
        return pdb_set_init_flags(sampass, PDB_LOGONTIME, flag);
 }
 
 BOOL pdb_set_logoff_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
-
        sampass->logoff_time = mytime;
-
        return pdb_set_init_flags(sampass, PDB_LOGOFFTIME, flag);
 }
 
 BOOL pdb_set_kickoff_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
-
        sampass->kickoff_time = mytime;
-
        return pdb_set_init_flags(sampass, PDB_KICKOFFTIME, flag);
 }
 
 BOOL pdb_set_bad_password_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
-
        sampass->bad_password_time = mytime;
-
        return pdb_set_init_flags(sampass, PDB_BAD_PASSWORD_TIME, flag);
 }
 
 BOOL pdb_set_pass_can_change_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
-
        sampass->pass_can_change_time = mytime;
-
        return pdb_set_init_flags(sampass, PDB_CANCHANGETIME, flag);
 }
 
 BOOL pdb_set_pass_must_change_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
-
        sampass->pass_must_change_time = mytime;
-
        return pdb_set_init_flags(sampass, PDB_MUSTCHANGETIME, flag);
 }
 
 BOOL pdb_set_pass_last_set_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
-
        sampass->pass_last_set_time = mytime;
-
        return pdb_set_init_flags(sampass, PDB_PASSLASTSET, flag);
 }
 
 BOOL pdb_set_hours_len(struct samu *sampass, uint32 len, enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
-
        sampass->hours_len = len;
-
        return pdb_set_init_flags(sampass, PDB_HOURSLEN, flag);
 }
 
 BOOL pdb_set_logon_divs(struct samu *sampass, uint16 hours, enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
-
        sampass->logon_divs = hours;
-
        return pdb_set_init_flags(sampass, PDB_LOGONDIVS, flag);
 }
 
@@ -435,9 +395,6 @@ BOOL pdb_set_logon_divs(struct samu *sampass, uint16 hours, enum pdb_value_state
  
 BOOL pdb_set_init_flags(struct samu *sampass, enum pdb_elements element, enum pdb_value_state value_flag)
 {
-        if (!sampass || !sampass)
-                return False;
-
         if (!sampass->set_flags) {
                if ((sampass->set_flags = 
                        bitmap_talloc(sampass, 
@@ -497,7 +454,7 @@ BOOL pdb_set_init_flags(struct samu *sampass, enum pdb_elements element, enum pd
 
 BOOL pdb_set_user_sid(struct samu *sampass, const DOM_SID *u_sid, enum pdb_value_state flag)
 {
-       if (!sampass || !u_sid)
+       if (!u_sid)
                return False;
        
        sid_copy(&sampass->user_sid, u_sid);
@@ -512,7 +469,7 @@ BOOL pdb_set_user_sid_from_string(struct samu *sampass, fstring u_sid, enum pdb_
 {
        DOM_SID new_sid;
        
-       if (!sampass || !u_sid)
+       if (!u_sid)
                return False;
 
        DEBUG(10, ("pdb_set_user_sid_from_string: setting user sid %s\n",
@@ -543,7 +500,7 @@ BOOL pdb_set_group_sid(struct samu *sampass, const DOM_SID *g_sid, enum pdb_valu
 {
        gid_t gid;
 
-       if (!sampass || !g_sid)
+       if (!g_sid)
                return False;
 
        if ( !(sampass->group_sid = TALLOC_P( sampass, DOM_SID )) ) {
@@ -572,9 +529,6 @@ BOOL pdb_set_group_sid(struct samu *sampass, const DOM_SID *g_sid, enum pdb_valu
 
 BOOL pdb_set_username(struct samu *sampass, const char *username, enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
        if (username) { 
                DEBUG(10, ("pdb_set_username: setting username %s, was %s\n", username,
                        (sampass->username)?(sampass->username):"NULL"));
@@ -585,7 +539,6 @@ BOOL pdb_set_username(struct samu *sampass, const char *username, enum pdb_value
                        DEBUG(0, ("pdb_set_username: talloc_strdup() failed!\n"));
                        return False;
                }
-
        } else {
                sampass->username = PDB_NOT_QUITE_NULL;
        }
@@ -599,9 +552,6 @@ BOOL pdb_set_username(struct samu *sampass, const char *username, enum pdb_value
 
 BOOL pdb_set_domain(struct samu *sampass, const char *domain, enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
-
        if (domain) { 
                DEBUG(10, ("pdb_set_domain: setting domain %s, was %s\n", domain,
                        (sampass->domain)?(sampass->domain):"NULL"));
@@ -612,7 +562,6 @@ BOOL pdb_set_domain(struct samu *sampass, const char *domain, enum pdb_value_sta
                        DEBUG(0, ("pdb_set_domain: talloc_strdup() failed!\n"));
                        return False;
                }
-
        } else {
                sampass->domain = PDB_NOT_QUITE_NULL;
        }
@@ -626,9 +575,6 @@ BOOL pdb_set_domain(struct samu *sampass, const char *domain, enum pdb_value_sta
 
 BOOL pdb_set_nt_username(struct samu *sampass, const char *nt_username, enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
-
        if (nt_username) { 
                DEBUG(10, ("pdb_set_nt_username: setting nt username %s, was %s\n", nt_username,
                        (sampass->nt_username)?(sampass->nt_username):"NULL"));
@@ -639,7 +585,6 @@ BOOL pdb_set_nt_username(struct samu *sampass, const char *nt_username, enum pdb
                        DEBUG(0, ("pdb_set_nt_username: talloc_strdup() failed!\n"));
                        return False;
                }
-
        } else {
                sampass->nt_username = PDB_NOT_QUITE_NULL;
        }
@@ -653,9 +598,6 @@ BOOL pdb_set_nt_username(struct samu *sampass, const char *nt_username, enum pdb
 
 BOOL pdb_set_fullname(struct samu *sampass, const char *full_name, enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
-
        if (full_name) { 
                DEBUG(10, ("pdb_set_full_name: setting full name %s, was %s\n", full_name,
                        (sampass->full_name)?(sampass->full_name):"NULL"));
@@ -666,7 +608,6 @@ BOOL pdb_set_fullname(struct samu *sampass, const char *full_name, enum pdb_valu
                        DEBUG(0, ("pdb_set_fullname: talloc_strdup() failed!\n"));
                        return False;
                }
-
        } else {
                sampass->full_name = PDB_NOT_QUITE_NULL;
        }
@@ -680,9 +621,6 @@ BOOL pdb_set_fullname(struct samu *sampass, const char *full_name, enum pdb_valu
 
 BOOL pdb_set_logon_script(struct samu *sampass, const char *logon_script, enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
-
        if (logon_script) { 
                DEBUG(10, ("pdb_set_logon_script: setting logon script %s, was %s\n", logon_script,
                        (sampass->logon_script)?(sampass->logon_script):"NULL"));
@@ -693,7 +631,6 @@ BOOL pdb_set_logon_script(struct samu *sampass, const char *logon_script, enum p
                        DEBUG(0, ("pdb_set_logon_script: talloc_strdup() failed!\n"));
                        return False;
                }
-
        } else {
                sampass->logon_script = PDB_NOT_QUITE_NULL;
        }
@@ -707,9 +644,6 @@ BOOL pdb_set_logon_script(struct samu *sampass, const char *logon_script, enum p
 
 BOOL pdb_set_profile_path(struct samu *sampass, const char *profile_path, enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
-
        if (profile_path) { 
                DEBUG(10, ("pdb_set_profile_path: setting profile path %s, was %s\n", profile_path,
                        (sampass->profile_path)?(sampass->profile_path):"NULL"));
@@ -720,7 +654,6 @@ BOOL pdb_set_profile_path(struct samu *sampass, const char *profile_path, enum p
                        DEBUG(0, ("pdb_set_profile_path: talloc_strdup() failed!\n"));
                        return False;
                }
-
        } else {
                sampass->profile_path = PDB_NOT_QUITE_NULL;
        }
@@ -734,9 +667,6 @@ BOOL pdb_set_profile_path(struct samu *sampass, const char *profile_path, enum p
 
 BOOL pdb_set_dir_drive(struct samu *sampass, const char *dir_drive, enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
-
        if (dir_drive) { 
                DEBUG(10, ("pdb_set_dir_drive: setting dir drive %s, was %s\n", dir_drive,
                        (sampass->dir_drive)?(sampass->dir_drive):"NULL"));
@@ -761,9 +691,6 @@ BOOL pdb_set_dir_drive(struct samu *sampass, const char *dir_drive, enum pdb_val
 
 BOOL pdb_set_homedir(struct samu *sampass, const char *home_dir, enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
-
        if (home_dir) { 
                DEBUG(10, ("pdb_set_homedir: setting home dir %s, was %s\n", home_dir,
                        (sampass->home_dir)?(sampass->home_dir):"NULL"));
@@ -774,7 +701,6 @@ BOOL pdb_set_homedir(struct samu *sampass, const char *home_dir, enum pdb_value_
                        DEBUG(0, ("pdb_set_home_dir: talloc_strdup() failed!\n"));
                        return False;
                }
-
        } else {
                sampass->home_dir = PDB_NOT_QUITE_NULL;
        }
@@ -788,9 +714,6 @@ BOOL pdb_set_homedir(struct samu *sampass, const char *home_dir, enum pdb_value_
 
 BOOL pdb_set_acct_desc(struct samu *sampass, const char *acct_desc, enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
-
        if (acct_desc) { 
                sampass->acct_desc = talloc_strdup(sampass, acct_desc);
 
@@ -798,7 +721,6 @@ BOOL pdb_set_acct_desc(struct samu *sampass, const char *acct_desc, enum pdb_val
                        DEBUG(0, ("pdb_set_acct_desc: talloc_strdup() failed!\n"));
                        return False;
                }
-
        } else {
                sampass->acct_desc = PDB_NOT_QUITE_NULL;
        }
@@ -812,9 +734,6 @@ BOOL pdb_set_acct_desc(struct samu *sampass, const char *acct_desc, enum pdb_val
 
 BOOL pdb_set_workstations(struct samu *sampass, const char *workstations, enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
-
        if (workstations) { 
                DEBUG(10, ("pdb_set_workstations: setting workstations %s, was %s\n", workstations,
                        (sampass->workstations)?(sampass->workstations):"NULL"));
@@ -825,7 +744,6 @@ BOOL pdb_set_workstations(struct samu *sampass, const char *workstations, enum p
                        DEBUG(0, ("pdb_set_workstations: talloc_strdup() failed!\n"));
                        return False;
                }
-
        } else {
                sampass->workstations = PDB_NOT_QUITE_NULL;
        }
@@ -839,9 +757,6 @@ BOOL pdb_set_workstations(struct samu *sampass, const char *workstations, enum p
 
 BOOL pdb_set_unknown_str(struct samu *sampass, const char *unknown_str, enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
-
        if (unknown_str) { 
                sampass->unknown_str = talloc_strdup(sampass, unknown_str);
                
@@ -849,7 +764,6 @@ BOOL pdb_set_unknown_str(struct samu *sampass, const char *unknown_str, enum pdb
                        DEBUG(0, ("pdb_set_unknown_str: talloc_strdup() failed!\n"));
                        return False;
                }
-
        } else {
                sampass->unknown_str = PDB_NOT_QUITE_NULL;
        }
@@ -863,9 +777,6 @@ BOOL pdb_set_unknown_str(struct samu *sampass, const char *unknown_str, enum pdb
 
 BOOL pdb_set_munged_dial(struct samu *sampass, const char *munged_dial, enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
-
        if (munged_dial) { 
                sampass->munged_dial = talloc_strdup(sampass, munged_dial);
                
@@ -873,7 +784,6 @@ BOOL pdb_set_munged_dial(struct samu *sampass, const char *munged_dial, enum pdb
                        DEBUG(0, ("pdb_set_munged_dial: talloc_strdup() failed!\n"));
                        return False;
                }
-
        } else {
                sampass->munged_dial = PDB_NOT_QUITE_NULL;
        }
@@ -887,9 +797,6 @@ BOOL pdb_set_munged_dial(struct samu *sampass, const char *munged_dial, enum pdb
 
 BOOL pdb_set_nt_passwd(struct samu *sampass, const uint8 pwd[NT_HASH_LEN], enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
-
        data_blob_clear_free(&sampass->nt_pw);
        
        if (pwd) {
@@ -908,9 +815,6 @@ BOOL pdb_set_nt_passwd(struct samu *sampass, const uint8 pwd[NT_HASH_LEN], enum
 
 BOOL pdb_set_lanman_passwd(struct samu *sampass, const uint8 pwd[LM_HASH_LEN], enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
-
        data_blob_clear_free(&sampass->lm_pw);
        
        /* on keep the password if we are allowing LANMAN authentication */
@@ -933,9 +837,6 @@ BOOL pdb_set_lanman_passwd(struct samu *sampass, const uint8 pwd[LM_HASH_LEN], e
 
 BOOL pdb_set_pw_history(struct samu *sampass, const uint8 *pwd, uint32 historyLen, enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
-
        if (historyLen && pwd){
                sampass->nt_pw_his = data_blob_talloc(sampass,
                                                pwd, historyLen*PW_HISTORY_ENTRY_LEN);
@@ -957,9 +858,6 @@ BOOL pdb_set_pw_history(struct samu *sampass, const uint8 *pwd, uint32 historyLe
 
 BOOL pdb_set_plaintext_pw_only(struct samu *sampass, const char *password, enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
-
        if (password) { 
                if (sampass->plaintext_pw!=NULL) 
                        memset(sampass->plaintext_pw,'\0',strlen(sampass->plaintext_pw)+1);
@@ -970,7 +868,6 @@ BOOL pdb_set_plaintext_pw_only(struct samu *sampass, const char *password, enum
                        DEBUG(0, ("pdb_set_unknown_str: talloc_strdup() failed!\n"));
                        return False;
                }
-
        } else {
                sampass->plaintext_pw = NULL;
        }
@@ -980,45 +877,29 @@ BOOL pdb_set_plaintext_pw_only(struct samu *sampass, const char *password, enum
 
 BOOL pdb_set_bad_password_count(struct samu *sampass, uint16 bad_password_count, enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
-
        sampass->bad_password_count = bad_password_count;
-
        return pdb_set_init_flags(sampass, PDB_BAD_PASSWORD_COUNT, flag);
 }
 
 BOOL pdb_set_logon_count(struct samu *sampass, uint16 logon_count, enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
-
        sampass->logon_count = logon_count;
-
        return pdb_set_init_flags(sampass, PDB_LOGON_COUNT, flag);
 }
 
 BOOL pdb_set_unknown_6(struct samu *sampass, uint32 unkn, enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
-
        sampass->unknown_6 = unkn;
-
        return pdb_set_init_flags(sampass, PDB_UNKNOWN6, flag);
 }
 
 BOOL pdb_set_hours(struct samu *sampass, const uint8 *hours, enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
-
        if (!hours) {
                memset ((char *)sampass->hours, 0, MAX_HOURS_LEN);
-               return True;
+       } else {
+               memcpy (sampass->hours, hours, MAX_HOURS_LEN);
        }
-       
-       memcpy (sampass->hours, hours, MAX_HOURS_LEN);
 
        return pdb_set_init_flags(sampass, PDB_HOURS, flag);
 }
@@ -1028,9 +909,6 @@ BOOL pdb_set_backend_private_data(struct samu *sampass, void *private_data,
                                   const struct pdb_methods *my_methods, 
                                   enum pdb_value_state flag)
 {
-       if (!sampass)
-               return False;
-
        if (sampass->backend_private_data &&
            sampass->backend_private_data_free_fn) {
                sampass->backend_private_data_free_fn(
@@ -1057,9 +935,6 @@ BOOL pdb_set_pass_changed_now(struct samu *sampass)
        uint32 expire;
        uint32 min_age;
 
-       if (!sampass)
-               return False;
-       
        if (!pdb_set_pass_last_set_time (sampass, time(NULL), PDB_CHANGED))
                return False;
 
@@ -1097,7 +972,7 @@ BOOL pdb_set_plaintext_passwd(struct samu *sampass, const char *plaintext)
        uchar new_lanman_p16[LM_HASH_LEN];
        uchar new_nt_p16[NT_HASH_LEN];
 
-       if (!sampass || !plaintext)
+       if (!plaintext)
                return False;
 
        /* Calculate the MD4 hash (NT compatible) of the password */
index 94adebe23277623b6cb32f11d6cbdc40aeb33a79..5d70c2c1227933904da3da4892bb065467bab773 100644 (file)
@@ -1470,6 +1470,11 @@ static BOOL lookup_global_sam_rid(TALLOC_CTX *mem_ctx, uint32 rid,
 
                unbecome_root();                /* -----> EXIT BECOME_ROOT() */
                *name = talloc_strdup(mem_ctx, pdb_get_username(sam_account));
+               if (!*name) {
+                       TALLOC_FREE(sam_account);
+                       return False;
+               }
+
                *psid_name_use = SID_NAME_USER;
 
                TALLOC_FREE(sam_account);
index 3fd4e6748aec6f058b300c059793cd7d28152754..2a824c137f9bc6cc878032e2117cc682a451f708 100644 (file)
@@ -2274,25 +2274,6 @@ static NTSTATUS ldapsam_getgrnam(struct pdb_methods *methods, GROUP_MAP *map,
        return ldapsam_getgroup(methods, filter, map);
 }
 
-static void add_rid_to_array_unique(TALLOC_CTX *mem_ctx,
-                                   uint32 rid, uint32 **pp_rids, size_t *p_num)
-{
-       size_t i;
-
-       for (i=0; i<*p_num; i++) {
-               if ((*pp_rids)[i] == rid)
-                       return;
-       }
-       
-       *pp_rids = TALLOC_REALLOC_ARRAY(mem_ctx, *pp_rids, uint32, *p_num+1);
-
-       if (*pp_rids == NULL)
-               return;
-
-       (*pp_rids)[*p_num] = rid;
-       *p_num += 1;
-}
-
 static BOOL ldapsam_extract_rid_from_entry(LDAP *ldap_struct,
                                           LDAPMessage *entry,
                                           const DOM_SID *domain_sid,
index 79061ebd41623a32ae01d913d06f9f45d616d489..6a7fd4d3986466203194482373f24a34d3e68c87 100644 (file)
@@ -250,7 +250,7 @@ static TDB_DATA make_printer_tdbkey( const char *sharename )
  generate a new TDB_DATA key for storing a printer security descriptor
 ****************************************************************************/
 
-static charmake_printers_secdesc_tdbkey( const char* sharename  )
+static char *make_printers_secdesc_tdbkey( const char* sharename  )
 {
        fstring share;
        static pstring keystr;
@@ -346,32 +346,41 @@ static int sec_desc_upg_fn( TDB_CONTEXT *the_tdb, TDB_DATA key,
        size_t size_new_sec;
        DOM_SID sid;
 
-       if (!data.dptr || data.dsize == 0)
+       if (!data.dptr || data.dsize == 0) {
                return 0;
+       }
 
-       if ( strncmp( key.dptr, SECDESC_PREFIX, strlen(SECDESC_PREFIX) ) != 0 )
+       if ( strncmp( key.dptr, SECDESC_PREFIX, strlen(SECDESC_PREFIX) ) != 0 ) {
                return 0;
+       }
 
        /* upgrade the security descriptor */
 
        ZERO_STRUCT( ps );
 
        prs_init( &ps, 0, ctx, UNMARSHALL );
-       prs_give_memory( &ps, data.dptr, data.dsize, True );
+       prs_give_memory( &ps, data.dptr, data.dsize, False );
 
        if ( !sec_io_desc_buf( "sec_desc_upg_fn", &sd_orig, &ps, 1 ) ) {
                /* delete bad entries */
                DEBUG(0,("sec_desc_upg_fn: Failed to parse original sec_desc for %si.  Deleting....\n", key.dptr ));
                tdb_delete( tdb_printers, key );
+               prs_mem_free( &ps );
                return 0;
        }
 
+       if (!sd_orig) {
+               prs_mem_free( &ps );
+               return 0;
+       }
        sec = sd_orig->sec;
                
        /* is this even valid? */
        
-       if ( !sec->dacl )
+       if ( !sec->dacl ) {
+               prs_mem_free( &ps );
                return 0;
+       }
                
        /* update access masks */
        
@@ -399,13 +408,24 @@ static int sec_desc_upg_fn( TDB_CONTEXT *the_tdb, TDB_DATA key,
        new_sec = make_sec_desc( ctx, SEC_DESC_REVISION, SEC_DESC_SELF_RELATIVE,
                &sid, &sid,
                NULL, NULL, &size_new_sec );
+       if (!new_sec) {
+               prs_mem_free( &ps );
+               return 0;
+       }
        sd_new = make_sec_desc_buf( ctx, size_new_sec, new_sec );
+       if (!sd_new) {
+               prs_mem_free( &ps );
+               return 0;
+       }
 
        if ( !(sd_store = sec_desc_merge( ctx, sd_new, sd_orig )) ) {
                DEBUG(0,("sec_desc_upg_fn: Failed to update sec_desc for %s\n", key.dptr ));
+               prs_mem_free( &ps );
                return 0;
        }
        
+       prs_mem_free( &ps );
+
        /* store it back */
        
        sd_size = sec_desc_size(sd_store->sec) + sizeof(SEC_DESC_BUF);
@@ -413,6 +433,7 @@ static int sec_desc_upg_fn( TDB_CONTEXT *the_tdb, TDB_DATA key,
 
        if ( !sec_io_desc_buf( "sec_desc_upg_fn", &sd_store, &ps, 1 ) ) {
                DEBUG(0,("sec_desc_upg_fn: Failed to parse new sec_desc for %s\n", key.dptr ));
+               prs_mem_free( &ps );
                return 0;
        }
 
@@ -943,6 +964,10 @@ int get_ntdrivers(fstring **list, const char *architecture, uint32 version)
        TDB_DATA kbuf, newkey;
 
        short_archi = get_short_archi(architecture);
+       if (!short_archi) {
+               return 0;
+       }
+
        slprintf(key, sizeof(key)-1, "%s%s/%d/", DRIVERS_PREFIX, short_archi, version);
 
        for (kbuf = tdb_firstkey(tdb_drivers);
@@ -965,9 +990,10 @@ int get_ntdrivers(fstring **list, const char *architecture, uint32 version)
 }
 
 /****************************************************************************
-function to do the mapping between the long architecture name and
-the short one.
+ Function to do the mapping between the long architecture name and
+ the short one.
 ****************************************************************************/
+
 const char *get_short_archi(const char *long_archi)
 {
         int i=-1;
@@ -985,7 +1011,6 @@ const char *get_short_archi(const char *long_archi)
 
        /* this might be client code - but shouldn't this be an fstrcpy etc? */
 
-
         DEBUGADD(108,("index: [%d]\n", i));
         DEBUGADD(108,("long architecture: [%s]\n", archi_table[i].long_archi));
         DEBUGADD(108,("short architecture: [%s]\n", archi_table[i].short_archi));
@@ -1546,6 +1571,9 @@ static WERROR clean_up_driver_struct_level_3(NT_PRINTER_DRIVER_INFO_LEVEL_3 *dri
        }
 
        architecture = get_short_archi(driver->environment);
+       if (!architecture) {
+               return WERR_UNKNOWN_PRINTER_DRIVER;
+       }
        
        /* jfm:7/16/2000 the client always sends the cversion=0.
         * The server should check which version the driver is by reading
@@ -1559,7 +1587,7 @@ static WERROR clean_up_driver_struct_level_3(NT_PRINTER_DRIVER_INFO_LEVEL_3 *dri
         *      NT2K: cversion=3
         */
        if ((driver->cversion = get_correct_cversion( architecture, driver->driverpath, user, &err)) == -1)
-                       return err;
+               return err;
 
        return WERR_OK;
 }
@@ -1609,6 +1637,9 @@ static WERROR clean_up_driver_struct_level_6(NT_PRINTER_DRIVER_INFO_LEVEL_6 *dri
        }
 
        architecture = get_short_archi(driver->environment);
+       if (!architecture) {
+               return WERR_UNKNOWN_PRINTER_DRIVER;
+       }
 
        /* jfm:7/16/2000 the client always sends the cversion=0.
         * The server should check which version the driver is by reading
@@ -1726,6 +1757,9 @@ WERROR move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract
        }
 
        architecture = get_short_archi(driver->environment);
+       if (!architecture) {
+               return WERR_UNKNOWN_PRINTER_DRIVER;
+       }
 
        /*
         * Connect to the print$ share under the same account as the user connected to the rpc pipe.
@@ -1901,6 +1935,9 @@ static uint32 add_a_printer_driver_3(NT_PRINTER_DRIVER_INFO_LEVEL_3 *driver)
        TDB_DATA kbuf, dbuf;
 
        architecture = get_short_archi(driver->environment);
+       if (!architecture) {
+               return (uint32)-1;
+       }
 
        /* The names are relative. We store them in the form: \print$\arch\version\driver.xxx
         * \\server is added in the rpc server layer.
@@ -2059,9 +2096,9 @@ static WERROR get_a_printer_driver_3(NT_PRINTER_DRIVER_INFO_LEVEL_3 **info_ptr,
        ZERO_STRUCT(driver);
 
        architecture = get_short_archi(arch);
-
-       if ( !architecture )
+       if ( !architecture ) {
                return WERR_UNKNOWN_PRINTER_DRIVER;
+       }
        
        /* Windows 4.0 (i.e. win9x) should always use a version of 0 */
        
@@ -3075,6 +3112,10 @@ static WERROR nt_printer_unpublish_ads(ADS_STRUCT *ads,
 
        if (ADS_ERR_OK(ads_rc) && ads_count_replies(ads, res)) {
                prt_dn = ads_get_dn(ads, res);
+               if (!prt_dn) {
+                       ads_msgfree(ads, res);
+                       return WERR_NOMEM;
+               }
                ads_rc = ads_del_dn(ads, prt_dn);
                ads_memfree(ads, prt_dn);
        }
@@ -3643,15 +3684,16 @@ static WERROR get_a_printer_2_default(NT_PRINTER_INFO_LEVEL_2 *info, const char
         */
 
        if (lp_default_devmode(snum)) {
-               if ((info->devmode = construct_nt_devicemode(info->printername)) == NULL)
+               if ((info->devmode = construct_nt_devicemode(info->printername)) == NULL) {
                        goto fail;
-       }
-       else {
+               }
+       else {
                info->devmode = NULL;
        }
 
-       if (!nt_printing_getsec(info, sharename, &info->secdesc_buf))
+       if (!nt_printing_getsec(info, sharename, &info->secdesc_buf)) {
                goto fail;
+       }
 
        return WERR_OK;
 
@@ -3675,8 +3717,9 @@ static WERROR get_a_printer_2(NT_PRINTER_INFO_LEVEL_2 *info, const char *servern
        kbuf = make_printer_tdbkey( sharename );
 
        dbuf = tdb_fetch(tdb_printers, kbuf);
-       if (!dbuf.dptr)
+       if (!dbuf.dptr) {
                return get_a_printer_2_default(info, servername, sharename);
+       }
 
        len += tdb_unpack(dbuf.dptr+len, dbuf.dsize-len, "dddddddddddfffffPfffff",
                        &info->attributes,
@@ -3709,10 +3752,11 @@ static WERROR get_a_printer_2(NT_PRINTER_INFO_LEVEL_2 *info, const char *servern
        /* Restore the stripped strings. */
        slprintf(info->servername, sizeof(info->servername)-1, "\\\\%s", servername);
 
-       if ( lp_force_printername(snum) )
+       if ( lp_force_printername(snum) ) {
                slprintf(printername, sizeof(printername)-1, "\\\\%s\\%s", servername, sharename );
-       else 
+       } else {
                slprintf(printername, sizeof(printername)-1, "\\\\%s\\%s", servername, info->printername);
+       }
 
        fstrcpy(info->printername, printername);
 
@@ -3739,6 +3783,7 @@ static WERROR get_a_printer_2(NT_PRINTER_INFO_LEVEL_2 *info, const char *servern
 
        if ( !(info->data = TALLOC_ZERO_P( info, NT_PRINTER_DATA )) ) {
                DEBUG(0,("unpack_values: talloc() failed!\n"));
+               SAFE_FREE(dbuf.dptr);
                return WERR_NOMEM;
        }
        len += unpack_values( info->data, dbuf.dptr+len, dbuf.dsize-len );
@@ -3746,12 +3791,16 @@ static WERROR get_a_printer_2(NT_PRINTER_INFO_LEVEL_2 *info, const char *servern
        /* This will get the current RPC talloc context, but we should be
           passing this as a parameter... fixme... JRA ! */
 
-       nt_printing_getsec(info, sharename, &info->secdesc_buf);
+       if (!nt_printing_getsec(info, sharename, &info->secdesc_buf)) {
+               SAFE_FREE(dbuf.dptr);
+               return WERR_NOMEM;
+       }
 
        /* Fix for OS/2 drivers. */
 
-       if (get_remote_arch() == RA_OS2)
+       if (get_remote_arch() == RA_OS2) {
                map_to_os2_driver(info->drivername);
+       }
 
        SAFE_FREE(dbuf.dptr);
 
@@ -4859,6 +4908,9 @@ WERROR delete_printer_driver( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info_3, struct cur
        /* delete the tdb data first */
 
        arch = get_short_archi(info_3->environment);
+       if (!arch) {
+               return WERR_UNKNOWN_PRINTER_DRIVER;
+       }
        slprintf(key, sizeof(key)-1, "%s%s/%d/%s", DRIVERS_PREFIX,
                arch, version, info_3->name);
 
@@ -4931,7 +4983,10 @@ WERROR nt_printing_setsec(const char *sharename, SEC_DESC_BUF *secdesc_ctr)
                SEC_DESC *psd = NULL;
                size_t size;
 
-               nt_printing_getsec(mem_ctx, sharename, &old_secdesc_ctr);
+               if (!nt_printing_getsec(mem_ctx, sharename, &old_secdesc_ctr)) {
+                       status = WERR_NOMEM;
+                       goto out;
+               }
 
                /* Pick out correct owner and group sids */
 
@@ -4959,6 +5014,11 @@ WERROR nt_printing_setsec(const char *sharename, SEC_DESC_BUF *secdesc_ctr)
                                    dacl,
                                    &size);
 
+               if (!psd) {
+                       status = WERR_NOMEM;
+                       goto out;
+               }
+
                new_secdesc_ctr = make_sec_desc_buf(mem_ctx, size, psd);
        }
 
@@ -5094,6 +5154,8 @@ BOOL nt_printing_getsec(TALLOC_CTX *ctx, const char *sharename, SEC_DESC_BUF **s
                sharename = temp + 1;
        }
 
+       ZERO_STRUCT(ps);
+
        /* Fetch security descriptor from tdb */
 
        key = make_printers_secdesc_tdbkey( sharename  );
@@ -5101,6 +5163,8 @@ BOOL nt_printing_getsec(TALLOC_CTX *ctx, const char *sharename, SEC_DESC_BUF **s
        if (tdb_prs_fetch(tdb_printers, key, &ps, ctx)!=0 ||
            !sec_io_desc_buf("nt_printing_getsec", secdesc_ctr, &ps, 1)) {
 
+               prs_mem_free(&ps);
+
                DEBUG(4,("using default secdesc for %s\n", sharename));
 
                if (!(*secdesc_ctr = construct_default_printer_sdb(ctx))) {
@@ -5112,14 +5176,17 @@ BOOL nt_printing_getsec(TALLOC_CTX *ctx, const char *sharename, SEC_DESC_BUF **s
                prs_init(&ps, (uint32)sec_desc_size((*secdesc_ctr)->sec) +
                                sizeof(SEC_DESC_BUF), ctx, MARSHALL);
 
-               if (sec_io_desc_buf("nt_printing_getsec", secdesc_ctr, &ps, 1))
+               if (sec_io_desc_buf("nt_printing_getsec", secdesc_ctr, &ps, 1)) {
                        tdb_prs_store(tdb_printers, key, &ps);
+               }
 
                prs_mem_free(&ps);
 
                return True;
        }
 
+       prs_mem_free(&ps);
+
        /* If security descriptor is owned by S-1-1-0 and winbindd is up,
           this security descriptor has been created when winbindd was
           down.  Take ownership of security descriptor. */
@@ -5145,7 +5212,14 @@ BOOL nt_printing_getsec(TALLOC_CTX *ctx, const char *sharename, SEC_DESC_BUF **s
                                            (*secdesc_ctr)->sec->dacl,
                                            &size);
 
+                       if (!psd) {
+                               return False;
+                       }
+
                        new_secdesc_ctr = make_sec_desc_buf(ctx, size, psd);
+                       if (!new_secdesc_ctr) {
+                               return False;
+                       }
 
                        /* Swap with other one */
 
@@ -5175,7 +5249,6 @@ BOOL nt_printing_getsec(TALLOC_CTX *ctx, const char *sharename, SEC_DESC_BUF **s
                }
        }
 
-       prs_mem_free(&ps);
        return True;
 }
 
@@ -5289,7 +5362,11 @@ BOOL print_access_check(struct current_user *user, int snum, int access_type)
                return False;
        }
 
-       nt_printing_getsec(mem_ctx, pname, &secdesc);
+       if (!nt_printing_getsec(mem_ctx, pname, &secdesc)) {
+               talloc_destroy(mem_ctx);
+               errno = ENOMEM;
+               return False;
+       }
 
        if (access_type == JOB_ACCESS_ADMINISTER) {
                SEC_DESC_BUF *parent_secdesc = secdesc;
@@ -5300,6 +5377,12 @@ BOOL print_access_check(struct current_user *user, int snum, int access_type)
 
                secdesc = se_create_child_secdesc(mem_ctx, parent_secdesc->sec, False);
 
+               if (!secdesc) {
+                       talloc_destroy(mem_ctx);
+                       errno = ENOMEM;
+                       return False;
+               }
+
                /* Now this is the bit that really confuses me.  The access
                   type needs to be changed from JOB_ACCESS_ADMINISTER to
                   PRINTER_ACCESS_ADMINISTER for this to work.  Something
@@ -5324,13 +5407,15 @@ BOOL print_access_check(struct current_user *user, int snum, int access_type)
            (token_contains_name_in_list(uidtoname(user->ut.uid), NULL,
                                         user->nt_user_token,
                                         lp_printer_admin(snum)))) {
+               talloc_destroy(mem_ctx);
                return True;
         }
 
        talloc_destroy(mem_ctx);
        
-       if (!result)
+       if (!result) {
                errno = EACCES;
+       }
 
        return result;
 }
index e445bc3ce0077eb595ce065d3fdb11eefa864bca..1ea762695b1707943c24eaacbf34deaf723f9d1e 100644 (file)
@@ -193,7 +193,7 @@ static int generic_queue_get(const char *printer_name,
        /* turn the lpq output into a series of job structures */
        qcount = 0;
        ZERO_STRUCTP(status);
-       if (numlines) {
+       if (numlines && qlines) {
                queue = SMB_MALLOC_ARRAY(print_queue_struct, numlines+1);
                if (!queue) {
                        file_lines_free(qlines);
index adea10dfa691b5277152a65f1e63ad1f5a5e3677..c62409c8908223b6bbcfaf5cad7e30ecc3ca5651 100644 (file)
@@ -55,7 +55,9 @@ struct tdb_print_db *get_print_db_byname(const char *printername)
        /* Not found. */
        if (num_open >= MAX_PRINT_DBS_OPEN) {
                /* Try and recycle the last entry. */
-               DLIST_PROMOTE(print_db_head, last_entry);
+               if (print_db_head && last_entry) {
+                       DLIST_PROMOTE(print_db_head, last_entry);
+               }
 
                for (p = print_db_head; p; p = p->next) {
                        if (p->ref_count)
@@ -72,7 +74,7 @@ struct tdb_print_db *get_print_db_byname(const char *printername)
                        memset(p->printer_name, '\0', sizeof(p->printer_name));
                        break;
                }
-               if (p) {
+               if (p && print_db_head) {
                        DLIST_PROMOTE(print_db_head, p);
                        p = print_db_head;
                }
index 385128e7b55800b28ef23bbb6c3a9e89b97fa7f5..c69e7b7e14e2076513325bfffb709ff84c4e9e3d 100644 (file)
@@ -718,6 +718,10 @@ BOOL _reg_perfcount_get_instance_info(PERF_INSTANCE_DEFINITION *inst,
                                                  inst->data,
                                                  uint8,
                                                  inst->NameLength);
+               if (inst->data == NULL) {
+                       SAFE_FREE(data.dptr);
+                       return False;
+               }
                memcpy(inst->data, name, inst->NameLength);
                SAFE_FREE(data.dptr);
        }
@@ -894,7 +898,8 @@ static BOOL _reg_perfcount_init_data_block_perf(PERF_DATA_BLOCK *block,
 /*********************************************************************
 *********************************************************************/
 
-static void _reg_perfcount_init_data_block(PERF_DATA_BLOCK *block, prs_struct *ps, TDB_CONTEXT *names)
+static BOOL _reg_perfcount_init_data_block(PERF_DATA_BLOCK *block,
+                                          prs_struct *ps, TDB_CONTEXT *names)
 {
        wpstring temp;
        time_t tm;
@@ -920,6 +925,9 @@ static void _reg_perfcount_init_data_block(PERF_DATA_BLOCK *block, prs_struct *p
        rpcstr_push((void *)temp, global_myname(), sizeof(temp), STR_TERMINATE);
        block->SystemNameLength = (strlen_w(temp) * 2) + 2;
        block->data = TALLOC_ZERO_ARRAY(ps->mem_ctx, uint8, block->SystemNameLength + (8 - (block->SystemNameLength % 8)));
+       if (block->data == NULL) {
+               return False;
+       }
        memcpy(block->data, temp, block->SystemNameLength);
        block->SystemNameOffset = sizeof(PERF_DATA_BLOCK) - sizeof(block->objects) - sizeof(block->data); 
        block->HeaderLength = block->SystemNameOffset + block->SystemNameLength;
@@ -927,7 +935,7 @@ static void _reg_perfcount_init_data_block(PERF_DATA_BLOCK *block, prs_struct *p
           so that the PERF_OBJECT_TYPE struct comes out 64-bit aligned */
        block->HeaderLength += 8 - (block->HeaderLength % 8);
 
-       return;
+       return True;
 }
 
 /*********************************************************************
@@ -968,6 +976,9 @@ static uint32 _reg_perfcount_perf_data_block_fixup(PERF_DATA_BLOCK *block, prs_s
                                                            temp, 
                                                            char, 
                                                            counter_data->ByteLength- sizeof(counter_data->ByteLength));
+                               if (temp == NULL) {
+                                       return 0;
+                               }
                                memset(temp, 0, counter_data->ByteLength - sizeof(counter_data->ByteLength));
                                src_addr = (char *)counter_data->data;
                                for(i = 0; i < object[obj].NumCounters; i++)
@@ -986,6 +997,9 @@ static uint32 _reg_perfcount_perf_data_block_fixup(PERF_DATA_BLOCK *block, prs_s
                                                                         counter_data->data,
                                                                         uint8,
                                                                         counter_data->ByteLength - sizeof(counter_data->ByteLength) + pad);
+                               if (counter_data->data == NULL) {
+                                       return 0;
+                               }
                                memset(counter_data->data, 0, counter_data->ByteLength - sizeof(counter_data->ByteLength) + pad);
                                memcpy(counter_data->data, temp, counter_data->ByteLength - sizeof(counter_data->ByteLength));
                                counter_data->ByteLength += pad;
@@ -1039,7 +1053,11 @@ uint32 reg_perfcount_get_perf_data_block(uint32 base_index,
                return 0;
        }
 
-       _reg_perfcount_init_data_block(block, ps, names);
+       if (!_reg_perfcount_init_data_block(block, ps, names)) {
+               DEBUG(0, ("_reg_perfcount_init_data_block failed\n"));
+               tdb_close(names);
+               return 0;
+       }
 
        last_counter = reg_perfcount_get_last_counter(base_index);
     
index 954f4ae7bd0b6916984c3e783a429ef1d1f07bb4..f164d4e19d46a14f390c34e51813ae9f78c9c743 100644 (file)
@@ -1647,11 +1647,16 @@ static BOOL create_vk_record( REGF_FILE *file, REGF_VK_REC *vk, REGISTRY_VALUE *
                uint32 data_size = ( (vk->data_size+sizeof(uint32)) & 0xfffffff8 ) + 8;
 
                vk->data = TALLOC_MEMDUP( file->mem_ctx, regval_data_p(value), vk->data_size );
+               if (vk->data == NULL) {
+                       return False;
+               }
 
                /* go ahead and store the offset....we'll pick this hbin block back up when 
                   we stream the data */
 
-               data_hbin = find_free_space(file, data_size );
+               if ((data_hbin = find_free_space(file, data_size )) == NULL) {
+                       return False;
+               }
                vk->data_off = prs_offset( &data_hbin->ps ) + data_hbin->first_hbin_off - HBIN_HDR_SIZE;
        }
        else {
@@ -1712,7 +1717,9 @@ static int hashrec_cmp( REGF_HASH_REC *h1, REGF_HASH_REC *h2 )
 
        size = nk_record_data_size( nk );
        nk->rec_size = ( size - 1 ) ^ 0XFFFFFFFF;
-       nk->hbin = find_free_space( file, size );
+       if ((nk->hbin = find_free_space( file, size )) == NULL) {
+               return NULL;
+       }
        nk->hbin_off = prs_offset( &nk->hbin->ps );
 
        /* Update the hash record in the parent */
@@ -1746,7 +1753,9 @@ static int hashrec_cmp( REGF_HASH_REC *h1, REGF_HASH_REC *h2 )
                if ( (nk->sec_desc = find_sk_record_by_sec_desc( file, sec_desc )) == NULL ) {
                        /* not found so add it to the list */
 
-                       sk_hbin = find_free_space( file, sk_size );
+                       if (!(sk_hbin = find_free_space( file, sk_size ))) {
+                               return NULL;
+                       }
 
                        if ( !(nk->sec_desc = TALLOC_ZERO_P( file->mem_ctx, REGF_SK_REC )) )
                                return NULL;
@@ -1803,7 +1812,9 @@ static int hashrec_cmp( REGF_HASH_REC *h1, REGF_HASH_REC *h2 )
                uint32 namelen;
                int i;
                
-               nk->subkeys.hbin = find_free_space( file, lf_size );
+               if (!(nk->subkeys.hbin = find_free_space( file, lf_size ))) {
+                       return NULL;
+               }
                nk->subkeys.hbin_off = prs_offset( &nk->subkeys.hbin->ps );
                nk->subkeys.rec_size = (lf_size-1) ^ 0xFFFFFFFF;
                nk->subkeys_off = prs_offset( &nk->subkeys.hbin->ps ) + nk->subkeys.hbin->first_hbin_off - HBIN_HDR_SIZE;
@@ -1830,7 +1841,9 @@ static int hashrec_cmp( REGF_HASH_REC *h1, REGF_HASH_REC *h2 )
                uint32 vlist_size = ( ( nk->num_values * sizeof(uint32) ) & 0xfffffff8 ) + 8;
                int i;
                
-               vlist_hbin = find_free_space( file, vlist_size );
+               if (!(vlist_hbin = find_free_space( file, vlist_size ))) {
+                       return NULL;
+               }
                nk->values_off = prs_offset( &vlist_hbin->ps ) + vlist_hbin->first_hbin_off - HBIN_HDR_SIZE;
        
                if ( !(nk->values = TALLOC_ARRAY( file->mem_ctx, REGF_VK_REC, nk->num_values )) )
index 12f18d319b4c18ef9abadfca4d74974b91be21d9..ae4cff53e4ba17b29a2afb5a3db0acd94f3cf2d8 100644 (file)
@@ -738,6 +738,9 @@ static BOOL lsa_io_dom_query_2(const char *desc, DOM_QUERY_2 *d_q, prs_struct *p
 
                if (UNMARSHALLING(ps)) {
                        d_q->auditsettings = TALLOC_ZERO_ARRAY(ps->mem_ctx, uint32, d_q->count2);
+                       if (!d_q->auditsettings) {
+                               return False;
+                       }
                }
 
                if (!prs_uint32s(False, "auditsettings", ps, depth, d_q->auditsettings, d_q->count2))
index b56f36f5900e67df777cccddb21c5502dfba7923..cb7c06eb459a8ca4be5ca4667f8972b19013e801 100644 (file)
@@ -226,56 +226,6 @@ BOOL smb_io_dom_sid(const char *desc, DOM_SID *sid, prs_struct *ps, int depth)
        return True;
 }
 
-/*******************************************************************
- Inits a DOM_SID structure.
-
- BIG NOTE: this function only does SIDS where the identauth is not >= 2^32 
- identauth >= 2^32 can be detected because it will be specified in hex
-********************************************************************/
-
-void init_dom_sid(DOM_SID *sid, const char *str_sid)
-{
-       pstring domsid;
-       int identauth;
-       char *p;
-
-       if (str_sid == NULL) {
-               DEBUG(4,("netlogon domain SID: none\n"));
-               sid->sid_rev_num = 0;
-               sid->num_auths = 0;
-               return;
-       }
-               
-       pstrcpy(domsid, str_sid);
-
-       DEBUG(4,("init_dom_sid %d SID:  %s\n", __LINE__, domsid));
-
-       /* assume, but should check, that domsid starts "S-" */
-       p = strtok(domsid+2,"-");
-       sid->sid_rev_num = atoi(p);
-
-       /* identauth in decimal should be <  2^32 */
-       /* identauth in hex     should be >= 2^32 */
-       identauth = atoi(strtok(0,"-"));
-
-       DEBUG(4,("netlogon rev %d\n", sid->sid_rev_num));
-       DEBUG(4,("netlogon %s ia %d\n", p, identauth));
-
-       sid->id_auth[0] = 0;
-       sid->id_auth[1] = 0;
-       sid->id_auth[2] = (identauth & 0xff000000) >> 24;
-       sid->id_auth[3] = (identauth & 0x00ff0000) >> 16;
-       sid->id_auth[4] = (identauth & 0x0000ff00) >> 8;
-       sid->id_auth[5] = (identauth & 0x000000ff);
-
-       sid->num_auths = 0;
-
-       while ((p = strtok(0, "-")) != NULL && sid->num_auths < MAXSUBAUTHS)
-               sid->sub_auths[sid->num_auths++] = atoi(p);
-
-       DEBUG(4,("init_dom_sid: %d SID:  %s\n", __LINE__, domsid));
-}
-
 /*******************************************************************
  Inits a DOM_SID2 structure.
 ********************************************************************/
index 24bf3a455bf317c6b1fa35bbca1c71c9574410ef..599257e8020ff7025e3c03f48fe7ee142949ddcb 100644 (file)
@@ -299,8 +299,12 @@ BOOL ntsvcs_io_q_get_hw_profile_info(const char *desc, NTSVCS_Q_GET_HW_PROFILE_I
 
        q_u->buffer_size = 0x000000a8;
 
-       if ( UNMARSHALLING(ps) )
+       if ( UNMARSHALLING(ps) ) {
                q_u->buffer = TALLOC_ARRAY(get_talloc_ctx(), uint8, q_u->buffer_size );
+               if (!q_u->buffer) {
+                       return False;
+               }
+       }
 
        if ( !prs_uint8s(True, "buffer", ps, depth, q_u->buffer, q_u->buffer_size) )
                return False;
@@ -329,8 +333,12 @@ BOOL ntsvcs_io_r_get_hw_profile_info(const char *desc, NTSVCS_R_GET_HW_PROFILE_I
        if ( !prs_align(ps) )
                return False;
 
-       if ( UNMARSHALLING(ps) )
+       if ( UNMARSHALLING(ps) ) {
                r_u->buffer = TALLOC_ARRAY(get_talloc_ctx(), uint8, r_u->buffer_size );
+               if (!r_u->buffer) {
+                       return False;
+               }
+       }
 
        if ( !prs_uint8s(True, "buffer", ps, depth, r_u->buffer, r_u->buffer_size) )
                return False;
index f2b002c48cf5f5cc4daa20c063c43a46688df0cf..14e190892d77bd76f6b5439b73077c7dc147f768 100644 (file)
@@ -1469,11 +1469,12 @@ int tdb_prs_fetch(TDB_CONTEXT *tdb, char *keystr, prs_struct *ps, TALLOC_CTX *me
     kbuf.dptr = keystr;
     kbuf.dsize = strlen(keystr)+1;
 
+    prs_init(ps, 0, mem_ctx, UNMARSHALL);
+
     dbuf = tdb_fetch(tdb, kbuf);
     if (!dbuf.dptr)
            return -1;
 
-    prs_init(ps, 0, mem_ctx, UNMARSHALL);
     prs_give_memory(ps, dbuf.dptr, dbuf.dsize, True);
 
     return 0;
index d661b225e0632baeb4ab29e0b08c4c333c898741..9026d503c307b951fb69a1fbbe9b2ebf956414d4 100644 (file)
@@ -6471,8 +6471,14 @@ static BOOL sam_io_user_info21(const char *desc, SAM_USER_INFO_21 * usr,
 void init_sam_user_info20A(SAM_USER_INFO_20 *usr, struct samu *pw)
 {
        const char *munged_dial = pdb_get_munged_dial(pw);
-       DATA_BLOB blob = base64_decode_data_blob(munged_dial);
-       
+       DATA_BLOB blob;
+
+       if (munged_dial) {
+               blob = base64_decode_data_blob(munged_dial);
+       } else {
+               blob = data_blob(NULL, 0);
+       }
+
        init_unistr2_from_datablob(&usr->uni_munged_dial, &blob);
        init_uni_hdr(&usr->hdr_munged_dial, &usr->uni_munged_dial);
        data_blob_free(&blob);
index ec2d6b84300fe4c73150969340aad5eea6d74a66..2884883e893763abc3bebd2a44f2e750333ed2a1 100644 (file)
@@ -4989,6 +4989,7 @@ BOOL spool_io_printer_driver_info_level_6(const char *desc, SPOOL_PRINTER_DRIVER
  dynamically allocate memory
  
 ********************************************************************/  
+
 static BOOL uniarray_2_dosarray(BUFFER5 *buf5, fstring **ar)
 {
        fstring f;
@@ -4999,25 +5000,27 @@ static BOOL uniarray_2_dosarray(BUFFER5 *buf5, fstring **ar)
                return False;
 
        src = (char *)buf5->buffer;
-       *ar = NULL;
+       *ar = SMB_MALLOC_ARRAY(fstring, 1);
+       if (!*ar) {
+               return False;
+       }
 
        while (src < ((char *)buf5->buffer) + buf5->buf_len*2) {
                rpcstr_pull(f, src, sizeof(f)-1, -1, STR_TERMINATE);
                src = skip_unibuf(src, 2*buf5->buf_len - PTR_DIFF(src,buf5->buffer));
                *ar = SMB_REALLOC_ARRAY(*ar, fstring, n+2);
-               if (!*ar)
+               if (!*ar) {
                        return False;
+               }
                fstrcpy((*ar)[n], f);
                n++;
        }
+
        fstrcpy((*ar)[n], "");
  
        return True;
 }
 
-
-
-
 /*******************************************************************
  read a UNICODE array with null terminated strings 
  and null terminated array 
@@ -5115,9 +5118,6 @@ BOOL make_spoolss_driver_info_3(TALLOC_CTX *mem_ctx,
                                DRIVER_INFO_3 *info3)
 {
        uint32          len = 0;
-       uint16          *ptr = info3->dependentfiles;
-       BOOL            done = False;
-       BOOL            null_char = False;
        SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *inf;
 
        if (!(inf=TALLOC_ZERO_P(mem_ctx, SPOOL_PRINTER_DRIVER_INFO_LEVEL_3)))
@@ -5142,31 +5142,35 @@ BOOL make_spoolss_driver_info_3(TALLOC_CTX *mem_ctx,
        init_unistr2_from_unistr(&inf->monitorname, &info3->monitorname);
        init_unistr2_from_unistr(&inf->defaultdatatype, &info3->defaultdatatype);
 
-       while (!done)
-       {
-               switch (*ptr)
-               {
-                       case 0:
-                               /* the null_char BOOL is used to help locate
-                                  two '\0's back to back */
-                               if (null_char)
-                                       done = True;
-                               else
-                                       null_char = True;
-                               break;
+       if (info3->dependentfiles) {
+               BOOL done = False;
+               BOOL null_char = False;
+               uint16 *ptr = info3->dependentfiles;
+
+               while (!done) {
+                       switch (*ptr) {
+                               case 0:
+                                       /* the null_char BOOL is used to help locate
+                                          two '\0's back to back */
+                                       if (null_char) {
+                                               done = True;
+                                       } else {
+                                               null_char = True;
+                                       }
+                                       break;
                                        
-                       default:
-                               null_char = False;
-                               ;;
-                               break;                          
+                               default:
+                                       null_char = False;
+                                       break;                          
+                       }
+                       len++;
+                       ptr++;
                }
-               len++;
-               ptr++;
        }
+
        inf->dependentfiles_ptr = (info3->dependentfiles != NULL) ? 1 : 0;
-       inf->dependentfilessize = len;
-       if(!make_spoolss_buffer5(mem_ctx, &inf->dependentfiles, len, info3->dependentfiles))
-       {
+       inf->dependentfilessize = (info3->dependentfiles != NULL) ? len : 0;
+       if(!make_spoolss_buffer5(mem_ctx, &inf->dependentfiles, len, info3->dependentfiles)) {
                SAFE_FREE(inf);
                return False;
        }
@@ -5179,13 +5183,18 @@ BOOL make_spoolss_driver_info_3(TALLOC_CTX *mem_ctx,
 /*******************************************************************
  make a BUFFER5 struct from a uint16*
  ******************************************************************/
+
 BOOL make_spoolss_buffer5(TALLOC_CTX *mem_ctx, BUFFER5 *buf5, uint32 len, uint16 *src)
 {
 
        buf5->buf_len = len;
-       if((buf5->buffer=(uint16*)TALLOC_MEMDUP(mem_ctx, src, sizeof(uint16)*len)) == NULL) {
-               DEBUG(0,("make_spoolss_buffer5: Unable to malloc memory for buffer!\n"));
-               return False;
+       if (src) {
+               if((buf5->buffer=(uint16*)TALLOC_MEMDUP(mem_ctx, src, sizeof(uint16)*len)) == NULL) {
+                       DEBUG(0,("make_spoolss_buffer5: Unable to malloc memory for buffer!\n"));
+                       return False;
+               }
+       } else {
+               buf5->buffer=NULL;
        }
        
        return True;
index 284ee37348e85c399aad816caf8197df7cde9481..c1c0b6a0e24317b3455d03be63a9ced5f2206c41 100644 (file)
@@ -682,6 +682,10 @@ NTSTATUS _eventlog_read_eventlog( pipes_struct * p,
        int bytes_left, record_number;
        uint32 elog_read_type, elog_read_dir;
 
+       if (info == NULL) {
+               return NT_STATUS_INVALID_HANDLE;
+       }
+
        info->flags = q_u->flags;
        ps = &p->out_data.rdata;
 
@@ -768,6 +772,10 @@ NTSTATUS _eventlog_get_oldest_entry( pipes_struct * p,
 {
        EVENTLOG_INFO *info = find_eventlog_info_by_hnd( p, &q_u->handle );
 
+       if (info == NULL) {
+               return NT_STATUS_INVALID_HANDLE;
+       }
+
        if ( !( get_oldest_entry_hook( info ) ) )
                return NT_STATUS_ACCESS_DENIED;
 
@@ -785,6 +793,10 @@ NTSTATUS _eventlog_get_num_records( pipes_struct * p,
 {
        EVENTLOG_INFO *info = find_eventlog_info_by_hnd( p, &q_u->handle );
 
+       if (info == NULL) {
+               return NT_STATUS_INVALID_HANDLE;
+       }
+
        if ( !( get_num_records_hook( info ) ) )
                return NT_STATUS_ACCESS_DENIED;
 
index d5222bbcb98deb0c11ee49903c9316c23b531be1..ae9795952cf065fa88379e56e9a6d460eadd8093 100644 (file)
@@ -1133,6 +1133,11 @@ NTSTATUS _lsa_lookup_names2(pipes_struct *p, LSA_Q_LOOKUP_NAMES2 *q_u, LSA_R_LOO
        rids = TALLOC_ZERO_ARRAY(p->mem_ctx, DOM_RID, num_entries);
        rids2 = TALLOC_ZERO_ARRAY(p->mem_ctx, DOM_RID2, num_entries);
 
+       if ((ref == NULL) || (rids == NULL) || (rids2 == NULL)) {
+               r_u->status = NT_STATUS_NO_MEMORY;
+               goto done;
+       }
+
        if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle)) {
                r_u->status = NT_STATUS_INVALID_HANDLE;
                goto done;
index 10cd5c82bae035f9389bd555c47760d6534b7029..6603d2f1d447a685d4450cd6da87b90cb78a3a78 100644 (file)
@@ -985,6 +985,11 @@ static NTSTATUS _net_sam_logon_internal(pipes_struct *p,
                user_sid = pdb_get_user_sid(sampw);
                group_sid = pdb_get_group_sid(sampw);
 
+               if ((user_sid == NULL) || (group_sid == NULL)) {
+                       DEBUG(1, ("_net_sam_logon: User without group or user SID\n"));
+                       return NT_STATUS_UNSUCCESSFUL;
+               }
+
                sid_copy(&domain_sid, user_sid);
                sid_split_rid(&domain_sid, &user_rid);
 
index 5e82ecd0cae0de26517120b2396dc33dcabadca7..bfae47ef250c41231cfcee8885d8844a0d79b351 100644 (file)
@@ -3207,8 +3207,14 @@ static NTSTATUS set_user_info_23(TALLOC_CTX *mem_ctx, SAM_USER_INFO_23 *id23,
        } else  {
                /* update the UNIX password */
                if (lp_unix_password_sync() ) {
-                       struct passwd *passwd = Get_Pwnam(pdb_get_username(pwd));
-                       if (!passwd) {
+                       struct passwd *passwd;
+                       if (pdb_get_username(pwd) == NULL) {
+                               DEBUG(1, ("chgpasswd: User without name???\n"));
+                               TALLOC_FREE(pwd);
+                               return NT_STATUS_ACCESS_DENIED;
+                       }
+
+                       if ((passwd = Get_Pwnam(pdb_get_username(pwd))) == NULL) {
                                DEBUG(1, ("chgpasswd: Username does not exist in system !?!\n"));
                        }
                        
@@ -3273,8 +3279,15 @@ static BOOL set_user_info_pw(uint8 *pass, struct samu *pwd)
        } else {
                /* update the UNIX password */
                if (lp_unix_password_sync()) {
-                       struct passwd *passwd = Get_Pwnam(pdb_get_username(pwd));
-                       if (!passwd) {
+                       struct passwd *passwd;
+
+                       if (pdb_get_username(pwd) == NULL) {
+                               DEBUG(1, ("chgpasswd: User without name???\n"));
+                               TALLOC_FREE(pwd);
+                               return False;
+                       }
+
+                       if ((passwd = Get_Pwnam(pdb_get_username(pwd))) == NULL) {
                                DEBUG(1, ("chgpasswd: Username does not exist in system !?!\n"));
                        }
                        
@@ -3800,7 +3813,7 @@ NTSTATUS _samr_query_groupmem(pipes_struct *p, SAMR_Q_QUERY_GROUPMEM *q_u, SAMR_
 
        attr=TALLOC_ZERO_ARRAY(p->mem_ctx, uint32, num_members);
        
-       if ((num_members!=0) && (rid==NULL))
+       if ((num_members!=0) && (attr==NULL))
                return NT_STATUS_NO_MEMORY;
        
        for (i=0; i<num_members; i++)
index fd28df0d801fa2aeab2c715d8a20d7f5d45f82dd..31dab458443cb24b670f65bcb507d4037aae74d6 100644 (file)
@@ -34,211 +34,210 @@ static fstring msgfrom;
 static fstring msgto;
 
 /****************************************************************************
-deliver the message
+ Deliver the message.
 ****************************************************************************/
+
 static void msg_deliver(void)
 {
-  pstring name;
-  int i;
-  int fd;
-  char *msg;
-  int len;
-  ssize_t sz;
-
-  if (! (*lp_msg_command()))
-    {
-      DEBUG(1,("no messaging command specified\n"));
-      msgpos = 0;
-      return;
-    }
-
-  /* put it in a temporary file */
-  slprintf(name,sizeof(name)-1, "%s/msg.XXXXXX",tmpdir());
-  fd = smb_mkstemp(name);
-
-  if (fd == -1) {
-    DEBUG(1,("can't open message file %s\n",name));
-    return;
-  }
-
-  /*
-   * Incoming message is in DOS codepage format. Convert to UNIX.
-   */
+       pstring name;
+       int i;
+       int fd;
+       char *msg;
+       int len;
+       ssize_t sz;
+
+       if (! (*lp_msg_command())) {
+               DEBUG(1,("no messaging command specified\n"));
+               msgpos = 0;
+               return;
+       }
+
+       /* put it in a temporary file */
+       slprintf(name,sizeof(name)-1, "%s/msg.XXXXXX",tmpdir());
+       fd = smb_mkstemp(name);
+
+       if (fd == -1) {
+               DEBUG(1,("can't open message file %s\n",name));
+               return;
+       }
+
+       /*
+        * Incoming message is in DOS codepage format. Convert to UNIX.
+        */
   
-  if ((len = (int)convert_string_allocate(NULL,CH_DOS, CH_UNIX, msgbuf, msgpos, (void **)(void *)&msg, True)) < 0 || !msg) {
-    DEBUG(3,("Conversion failed, delivering message in DOS codepage format\n"));
-    for (i = 0; i < msgpos;) {
-      if (msgbuf[i] == '\r' && i < (msgpos-1) && msgbuf[i+1] == '\n') {
-       i++; continue;
-      }
-      sz = write(fd, &msgbuf[i++], 1);
-      if ( sz != 1 ) {
-       DEBUG(0,("Write error to fd %d: %ld(%d)\n",fd, (long)sz, errno ));
-      }
-    }
-  } else {
-    for (i = 0; i < len;) {
-      if (msg[i] == '\r' && i < (len-1) && msg[i+1] == '\n') {
-       i++; continue;
-      }
-      sz = write(fd, &msg[i++],1);
-      if ( sz != 1 ) {
-       DEBUG(0,("Write error to fd %d: %ld(%d)\n",fd, (long)sz, errno ));
-      }
-    }
-    SAFE_FREE(msg);
-  }
-  close(fd);
-
-
-  /* run the command */
-  if (*lp_msg_command())
-    {
-      fstring alpha_msgfrom;
-      fstring alpha_msgto;
-      pstring s;
-
-      pstrcpy(s,lp_msg_command());
-      pstring_sub(s,"%f",alpha_strcpy(alpha_msgfrom,msgfrom,NULL,sizeof(alpha_msgfrom)));
-      pstring_sub(s,"%t",alpha_strcpy(alpha_msgto,msgto,NULL,sizeof(alpha_msgto)));
-      standard_sub_basic(current_user_info.smb_name, s, sizeof(s));
-      pstring_sub(s,"%s",name);
-      smbrun(s,NULL);
-    }
-
-  msgpos = 0;
+       if ((len = (int)convert_string_allocate(NULL,CH_DOS, CH_UNIX, msgbuf, msgpos, (void **)(void *)&msg, True)) < 0 || !msg) {
+               DEBUG(3,("Conversion failed, delivering message in DOS codepage format\n"));
+               for (i = 0; i < msgpos;) {
+                       if (msgbuf[i] == '\r' && i < (msgpos-1) && msgbuf[i+1] == '\n') {
+                               i++;
+                               continue;
+                       }
+                       sz = write(fd, &msgbuf[i++], 1);
+                       if ( sz != 1 ) {
+                               DEBUG(0,("Write error to fd %d: %ld(%d)\n",fd, (long)sz, errno ));
+                       }
+               }
+       } else {
+               for (i = 0; i < len;) {
+                       if (msg[i] == '\r' && i < (len-1) && msg[i+1] == '\n') {
+                               i++;
+                               continue;
+                       }
+                       sz = write(fd, &msg[i++],1);
+                       if ( sz != 1 ) {
+                               DEBUG(0,("Write error to fd %d: %ld(%d)\n",fd, (long)sz, errno ));
+                       }
+               }
+               SAFE_FREE(msg);
+       }
+       close(fd);
+
+       /* run the command */
+       if (*lp_msg_command()) {
+               fstring alpha_msgfrom;
+               fstring alpha_msgto;
+               pstring s;
+
+               pstrcpy(s,lp_msg_command());
+               pstring_sub(s,"%f",alpha_strcpy(alpha_msgfrom,msgfrom,NULL,sizeof(alpha_msgfrom)));
+               pstring_sub(s,"%t",alpha_strcpy(alpha_msgto,msgto,NULL,sizeof(alpha_msgto)));
+               standard_sub_basic(current_user_info.smb_name, s, sizeof(s));
+               pstring_sub(s,"%s",name);
+               smbrun(s,NULL);
+       }
+
+       msgpos = 0;
 }
 
-
-
 /****************************************************************************
-  reply to a sends
+ Reply to a sends.
+ conn POINTER CAN BE NULL HERE !
 ****************************************************************************/
-int reply_sends(connection_struct *conn,
-               char *inbuf,char *outbuf, int dum_size, int dum_buffsize)
+
+int reply_sends(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize)
 {
-  int len;
-  char *msg;
-  int outsize = 0;
-  char *p;
+       int len;
+       char *msg;
+       int outsize = 0;
+       char *p;
 
-  START_PROFILE(SMBsends);
+       START_PROFILE(SMBsends);
 
-  msgpos = 0;
+       msgpos = 0;
 
-  if (! (*lp_msg_command())) {
-    END_PROFILE(SMBsends);
-    return(ERROR_DOS(ERRSRV,ERRmsgoff));
-  }
+       if (! (*lp_msg_command())) {
+               END_PROFILE(SMBsends);
+               return(ERROR_DOS(ERRSRV,ERRmsgoff));
+       }
 
-  outsize = set_message(outbuf,0,0,True);
+       outsize = set_message(outbuf,0,0,True);
 
-  p = smb_buf(inbuf)+1;
-  p += srvstr_pull_buf(inbuf, msgfrom, p, sizeof(msgfrom), STR_ASCII|STR_TERMINATE) + 1;
-  p += srvstr_pull_buf(inbuf, msgto, p, sizeof(msgto), STR_ASCII|STR_TERMINATE) + 1;
+       p = smb_buf(inbuf)+1;
+       p += srvstr_pull_buf(inbuf, msgfrom, p, sizeof(msgfrom), STR_ASCII|STR_TERMINATE) + 1;
+       p += srvstr_pull_buf(inbuf, msgto, p, sizeof(msgto), STR_ASCII|STR_TERMINATE) + 1;
 
-  msg = p;
+       msg = p;
 
-  len = SVAL(msg,0);
-  len = MIN(len,sizeof(msgbuf)-msgpos);
+       len = SVAL(msg,0);
+       len = MIN(len,sizeof(msgbuf)-msgpos);
 
-  memset(msgbuf,'\0',sizeof(msgbuf));
+       memset(msgbuf,'\0',sizeof(msgbuf));
 
-  memcpy(&msgbuf[msgpos],msg+2,len);
-  msgpos += len;
+       memcpy(&msgbuf[msgpos],msg+2,len);
+       msgpos += len;
 
-  msg_deliver();
+       msg_deliver();
 
-  END_PROFILE(SMBsends);
-  return(outsize);
+       END_PROFILE(SMBsends);
+       return(outsize);
 }
 
-
 /****************************************************************************
-  reply to a sendstrt
+ Reply to a sendstrt.
+ conn POINTER CAN BE NULL HERE !
 ****************************************************************************/
-int reply_sendstrt(connection_struct *conn,
-                  char *inbuf,char *outbuf, int dum_size, int dum_buffsize)
+
+int reply_sendstrt(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize)
 {
-  int outsize = 0;
-  char *p;
+       int outsize = 0;
+       char *p;
 
-  START_PROFILE(SMBsendstrt);
+       START_PROFILE(SMBsendstrt);
 
-  if (! (*lp_msg_command())) {
-    END_PROFILE(SMBsendstrt);
-    return(ERROR_DOS(ERRSRV,ERRmsgoff));
-  }
+       if (! (*lp_msg_command())) {
+               END_PROFILE(SMBsendstrt);
+               return(ERROR_DOS(ERRSRV,ERRmsgoff));
+       }
 
-  outsize = set_message(outbuf,1,0,True);
+       outsize = set_message(outbuf,1,0,True);
 
-  memset(msgbuf,'\0',sizeof(msgbuf));
-  msgpos = 0;
+       memset(msgbuf,'\0',sizeof(msgbuf));
+       msgpos = 0;
 
-  p = smb_buf(inbuf)+1;
-  p += srvstr_pull_buf(inbuf, msgfrom, p, sizeof(msgfrom), STR_ASCII|STR_TERMINATE) + 1;
-  p += srvstr_pull_buf(inbuf, msgto, p, sizeof(msgto), STR_ASCII|STR_TERMINATE) + 1;
+       p = smb_buf(inbuf)+1;
+       p += srvstr_pull_buf(inbuf, msgfrom, p, sizeof(msgfrom), STR_ASCII|STR_TERMINATE) + 1;
+       p += srvstr_pull_buf(inbuf, msgto, p, sizeof(msgto), STR_ASCII|STR_TERMINATE) + 1;
 
-  DEBUG( 3, ( "SMBsendstrt (from %s to %s)\n", msgfrom, msgto ) );
+       DEBUG( 3, ( "SMBsendstrt (from %s to %s)\n", msgfrom, msgto ) );
 
-  END_PROFILE(SMBsendstrt);
-  return(outsize);
+       END_PROFILE(SMBsendstrt);
+       return(outsize);
 }
 
-
 /****************************************************************************
-  reply to a sendtxt
+ Reply to a sendtxt.
+ conn POINTER CAN BE NULL HERE !
 ****************************************************************************/
-int reply_sendtxt(connection_struct *conn,
-                 char *inbuf,char *outbuf, int dum_size, int dum_buffsize)
+
+int reply_sendtxt(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize)
 {
-  int len;
-  int outsize = 0;
-  char *msg;
-  START_PROFILE(SMBsendtxt);
+       int len;
+       int outsize = 0;
+       char *msg;
+       START_PROFILE(SMBsendtxt);
 
-  if (! (*lp_msg_command())) {
-    END_PROFILE(SMBsendtxt);
-    return(ERROR_DOS(ERRSRV,ERRmsgoff));
-  }
+       if (! (*lp_msg_command())) {
+               END_PROFILE(SMBsendtxt);
+               return(ERROR_DOS(ERRSRV,ERRmsgoff));
+       }
 
-  outsize = set_message(outbuf,0,0,True);
+       outsize = set_message(outbuf,0,0,True);
 
-  msg = smb_buf(inbuf) + 1;
+       msg = smb_buf(inbuf) + 1;
 
-  len = SVAL(msg,0);
-  len = MIN(len,sizeof(msgbuf)-msgpos);
+       len = SVAL(msg,0);
+       len = MIN(len,sizeof(msgbuf)-msgpos);
 
-  memcpy(&msgbuf[msgpos],msg+2,len);
-  msgpos += len;
+       memcpy(&msgbuf[msgpos],msg+2,len);
+       msgpos += len;
 
-  DEBUG( 3, ( "SMBsendtxt\n" ) );
+       DEBUG( 3, ( "SMBsendtxt\n" ) );
 
-  END_PROFILE(SMBsendtxt);
-  return(outsize);
+       END_PROFILE(SMBsendtxt);
+       return(outsize);
 }
 
-
 /****************************************************************************
-  reply to a sendend
+ Reply to a sendend.
+ conn POINTER CAN BE NULL HERE !
 ****************************************************************************/
-int reply_sendend(connection_struct *conn,
-                 char *inbuf,char *outbuf, int dum_size, int dum_buffsize)
+
+int reply_sendend(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize)
 {
-  int outsize = 0;
-  START_PROFILE(SMBsendend);
+       int outsize = 0;
+       START_PROFILE(SMBsendend);
 
-  if (! (*lp_msg_command())) {
-    END_PROFILE(SMBsendend);
-    return(ERROR_DOS(ERRSRV,ERRmsgoff));
-  }
+       if (! (*lp_msg_command())) {
+               END_PROFILE(SMBsendend);
+               return(ERROR_DOS(ERRSRV,ERRmsgoff));
+       }
 
-  outsize = set_message(outbuf,0,0,True);
+       outsize = set_message(outbuf,0,0,True);
 
-  DEBUG(3,("SMBsendend\n"));
+       DEBUG(3,("SMBsendend\n"));
 
-  msg_deliver();
+       msg_deliver();
 
-  END_PROFILE(SMBsendend);
-  return(outsize);
+       END_PROFILE(SMBsendend);
+       return(outsize);
 }
index 5d2ed6a10d14ccd212076a477b00abbc5e65d0f3..3347008cdf8a523b0e46b39d05d7e59edb3aff04 100644 (file)
@@ -456,6 +456,7 @@ static const struct {
 
 /****************************************************************************
  Reply to a negprot.
+ conn POINTER CAN BE NULL HERE !
 ****************************************************************************/
 
 int reply_negprot(connection_struct *conn, 
index e397139d2efe443da2af89420e7835a9ceff23d7..aa6f79e16571c0c4829b46a8bca5aa04cb913478 100644 (file)
@@ -1545,6 +1545,7 @@ static int call_nt_transact_create(connection_struct *conn, char *inbuf, char *o
 
 /****************************************************************************
  Reply to a NT CANCEL request.
+ conn POINTER CAN BE NULL HERE !
 ****************************************************************************/
 
 int reply_ntcancel(connection_struct *conn,
index 440d0ac0a50505fb4cc177c712286add09b73b07..b3ce49360d836ef438258c2d912de69f00e22183 100644 (file)
@@ -567,10 +567,10 @@ are used by some brain-dead clients when printing, and I don't want to
 force write permissions on print services.
 */
 #define AS_USER (1<<0)
-#define NEED_WRITE (1<<1)
+#define NEED_WRITE (1<<1) /* Must be paired with AS_USER */
 #define TIME_INIT (1<<2)
-#define CAN_IPC (1<<3)
-#define AS_GUEST (1<<5)
+#define CAN_IPC (1<<3) /* Must be paired with AS_USER */
+#define AS_GUEST (1<<5) /* Must *NOT* be paired with AS_USER */
 #define DO_CHDIR (1<<6)
 
 /* 
@@ -932,48 +932,46 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize
                        user_struct *vuser = NULL;
 
                        last_session_tag = session_tag;
-                       if(session_tag != UID_FIELD_INVALID)
+                       if(session_tag != UID_FIELD_INVALID) {
                                vuser = get_valid_user_struct(session_tag);           
-                       if(vuser != NULL)
-                               set_current_user_info(&vuser->user);
-               }
-
-               /* does this protocol need to be run as root? */
-               if (!(flags & AS_USER))
-                       change_to_root_user();
-
-               /* does this protocol need a valid tree connection? */
-               if ((flags & AS_USER) && !conn) {
-                       /* Amazingly, the error code depends on the command (from Samba4). */
-                       if (type == SMBntcreateX) {
-                               return ERROR_NT(NT_STATUS_INVALID_HANDLE);
-                       } else {
-                               return ERROR_DOS(ERRSRV, ERRinvnid);
+                               if (vuser) {
+                                       set_current_user_info(&vuser->user);
+                               }
                        }
                }
 
+               /* Does this call need to be run as the connected user? */
+               if (flags & AS_USER) {
+
+                       /* Does this call need a valid tree connection? */
+                       if (!conn) {
+                               /* Amazingly, the error code depends on the command (from Samba4). */
+                               if (type == SMBntcreateX) {
+                                       return ERROR_NT(NT_STATUS_INVALID_HANDLE);
+                               } else {
+                                       return ERROR_DOS(ERRSRV, ERRinvnid);
+                               }
+                       }
 
-               /* does this protocol need to be run as the connected user? */
-               if ((flags & AS_USER) && !change_to_user(conn,session_tag)) {
-                       if (flags & AS_GUEST) 
-                               flags &= ~AS_USER;
-                       else
+                       if (!change_to_user(conn,session_tag)) {
                                return(ERROR_FORCE_DOS(ERRSRV,ERRbaduid));
-               }
+                       }
 
-               /* this code is to work around a bug is MS client 3 without
-                       introducing a security hole - it needs to be able to do
-                       print queue checks as guest if it isn't logged in properly */
-               if (flags & AS_USER)
-                       flags &= ~AS_GUEST;
+                       /* All NEED_WRITE and CAN_IPC flags must also have AS_USER. */
 
-               /* does it need write permission? */
-               if ((flags & NEED_WRITE) && !CAN_WRITE(conn))
-                       return(ERROR_DOS(ERRSRV,ERRaccess));
+                       /* Does it need write permission? */
+                       if ((flags & NEED_WRITE) && !CAN_WRITE(conn)) {
+                               return(ERROR_DOS(ERRSRV,ERRaccess));
+                       }
 
-               /* ipc services are limited */
-               if (IS_IPC(conn) && (flags & AS_USER) && !(flags & CAN_IPC))
-                       return(ERROR_DOS(ERRSRV,ERRaccess));        
+                       /* IPC services are limited */
+                       if (IS_IPC(conn) && !(flags & CAN_IPC)) {
+                               return(ERROR_DOS(ERRSRV,ERRaccess));
+                       }
+               } else {
+                       /* This call needs to be run as root */
+                       change_to_root_user();
+               }
 
                /* load service specific parameters */
                if (conn) {
@@ -985,8 +983,9 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize
 
                /* does this protocol need to be run as guest? */
                if ((flags & AS_GUEST) && (!change_to_guest() || 
-                               !check_access(smbd_server_fd(), lp_hostsallow(-1), lp_hostsdeny(-1))))
+                               !check_access(smbd_server_fd(), lp_hostsallow(-1), lp_hostsdeny(-1)))) {
                        return(ERROR_DOS(ERRSRV,ERRaccess));
+               }
 
                current_inbuf = inbuf; /* In case we need to defer this message in open... */
                outsize = smb_messages[type].fn(conn, inbuf,outbuf,size,bufsize);
@@ -997,7 +996,6 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize
        return(outsize);
 }
 
-
 /****************************************************************************
  Construct a reply to the incoming packet.
 ****************************************************************************/
index d333ebf32eb4985aba3a08f720b54ef58ccb990c..e68e8662d74f2a236e3851f104e6e10cd67eb103 100644 (file)
@@ -547,6 +547,7 @@ int reply_special(char *inbuf,char *outbuf)
 
 /****************************************************************************
  Reply to a tcon.
+ conn POINTER CAN BE NULL HERE !
 ****************************************************************************/
 
 int reply_tcon(connection_struct *conn,
@@ -605,6 +606,7 @@ int reply_tcon(connection_struct *conn,
 
 /****************************************************************************
  Reply to a tcon and X.
+ conn POINTER CAN BE NULL HERE !
 ****************************************************************************/
 
 int reply_tcon_and_X(connection_struct *conn, char *inbuf,char *outbuf,int length,int bufsize)
@@ -738,6 +740,7 @@ int reply_unknown(char *inbuf,char *outbuf)
 
 /****************************************************************************
  Reply to an ioctl.
+ conn POINTER CAN BE NULL HERE !
 ****************************************************************************/
 
 int reply_ioctl(connection_struct *conn,
@@ -1591,6 +1594,7 @@ int reply_open_and_X(connection_struct *conn, char *inbuf,char *outbuf,int lengt
 
 /****************************************************************************
  Reply to a SMBulogoffX.
+ conn POINTER CAN BE NULL HERE !
 ****************************************************************************/
 
 int reply_ulogoffX(connection_struct *conn, char *inbuf,char *outbuf,int length,int bufsize)
@@ -3236,6 +3240,7 @@ int reply_flush(connection_struct *conn, char *inbuf,char *outbuf, int size, int
 
 /****************************************************************************
  Reply to a exit.
+ conn POINTER CAN BE NULL HERE !
 ****************************************************************************/
 
 int reply_exit(connection_struct *conn, 
@@ -3511,6 +3516,7 @@ int reply_unlock(connection_struct *conn, char *inbuf,char *outbuf, int size,
 
 /****************************************************************************
  Reply to a tdis.
+ conn POINTER CAN BE NULL HERE !
 ****************************************************************************/
 
 int reply_tdis(connection_struct *conn, 
@@ -3538,6 +3544,7 @@ int reply_tdis(connection_struct *conn,
 
 /****************************************************************************
  Reply to a echo.
+ conn POINTER CAN BE NULL HERE !
 ****************************************************************************/
 
 int reply_echo(connection_struct *conn,
index 46acb20bdadce44dccf386cd357684e03bb5dec4..fb579707caeb24ab0d2e024bbfc68567efd9928d 100644 (file)
@@ -635,6 +635,7 @@ static int reply_spnego_auth(connection_struct *conn, char *inbuf, char *outbuf,
 
 /****************************************************************************
  Reply to a session setup command.
+ conn POINTER CAN BE NULL HERE !
 ****************************************************************************/
 
 static int reply_sesssetup_and_X_spnego(connection_struct *conn, char *inbuf,
index 30d7b7be20444bc1d76fa2a48821a87c888b839c..f29398c822c059e4a2c94a8470a7e3c8c5b5630d 100644 (file)
@@ -858,7 +858,10 @@ static NTSTATUS rpc_user_rename_internals(const DOM_SID *domain_sid,
                goto done;
        }
 
-       names = TALLOC_ARRAY(mem_ctx, const char *, num_names);
+       if ((names = TALLOC_ARRAY(mem_ctx, const char *, num_names)) == NULL) {
+               result = NT_STATUS_NO_MEMORY;
+               goto done;
+       }
        names[0] = old_name;
        result = rpccli_samr_lookup_names(pipe_hnd, mem_ctx, &domain_pol,
                                       flags, num_names, names,
@@ -1141,7 +1144,10 @@ static NTSTATUS rpc_user_info_internals(const DOM_SID *domain_sid,
        /* Look up rids */
 
        if (num_rids) {
-               rids = TALLOC_ARRAY(mem_ctx, uint32, num_rids);
+               if ((rids = TALLOC_ARRAY(mem_ctx, uint32, num_rids)) == NULL) {
+                       result = NT_STATUS_NO_MEMORY;
+                       goto done;
+               }
 
                for (i = 0; i < num_rids; i++)
                        rids[i] = user_gids[i].g_rid;
@@ -3008,13 +3014,17 @@ static NTSTATUS rpc_share_add_internals(const DOM_SID *domain_sid,
                                        const char **argv)
 {
        WERROR result;
-       char *sharename=talloc_strdup(mem_ctx, argv[0]);
+       char *sharename;
        char *path;
        uint32 type = STYPE_DISKTREE; /* only allow disk shares to be added */
        uint32 num_users=0, perms=0;
        char *password=NULL; /* don't allow a share password */
        uint32 level = 2;
 
+       if ((sharename = talloc_strdup(mem_ctx, argv[0])) == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
        path = strchr(sharename, '=');
        if (!path)
                return NT_STATUS_UNSUCCESSFUL;
@@ -3152,6 +3162,10 @@ static WERROR get_share_info(struct rpc_pipe_client *pipe_hnd,
                SRV_SHARE_INFO_1 *info1;
                
                ctr->share.info1 = TALLOC_ARRAY(mem_ctx, SRV_SHARE_INFO_1, 1);
+               if (ctr->share.info1 == NULL) {
+                       result = WERR_NOMEM;
+                       goto done;
+               }
                info1 = ctr->share.info1;
                                
                memset(ctr->share.info1, 0, sizeof(SRV_SHARE_INFO_1));
@@ -3176,6 +3190,10 @@ static WERROR get_share_info(struct rpc_pipe_client *pipe_hnd,
                SRV_SHARE_INFO_2 *info2;
                
                ctr->share.info2 = TALLOC_ARRAY(mem_ctx, SRV_SHARE_INFO_2, 1);
+               if (ctr->share.info2 == NULL) {
+                       result = WERR_NOMEM;
+                       goto done;
+               }
                info2 = ctr->share.info2;
                                
                memset(ctr->share.info2, 0, sizeof(SRV_SHARE_INFO_2));
@@ -3208,6 +3226,10 @@ static WERROR get_share_info(struct rpc_pipe_client *pipe_hnd,
                SRV_SHARE_INFO_502 *info502;
 
                ctr->share.info502 = TALLOC_ARRAY(mem_ctx, SRV_SHARE_INFO_502, 1);
+               if (ctr->share.info502 == NULL) {
+                       result = WERR_NOMEM;
+                       goto done;
+               }
                info502 = ctr->share.info502;
 
                memset(ctr->share.info502, 0, sizeof(SRV_SHARE_INFO_502));
@@ -5461,7 +5483,9 @@ static NTSTATUS rpc_trustdom_del_internals(const DOM_SID *domain_sid,
 
        strupper_m(acct_name);
 
-       names = TALLOC_ARRAY(mem_ctx, const char *, 1);
+       if ((names = TALLOC_ARRAY(mem_ctx, const char *, 1)) == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
        names[0] = acct_name;
 
 
index 5c81fe24d0985d39ba0888965f5ffd9c9f5398fb..981dc93fdd7097d9db65c5a1cc2e4af221216f11 100644 (file)
@@ -44,6 +44,13 @@ static void print_auditing_category(const char *policy, const char *value)
        fstring padding;
        int pad_len, col_len = 30;
 
+       if (policy == NULL) {
+               policy = "Unknown";
+       }
+       if (value == NULL) {
+               value = "Invalid";
+       }
+
        /* calculate padding space for d_printf to look nicer */
        pad_len = col_len - strlen(policy);
        padding[pad_len] = 0;
index 2c55b0e9462f6bb3df92aa25ad2bd12ca1189803..d23bd76751956ff7ce62c8f9d91ab887ea443acc 100644 (file)
@@ -222,7 +222,10 @@ int net_rpc_join_newstyle(int argc, const char **argv)
                      "could not open domain");
 
        /* Create domain user */
-       acct_name = talloc_asprintf(mem_ctx, "%s$", global_myname()); 
+       if ((acct_name = talloc_asprintf(mem_ctx, "%s$", global_myname())) == NULL) {
+               result = NT_STATUS_NO_MEMORY;
+               goto done;
+       }
        strlower_m(acct_name);
        const_acct_name = acct_name;
 
index 33d5310698ea4923067e8b28a01755ae9ba17b0f..10ba28e02396ab8cbbe15b811651178d8ee38a52 100644 (file)
@@ -408,7 +408,10 @@ static int rpc_registry_dump( int argc, const char **argv )
        
        /* get the root of the registry file */
        
-       nk = regfio_rootkey( registry );
+       if ((nk = regfio_rootkey( registry )) == NULL) {
+               d_fprintf(stderr, "Could not get rootkey\n");
+               return 1;
+       }
        d_printf("[%s]\n", nk->keyname);
        dump_values( nk );
        d_printf("\n");
@@ -455,7 +458,10 @@ static int rpc_registry_copy( int argc, const char **argv )
        
        /* get the root of the registry file */
        
-       nk = regfio_rootkey( infile );
+       if ((nk = regfio_rootkey( infile )) == NULL) {
+               d_fprintf(stderr, "Could not get rootkey\n");
+               goto out_close_infile;
+       }
        d_printf("RootKey: [%s]\n", nk->keyname);
 
        write_registry_tree( infile, nk, NULL, outfile, "" );
index ef9a0627b589e9a12bf7a33d3ac99bc35d38044d..85b086a02ff2256bed57dd56149b8a15d03a669c 100644 (file)
@@ -574,6 +574,10 @@ static NTSTATUS fetch_account_info(uint32 rid, SAM_ACCOUNT_INFO *delta)
                }
        }
 
+       if (pdb_get_group_sid(sam_account) == NULL) {
+               return NT_STATUS_UNSUCCESSFUL;
+       }
+
        group_sid = *pdb_get_group_sid(sam_account);
 
        if (!pdb_getgrsid(&map, group_sid)) {
@@ -694,7 +698,11 @@ static NTSTATUS fetch_group_mem_info(uint32 rid, SAM_GROUP_MEM_INFO *delta)
                return NT_STATUS_NO_MEMORY;
        }
 
-       nt_members = TALLOC_ZERO_ARRAY(t, char *, delta->num_members);
+       if ((nt_members = TALLOC_ZERO_ARRAY(t, char *, delta->num_members)) == NULL) {
+               DEBUG(0, ("talloc failed\n"));
+               talloc_free(t);
+               return NT_STATUS_NO_MEMORY;
+       }
 
        for (i=0; i<delta->num_members; i++) {
                struct samu *member = NULL;
index 605d4bbc6bfcbd1f9a6a89b4fe199ebcfb45f033..654c9ec5b2a3c4fee8c0f9ef18958f8dd0ec5a18 100644 (file)
@@ -840,7 +840,11 @@ static int net_sam_provision(int argc, const char **argv)
                return -1;
        }
 
-       ldap_bk = talloc_strdup(tc, lp_passdb_backend());
+       if ((ldap_bk = talloc_strdup(tc, lp_passdb_backend())) == NULL) {
+               d_fprintf(stderr, "talloc failed\n");
+               talloc_free(tc);
+               return -1;
+       }
        p = strchr(ldap_bk, ':');
        if (p) {
                *p = 0;
@@ -1081,7 +1085,10 @@ doma_done:
                                d_fprintf(stderr, "Can't create Guest user, Domain Users group not available!\n");
                                goto done;
                        }
-                       pwd = talloc(tc, struct passwd);
+                       if ((pwd = talloc(tc, struct passwd)) == NULL) {
+                               d_fprintf(stderr, "talloc failed\n");
+                               goto done;
+                       }
                        pwd->pw_name = talloc_strdup(pwd, lp_guestaccount());
                        if (!winbind_allocate_uid(&(pwd->pw_uid))) {
                                d_fprintf(stderr, "Unable to allocate a new uid to create the Guest user!\n");
index 253416c5cb0d2214cadb63d96f2489ed4d5fb579..09ef8bd97f9ad1d2a749bda14fad327121f52ca2 100644 (file)
@@ -147,7 +147,10 @@ static int net_usershare_delete(int argc, const char **argv)
                return net_usershare_delete_usage(argc, argv);
        }
 
-       sharename = strdup_lower(argv[0]);
+       if ((sharename = strdup_lower(argv[0])) == NULL) {
+               d_fprintf(stderr, "strdup failed\n");
+               return -1;
+       }
 
        if (!validate_net_name(sharename, INVALID_SHARENAME_CHARS, strlen(sharename))) {
                d_fprintf(stderr, "net usershare delete: share name %s contains "
@@ -641,7 +644,12 @@ static int net_usershare_add(int argc, const char **argv)
                }
 
                /* Get the name */
-               name = talloc_strndup(ctx, pacl, pcolon - pacl);
+               if ((name = talloc_strndup(ctx, pacl, pcolon - pacl)) == NULL) {
+                       d_fprintf(stderr, "talloc_strndup failed\n");
+                       talloc_destroy(ctx);
+                       SAFE_FREE(sharename);
+                       return -1;
+               }
                if (!string_to_sid(&sid, name)) {
                        /* Convert to a SID */
                        NTSTATUS ntstatus = net_lookup_sid_from_name(ctx, name, &sid);
index 00149db9e24f8ea1abd909898dcea06de50eb12b..c8ea966a558a6e961501f97fc91109db5ce8333f 100644 (file)
@@ -464,7 +464,10 @@ static BOOL test_plaintext(enum ntlm_break break_which)
 
        nt_response.length = strlen_w(((void *)nt_response.data))*sizeof(smb_ucs2_t);
 
-       password = strdup_upper(opt_password);
+       if ((password = strdup_upper(opt_password)) == NULL) {
+               DEBUG(0, ("strdup_upper failed!\n"));
+               exit(1);
+       }
 
        if ((convert_string_allocate(NULL, CH_UNIX, 
                                     CH_DOS, password,
index 9629dffaea2fa496cb4da58aba24b0e8375a7cc7..d40a2deea3bac6a76b687a696ba298bac5bf3875 100644 (file)
@@ -213,7 +213,10 @@ int main( int argc, char *argv[] )
        
        /* actually do the update now */
        
-       nk = regfio_rootkey( infile );
+       if ((nk = regfio_rootkey( infile )) == NULL) {
+               fprintf(stderr, "Could not get rootkey\n");
+               exit(3);
+       }
        
        if ( !copy_registry_tree( infile, nk, NULL, outfile, "" ) ) {
                fprintf(stderr, "Failed to write updated registry file!\n");
index 1c34cd32a66acf9d1a1b15913952029200d78abe..b31fd95f7ab9b83c5b18a4749df18bef131f631b 100644 (file)
@@ -360,11 +360,12 @@ static BOOL add_ace(SEC_ACL **the_acl, SEC_ACE *ace)
        SEC_ACL *new_ace;
        SEC_ACE *aces;
        if (! *the_acl) {
-               (*the_acl) = make_sec_acl(ctx, 3, 1, ace);
-               return True;
+               return (((*the_acl) = make_sec_acl(ctx, 3, 1, ace)) != NULL);
        }
 
-       aces = SMB_CALLOC_ARRAY(SEC_ACE, 1+(*the_acl)->num_aces);
+       if (!(aces = SMB_CALLOC_ARRAY(SEC_ACE, 1+(*the_acl)->num_aces))) {
+               return False;
+       }
        memcpy(aces, (*the_acl)->ace, (*the_acl)->num_aces * sizeof(SEC_ACE));
        memcpy(aces+(*the_acl)->num_aces, ace, sizeof(SEC_ACE));
        new_ace = make_sec_acl(ctx,(*the_acl)->revision,1+(*the_acl)->num_aces, aces);