1 /*
2  *  Unix SMB/CIFS implementation.
3  *  ads (active directory) utility library
4  *
5  *  Copyright (C) Andrew Bartlett			2001
6  *  Copyright (C) Andrew Tridgell			2001
7  *  Copyright (C) Remus Koos (remuskoos@yahoo.com)	2001
8  *  Copyright (C) Alexey Kotovich			2002
9  *  Copyright (C) Jim McDonough <jmcd@us.ibm.com>	2002-2003
10  *  Copyright (C) Luke Howard				2003
11  *  Copyright (C) Guenther Deschner			2003-2008
12  *  Copyright (C) Rakesh Patel				2004
13  *  Copyright (C) Dan Perry				2004
14  *  Copyright (C) Jeremy Allison			2004
15  *  Copyright (C) Gerald Carter				2006
16  *  Copyright (C) Stefan Metzmacher			2007
17  *
18  *  This program is free software; you can redistribute it and/or modify
19  *  it under the terms of the GNU General Public License as published by
20  *  the Free Software Foundation; either version 3 of the License, or
21  *  (at your option) any later version.
22  *
23  *  This program is distributed in the hope that it will be useful,
24  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
25  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  *  GNU General Public License for more details.
27  *
28  *  You should have received a copy of the GNU General Public License
29  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
30  */
31 
32 #ifndef _LIBADS_ADS_PROTO_H_
33 #define _LIBADS_ADS_PROTO_H_
34 
35 enum ads_sasl_state_e {
36 	ADS_SASL_PLAIN = 0,
37 	ADS_SASL_SIGN,
38 	ADS_SASL_SEAL,
39 };
40 
41 /* The following definitions come from libads/ads_struct.c  */
42 
43 char *ads_build_path(const char *realm, const char *sep, const char *field, int reverse);
44 char *ads_build_dn(const char *realm);
45 char *ads_build_domain(const char *dn);
46 ADS_STRUCT *ads_init(const char *realm,
47 		     const char *workgroup,
48 		     const char *ldap_server,
49 		     enum ads_sasl_state_e sasl_state);
50 bool ads_set_sasl_wrap_flags(ADS_STRUCT *ads, int flags);
51 void ads_destroy(ADS_STRUCT **ads);
52 
53 /* The following definitions come from libads/disp_sec.c  */
54 
55 void ads_disp_sd(ADS_STRUCT *ads, TALLOC_CTX *mem_ctx, struct security_descriptor *sd);
56 
57 /* The following definitions come from libads/kerberos_keytab.c  */
58 
59 int ads_keytab_add_entry(ADS_STRUCT *ads, const char *srvPrinc,
60 			 bool update_ads);
61 int ads_keytab_flush(ADS_STRUCT *ads);
62 int ads_keytab_create_default(ADS_STRUCT *ads);
63 int ads_keytab_list(const char *keytab_name);
64 
65 /* The following definitions come from libads/net_ads_setspn.c  */
66 bool ads_setspn_list(ADS_STRUCT *ads, const char *machine);
67 bool ads_setspn_add(ADS_STRUCT *ads, const char *machine_name,
68 		    const char * spn);
69 bool ads_setspn_delete(ADS_STRUCT *ads, const char *machine_name,
70 		       const char * spn);
71 
72 /* The following definitions come from libads/krb5_errs.c  */
73 
74 /* The following definitions come from libads/kerberos_util.c  */
75 
76 int ads_kinit_password(ADS_STRUCT *ads);
77 
78 /* The following definitions come from libads/ldap.c  */
79 
80 bool ads_sitename_match(ADS_STRUCT *ads);
81 bool ads_closest_dc(ADS_STRUCT *ads);
82 ADS_STATUS ads_connect(ADS_STRUCT *ads);
83 ADS_STATUS ads_connect_user_creds(ADS_STRUCT *ads);
84 void ads_disconnect(ADS_STRUCT *ads);
85 ADS_STATUS ads_do_search_all_fn(ADS_STRUCT *ads, const char *bind_path,
86 				int scope, const char *expr, const char **attrs,
87 				bool (*fn)(ADS_STRUCT *, char *, void **, void *),
88 				void *data_area);
89 char *ads_parent_dn(const char *dn);
90 ADS_MODLIST ads_init_mods(TALLOC_CTX *ctx);
91 ADS_STATUS ads_mod_str(TALLOC_CTX *ctx, ADS_MODLIST *mods,
92 		       const char *name, const char *val);
93 ADS_STATUS ads_mod_strlist(TALLOC_CTX *ctx, ADS_MODLIST *mods,
94 			   const char *name, const char **vals);
95 ADS_STATUS ads_gen_mod(ADS_STRUCT *ads, const char *mod_dn, ADS_MODLIST mods);
96 ADS_STATUS ads_gen_add(ADS_STRUCT *ads, const char *new_dn, ADS_MODLIST mods);
97 ADS_STATUS ads_del_dn(ADS_STRUCT *ads, char *del_dn);
98 char *ads_ou_string(ADS_STRUCT *ads, const char *org_unit);
99 char *ads_default_ou_string(ADS_STRUCT *ads, const char *wknguid);
100 ADS_STATUS ads_add_strlist(TALLOC_CTX *ctx, ADS_MODLIST *mods,
101 				const char *name, const char **vals);
102 uint32_t ads_get_kvno(ADS_STRUCT *ads, const char *account_name);
103 uint32_t ads_get_machine_kvno(ADS_STRUCT *ads, const char *machine_name);
104 
105 bool ads_element_in_array(const char **el_array, size_t num_el, const char *el);
106 
107 ADS_STATUS ads_get_service_principal_names(TALLOC_CTX *mem_ctx,
108 					   ADS_STRUCT *ads,
109 					   const char *machine_name,
110 					   char ***spn_array,
111 					   size_t *num_spns);
112 ADS_STATUS ads_clear_service_principal_names(ADS_STRUCT *ads, const char *machine_name);
113 ADS_STATUS ads_add_service_principal_names(ADS_STRUCT *ads, const char *machine_name,
114                                           const char **spns);
115 ADS_STATUS ads_create_machine_acct(ADS_STRUCT *ads,
116 				   const char *machine_name,
117 				   const char *machine_password,
118 				   const char *org_unit,
119 				   uint32_t etype_list,
120 				   const char *dns_domain_name);
121 ADS_STATUS ads_move_machine_acct(ADS_STRUCT *ads, const char *machine_name,
122                                  const char *org_unit, bool *moved);
123 int ads_count_replies(ADS_STRUCT *ads, void *res);
124 ADS_STATUS ads_USN(ADS_STRUCT *ads, uint32_t *usn);
125 ADS_STATUS ads_current_time(ADS_STRUCT *ads);
126 ADS_STATUS ads_domain_func_level(ADS_STRUCT *ads, uint32_t *val);
127 ADS_STATUS ads_domain_sid(ADS_STRUCT *ads, struct dom_sid *sid);
128 ADS_STATUS ads_site_dn(ADS_STRUCT *ads, TALLOC_CTX *mem_ctx, const char **site_name);
129 ADS_STATUS ads_site_dn_for_machine(ADS_STRUCT *ads, TALLOC_CTX *mem_ctx, const char *computer_name, const char **site_dn);
130 ADS_STATUS ads_upn_suffixes(ADS_STRUCT *ads, TALLOC_CTX *mem_ctx, char ***suffixes, size_t *num_suffixes);
131 ADS_STATUS ads_get_joinable_ous(ADS_STRUCT *ads,
132 				TALLOC_CTX *mem_ctx,
133 				char ***ous,
134 				size_t *num_ous);
135 ADS_STATUS ads_get_sid_from_extended_dn(TALLOC_CTX *mem_ctx,
136 					const char *extended_dn,
137 					enum ads_extended_dn_flags flags,
138 					struct dom_sid *sid);
139 char* ads_get_dnshostname( ADS_STRUCT *ads, TALLOC_CTX *ctx, const char *machine_name );
140 ADS_STATUS ads_get_additional_dns_hostnames(TALLOC_CTX *mem_ctx,
141                                             ADS_STRUCT *ads,
142                                             const char *machine_name,
143                                             char ***hostnames_array,
144                                             size_t *num_hostnames);
145 char* ads_get_upn( ADS_STRUCT *ads, TALLOC_CTX *ctx, const char *machine_name );
146 bool ads_has_samaccountname( ADS_STRUCT *ads, TALLOC_CTX *ctx, const char *machine_name );
147 ADS_STATUS ads_join_realm(ADS_STRUCT *ads, const char *machine_name,
148 			uint32_t account_type, const char *org_unit);
149 ADS_STATUS ads_leave_realm(ADS_STRUCT *ads, const char *hostname);
150 ADS_STATUS ads_find_samaccount(ADS_STRUCT *ads,
151 			       TALLOC_CTX *mem_ctx,
152 			       const char *samaccountname,
153 			       uint32_t *uac_ret,
154 			       const char **dn_ret);
155 ADS_STATUS ads_config_path(ADS_STRUCT *ads,
156 			   TALLOC_CTX *mem_ctx,
157 			   char **config_path);
158 const char *ads_get_extended_right_name_by_guid(ADS_STRUCT *ads,
159 						const char *config_path,
160 						TALLOC_CTX *mem_ctx,
161 						const struct GUID *rights_guid);
162 ADS_STATUS ads_check_ou_dn(TALLOC_CTX *mem_ctx,
163 			   ADS_STRUCT *ads,
164 			   const char **account_ou);
165 
166 /* The following definitions come from libads/ldap_printer.c  */
167 
168 ADS_STATUS ads_mod_printer_entry(ADS_STRUCT *ads, char *prt_dn,
169 				 TALLOC_CTX *ctx, const ADS_MODLIST *mods);
170 ADS_STATUS ads_add_printer_entry(ADS_STRUCT *ads, char *prt_dn,
171 					TALLOC_CTX *ctx, ADS_MODLIST *mods);
172 WERROR get_remote_printer_publishing_data(struct rpc_pipe_client *cli,
173 					  TALLOC_CTX *mem_ctx,
174 					  ADS_MODLIST *mods,
175 					  const char *printer);
176 
177 /* The following definitions come from libads/ldap_user.c  */
178 
179 ADS_STATUS ads_add_user_acct(ADS_STRUCT *ads, const char *user,
180 			     const char *container, const char *fullname);
181 ADS_STATUS ads_add_group_acct(ADS_STRUCT *ads, const char *group,
182 			      const char *container, const char *comment);
183 
184 /* The following definitions come from libads/ldap_utils.c  */
185 
186 ADS_STATUS ads_ranged_search(ADS_STRUCT *ads,
187 			     TALLOC_CTX *mem_ctx,
188 			     int scope,
189 			     const char *base,
190 			     const char *filter,
191 			     void *args,
192 			     const char *range_attr,
193 			     char ***strings,
194 			     size_t *num_strings);
195 
196 /* The following definitions come from libads/ndr.c  */
197 
198 struct ndr_print;
199 void ndr_print_ads_struct(struct ndr_print *ndr, const char *name, const struct ads_struct *r);
200 
201 /* The following definitions come from libads/sasl.c  */
202 
203 ADS_STATUS ads_sasl_bind(ADS_STRUCT *ads);
204 
205 /* The following definitions come from libads/sasl_wrapping.c  */
206 
207 ADS_STATUS ads_setup_sasl_wrapping(struct ads_saslwrap *wrap, LDAP *ld,
208 				   const struct ads_saslwrap_ops *ops,
209 				   void *private_data);
210 void ndr_print_ads_saslwrap_struct(struct ndr_print *ndr,
211 				   const char *name,
212 				   const struct ads_saslwrap *r);
213 
214 /* The following definitions come from libads/util.c  */
215 
216 ADS_STATUS ads_change_trust_account_password(ADS_STRUCT *ads, char *host_principal);
217 
218 struct spn_struct {
219 	const char *serviceclass;
220 	const char *servicename;
221 	const char *host;
222 	int32_t port;
223 };
224 
225 /* parse a windows style SPN, returns NULL if parsing fails */
226 struct spn_struct *parse_spn(TALLOC_CTX *ctx, const char *srvprinc);
227 
228 #endif /* _LIBADS_ADS_PROTO_H_ */
229