added a query_user backend
[metze/samba/wip.git] / source3 / nsswitch / winbindd.h
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 2.0
4
5    Winbind daemon for ntdom nss module
6
7    Copyright (C) Tim Potter 2000
8    
9    This library is free software; you can redistribute it and/or
10    modify it under the terms of the GNU Library General Public
11    License as published by the Free Software Foundation; either
12    version 2 of the License, or (at your option) any later version.
13    
14    This library is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17    Library General Public License for more details.
18    
19    You should have received a copy of the GNU Library General Public
20    License along with this library; if not, write to the
21    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22    Boston, MA  02111-1307, USA.   
23 */
24
25 #ifndef _WINBINDD_H
26 #define _WINBINDD_H
27
28 #include "includes.h"
29 #include "nterr.h"
30
31 #include "winbindd_nss.h"
32
33 /* Client state structure */
34
35 struct winbindd_cli_state {
36     struct winbindd_cli_state *prev, *next;   /* Linked list pointers */
37     int sock;                                 /* Open socket from client */
38     pid_t pid;                                /* pid of client */
39     int read_buf_len, write_buf_len;          /* Indexes in request/response */
40     BOOL finished;                            /* Can delete from list */
41     BOOL write_extra_data;                    /* Write extra_data field */
42     struct winbindd_request request;          /* Request from client */
43     struct winbindd_response response;        /* Respose to client */
44     struct getent_state *getpwent_state;      /* State for getpwent() */
45     struct getent_state *getgrent_state;      /* State for getgrent() */
46 };
47
48 /* State between get{pw,gr}ent() calls */
49
50 struct getent_state {
51         struct getent_state *prev, *next;
52         void *sam_entries;
53         uint32 sam_entry_index, num_sam_entries;
54         uint32 dispinfo_ndx;
55         uint32 grp_query_start_ndx;
56         BOOL got_all_sam_entries, got_sam_entries;
57         struct winbindd_domain *domain;
58 };
59
60 /* Storage for cached getpwent() user entries */
61
62 struct getpwent_user {
63         fstring name;                        /* Account name */
64         fstring gecos;                       /* User information */
65         uint32 user_rid, group_rid;          /* NT user and group rids */
66 };
67
68 /* Server state structure */
69
70 struct winbindd_state {
71
72         /* User and group id pool */
73
74         uid_t uid_low, uid_high;               /* Range of uids to allocate */
75         gid_t gid_low, gid_high;               /* Range of gids to allocate */
76 };
77
78 extern struct winbindd_state server_state;  /* Server information */
79
80 typedef struct {
81         char *acct_name;
82         char *full_name;
83         uint32 user_rid;
84         uint32 group_rid; /* primary group */
85 } WINBIND_USERINFO;
86
87 /* per-domain methods. This is how LDAP vs RPC is selected
88    This will eventually be the sole entry point to all the methods,
89    I'm just starting small
90  */
91 struct winbindd_methods {
92         NTSTATUS (*query_user_list)(struct winbindd_domain *domain,
93                                    TALLOC_CTX *mem_ctx,
94                                    uint32 *start_ndx, uint32 *num_entries, 
95                                    WINBIND_USERINFO **info);
96
97         NTSTATUS (*enum_dom_groups)(struct winbindd_domain *domain,
98                                     TALLOC_CTX *mem_ctx,
99                                     uint32 *start_ndx, uint32 *num_entries, 
100                                     struct acct_info **info);
101
102         NTSTATUS (*name_to_sid)(struct winbindd_domain *domain,
103                                 const char *name,
104                                 DOM_SID *sid,
105                                 enum SID_NAME_USE *type);
106
107         NTSTATUS (*sid_to_name)(struct winbindd_domain *domain,
108                                 TALLOC_CTX *mem_ctx,
109                                 DOM_SID *sid,
110                                 char **name,
111                                 enum SID_NAME_USE *type);
112
113         /* query_user is a bit strange. The backend has a choice of
114            doing the lookup by user name or rid */
115         NTSTATUS (*query_user)(struct winbindd_domain *domain, 
116                                TALLOC_CTX *mem_ctx, 
117                                const char *user_name, uint32 user_rid, 
118                                WINBIND_USERINFO *user_info);
119 };
120
121 /* Structures to hold per domain information */
122 struct winbindd_domain {
123         fstring name;                          /* Domain name */        
124         DOM_SID sid;                           /* SID for this domain */
125         struct winbindd_methods *methods;      /* lookup methods for
126                                                   this domain (LDAP or
127                                                   RPC) */
128         struct winbindd_domain *prev, *next;   /* Linked list info */
129 };
130
131 extern struct winbindd_domain *domain_list;  /* List of domains we know */
132
133 /* Used to glue a policy handle and cli_state together */
134
135 typedef struct {
136         struct cli_state *cli;
137         POLICY_HND pol;
138 } CLI_POLICY_HND;
139
140 #include "winbindd_proto.h"
141
142 #include "rpc_parse.h"
143 #include "rpc_client.h"
144
145 #define WINBINDD_ESTABLISH_LOOP 30
146 #define DOM_SEQUENCE_NONE ((uint32)-1)
147
148 /* SETENV */
149 #if HAVE_SETENV
150 #define SETENV(name, value, overwrite) setenv(name,value,overwrite)
151 #elif HAVE_PUTENV
152 #define SETENV(name, value, overwrite)                                   \
153 {                                                                        \
154         fstring envvar;                                                  \
155         slprintf(envvar, sizeof(fstring), "%s=%s", name, value);         \
156         putenv(envvar);                                                  \
157 }
158 #else
159 #define SETENV(name, value, overwrite) ;
160 #endif
161
162 #endif /* _WINBINDD_H */