source: branches/samba-3.2.x/source/lib/smbldap_util.c@ 553

Last change on this file since 553 was 133, checked in by Paul Smedley, 18 years ago

Update trunk to 3.2.0pre3

File size: 9.5 KB
Line 
1/*
2 Unix SMB/CIFS mplementation.
3 LDAP protocol helper functions for SAMBA
4 Copyright (C) Jean François Micouleau 1998
5 Copyright (C) Gerald Carter 2001-2003
6 Copyright (C) Shahms King 2001
7 Copyright (C) Andrew Bartlett 2002-2003
8 Copyright (C) Stefan (metze) Metzmacher 2002-2003
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
22
23*/
24
25#include "includes.h"
26#include "smbldap.h"
27
28/**********************************************************************
29 Add the account-policies below the sambaDomain object to LDAP,
30*********************************************************************/
31
32static NTSTATUS add_new_domain_account_policies(struct smbldap_state *ldap_state,
33 const char *domain_name)
34{
35 NTSTATUS ntstatus = NT_STATUS_UNSUCCESSFUL;
36 int i, rc;
37 uint32 policy_default;
38 const char *policy_attr = NULL;
39 char *dn = NULL;
40 LDAPMod **mods = NULL;
41 char *escape_domain_name;
42
43 DEBUG(3,("add_new_domain_account_policies: Adding new account policies for domain\n"));
44
45 escape_domain_name = escape_rdn_val_string_alloc(domain_name);
46 if (!escape_domain_name) {
47 DEBUG(0, ("Out of memory!\n"));
48 return NT_STATUS_NO_MEMORY;
49 }
50
51 if (asprintf(&dn, "%s=%s,%s",
52 get_attr_key2string(dominfo_attr_list, LDAP_ATTR_DOMAIN),
53 escape_domain_name, lp_ldap_suffix()) < 0) {
54 SAFE_FREE(escape_domain_name);
55 return NT_STATUS_NO_MEMORY;
56 }
57
58 SAFE_FREE(escape_domain_name);
59
60 for (i=1; decode_account_policy_name(i) != NULL; i++) {
61 char *val = NULL;
62
63 policy_attr = get_account_policy_attr(i);
64 if (!policy_attr) {
65 DEBUG(0,("add_new_domain_account_policies: ops. no policy!\n"));
66 continue;
67 }
68
69 if (!account_policy_get_default(i, &policy_default)) {
70 DEBUG(0,("add_new_domain_account_policies: failed to get default account policy\n"));
71 SAFE_FREE(dn);
72 return ntstatus;
73 }
74
75 DEBUG(10,("add_new_domain_account_policies: adding \"%s\" with value: %d\n", policy_attr, policy_default));
76
77 if (asprintf(&val, "%d", policy_default) < 0) {
78 SAFE_FREE(dn);
79 return NT_STATUS_NO_MEMORY;
80 }
81
82 smbldap_set_mod( &mods, LDAP_MOD_REPLACE, policy_attr, val);
83
84 rc = smbldap_modify(ldap_state, dn, mods);
85
86 SAFE_FREE(val);
87
88 if (rc!=LDAP_SUCCESS) {
89 char *ld_error = NULL;
90 ldap_get_option(ldap_state->ldap_struct, LDAP_OPT_ERROR_STRING, &ld_error);
91 DEBUG(1,("add_new_domain_account_policies: failed to add account policies to dn= %s with: %s\n\t%s\n",
92 dn, ldap_err2string(rc),
93 ld_error ? ld_error : "unknown"));
94 SAFE_FREE(ld_error);
95 SAFE_FREE(dn);
96 ldap_mods_free(mods, True);
97 return ntstatus;
98 }
99 }
100