s4:dcesrv_samr_QueryDomainInfo - allocate the "info" structure only when really needed
authorMatthias Dieter Wallnöfer <mdw@samba.org>
Fri, 11 Jun 2010 21:57:39 +0000 (23:57 +0200)
committerMatthias Dieter Wallnöfer <mdw@samba.org>
Sat, 12 Jun 2010 14:45:47 +0000 (16:45 +0200)
That means the allocation should move after the lookup (as it is on
"QueryUserInfo"). Return "NT_STATUS_NO_SUCH_DOMAIN" on an invalid domain.

source4/rpc_server/samr/dcesrv_samr.c

index 12249eb066cf79bc0cc47a56f7193ca4f49b49c0..8e1b2b068ed136c27ce3e5bc012eb914e9ef0765 100644 (file)
@@ -732,11 +732,6 @@ static NTSTATUS dcesrv_samr_QueryDomainInfo(struct dcesrv_call_state *dce_call,
 
        d_state = h->data;
 
-       info = talloc(mem_ctx, union samr_DomainInfo);
-       if (!info) {
-               return NT_STATUS_NO_MEMORY;
-       }
-
        switch (r->in.level) {
        case 1: 
        {
@@ -843,14 +838,21 @@ static NTSTATUS dcesrv_samr_QueryDomainInfo(struct dcesrv_call_state *dce_call,
                int ret;
                ret = gendb_search_dn(d_state->sam_ctx, mem_ctx,
                                      d_state->domain_dn, &dom_msgs, attrs);
+               if (ret == 0) {
+                       return NT_STATUS_NO_SUCH_DOMAIN;
+               }
                if (ret != 1) {
                        return NT_STATUS_INTERNAL_DB_CORRUPTION;
                }
        }
 
-       *r->out.info = info;
+       /* allocate the info structure */
+       info = talloc_zero(mem_ctx, union samr_DomainInfo);
+       if (info == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
 
-       ZERO_STRUCTP(info);
+       *r->out.info = info;
 
        switch (r->in.level) {
        case 1: