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 50
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 */
55 struct samr_info samr;
60 } Policy[MAX_OPEN_POLS];
63 #define VALID_POL(pnum) (((pnum) >= 0) && ((pnum) < MAX_OPEN_POLS))
64 #define OPEN_POL(pnum) (VALID_POL(pnum) && Policy[pnum].open)
66 /****************************************************************************
67 create a unique policy handle
68 ****************************************************************************/
69 void create_pol_hnd(POLICY_HND *hnd)
71 static uint32 pol_hnd_low = 0;
72 static uint32 pol_hnd_high = 0;
74 if (hnd == NULL) return;
76 /* i severely doubt that pol_hnd_high will ever be non-zero... */
78 if (pol_hnd_low == 0) pol_hnd_high++;
80 SIVAL(hnd->data, 0 , 0x0); /* first bit must be null */
81 SIVAL(hnd->data, 4 , pol_hnd_low ); /* second bit is incrementing */
82 SIVAL(hnd->data, 8 , pol_hnd_high); /* second bit is incrementing */
83 SIVAL(hnd->data, 12, time(NULL)); /* something random */
84 SIVAL(hnd->data, 16, getpid()); /* something more random */
87 /****************************************************************************
88 initialise policy handle states...
89 ****************************************************************************/
90 void init_lsa_policy_hnd(void)
93 for (i = 0; i < MAX_OPEN_POLS; i++)
95 Policy[i].open = False;
101 /****************************************************************************
102 find first available policy slot. creates a policy handle for you.
103 ****************************************************************************/
104 BOOL open_lsa_policy_hnd(POLICY_HND *hnd)
108 for (i = 0; i < MAX_OPEN_POLS; i++)
112 Policy[i].open = True;
115 memcpy(&(Policy[i].pol_hnd), hnd, sizeof(*hnd));
117 DEBUG(4,("Opened policy hnd[%x] ", i));
118 dump_data(4, hnd->data, sizeof(hnd->data));
124 /* i love obscure error messages. */
125 #if TERRY_PRATCHET_INTERESTING_TIMES
126 DEBUG(1,("+++ OUT OF CHEESE ERROR +++ REDO FROM START ... @?!*@@\n"));
128 DEBUG(1,("ERROR - open_lsa_policy_hnd: out of Policy Handles!\n"));
134 /****************************************************************************
135 find policy index by handle
136 ****************************************************************************/
137 int find_lsa_policy_by_hnd(POLICY_HND *hnd)
141 for (i = 0; i < MAX_OPEN_POLS; i++)
143 if (memcmp(&(Policy[i].pol_hnd), hnd, sizeof(*hnd)) == 0)
145 DEBUG(4,("Found policy hnd[%x] ", i));
146 dump_data(4, hnd->data, sizeof(hnd->data));
152 DEBUG(4,("Policy not found: "));
153 dump_data(4, hnd->data, sizeof(hnd->data));
158 /****************************************************************************
160 ****************************************************************************/
161 BOOL set_lsa_policy_samr_rid(POLICY_HND *hnd, uint32 rid)
163 int pnum = find_lsa_policy_by_hnd(hnd);
167 DEBUG(3,("%s Setting policy device rid=%x pnum=%x\n",
168 timestring(), rid, pnum));
170 Policy[pnum].dev.samr.rid = rid;
175 DEBUG(3,("%s Error setting policy rid=%x (pnum=%x)\n",
176 timestring(), rid, pnum));
181 /****************************************************************************
182 set samr pol status. absolutely no idea what this is.
183 ****************************************************************************/
184 BOOL set_lsa_policy_samr_pol_status(POLICY_HND *hnd, uint32 pol_status)
186 int pnum = find_lsa_policy_by_hnd(hnd);
190 DEBUG(3,("%s Setting policy status=%x pnum=%x\n",
191 timestring(), pol_status, pnum));
193 Policy[pnum].dev.samr.status = pol_status;
198 DEBUG(3,("%s Error setting policy status=%x (pnum=%x)\n",
199 timestring(), pol_status, pnum));
204 /****************************************************************************
206 ****************************************************************************/
207 BOOL set_lsa_policy_samr_sid(POLICY_HND *hnd, DOM_SID *sid)
209 int pnum = find_lsa_policy_by_hnd(hnd);
213 DEBUG(3,("%s Setting policy sid=%s pnum=%x\n",
214 timestring(), dom_sid_to_string(sid), pnum));
216 memcpy(&(Policy[pnum].dev.samr.sid), sid, sizeof(*sid));
221 DEBUG(3,("%s Error setting policy sid=%s (pnum=%x)\n",
222 timestring(), dom_sid_to_string(sid), pnum));
227 /****************************************************************************
229 ****************************************************************************/
230 uint32 get_lsa_policy_samr_rid(POLICY_HND *hnd)
232 int pnum = find_lsa_policy_by_hnd(hnd);
236 uint32 rid = Policy[pnum].dev.samr.rid;
237 DEBUG(3,("%s Getting policy device rid=%x pnum=%x\n",
238 timestring(), rid, pnum));
244 DEBUG(3,("%s Error getting policy (pnum=%x)\n",
245 timestring(), pnum));
250 /****************************************************************************
252 ****************************************************************************/
253 BOOL set_lsa_policy_reg_name(POLICY_HND *hnd, fstring name)
255 int pnum = find_lsa_policy_by_hnd(hnd);
259 DEBUG(3,("%s Setting policy pnum=%x name=%s\n",
260 timestring(), pnum, name));
262 fstrcpy(Policy[pnum].dev.reg.name, name);
267 DEBUG(3,("%s Error setting policy (pnum=%x) name=%s\n",
268 timestring(), pnum, name));
273 /****************************************************************************
275 ****************************************************************************/
276 BOOL get_lsa_policy_reg_name(POLICY_HND *hnd, fstring name)
278 int pnum = find_lsa_policy_by_hnd(hnd);
282 fstrcpy(name, Policy[pnum].dev.reg.name);
284 DEBUG(3,("%s Getting policy pnum=%x name=%s\n",
285 timestring(), pnum, name));
291 DEBUG(3,("%s Error getting policy (pnum=%x)\n",
292 timestring(), pnum));
297 /****************************************************************************
299 ****************************************************************************/
300 BOOL close_lsa_policy_hnd(POLICY_HND *hnd)
302 int pnum = find_lsa_policy_by_hnd(hnd);
306 DEBUG(3,("%s Closed policy name pnum=%x\n", timestring(), pnum));
307 Policy[pnum].open = False;
312 DEBUG(3,("%s Error closing policy pnum=%x\n", timestring(), pnum));