s4:torture/rpc/samba3rpc.c: make use of dcerpc_binding_handle stubs
[Samba/nascimento.git] / source4 / libgpo / ads_convenience.h
blobce2b9b6a06ba17a8d8495ebb59aebae1b13391ac
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 char *ldap_server_name;
50 /* State information for the smb connection */
51 struct cli_credentials *credentials;
52 struct smbcli_state *cli;
53 } ADS_STRUCT;
56 typedef struct security_token NT_USER_TOKEN;
58 typedef struct ldb_result LDAPMessage;
59 typedef void ** ADS_MODLIST;
61 /* there are 3 possible types of errors the ads subsystem can produce */
62 enum ads_error_type { ENUM_ADS_ERROR_LDAP, ENUM_ADS_ERROR_SYSTEM, ENUM_ADS_ERROR_NT};
64 typedef struct {
65 enum ads_error_type error_type;
66 union err_state{
67 int rc;
68 NTSTATUS nt_status;
69 } err;
70 int minor_status;
71 } ADS_STATUS;
74 /* Prototypes from ads_convenience.c */
75 ADS_STATUS ads_build_nt_error(NTSTATUS);
76 ADS_STATUS ads_build_ldap_error(int);
78 ADS_STATUS ads_startup (struct libnet_context *netctx, ADS_STRUCT **ads);
79 const char *ads_errstr(ADS_STATUS status);
80 const char * ads_get_dn(ADS_STRUCT *ads, LDAPMessage *res);
81 bool ads_pull_sd(ADS_STRUCT *ads, TALLOC_CTX *ctx, LDAPMessage *res, const char *field, struct security_descriptor **sd);
82 const char * ads_pull_string(ADS_STRUCT *ads, TALLOC_CTX *ctx, LDAPMessage *res, const char *field);
83 bool ads_pull_uint32(ADS_STRUCT *ads, LDAPMessage *res, const char *field, uint32_t *ret);
84 int ads_count_replies(ADS_STRUCT *ads, LDAPMessage *res);
85 ADS_STATUS ads_do_search_all_sd_flags (ADS_STRUCT *ads, const char *dn, int scope,
86 const char *filter, const char **attrs,
87 uint32_t sd_flags, LDAPMessage **res);
88 ADS_STATUS ads_search_dn(ADS_STRUCT *ads, LDAPMessage **res,
89 const char *dn, const char **attrs);
90 ADS_STATUS ads_search_retry_dn_sd_flags(ADS_STRUCT *ads, LDAPMessage **res, uint32_t sd_flags,
91 const char *dn, const char **attrs);
92 ADS_STATUS ads_msgfree(ADS_STRUCT *ads, LDAPMessage *res);
93 NTSTATUS ads_ntstatus(ADS_STATUS status);
94 ADS_STATUS ads_build_ldap_error(int ldb_error);
95 ADS_STATUS ads_build_nt_error(NTSTATUS nt_status);
96 bool nt_token_check_sid( const struct dom_sid *sid, const NT_USER_TOKEN *token);
97 ADS_MODLIST ads_init_mods(TALLOC_CTX *ctx);
98 ADS_STATUS ads_mod_str(TALLOC_CTX *ctx, ADS_MODLIST *mods, const char *name, const char *val);
99 ADS_STATUS ads_gen_mod(ADS_STRUCT *ads, const char *mod_dn, ADS_MODLIST mods);
100 const char *ads_get_ldap_server_name(ADS_STRUCT *ads);
103 #endif