Make gpo_ldap.c compatible with samba 4. Add ads_get_ldap_server_name() function...
[Samba.git] / source4 / libgpo / ads_convenience.h
blob48e7357fdab8edd79269c5848f58d194129877b8
1 /*
2 Samba CIFS implementation
3 ADS convenience functions for GPO
5 Copyright (C) 2008 Jelmer Vernooij, jelmer@samba.org
6 Copyright (C) 2008 Wilco Baan Hofman, wilco@baanhofman.nl
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef __ADS_CONVENIENCE_H__
23 #define __ADS_CONVENIENCE_H__
25 #include "librpc/gen_ndr/security.h"
27 #define ADS_ERR_OK(status) ((status.error_type == ENUM_ADS_ERROR_NT) ? NT_STATUS_IS_OK(status.err.nt_status):(status.err.rc == 0))
28 #define ADS_ERROR(rc) ads_build_ldap_error(rc)
29 #define ADS_ERROR_NT(rc) ads_build_nt_error(rc)
30 #define ADS_SUCCESS ADS_ERROR(0)
32 #define ADS_ERROR_HAVE_NO_MEMORY(x) do { \
33 if (!(x)) {\
34 return ADS_ERROR_NT(NT_STATUS_NO_MEMORY);\
36 } while (0)
38 #define LDAP_SCOPE_BASE LDB_SCOPE_BASE
39 #define LDAP_SCOPE_SUBTREE LDB_SCOPE_SUBTREE
40 #define LDAP_SCOPE_ONELEVEL LDB_SCOPE_ONELEVEL
45 typedef struct {
46 struct libnet_context *netctx;
47 struct ldb_context *ldbctx;
48 } ADS_STRUCT;
50 typedef struct ldb_result LDAPMessage;
51 typedef void ** ADS_MODLIST;
53 /* there are 3 possible types of errors the ads subsystem can produce */
54 enum ads_error_type { ENUM_ADS_ERROR_LDAP, ENUM_ADS_ERROR_SYSTEM, ENUM_ADS_ERROR_NT};
56 typedef struct {
57 enum ads_error_type error_type;
58 union err_state{
59 int rc;
60 NTSTATUS nt_status;
61 } err;
62 int minor_status;
63 } ADS_STATUS;
66 /* Prototypes from ads_convenience.c */
67 ADS_STATUS ads_build_nt_error(NTSTATUS);
68 ADS_STATUS ads_build_ldap_error(int);
70 ADS_STATUS ads_startup (struct libnet_context *netctx, ADS_STRUCT **ads);
71 const char *ads_errstr(ADS_STATUS status);
72 const char * ads_get_dn(ADS_STRUCT *ads, LDAPMessage *res);
73 bool ads_pull_sd(ADS_STRUCT *ads, TALLOC_CTX *ctx, LDAPMessage *res, const char *field, struct security_descriptor **sd);
74 const char * ads_pull_string(ADS_STRUCT *ads, TALLOC_CTX *ctx, LDAPMessage *res, const char *field);
75 bool ads_pull_uint32(ADS_STRUCT *ads, LDAPMessage *res, const char *field, uint32_t *ret);
76 int ads_count_replies(ADS_STRUCT *ads, LDAPMessage *res);
77 ADS_STATUS ads_do_search_all_sd_flags (ADS_STRUCT *ads, const char *dn, int scope,
78 const char *filter, const char **attrs,
79 uint32_t sd_flags, LDAPMessage **res);
80 ADS_STATUS ads_search_dn(ADS_STRUCT *ads, LDAPMessage **res,
81 const char *dn, const char **attrs);
82 ADS_STATUS ads_search_retry_dn_sd_flags(ADS_STRUCT *ads, LDAPMessage **res, uint32_t sd_flags,
83 const char *dn, const char **attrs);
84 ADS_STATUS ads_msgfree(ADS_STRUCT *ads, LDAPMessage *res);
85 NTSTATUS ads_ntstatus(ADS_STATUS status);
86 ADS_STATUS ads_build_ldap_error(int ldb_error);
87 ADS_STATUS ads_build_nt_error(NTSTATUS nt_status);
88 ADS_MODLIST ads_init_mods(TALLOC_CTX *ctx);
89 ADS_STATUS ads_mod_str(TALLOC_CTX *ctx, ADS_MODLIST *mods, const char *name, const char *val);
90 ADS_STATUS ads_gen_mod(ADS_STRUCT *ads, const char *mod_dn, ADS_MODLIST mods);
93 #endif