3 * Unix SMB/Netbios implementation.
5 * RPC Pipe client / server routines
6 * Copyright (C) Andrew Tridgell 1992-1997,
7 * Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program 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
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 extern int DEBUGLEVEL;
31 #define MAX_OPEN_POLS 64
36 /* for use by \PIPE\winreg */
37 fstring name; /* name of registry key */
42 /* for use by the \PIPE\samr policy */
44 uint32 rid; /* relative id associated with the pol_hnd */
45 uint32 status; /* some sort of flag. best to record it. comes from opnum 0x39 */
50 struct policy *next, *prev;
56 struct samr_info samr;
61 static struct bitmap *bmap;
64 /****************************************************************************
65 create a unique policy handle
66 ****************************************************************************/
67 static void create_pol_hnd(POLICY_HND *hnd)
69 static uint32 pol_hnd_low = 0;
70 static uint32 pol_hnd_high = 0;
72 if (hnd == NULL) return;
74 /* i severely doubt that pol_hnd_high will ever be non-zero... */
76 if (pol_hnd_low == 0) pol_hnd_high++;
78 SIVAL(hnd->data, 0 , 0x0); /* first bit must be null */
79 SIVAL(hnd->data, 4 , pol_hnd_low ); /* second bit is incrementing */
80 SIVAL(hnd->data, 8 , pol_hnd_high); /* second bit is incrementing */
81 SIVAL(hnd->data, 12, time(NULL)); /* something random */
82 SIVAL(hnd->data, 16, getpid()); /* something more random */
85 /****************************************************************************
86 initialise policy handle states...
87 ****************************************************************************/
88 void init_lsa_policy_hnd(void)
90 bmap = bitmap_allocate(MAX_OPEN_POLS);
92 exit_server("out of memory in init_lsa_policy_hnd\n");
96 /****************************************************************************
97 find first available policy slot. creates a policy handle for you.
98 ****************************************************************************/
99 BOOL open_lsa_policy_hnd(POLICY_HND *hnd)
104 i = bitmap_find(bmap, 1);
107 DEBUG(0,("ERROR: out of Policy Handles!\n"));
111 p = (struct policy *)malloc(sizeof(*p));
113 DEBUG(0,("ERROR: out of memory!\n"));
123 memcpy(&p->pol_hnd, hnd, sizeof(*hnd));
127 DLIST_ADD(Policy, p);
129 DEBUG(4,("Opened policy hnd[%x] ", i));
130 dump_data(4, (char *)hnd->data, sizeof(hnd->data));
135 /****************************************************************************
136 find policy by handle
137 ****************************************************************************/
138 static struct policy *find_lsa_policy(POLICY_HND *hnd)
142 for (p=Policy;p;p=p->next) {
143 if (memcmp(&p->pol_hnd, hnd, sizeof(*hnd)) == 0) {
144 DEBUG(4,("Found policy hnd[%x] ", p->pnum));
145 dump_data(4, (char *)hnd->data, sizeof(hnd->data));
150 DEBUG(4,("Policy not found: "));
151 dump_data(4, (char *)hnd->data, sizeof(hnd->data));
156 /****************************************************************************
157 find policy index by handle
158 ****************************************************************************/
159 int find_lsa_policy_by_hnd(POLICY_HND *hnd)
161 struct policy *p = find_lsa_policy(hnd);
166 /****************************************************************************
168 ****************************************************************************/
169 BOOL set_lsa_policy_samr_rid(POLICY_HND *hnd, uint32 rid)
171 struct policy *p = find_lsa_policy(hnd);
174 DEBUG(3,("Setting policy device rid=%x pnum=%x\n",
177 p->dev.samr.rid = rid;
181 DEBUG(3,("Error setting policy rid=%x\n",rid));
186 /****************************************************************************
187 set samr pol status. absolutely no idea what this is.
188 ****************************************************************************/
189 BOOL set_lsa_policy_samr_pol_status(POLICY_HND *hnd, uint32 pol_status)
191 struct policy *p = find_lsa_policy(hnd);
194 DEBUG(3,("Setting policy status=%x pnum=%x\n",
195 pol_status, p->pnum));
197 p->dev.samr.status = pol_status;
201 DEBUG(3,("Error setting policy status=%x\n",
206 /****************************************************************************
208 ****************************************************************************/
209 BOOL set_lsa_policy_samr_sid(POLICY_HND *hnd, DOM_SID *sid)
212 struct policy *p = find_lsa_policy(hnd);
215 DEBUG(3,("Setting policy sid=%s pnum=%x\n",
216 sid_to_string(sidstr, sid), p->pnum));
218 memcpy(&p->dev.samr.sid, sid, sizeof(*sid));
222 DEBUG(3,("Error setting policy sid=%s\n",
223 sid_to_string(sidstr, sid)));
227 /****************************************************************************
229 ****************************************************************************/
230 uint32 get_lsa_policy_samr_rid(POLICY_HND *hnd)
232 struct policy *p = find_lsa_policy(hnd);
235 uint32 rid = p->dev.samr.rid;
236 DEBUG(3,("Getting policy device rid=%x pnum=%x\n",
242 DEBUG(3,("Error getting policy\n"));
246 /****************************************************************************
248 ****************************************************************************/
249 BOOL set_lsa_policy_reg_name(POLICY_HND *hnd, fstring name)
251 struct policy *p = find_lsa_policy(hnd);
254 DEBUG(3,("Setting policy pnum=%x name=%s\n",
257 fstrcpy(p->dev.reg.name, name);
261 DEBUG(3,("Error setting policy name=%s\n", name));
265 /****************************************************************************
267 ****************************************************************************/
268 BOOL close_lsa_policy_hnd(POLICY_HND *hnd)
270 struct policy *p = find_lsa_policy(hnd);
273 DEBUG(3,("Error closing policy\n"));
277 DEBUG(3,("Closed policy name pnum=%x\n", p->pnum));
279 DLIST_REMOVE(Policy, p);
281 bitmap_clear(bmap, p->pnum);