home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / samba-1.9.18p7.tar.gz / samba-1.9.18p7.tar / samba-1.9.18p7 / source / rpc_pipes / lsa_hnd.c next >
C/C++ Source or Header  |  1997-11-06  |  7KB  |  266 lines

  1.  
  2. /* 
  3.  *  Unix SMB/Netbios implementation.
  4.  *  Version 1.9.
  5.  *  RPC Pipe client / server routines
  6.  *  Copyright (C) Andrew Tridgell              1992-1997,
  7.  *  Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
  8.  *  
  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.
  13.  *  
  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.
  18.  *  
  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.
  22.  */
  23.  
  24.  
  25. #include "../includes.h"
  26.  
  27.  
  28. #ifdef NTDOMAIN
  29.  
  30. extern int DEBUGLEVEL;
  31.  
  32. #ifndef MAX_OPEN_POLS
  33. #define MAX_OPEN_POLS 50
  34. #endif
  35.  
  36. struct samr_info
  37. {
  38.     /* for use by the \PIPE\samr policy */
  39.     DOM_SID sid;
  40.     uint32 rid; /* relative id associated with the pol_hnd */
  41.     uint32 status; /* some sort of flag.  best to record it.  comes from opnum 0x39 */
  42. };
  43.  
  44. static struct
  45. {
  46.   BOOL open;
  47.   LSA_POL_HND pol_hnd;
  48.  
  49.   union
  50.   {
  51.     struct samr_info samr;
  52.  
  53.   } dev;
  54.  
  55. } Policy[MAX_OPEN_POLS];
  56.  
  57.  
  58. #define VALID_POL(pnum)   (((pnum) >= 0) && ((pnum) < MAX_OPEN_POLS))
  59. #define OPEN_POL(pnum)    (VALID_POL(pnum) && Policy[pnum].open)
  60.  
  61. /****************************************************************************
  62.   create a unique policy handle
  63. ****************************************************************************/
  64. static void create_pol_hnd(LSA_POL_HND *hnd)
  65. {
  66.     static uint32 pol_hnd_low  = 0;
  67.     static uint32 pol_hnd_high = 0;
  68.  
  69.     if (hnd == NULL) return;
  70.  
  71.     /* i severely doubt that pol_hnd_high will ever be non-zero... */
  72.     pol_hnd_low++;
  73.     if (pol_hnd_low == 0) pol_hnd_high++;
  74.  
  75.     SIVAL(hnd->data, 0 , 0x0);  /* first bit must be null */
  76.     SIVAL(hnd->data, 4 , pol_hnd_low ); /* second bit is incrementing */
  77.     SIVAL(hnd->data, 8 , pol_hnd_high); /* second bit is incrementing */
  78.     SIVAL(hnd->data, 12, time(NULL)); /* something random */
  79.     SIVAL(hnd->data, 16, getpid()); /* something more random */
  80. }
  81.  
  82. /****************************************************************************
  83.   initialise policy handle states...
  84. ****************************************************************************/
  85. void init_lsa_policy_hnd(void)
  86. {
  87.     int i;
  88.     for (i = 0; i < MAX_OPEN_POLS; i++)
  89.     {
  90.         Policy[i].open = False;
  91.     }
  92.  
  93.     return;
  94. }
  95.  
  96. /****************************************************************************
  97.   find first available policy slot.  creates a policy handle for you.
  98. ****************************************************************************/
  99. BOOL open_lsa_policy_hnd(LSA_POL_HND *hnd)
  100. {
  101.     int i;
  102.  
  103.     for (i = 0; i < MAX_OPEN_POLS; i++)
  104.     {
  105.         if (!Policy[i].open)
  106.         {
  107.             Policy[i].open = True;
  108.                 
  109.             create_pol_hnd(hnd);
  110.             memcpy(&(Policy[i].pol_hnd), hnd, sizeof(*hnd));
  111.  
  112.             DEBUG(4,("Opened policy hnd[%x] ", i));
  113.             dump_data(4, hnd->data, sizeof(hnd->data));
  114.  
  115.             return True;
  116.         }
  117.     }
  118.  
  119.     /* i love obscure error messages. */
  120. #if TERRY_PRATCHET_INTERESTING_TIMES
  121.     DEBUG(1,("+++ OUT OF CHEESE ERROR +++ REDO FROM START ... @?!*@@\n"));
  122. #else
  123.     DEBUG(1,("ERROR - open_lsa_policy_hnd: out of Policy Handles!\n"));
  124. #endif
  125.  
  126.     return False;
  127. }
  128.  
  129. /****************************************************************************
  130.   find policy index by handle
  131. ****************************************************************************/
  132. static int find_lsa_policy_by_hnd(LSA_POL_HND *hnd)
  133. {
  134.     int i;
  135.  
  136.     for (i = 0; i < MAX_OPEN_POLS; i++)
  137.     {
  138.         if (memcmp(&(Policy[i].pol_hnd), hnd, sizeof(*hnd)) == 0)
  139.         {
  140.             DEBUG(4,("Found policy hnd[%x] ", i));
  141.             dump_data(4, hnd->data, sizeof(hnd->data));
  142.  
  143.             return i;
  144.         }
  145.     }
  146.  
  147.     DEBUG(4,("Policy not found: "));
  148.     dump_data(4, hnd->data, sizeof(hnd->data));
  149.  
  150.     return -1;
  151. }
  152.  
  153. /****************************************************************************
  154.   set samr rid
  155. ****************************************************************************/
  156. BOOL set_lsa_policy_samr_rid(LSA_POL_HND *hnd, uint32 rid)
  157. {
  158.     int pnum = find_lsa_policy_by_hnd(hnd);
  159.  
  160.     if (OPEN_POL(pnum))
  161.     {
  162.         DEBUG(3,("%s Setting policy device rid=%x pnum=%x\n",
  163.                   timestring(), rid, pnum));
  164.  
  165.         Policy[pnum].dev.samr.rid = rid;
  166.         return True;
  167.     }
  168.     else
  169.     {
  170.         DEBUG(3,("%s Error setting policy rid=%x (pnum=%x)\n",
  171.                   timestring(), rid, pnum));
  172.         return False;
  173.     }
  174. }
  175.  
  176. /****************************************************************************
  177.   set samr pol status.  absolutely no idea what this is.
  178. ****************************************************************************/
  179. BOOL set_lsa_policy_samr_pol_status(LSA_POL_HND *hnd, uint32 pol_status)
  180. {
  181.     int pnum = find_lsa_policy_by_hnd(hnd);
  182.  
  183.     if (OPEN_POL(pnum))
  184.     {
  185.         DEBUG(3,("%s Setting policy status=%x pnum=%x\n",
  186.                   timestring(), pol_status, pnum));
  187.  
  188.         Policy[pnum].dev.samr.status = pol_status;
  189.         return True;
  190.     }
  191.     else
  192.     {
  193.         DEBUG(3,("%s Error setting policy status=%x (pnum=%x)\n",
  194.                   timestring(), pol_status, pnum));
  195.         return False;
  196.     }
  197. }
  198.  
  199. /****************************************************************************
  200.   set samr sid
  201. ****************************************************************************/
  202. BOOL set_lsa_policy_samr_sid(LSA_POL_HND *hnd, DOM_SID *sid)
  203. {
  204.     int pnum = find_lsa_policy_by_hnd(hnd);
  205.  
  206.     if (OPEN_POL(pnum))
  207.     {
  208.         DEBUG(3,("%s Setting policy sid=%s pnum=%x\n",
  209.                   timestring(), dom_sid_to_string(sid), pnum));
  210.  
  211.         memcpy(&(Policy[pnum].dev.samr.sid), sid, sizeof(*sid));
  212.         return True;
  213.     }
  214.     else
  215.     {
  216.         DEBUG(3,("%s Error setting policy sid=%s (pnum=%x)\n",
  217.                   timestring(), dom_sid_to_string(sid), pnum));
  218.         return False;
  219.     }
  220. }
  221.  
  222. /****************************************************************************
  223.   set samr rid
  224. ****************************************************************************/
  225. uint32 get_lsa_policy_samr_rid(LSA_POL_HND *hnd)
  226. {
  227.     int pnum = find_lsa_policy_by_hnd(hnd);
  228.  
  229.     if (OPEN_POL(pnum))
  230.     {
  231.         uint32 rid = Policy[pnum].dev.samr.rid;
  232.         DEBUG(3,("%s Getting policy device rid=%x pnum=%x\n",
  233.                   timestring(), rid, pnum));
  234.  
  235.         return rid;
  236.     }
  237.     else
  238.     {
  239.         DEBUG(3,("%s Error getting policy (pnum=%x)\n",
  240.                   timestring(), pnum));
  241.         return 0xffffffff;
  242.     }
  243. }
  244.  
  245. /****************************************************************************
  246.   close an lsa policy
  247. ****************************************************************************/
  248. BOOL close_lsa_policy_hnd(LSA_POL_HND *hnd)
  249. {
  250.     int pnum = find_lsa_policy_by_hnd(hnd);
  251.  
  252.     if (OPEN_POL(pnum))
  253.     {
  254.         DEBUG(3,("%s Closed policy name pnum=%x\n", timestring(), pnum));
  255.         Policy[pnum].open = False;
  256.         return True;
  257.     }
  258.     else
  259.     {
  260.         DEBUG(3,("%s Error closing policy pnum=%x\n", timestring(), pnum));
  261.         return False;
  262.     }
  263. }
  264.  
  265. #endif
  266.