| 1 | /* 
 | 
|---|
| 2 |    Unix SMB/CIFS implementation.
 | 
|---|
| 3 |    Main winbindd server routines
 | 
|---|
| 4 | 
 | 
|---|
| 5 |    Copyright (C) Stefan Metzmacher      2005
 | 
|---|
| 6 |    Copyright (C) Andrew Tridgell        2005
 | 
|---|
| 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 | #include "nsswitch/winbind_nss_config.h"
 | 
|---|
| 23 | #include "nsswitch/winbind_struct_protocol.h"
 | 
|---|
| 24 | #include "winbind/idmap.h"
 | 
|---|
| 25 | #include "libnet/libnet.h"
 | 
|---|
| 26 | 
 | 
|---|
| 27 | /* this struct stores global data for the winbind task */
 | 
|---|
| 28 | struct wbsrv_service {
 | 
|---|
| 29 |         struct task_server *task;
 | 
|---|
| 30 | 
 | 
|---|
| 31 |         const struct dom_sid *primary_sid;
 | 
|---|
| 32 |         enum netr_SchannelType sec_channel_type;
 | 
|---|
| 33 |         struct wbsrv_domain *domains;
 | 
|---|
| 34 |         struct idmap_context *idmap_ctx;
 | 
|---|
| 35 |         const char *priv_pipe_dir;
 | 
|---|
| 36 |         const char *pipe_dir;
 | 
|---|
| 37 | };
 | 
|---|
| 38 | 
 | 
|---|
| 39 | struct wbsrv_samconn {
 | 
|---|
| 40 |         struct wbsrv_domain *domain;
 | 
|---|
| 41 |         void *private_data;
 | 
|---|
| 42 | 
 | 
|---|
| 43 |         struct composite_context (*seqnum_send)(struct wbsrv_samconn *);
 | 
|---|
| 44 |         NTSTATUS (*seqnum_recv)(struct composite_context *, uint64_t *);
 | 
|---|
| 45 | };
 | 
|---|
| 46 | 
 | 
|---|
| 47 | struct wb_dom_info {
 | 
|---|
| 48 |         const char *name;
 | 
|---|
| 49 |         const char *dns_name;
 | 
|---|
| 50 |         const struct dom_sid *sid;
 | 
|---|
| 51 |         struct nbt_dc_name *dc;
 | 
|---|
| 52 | };
 | 
|---|
| 53 | 
 | 
|---|
| 54 | struct wbsrv_domain {
 | 
|---|
| 55 |         struct wbsrv_domain *next, *prev;
 | 
|---|
| 56 | 
 | 
|---|
| 57 |         struct wb_dom_info *info;
 | 
|---|
| 58 | 
 | 
|---|
| 59 |         /* Details for the server we are currently talking to */
 | 
|---|
| 60 |         const char *dc_address;
 | 
|---|
| 61 |         const char *dc_name;
 | 
|---|
| 62 | 
 | 
|---|
| 63 |         struct libnet_context *libnet_ctx;
 | 
|---|
| 64 | 
 | 
|---|
| 65 |         struct dcerpc_binding *lsa_binding;
 | 
|---|
| 66 | 
 | 
|---|
| 67 |         struct dcerpc_binding *samr_binding;
 | 
|---|
| 68 | 
 | 
|---|
| 69 |         struct dcerpc_pipe *netlogon_pipe;
 | 
|---|
| 70 |         struct dcerpc_binding *netlogon_binding;
 | 
|---|
| 71 | };
 | 
|---|
| 72 | 
 | 
|---|
| 73 | /*
 | 
|---|
| 74 |   state of a listen socket and it's protocol information
 | 
|---|
| 75 | */
 | 
|---|
| 76 | struct wbsrv_listen_socket {
 | 
|---|
| 77 |         const char *socket_path;
 | 
|---|
| 78 |         struct wbsrv_service *service;
 | 
|---|
| 79 |         bool privileged;
 | 
|---|
| 80 | };
 | 
|---|
| 81 | 
 | 
|---|
| 82 | /*
 | 
|---|
| 83 |   state of an open winbind connection
 | 
|---|
| 84 | */
 | 
|---|
| 85 | struct wbsrv_connection {
 | 
|---|
| 86 |         /* stream connection we belong to */
 | 
|---|
| 87 |         struct stream_connection *conn;
 | 
|---|
| 88 | 
 | 
|---|
| 89 |         /* the listening socket we belong to, it holds protocol hooks */
 | 
|---|
| 90 |         struct wbsrv_listen_socket *listen_socket;
 | 
|---|
| 91 | 
 | 
|---|
| 92 |         /* storage for protocol specific data */
 | 
|---|
| 93 |         void *protocol_private_data;
 | 
|---|
| 94 | 
 | 
|---|
| 95 |         /* how many calls are pending */
 | 
|---|
| 96 |         uint32_t pending_calls;
 | 
|---|
| 97 | 
 | 
|---|
| 98 |         struct tstream_context *tstream;
 | 
|---|
| 99 | 
 | 
|---|
| 100 |         struct tevent_queue *send_queue;
 | 
|---|
| 101 | 
 | 
|---|
| 102 |         struct loadparm_context *lp_ctx;
 | 
|---|
| 103 | };
 | 
|---|
| 104 | 
 | 
|---|
| 105 | #define WBSRV_SAMBA3_SET_STRING(dest, src) do { \
 | 
|---|
| 106 |         memset(dest, 0, sizeof(dest));\
 | 
|---|
| 107 |         safe_strcpy(dest, src, sizeof(dest)-1);\
 | 
|---|
| 108 | } while(0)
 | 
|---|
| 109 | 
 | 
|---|
| 110 | /*
 | 
|---|
| 111 |   state of a pwent query
 | 
|---|
| 112 | */
 | 
|---|
| 113 | struct wbsrv_pwent {
 | 
|---|
| 114 |         /* Current UserList structure, contains 1+ user structs */
 | 
|---|
| 115 |         struct libnet_UserList *user_list;
 | 
|---|
| 116 | 
 | 
|---|
| 117 |         /* Index of the next user struct in the current UserList struct */
 | 
|---|
| 118 |         uint32_t page_index;
 | 
|---|
| 119 | 
 | 
|---|
| 120 |         /* The libnet_ctx to use for the libnet_UserList call */
 | 
|---|
| 121 |         struct libnet_context *libnet_ctx;
 | 
|---|
| 122 | };
 | 
|---|
| 123 | /*
 | 
|---|
| 124 |   state of a grent query
 | 
|---|
| 125 | */
 | 
|---|
| 126 | struct wbsrv_grent {
 | 
|---|
| 127 |         /* Current UserList structure, contains 1+ user structs */
 | 
|---|
| 128 |         struct libnet_GroupList *group_list;
 | 
|---|
| 129 | 
 | 
|---|
| 130 |         /* Index of the next user struct in the current UserList struct */
 | 
|---|
| 131 |         uint32_t page_index;
 | 
|---|
| 132 | 
 | 
|---|
| 133 |         /* The libnet_ctx to use for the libnet_UserList call */
 | 
|---|
| 134 |         struct libnet_context *libnet_ctx;
 | 
|---|
| 135 | };
 | 
|---|
| 136 | 
 | 
|---|
| 137 | /*
 | 
|---|
| 138 |   state of one request
 | 
|---|
| 139 | 
 | 
|---|
| 140 |   NOTE about async replies:
 | 
|---|
| 141 |    if the backend wants to reply later:
 | 
|---|
| 142 | 
 | 
|---|
| 143 |    - it should set the WBSRV_CALL_FLAGS_REPLY_ASYNC flag, and may set a 
 | 
|---|
| 144 |      talloc_destructor on the this structure or on the private_data (if it's a
 | 
|---|
| 145 |      talloc child of this structure), so that wbsrv_terminate_connection
 | 
|---|
| 146 |      called by another call clean up the whole connection correct.
 | 
|---|
| 147 |    - When the backend is ready to reply it should call wbsrv_send_reply(call),
 | 
|---|
| 148 |      wbsrv_send_reply implies talloc_free(call), so the backend should use 
 | 
|---|
| 149 |      talloc_reference(call), if it needs it later. 
 | 
|---|
| 150 |    - If wbsrv_send_reply doesn't return NT_STATUS_OK, the backend function 
 | 
|---|
| 151 |      should call, wbsrv_terminate_connection(call->wbconn, nt_errstr(status));
 | 
|---|
| 152 |      return;
 | 
|---|
| 153 | 
 | 
|---|
| 154 | */
 | 
|---|
| 155 | struct wbsrv_samba3_call {
 | 
|---|
| 156 | #define WBSRV_CALL_FLAGS_REPLY_ASYNC 0x00000001
 | 
|---|
| 157 |         uint32_t flags;
 | 
|---|
| 158 | 
 | 
|---|
| 159 |         /* the connection the call belongs to */
 | 
|---|
| 160 |         struct wbsrv_connection *wbconn;
 | 
|---|
| 161 | 
 | 
|---|
| 162 |         /* here the backend can store stuff like composite_context's ... */
 | 
|---|
| 163 |         void *private_data;
 | 
|---|
| 164 | 
 | 
|---|
| 165 |         /* the request structure of the samba3 protocol */
 | 
|---|
| 166 |         struct winbindd_request *request;
 | 
|---|
| 167 |         
 | 
|---|
| 168 |         /* the response structure of the samba3 protocol*/
 | 
|---|
| 169 |         struct winbindd_response *response;
 | 
|---|
| 170 | 
 | 
|---|
| 171 |         DATA_BLOB in;
 | 
|---|
| 172 |         DATA_BLOB out;
 | 
|---|
| 173 |         struct iovec out_iov[1];
 | 
|---|
| 174 | };
 | 
|---|
| 175 | 
 | 
|---|
| 176 | struct netr_LMSessionKey;
 | 
|---|
| 177 | struct netr_UserSessionKey;
 | 
|---|
| 178 | struct winbind_SamLogon;
 | 
|---|
| 179 | struct winbind_DsrUpdateReadOnlyServerDnsRecords;
 | 
|---|
| 180 | 
 | 
|---|
| 181 | #include "winbind/wb_async_helpers.h"
 | 
|---|
| 182 | #include "winbind/wb_proto.h"
 | 
|---|