2 Unix SMB/CIFS implementation.
3 IPA helper functions for SAMBA
4 Copyright (C) Sumit Bose <sbose@redhat.com> 2010
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "libcli/security/dom_sid.h"
26 #define LDAP_TRUST_CONTAINER "ou=system"
27 #define LDAP_ATTRIBUTE_CN "cn"
28 #define LDAP_ATTRIBUTE_TRUST_TYPE "sambaTrustType"
29 #define LDAP_ATTRIBUTE_TRUST_ATTRIBUTES "sambaTrustAttributes"
30 #define LDAP_ATTRIBUTE_TRUST_DIRECTION "sambaTrustDirection"
31 #define LDAP_ATTRIBUTE_TRUST_PARTNER "sambaTrustPartner"
32 #define LDAP_ATTRIBUTE_FLAT_NAME "sambaFlatName"
33 #define LDAP_ATTRIBUTE_TRUST_AUTH_OUTGOING "sambaTrustAuthOutgoing"
34 #define LDAP_ATTRIBUTE_TRUST_AUTH_INCOMING "sambaTrustAuthIncoming"
35 #define LDAP_ATTRIBUTE_SECURITY_IDENTIFIER "sambaSecurityIdentifier"
36 #define LDAP_ATTRIBUTE_TRUST_FOREST_TRUST_INFO "sambaTrustForestTrustInfo"
38 #define LDAP_OBJ_KRB_PRINCIPAL "krbPrincipal"
39 #define LDAP_OBJ_KRB_PRINCIPAL_AUX "krbPrincipalAux"
40 #define LDAP_ATTRIBUTE_KRB_PRINCIPAL "krbPrincipalName"
42 struct ipasam_privates
{
43 NTSTATUS (*ldapsam_add_sam_account
)(struct pdb_methods
*,
44 struct samu
*sampass
);
45 NTSTATUS (*ldapsam_update_sam_account
)(struct pdb_methods
*,
46 struct samu
*sampass
);
49 static bool ipasam_get_trusteddom_pw(struct pdb_methods
*methods
,
53 time_t *pass_last_set_time
)
58 static bool ipasam_set_trusteddom_pw(struct pdb_methods
*methods
,
61 const struct dom_sid
*sid
)
66 static bool ipasam_del_trusteddom_pw(struct pdb_methods
*methods
,
72 static char *get_account_dn(const char *name
)
77 escape_name
= escape_rdn_val_string_alloc(name
);
82 if (name
[strlen(name
)-1] == '$') {
83 dn
= talloc_asprintf(talloc_tos(), "uid=%s,%s", escape_name
,
84 lp_ldap_machine_suffix());
86 dn
= talloc_asprintf(talloc_tos(), "uid=%s,%s", escape_name
,
87 lp_ldap_user_suffix());
90 SAFE_FREE(escape_name
);
95 static char *trusted_domain_dn(struct ldapsam_privates
*ldap_state
,
98 return talloc_asprintf(talloc_tos(), "%s=%s,%s,%s",
99 LDAP_ATTRIBUTE_CN
, domain
,
100 LDAP_TRUST_CONTAINER
, ldap_state
->domain_dn
);
103 static char *trusted_domain_base_dn(struct ldapsam_privates
*ldap_state
)
105 return talloc_asprintf(talloc_tos(), "%s,%s",
106 LDAP_TRUST_CONTAINER
, ldap_state
->domain_dn
);
109 static bool get_trusted_domain_int(struct ldapsam_privates
*ldap_state
,
111 const char *filter
, LDAPMessage
**entry
)
114 char *base_dn
= NULL
;
115 LDAPMessage
*result
= NULL
;
118 base_dn
= trusted_domain_base_dn(ldap_state
);
119 if (base_dn
== NULL
) {
123 rc
= smbldap_search(ldap_state
->smbldap_state
, base_dn
,
124 LDAP_SCOPE_SUBTREE
, filter
, NULL
, 0, &result
);
125 TALLOC_FREE(base_dn
);
127 if (result
!= NULL
) {
128 talloc_autofree_ldapmsg(mem_ctx
, result
);
131 if (rc
== LDAP_NO_SUCH_OBJECT
) {
136 if (rc
!= LDAP_SUCCESS
) {
140 num_result
= ldap_count_entries(priv2ld(ldap_state
), result
);
142 if (num_result
> 1) {
143 DEBUG(1, ("get_trusted_domain_int: more than one "
144 "%s object with filter '%s'?!\n",
145 LDAP_OBJ_TRUSTED_DOMAIN
, filter
));
149 if (num_result
== 0) {
150 DEBUG(1, ("get_trusted_domain_int: no "
151 "%s object with filter '%s'.\n",
152 LDAP_OBJ_TRUSTED_DOMAIN
, filter
));
155 *entry
= ldap_first_entry(priv2ld(ldap_state
), result
);
161 static bool get_trusted_domain_by_name_int(struct ldapsam_privates
*ldap_state
,
168 filter
= talloc_asprintf(talloc_tos(),
169 "(&(objectClass=%s)(|(%s=%s)(%s=%s)(cn=%s)))",
170 LDAP_OBJ_TRUSTED_DOMAIN
,
171 LDAP_ATTRIBUTE_FLAT_NAME
, domain
,
172 LDAP_ATTRIBUTE_TRUST_PARTNER
, domain
, domain
);
173 if (filter
== NULL
) {
177 return get_trusted_domain_int(ldap_state
, mem_ctx
, filter
, entry
);
180 static bool get_trusted_domain_by_sid_int(struct ldapsam_privates
*ldap_state
,
182 const char *sid
, LDAPMessage
**entry
)
186 filter
= talloc_asprintf(talloc_tos(), "(&(objectClass=%s)(%s=%s))",
187 LDAP_OBJ_TRUSTED_DOMAIN
,
188 LDAP_ATTRIBUTE_SECURITY_IDENTIFIER
, sid
);
189 if (filter
== NULL
) {
193 return get_trusted_domain_int(ldap_state
, mem_ctx
, filter
, entry
);
196 static bool get_uint32_t_from_ldap_msg(struct ldapsam_privates
*ldap_state
,
205 dummy
= smbldap_talloc_single_attribute(priv2ld(ldap_state
), entry
,
208 DEBUG(9, ("Attribute %s not present.\n", attr
));
213 l
= strtoul(dummy
, &endptr
, 10);
216 if (l
< 0 || l
> UINT32_MAX
|| *endptr
!= '\0') {
225 static void get_data_blob_from_ldap_msg(TALLOC_CTX
*mem_ctx
,
226 struct ldapsam_privates
*ldap_state
,
227 LDAPMessage
*entry
, const char *attr
,
233 dummy
= smbldap_talloc_single_attribute(priv2ld(ldap_state
), entry
, attr
,
236 DEBUG(9, ("Attribute %s not present.\n", attr
));
239 blob
= base64_decode_data_blob(dummy
);
240 if (blob
.length
== 0) {
243 _blob
->length
= blob
.length
;
244 _blob
->data
= talloc_steal(mem_ctx
, blob
.data
);
250 static bool fill_pdb_trusted_domain(TALLOC_CTX
*mem_ctx
,
251 struct ldapsam_privates
*ldap_state
,
253 struct pdb_trusted_domain
**_td
)
257 struct pdb_trusted_domain
*td
;
263 td
= talloc_zero(mem_ctx
, struct pdb_trusted_domain
);
268 /* All attributes are MAY */
270 dummy
= smbldap_talloc_single_attribute(priv2ld(ldap_state
), entry
,
271 LDAP_ATTRIBUTE_SECURITY_IDENTIFIER
,
274 DEBUG(9, ("Attribute %s not present.\n",
275 LDAP_ATTRIBUTE_SECURITY_IDENTIFIER
));
276 ZERO_STRUCT(td
->security_identifier
);
278 res
= string_to_sid(&td
->security_identifier
, dummy
);
285 get_data_blob_from_ldap_msg(td
, ldap_state
, entry
,
286 LDAP_ATTRIBUTE_TRUST_AUTH_INCOMING
,
287 &td
->trust_auth_incoming
);
289 get_data_blob_from_ldap_msg(td
, ldap_state
, entry
,
290 LDAP_ATTRIBUTE_TRUST_AUTH_OUTGOING
,
291 &td
->trust_auth_outgoing
);
293 td
->netbios_name
= smbldap_talloc_single_attribute(priv2ld(ldap_state
),
295 LDAP_ATTRIBUTE_FLAT_NAME
,
297 if (td
->netbios_name
== NULL
) {
298 DEBUG(9, ("Attribute %s not present.\n",
299 LDAP_ATTRIBUTE_FLAT_NAME
));
302 td
->domain_name
= smbldap_talloc_single_attribute(priv2ld(ldap_state
),
304 LDAP_ATTRIBUTE_TRUST_PARTNER
,
306 if (td
->domain_name
== NULL
) {
307 DEBUG(9, ("Attribute %s not present.\n",
308 LDAP_ATTRIBUTE_TRUST_PARTNER
));
311 res
= get_uint32_t_from_ldap_msg(ldap_state
, entry
,
312 LDAP_ATTRIBUTE_TRUST_DIRECTION
,
313 &td
->trust_direction
);
318 res
= get_uint32_t_from_ldap_msg(ldap_state
, entry
,
319 LDAP_ATTRIBUTE_TRUST_ATTRIBUTES
,
320 &td
->trust_attributes
);
325 res
= get_uint32_t_from_ldap_msg(ldap_state
, entry
,
326 LDAP_ATTRIBUTE_TRUST_TYPE
,
332 get_data_blob_from_ldap_msg(td
, ldap_state
, entry
,
333 LDAP_ATTRIBUTE_TRUST_FOREST_TRUST_INFO
,
334 &td
->trust_forest_trust_info
);
341 static NTSTATUS
ipasam_get_trusted_domain(struct pdb_methods
*methods
,
344 struct pdb_trusted_domain
**td
)
346 struct ldapsam_privates
*ldap_state
=
347 (struct ldapsam_privates
*)methods
->private_data
;
348 LDAPMessage
*entry
= NULL
;
350 DEBUG(10, ("ipasam_get_trusted_domain called for domain %s\n", domain
));
352 if (!get_trusted_domain_by_name_int(ldap_state
, talloc_tos(), domain
,
354 return NT_STATUS_UNSUCCESSFUL
;
357 DEBUG(5, ("ipasam_get_trusted_domain: no such trusted domain: "
359 return NT_STATUS_NO_SUCH_DOMAIN
;
362 if (!fill_pdb_trusted_domain(mem_ctx
, ldap_state
, entry
, td
)) {
363 return NT_STATUS_UNSUCCESSFUL
;
369 static NTSTATUS
ipasam_get_trusted_domain_by_sid(struct pdb_methods
*methods
,
372 struct pdb_trusted_domain
**td
)
374 struct ldapsam_privates
*ldap_state
=
375 (struct ldapsam_privates
*)methods
->private_data
;
376 LDAPMessage
*entry
= NULL
;
379 sid_str
= sid_string_tos(sid
);
381 DEBUG(10, ("ipasam_get_trusted_domain_by_sid called for sid %s\n",
384 if (!get_trusted_domain_by_sid_int(ldap_state
, talloc_tos(), sid_str
,
386 return NT_STATUS_UNSUCCESSFUL
;
389 DEBUG(5, ("ipasam_get_trusted_domain_by_sid: no trusted domain "
390 "with sid: %s\n", sid_str
));
391 return NT_STATUS_NO_SUCH_DOMAIN
;
394 if (!fill_pdb_trusted_domain(mem_ctx
, ldap_state
, entry
, td
)) {
395 return NT_STATUS_UNSUCCESSFUL
;
401 static bool smbldap_make_mod_uint32_t(LDAP
*ldap_struct
, LDAPMessage
*entry
,
402 LDAPMod
***mods
, const char *attribute
,
407 dummy
= talloc_asprintf(talloc_tos(), "%lu", (unsigned long) val
);
411 smbldap_make_mod(ldap_struct
, entry
, mods
, attribute
, dummy
);
417 static bool smbldap_make_mod_blob(LDAP
*ldap_struct
, LDAPMessage
*entry
,
418 LDAPMod
***mods
, const char *attribute
,
423 dummy
= base64_encode_data_blob(talloc_tos(), blob
);
428 smbldap_make_mod(ldap_struct
, entry
, mods
, attribute
, dummy
);
434 static NTSTATUS
ipasam_set_trusted_domain(struct pdb_methods
*methods
,
436 const struct pdb_trusted_domain
*td
)
438 struct ldapsam_privates
*ldap_state
=
439 (struct ldapsam_privates
*)methods
->private_data
;
440 LDAPMessage
*entry
= NULL
;
443 char *trusted_dn
= NULL
;
446 DEBUG(10, ("ipasam_set_trusted_domain called for domain %s\n", domain
));
448 res
= get_trusted_domain_by_name_int(ldap_state
, talloc_tos(), domain
,
451 return NT_STATUS_UNSUCCESSFUL
;
455 smbldap_make_mod(priv2ld(ldap_state
), entry
, &mods
, "objectClass",
456 LDAP_OBJ_TRUSTED_DOMAIN
);
458 if (td
->netbios_name
!= NULL
) {
459 smbldap_make_mod(priv2ld(ldap_state
), entry
, &mods
,
460 LDAP_ATTRIBUTE_FLAT_NAME
,
464 if (td
->domain_name
!= NULL
) {
465 smbldap_make_mod(priv2ld(ldap_state
), entry
, &mods
,
466 LDAP_ATTRIBUTE_TRUST_PARTNER
,
470 if (!is_null_sid(&td
->security_identifier
)) {
471 smbldap_make_mod(priv2ld(ldap_state
), entry
, &mods
,
472 LDAP_ATTRIBUTE_SECURITY_IDENTIFIER
,
473 sid_string_tos(&td
->security_identifier
));
476 if (td
->trust_type
!= 0) {
477 res
= smbldap_make_mod_uint32_t(priv2ld(ldap_state
), entry
,
478 &mods
, LDAP_ATTRIBUTE_TRUST_TYPE
,
481 return NT_STATUS_UNSUCCESSFUL
;
485 if (td
->trust_attributes
!= 0) {
486 res
= smbldap_make_mod_uint32_t(priv2ld(ldap_state
), entry
,
488 LDAP_ATTRIBUTE_TRUST_ATTRIBUTES
,
489 td
->trust_attributes
);
491 return NT_STATUS_UNSUCCESSFUL
;
495 if (td
->trust_direction
!= 0) {
496 res
= smbldap_make_mod_uint32_t(priv2ld(ldap_state
), entry
,
498 LDAP_ATTRIBUTE_TRUST_DIRECTION
,
499 td
->trust_direction
);
501 return NT_STATUS_UNSUCCESSFUL
;
505 if (td
->trust_auth_outgoing
.data
!= NULL
) {
506 res
= smbldap_make_mod_blob(priv2ld(ldap_state
), entry
,
508 LDAP_ATTRIBUTE_TRUST_AUTH_OUTGOING
,
509 td
->trust_auth_outgoing
);
511 return NT_STATUS_UNSUCCESSFUL
;
515 if (td
->trust_auth_incoming
.data
!= NULL
) {
516 res
= smbldap_make_mod_blob(priv2ld(ldap_state
), entry
,
518 LDAP_ATTRIBUTE_TRUST_AUTH_INCOMING
,
519 td
->trust_auth_incoming
);
521 return NT_STATUS_UNSUCCESSFUL
;
525 if (td
->trust_forest_trust_info
.data
!= NULL
) {
526 res
= smbldap_make_mod_blob(priv2ld(ldap_state
), entry
,
528 LDAP_ATTRIBUTE_TRUST_FOREST_TRUST_INFO
,
529 td
->trust_forest_trust_info
);
531 return NT_STATUS_UNSUCCESSFUL
;
535 talloc_autofree_ldapmod(talloc_tos(), mods
);
537 trusted_dn
= trusted_domain_dn(ldap_state
, domain
);
538 if (trusted_dn
== NULL
) {
539 return NT_STATUS_NO_MEMORY
;
542 ret
= smbldap_add(ldap_state
->smbldap_state
, trusted_dn
, mods
);
544 ret
= smbldap_modify(ldap_state
->smbldap_state
, trusted_dn
, mods
);
547 if (ret
!= LDAP_SUCCESS
) {
548 DEBUG(1, ("error writing trusted domain data!\n"));
549 return NT_STATUS_UNSUCCESSFUL
;
554 static NTSTATUS
ipasam_del_trusted_domain(struct pdb_methods
*methods
,
558 struct ldapsam_privates
*ldap_state
=
559 (struct ldapsam_privates
*)methods
->private_data
;
560 LDAPMessage
*entry
= NULL
;
563 if (!get_trusted_domain_by_name_int(ldap_state
, talloc_tos(), domain
,
565 return NT_STATUS_UNSUCCESSFUL
;
569 DEBUG(5, ("ipasam_del_trusted_domain: no such trusted domain: "
571 return NT_STATUS_NO_SUCH_DOMAIN
;
574 dn
= smbldap_talloc_dn(talloc_tos(), priv2ld(ldap_state
), entry
);
576 DEBUG(0,("ipasam_del_trusted_domain: Out of memory!\n"));
577 return NT_STATUS_NO_MEMORY
;
580 ret
= smbldap_delete(ldap_state
->smbldap_state
, dn
);
581 if (ret
!= LDAP_SUCCESS
) {
582 return NT_STATUS_UNSUCCESSFUL
;
588 static NTSTATUS
ipasam_enum_trusted_domains(struct pdb_methods
*methods
,
590 uint32_t *num_domains
,
591 struct pdb_trusted_domain
***domains
)
594 struct ldapsam_privates
*ldap_state
=
595 (struct ldapsam_privates
*)methods
->private_data
;
596 char *base_dn
= NULL
;
598 int scope
= LDAP_SCOPE_SUBTREE
;
599 LDAPMessage
*result
= NULL
;
600 LDAPMessage
*entry
= NULL
;
602 filter
= talloc_asprintf(talloc_tos(), "(objectClass=%s)",
603 LDAP_OBJ_TRUSTED_DOMAIN
);
604 if (filter
== NULL
) {
605 return NT_STATUS_NO_MEMORY
;
608 base_dn
= trusted_domain_base_dn(ldap_state
);
609 if (base_dn
== NULL
) {
611 return NT_STATUS_NO_MEMORY
;
614 rc
= smbldap_search(ldap_state
->smbldap_state
, base_dn
, scope
, filter
,
617 TALLOC_FREE(base_dn
);
619 if (result
!= NULL
) {
620 talloc_autofree_ldapmsg(mem_ctx
, result
);
623 if (rc
== LDAP_NO_SUCH_OBJECT
) {
629 if (rc
!= LDAP_SUCCESS
) {
630 return NT_STATUS_UNSUCCESSFUL
;
634 if (!(*domains
= TALLOC_ARRAY(mem_ctx
, struct pdb_trusted_domain
*, 1))) {
635 DEBUG(1, ("talloc failed\n"));
636 return NT_STATUS_NO_MEMORY
;
639 for (entry
= ldap_first_entry(priv2ld(ldap_state
), result
);
641 entry
= ldap_next_entry(priv2ld(ldap_state
), entry
))
643 struct pdb_trusted_domain
*dom_info
;
645 if (!fill_pdb_trusted_domain(*domains
, ldap_state
, entry
,
647 return NT_STATUS_UNSUCCESSFUL
;
650 ADD_TO_ARRAY(*domains
, struct pdb_trusted_domain
*, dom_info
,
651 domains
, num_domains
);
653 if (*domains
== NULL
) {
654 DEBUG(1, ("talloc failed\n"));
655 return NT_STATUS_NO_MEMORY
;
659 DEBUG(5, ("ipasam_enum_trusted_domains: got %d domains\n", *num_domains
));
663 static NTSTATUS
ipasam_enum_trusteddoms(struct pdb_methods
*methods
,
665 uint32_t *num_domains
,
666 struct trustdom_info
***domains
)
669 struct pdb_trusted_domain
**td
;
672 status
= ipasam_enum_trusted_domains(methods
, talloc_tos(),
674 if (!NT_STATUS_IS_OK(status
)) {
678 if (*num_domains
== 0) {
682 if (!(*domains
= TALLOC_ARRAY(mem_ctx
, struct trustdom_info
*,
684 DEBUG(1, ("talloc failed\n"));
685 return NT_STATUS_NO_MEMORY
;
688 for (i
= 0; i
< *num_domains
; i
++) {
689 struct trustdom_info
*dom_info
;
691 dom_info
= TALLOC_P(*domains
, struct trustdom_info
);
692 if (dom_info
== NULL
) {
693 DEBUG(1, ("talloc failed\n"));
694 return NT_STATUS_NO_MEMORY
;
697 dom_info
->name
= talloc_steal(mem_ctx
, td
[i
]->netbios_name
);
698 sid_copy(&dom_info
->sid
, &td
[i
]->security_identifier
);
700 (*domains
)[i
] = dom_info
;
706 static uint32_t pdb_ipasam_capabilities(struct pdb_methods
*methods
)
708 return PDB_CAP_STORE_RIDS
| PDB_CAP_ADS
;
711 static struct pdb_domain_info
*pdb_ipasam_get_domain_info(struct pdb_methods
*pdb_methods
,
714 struct pdb_domain_info
*info
;
716 struct ldapsam_privates
*ldap_state
= (struct ldapsam_privates
*)pdb_methods
->private_data
;
718 info
= talloc(mem_ctx
, struct pdb_domain_info
);
723 info
->name
= talloc_strdup(info
, ldap_state
->domain_name
);
724 if (info
->name
== NULL
) {
728 /* TODO: read dns_domain, dns_forest and guid from LDAP */
729 info
->dns_domain
= talloc_strdup(info
, lp_realm());
730 if (info
->dns_domain
== NULL
) {
733 strlower_m(info
->dns_domain
);
734 info
->dns_forest
= talloc_strdup(info
, info
->dns_domain
);
736 sid_copy(&info
->sid
, &ldap_state
->domain_sid
);
738 status
= GUID_from_string("testguid", &info
->guid
);
747 static NTSTATUS
modify_ipa_password_exop(struct ldapsam_privates
*ldap_state
,
748 struct samu
*sampass
)
751 BerElement
*ber
= NULL
;
752 struct berval
*bv
= NULL
;
754 struct berval
*retdata
= NULL
;
755 const char *password
;
758 password
= pdb_get_plaintext_passwd(sampass
);
759 if (password
== NULL
|| *password
== '\0') {
760 return NT_STATUS_INVALID_PARAMETER
;
763 dn
= get_account_dn(pdb_get_username(sampass
));
765 return NT_STATUS_INVALID_PARAMETER
;
768 ber
= ber_alloc_t( LBER_USE_DER
);
770 DEBUG(7, ("ber_alloc_t failed.\n"));
771 return NT_STATUS_NO_MEMORY
;
774 ret
= ber_printf(ber
, "{tsts}", LDAP_TAG_EXOP_MODIFY_PASSWD_ID
, dn
,
775 LDAP_TAG_EXOP_MODIFY_PASSWD_NEW
, password
);
777 DEBUG(7, ("ber_printf failed.\n"));
779 return NT_STATUS_UNSUCCESSFUL
;
782 ret
= ber_flatten(ber
, &bv
);
785 DEBUG(1, ("ber_flatten failed.\n"));
786 return NT_STATUS_UNSUCCESSFUL
;
789 ret
= smbldap_extended_operation(ldap_state
->smbldap_state
,
790 LDAP_EXOP_MODIFY_PASSWD
, bv
, NULL
,
791 NULL
, &retoid
, &retdata
);
797 ldap_memfree(retoid
);
799 if (ret
!= LDAP_SUCCESS
) {
800 DEBUG(1, ("smbldap_extended_operation LDAP_EXOP_MODIFY_PASSWD failed.\n"));
801 return NT_STATUS_UNSUCCESSFUL
;
807 static NTSTATUS
ipasam_add_objectclasses(struct ldapsam_privates
*ldap_state
,
808 struct samu
*sampass
)
811 LDAPMod
**mods
= NULL
;
816 char *domain_with_dot
;
818 dn
= get_account_dn(pdb_get_username(sampass
));
820 return NT_STATUS_INVALID_PARAMETER
;
823 princ
= talloc_asprintf(talloc_tos(), "%s@%s", pdb_get_username(sampass
), lp_realm());
825 return NT_STATUS_NO_MEMORY
;
828 domain
= pdb_get_domain(sampass
);
829 if (domain
== NULL
) {
830 return NT_STATUS_INVALID_PARAMETER
;
833 domain_with_dot
= talloc_asprintf(talloc_tos(), "%s.", domain
);
834 if (domain_with_dot
== NULL
) {
835 return NT_STATUS_NO_MEMORY
;
838 smbldap_set_mod(&mods
, LDAP_MOD_ADD
,
839 "objectclass", LDAP_OBJ_KRB_PRINCIPAL
);
840 smbldap_set_mod(&mods
, LDAP_MOD_ADD
,
841 LDAP_ATTRIBUTE_KRB_PRINCIPAL
, princ
);
842 smbldap_set_mod(&mods
, LDAP_MOD_ADD
,
843 "objectclass", LDAP_OBJ_KRB_PRINCIPAL_AUX
);
844 smbldap_set_mod(&mods
, LDAP_MOD_ADD
,
845 "objectclass", "ipaHost");
846 smbldap_set_mod(&mods
, LDAP_MOD_ADD
,
848 smbldap_set_mod(&mods
, LDAP_MOD_ADD
,
849 "objectclass", "posixAccount");
850 smbldap_set_mod(&mods
, LDAP_MOD_ADD
,
851 "cn", pdb_get_username(sampass
));
852 smbldap_set_mod(&mods
, LDAP_MOD_ADD
,
853 "gidNumber", "12345");
854 smbldap_set_mod(&mods
, LDAP_MOD_ADD
,
855 "homeDirectory", "/dev/null");
856 smbldap_set_mod(&mods
, LDAP_MOD_ADD
, "uid", domain
);
857 smbldap_set_mod(&mods
, LDAP_MOD_ADD
, "uid", domain_with_dot
);
859 ret
= smbldap_modify(ldap_state
->smbldap_state
, dn
, mods
);
860 ldap_mods_free(mods
, true);
861 if (ret
!= LDAP_SUCCESS
) {
862 DEBUG(1, ("failed to modify/add user with uid = %s (dn = %s)\n",
863 pdb_get_username(sampass
),dn
));
870 static NTSTATUS
pdb_ipasam_add_sam_account(struct pdb_methods
*pdb_methods
,
871 struct samu
*sampass
)
874 struct ldapsam_privates
*ldap_state
;
876 ldap_state
= (struct ldapsam_privates
*)(pdb_methods
->private_data
);
878 status
=ldap_state
->ipasam_privates
->ldapsam_add_sam_account(pdb_methods
,
880 if (!NT_STATUS_IS_OK(status
)) {
884 status
= ipasam_add_objectclasses(ldap_state
, sampass
);
885 if (!NT_STATUS_IS_OK(status
)) {
889 if (pdb_get_init_flags(sampass
, PDB_PLAINTEXT_PW
) == PDB_CHANGED
) {
890 status
= modify_ipa_password_exop(ldap_state
, sampass
);
891 if (!NT_STATUS_IS_OK(status
)) {
899 static NTSTATUS
pdb_ipasam_update_sam_account(struct pdb_methods
*pdb_methods
,
900 struct samu
*sampass
)
903 struct ldapsam_privates
*ldap_state
;
904 ldap_state
= (struct ldapsam_privates
*)(pdb_methods
->private_data
);
906 status
= ldap_state
->ipasam_privates
->ldapsam_update_sam_account(pdb_methods
,
908 if (!NT_STATUS_IS_OK(status
)) {
912 if (pdb_get_init_flags(sampass
, PDB_PLAINTEXT_PW
) == PDB_CHANGED
) {
913 status
= modify_ipa_password_exop(ldap_state
, sampass
);
914 if (!NT_STATUS_IS_OK(status
)) {
922 static NTSTATUS
pdb_init_IPA_ldapsam(struct pdb_methods
**pdb_method
, const char *location
)
924 struct ldapsam_privates
*ldap_state
;
927 status
= pdb_init_ldapsam(pdb_method
, location
);
928 if (!NT_STATUS_IS_OK(status
)) {
932 (*pdb_method
)->name
= "IPA_ldapsam";
934 ldap_state
= (struct ldapsam_privates
*)((*pdb_method
)->private_data
);
935 ldap_state
->ipasam_privates
= talloc_zero(ldap_state
,
936 struct ipasam_privates
);
937 if (ldap_state
->ipasam_privates
== NULL
) {
938 return NT_STATUS_NO_MEMORY
;
940 ldap_state
->is_ipa_ldap
= true;
941 ldap_state
->ipasam_privates
->ldapsam_add_sam_account
= (*pdb_method
)->add_sam_account
;
942 ldap_state
->ipasam_privates
->ldapsam_update_sam_account
= (*pdb_method
)->update_sam_account
;
944 (*pdb_method
)->add_sam_account
= pdb_ipasam_add_sam_account
;
945 (*pdb_method
)->update_sam_account
= pdb_ipasam_update_sam_account
;
947 (*pdb_method
)->capabilities
= pdb_ipasam_capabilities
;
948 (*pdb_method
)->get_domain_info
= pdb_ipasam_get_domain_info
;
950 (*pdb_method
)->get_trusteddom_pw
= ipasam_get_trusteddom_pw
;
951 (*pdb_method
)->set_trusteddom_pw
= ipasam_set_trusteddom_pw
;
952 (*pdb_method
)->del_trusteddom_pw
= ipasam_del_trusteddom_pw
;
953 (*pdb_method
)->enum_trusteddoms
= ipasam_enum_trusteddoms
;
955 (*pdb_method
)->get_trusted_domain
= ipasam_get_trusted_domain
;
956 (*pdb_method
)->get_trusted_domain_by_sid
= ipasam_get_trusted_domain_by_sid
;
957 (*pdb_method
)->set_trusted_domain
= ipasam_set_trusted_domain
;
958 (*pdb_method
)->del_trusted_domain
= ipasam_del_trusted_domain
;
959 (*pdb_method
)->enum_trusted_domains
= ipasam_enum_trusted_domains
;
964 NTSTATUS
pdb_ipa_init(void)
968 if (!NT_STATUS_IS_OK(nt_status
= smb_register_passdb(PASSDB_INTERFACE_VERSION
, "IPA_ldapsam", pdb_init_IPA_ldapsam
)))