Add nt_token_check_sid convenience function. Map NT_USER_TOKEN to struct security_tok...
[jra/samba/.git] / source4 / libgpo / ads_convenience.h
1 /*
2    Samba CIFS implementation
3    ADS convenience functions for GPO
4
5    Copyright (C) 2008 Jelmer Vernooij, jelmer@samba.org
6    Copyright (C) 2008 Wilco Baan Hofman, wilco@baanhofman.nl
7
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.
12
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.
17
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/>.
20 */
21
22 #ifndef __ADS_CONVENIENCE_H__
23 #define __ADS_CONVENIENCE_H__
24
25 #include "librpc/gen_ndr/security.h"
26
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)
31
32 #define ADS_ERROR_HAVE_NO_MEMORY(x) do { \
33         if (!(x)) {\
34                 return ADS_ERROR_NT(NT_STATUS_NO_MEMORY);\
35         }\
36 } while (0)
37
38 #define LDAP_SCOPE_BASE         LDB_SCOPE_BASE
39 #define LDAP_SCOPE_SUBTREE      LDB_SCOPE_SUBTREE
40 #define LDAP_SCOPE_ONELEVEL     LDB_SCOPE_ONELEVEL
41
42
43
44
45 typedef struct {
46         struct libnet_context *netctx;
47         struct ldb_context *ldbctx;
48 } ADS_STRUCT;
49
50
51 typedef struct security_token NT_USER_TOKEN;
52
53 typedef struct ldb_result LDAPMessage;
54 typedef void ** ADS_MODLIST;
55
56 /* there are 3 possible types of errors the ads subsystem can produce */
57 enum ads_error_type { ENUM_ADS_ERROR_LDAP, ENUM_ADS_ERROR_SYSTEM, ENUM_ADS_ERROR_NT};
58
59 typedef struct {
60         enum ads_error_type error_type;
61         union err_state{
62                 int rc;
63                 NTSTATUS nt_status;
64         } err;
65         int minor_status;
66 } ADS_STATUS;
67
68
69 /* Prototypes from ads_convenience.c */
70 ADS_STATUS ads_build_nt_error(NTSTATUS);
71 ADS_STATUS ads_build_ldap_error(int);
72
73 ADS_STATUS ads_startup (struct libnet_context *netctx, ADS_STRUCT **ads);
74 const char *ads_errstr(ADS_STATUS status);
75 const char * ads_get_dn(ADS_STRUCT *ads, LDAPMessage *res);
76 bool ads_pull_sd(ADS_STRUCT *ads, TALLOC_CTX *ctx, LDAPMessage *res, const char *field, struct security_descriptor **sd);
77 const char * ads_pull_string(ADS_STRUCT *ads, TALLOC_CTX *ctx, LDAPMessage *res, const char *field);
78 bool ads_pull_uint32(ADS_STRUCT *ads, LDAPMessage *res, const char *field, uint32_t *ret);
79 int ads_count_replies(ADS_STRUCT *ads, LDAPMessage *res);
80 ADS_STATUS ads_do_search_all_sd_flags (ADS_STRUCT *ads, const char *dn, int scope,
81                                               const char *filter, const char **attrs,
82                                               uint32_t sd_flags, LDAPMessage **res);
83 ADS_STATUS ads_search_dn(ADS_STRUCT *ads, LDAPMessage **res,
84                          const char *dn, const char **attrs);
85 ADS_STATUS ads_search_retry_dn_sd_flags(ADS_STRUCT *ads, LDAPMessage **res, uint32_t sd_flags,
86                                         const char *dn, const char **attrs);
87 ADS_STATUS ads_msgfree(ADS_STRUCT *ads, LDAPMessage *res);
88 NTSTATUS ads_ntstatus(ADS_STATUS status);
89 ADS_STATUS ads_build_ldap_error(int ldb_error);
90 ADS_STATUS ads_build_nt_error(NTSTATUS nt_status);
91 bool nt_token_check_sid( const struct dom_sid *sid, const NT_USER_TOKEN *token);
92 ADS_MODLIST ads_init_mods(TALLOC_CTX *ctx);
93 ADS_STATUS ads_mod_str(TALLOC_CTX *ctx, ADS_MODLIST *mods, const char *name, const char *val);
94 ADS_STATUS ads_gen_mod(ADS_STRUCT *ads, const char *mod_dn, ADS_MODLIST mods);
95
96
97 #endif