00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "includes.h"
00024
00025 #undef DBGC_CLASS
00026 #define DBGC_CLASS DBGC_RPC_SRV
00027
00028
00029 #ifndef MAX_OPEN_POLS
00030 #define MAX_OPEN_POLS 1024
00031 #endif
00032
00033
00034
00035
00036
00037
00038 static BOOL is_samr_lsa_pipe(const char *pipe_name)
00039 {
00040 return (strstr(pipe_name, "samr") || strstr(pipe_name, "lsa"));
00041 }
00042
00043
00044
00045
00046
00047
00048 BOOL init_pipe_handle_list(pipes_struct *p, char *pipe_name)
00049 {
00050 pipes_struct *plist = get_first_internal_pipe();
00051 struct handle_list *hl = NULL;
00052
00053 for (plist = get_first_internal_pipe(); plist; plist = get_next_internal_pipe(plist)) {
00054 if (strequal( plist->name, pipe_name) ||
00055 (is_samr_lsa_pipe(plist->name) && is_samr_lsa_pipe(pipe_name))) {
00056 if (!plist->pipe_handles) {
00057 pstring msg;
00058 slprintf(msg, sizeof(msg)-1, "init_pipe_handles: NULL pipe_handle pointer in pipe %s",
00059 pipe_name );
00060 smb_panic(msg);
00061 }
00062 hl = plist->pipe_handles;
00063 break;
00064 }
00065 }
00066
00067 if (!hl) {
00068
00069
00070
00071
00072
00073 if ((hl = SMB_MALLOC_P(struct handle_list)) == NULL)
00074 return False;
00075 ZERO_STRUCTP(hl);
00076
00077 DEBUG(10,("init_pipe_handles: created handle list for pipe %s\n", pipe_name ));
00078 }
00079
00080
00081
00082
00083
00084 hl->pipe_ref_count++;
00085
00086
00087
00088
00089
00090 p->pipe_handles = hl;
00091
00092 DEBUG(10,("init_pipe_handles: pipe_handles ref count = %lu for pipe %s\n",
00093 (unsigned long)p->pipe_handles->pipe_ref_count, pipe_name ));
00094
00095 return True;
00096 }
00097
00098
00099
00100
00101
00102 BOOL create_policy_hnd(pipes_struct *p, POLICY_HND *hnd, void (*free_fn)(void *), void *data_ptr)
00103 {
00104 static uint32 pol_hnd_low = 0;
00105 static uint32 pol_hnd_high = 0;
00106 time_t t = time(NULL);
00107
00108 struct policy *pol;
00109
00110 if (p->pipe_handles->count > MAX_OPEN_POLS) {
00111 DEBUG(0,("create_policy_hnd: ERROR: too many handles (%d) on this pipe.\n",
00112 (int)p->pipe_handles->count));
00113 return False;
00114 }
00115
00116 pol = SMB_MALLOC_P(struct policy);
00117 if (!pol) {
00118 DEBUG(0,("create_policy_hnd: ERROR: out of memory!\n"));
00119 return False;
00120 }
00121
00122 ZERO_STRUCTP(pol);
00123
00124 pol->data_ptr = data_ptr;
00125 pol->free_fn = free_fn;
00126
00127 pol_hnd_low++;
00128 if (pol_hnd_low == 0)
00129 (pol_hnd_high)++;
00130
00131 SIVAL(&pol->pol_hnd.handle_type, 0 , 0);
00132 SIVAL(&pol->pol_hnd.uuid.time_low, 0 , pol_hnd_low );
00133 SSVAL(&pol->pol_hnd.uuid.time_mid, 0 , pol_hnd_high);
00134 SSVAL(&pol->pol_hnd.uuid.time_hi_and_version, 0 , (pol_hnd_high>>16));
00135
00136
00137
00138 SSVAL(pol->pol_hnd.uuid.clock_seq, 0, (t>>16));
00139 SSVAL(pol->pol_hnd.uuid.node, 0, t);
00140
00141 SIVAL(pol->pol_hnd.uuid.node, 2, sys_getpid());
00142
00143 DLIST_ADD(p->pipe_handles->Policy, pol);
00144 p->pipe_handles->count++;
00145
00146 *hnd = pol->pol_hnd;
00147
00148 DEBUG(4,("Opened policy hnd[%d] ", (int)p->pipe_handles->count));
00149 dump_data(4, (char *)hnd, sizeof(*hnd));
00150
00151 return True;
00152 }
00153
00154
00155
00156
00157
00158 static struct policy *find_policy_by_hnd_internal(pipes_struct *p, POLICY_HND *hnd, void **data_p)
00159 {
00160 struct policy *pol;
00161 size_t i;
00162
00163 if (data_p)
00164 *data_p = NULL;
00165
00166 for (i = 0, pol=p->pipe_handles->Policy;pol;pol=pol->next, i++) {
00167 if (memcmp(&pol->pol_hnd, hnd, sizeof(*hnd)) == 0) {
00168 DEBUG(4,("Found policy hnd[%d] ", (int)i));
00169 dump_data(4, (char *)hnd, sizeof(*hnd));
00170 if (data_p)
00171 *data_p = pol->data_ptr;
00172 return pol;
00173 }
00174 }
00175
00176 DEBUG(4,("Policy not found: "));
00177 dump_data(4, (char *)hnd, sizeof(*hnd));
00178
00179 p->bad_handle_fault_state = True;
00180
00181 return NULL;
00182 }
00183
00184
00185
00186
00187
00188 BOOL find_policy_by_hnd(pipes_struct *p, POLICY_HND *hnd, void **data_p)
00189 {
00190 return find_policy_by_hnd_internal(p, hnd, data_p) == NULL ? False : True;
00191 }
00192
00193
00194
00195
00196
00197 BOOL close_policy_hnd(pipes_struct *p, POLICY_HND *hnd)
00198 {
00199 struct policy *pol = find_policy_by_hnd_internal(p, hnd, NULL);
00200
00201 if (!pol) {
00202 DEBUG(3,("Error closing policy\n"));
00203 return False;
00204 }
00205
00206 DEBUG(3,("Closed policy\n"));
00207
00208 if (pol->free_fn && pol->data_ptr)
00209 (*pol->free_fn)(pol->data_ptr);
00210
00211 p->pipe_handles->count--;
00212
00213 DLIST_REMOVE(p->pipe_handles->Policy, pol);
00214
00215 ZERO_STRUCTP(pol);
00216
00217 SAFE_FREE(pol);
00218
00219 return True;
00220 }
00221
00222
00223
00224
00225
00226 void close_policy_by_pipe(pipes_struct *p)
00227 {
00228 p->pipe_handles->pipe_ref_count--;
00229
00230 if (p->pipe_handles->pipe_ref_count == 0) {
00231
00232
00233
00234 while (p->pipe_handles->Policy)
00235 close_policy_hnd(p, &p->pipe_handles->Policy->pol_hnd);
00236
00237 p->pipe_handles->Policy = NULL;
00238 p->pipe_handles->count = 0;
00239
00240 SAFE_FREE(p->pipe_handles);
00241 DEBUG(10,("close_policy_by_pipe: deleted handle list for pipe %s\n", p->name ));
00242 }
00243 }
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253 BOOL pipe_access_check(pipes_struct *p)
00254 {
00255
00256
00257
00258 if (lp_restrict_anonymous() > 0) {
00259 user_struct *user = get_valid_user_struct(p->vuid);
00260
00261
00262 if (p->pipe_bound && (p->auth.auth_type == PIPE_AUTH_TYPE_SCHANNEL)) {
00263 return True;
00264 }
00265
00266 if (!user) {
00267 DEBUG(3, ("invalid vuid %d\n", p->vuid));
00268 return False;
00269 }
00270
00271 if (user->guest) {
00272 return False;
00273 }
00274 }
00275
00276 return True;
00277 }