first pass at updating head branch to be to be the same as the SAMBA_2_0 branch
[kai/samba.git] / source3 / rpc_server / srv_util.c
index 1ccd14c813d38c2938ef07c9b5c9264b254736aa..097ab92d76a2d4b072f74cb25e5b8f9946e2324d 100644 (file)
 
 extern int DEBUGLEVEL;
 
-/* array lookup of well-known RID aliases.  the purpose of these escapes me.. */
-/* XXXX this structure should not have the well-known RID groups added to it,
-   i.e the DOMAIN_GROUP_RID_ADMIN/USER/GUEST.  */
-rid_name domain_alias_rids[] = 
-{
-       { BUILTIN_ALIAS_RID_ADMINS       , "admins" },
-       { BUILTIN_ALIAS_RID_USERS        , "users" },
-       { BUILTIN_ALIAS_RID_GUESTS       , "guests" },
-       { BUILTIN_ALIAS_RID_POWER_USERS  , "power_users" },
-
-       { BUILTIN_ALIAS_RID_ACCOUNT_OPS  , "account_ops" },
-       { BUILTIN_ALIAS_RID_SYSTEM_OPS   , "system_ops" },
-       { BUILTIN_ALIAS_RID_PRINT_OPS    , "print_ops" },
-       { BUILTIN_ALIAS_RID_BACKUP_OPS   , "backup_ops" },
-       { BUILTIN_ALIAS_RID_REPLICATOR   , "replicator" },
-       { 0                             , NULL }
+/*
+ * A list of the rids of well known BUILTIN and Domain users
+ * and groups.
+ */
+
+rid_name builtin_alias_rids[] =
+{  
+    { BUILTIN_ALIAS_RID_ADMINS       , "Administrators" },
+    { BUILTIN_ALIAS_RID_USERS        , "Users" },
+    { BUILTIN_ALIAS_RID_GUESTS       , "Guests" },
+    { BUILTIN_ALIAS_RID_POWER_USERS  , "Power Users" },
+   
+    { BUILTIN_ALIAS_RID_ACCOUNT_OPS  , "Account Operators" },
+    { BUILTIN_ALIAS_RID_SYSTEM_OPS   , "System Operators" },
+    { BUILTIN_ALIAS_RID_PRINT_OPS    , "Print Operators" },
+    { BUILTIN_ALIAS_RID_BACKUP_OPS   , "Backup Operators" },
+    { BUILTIN_ALIAS_RID_REPLICATOR   , "Replicator" },
+    { 0                             , NULL }
 };
 
 /* array lookup of well-known Domain RID users. */
-rid_name domain_user_rids[] = 
-{
-       { DOMAIN_USER_RID_ADMIN         , "Administrator" },
-       { DOMAIN_USER_RID_GUEST         , "Guest" },
-       { 0                             , NULL }
+rid_name domain_user_rids[] =
+{  
+    { DOMAIN_USER_RID_ADMIN         , "Administrator" },
+    { DOMAIN_USER_RID_GUEST         , "Guest" },
+    { 0                             , NULL }
 };
 
 /* array lookup of well-known Domain RID groups. */
-rid_name domain_group_rids[] = 
-{
-       { DOMAIN_GROUP_RID_ADMINS       , "domain admins" },
-       { DOMAIN_GROUP_RID_USERS        , "domain users" },
-       { DOMAIN_GROUP_RID_GUESTS       , "domain guests" },
-       { 0                             , NULL }
+rid_name domain_group_rids[] =
+{  
+    { DOMAIN_GROUP_RID_ADMINS       , "Domain Admins" },
+    { DOMAIN_GROUP_RID_USERS        , "Domain Users" },
+    { DOMAIN_GROUP_RID_GUESTS       , "Domain Guests" },
+    { 0                             , NULL }
 };
 
-
 int make_dom_gids(char *gids_str, DOM_GID **ppgids)
 {
   char *ptr;
@@ -93,7 +94,9 @@ int make_dom_gids(char *gids_str, DOM_GID **ppgids)
   if (gids_str == NULL || *gids_str == 0)
     return 0;
 
-  for (count = 0, ptr = gids_str; next_token(&ptr, s2, NULL); count++)
+  for (count = 0, ptr = gids_str; 
+       next_token(&ptr, s2, NULL, sizeof(s2)); 
+       count++)
     ;
 
   gids = (DOM_GID *)malloc( sizeof(DOM_GID) * count );
@@ -103,8 +106,10 @@ int make_dom_gids(char *gids_str, DOM_GID **ppgids)
     return 0;
   }
 
-  for (count = 0, ptr = gids_str; next_token(&ptr, s2, NULL) && 
-                       count < LSA_MAX_GROUPS; count++) 
+  for (count = 0, ptr = gids_str; 
+       next_token(&ptr, s2, NULL, sizeof(s2)) && 
+              count < LSA_MAX_GROUPS; 
+       count++) 
   {
     /* the entries are of the form GID/ATTR, ATTR being optional.*/
     char *attr;
@@ -119,11 +124,11 @@ int make_dom_gids(char *gids_str, DOM_GID **ppgids)
       attr = "7"; /* default value for attribute is 7 */
 
     /* look up the RID string and see if we can turn it into a rid number */
-    for (i = 0; domain_alias_rids[i].name != NULL; i++)
+    for (i = 0; builtin_alias_rids[i].name != NULL; i++)
     {
-      if (strequal(domain_alias_rids[i].name, s2))
+      if (strequal(builtin_alias_rids[i].name, s2))
       {
-        rid = domain_alias_rids[i].rid;
+        rid = builtin_alias_rids[i].rid;
         break;
       }
     }
@@ -149,155 +154,6 @@ int make_dom_gids(char *gids_str, DOM_GID **ppgids)
   return count;
 }
 
-/*******************************************************************
- turns a DCE/RPC request into a DCE/RPC reply
-
- this is where the data really should be split up into an array of
- headers and data sections.
-
- ********************************************************************/
-BOOL create_rpc_reply(pipes_struct *p,
-                               uint32 data_start, uint32 data_end)
-{
-       DEBUG(5,("create_rpc_reply: data_start: %d data_end: %d max_tsize: %d\n",
-                 data_start, data_end, p->hdr_ba.bba.max_tsize));
-
-       mem_buf_init(&(p->rhdr.data), 0);
-       mem_alloc_data(p->rhdr.data, 0x18);
-
-       p->rhdr.align = 4;
-       p->rhdr.io = False;
-
-       p->hdr_resp.alloc_hint = data_end - data_start; /* calculate remaining data to be sent */
-       p->hdr.pkt_type = RPC_RESPONSE; /* mark header as an rpc response */
-
-       /* set up rpc header (fragmentation issues) */
-       if (data_start == 0)
-       {
-               p->hdr.flags = RPC_FLG_FIRST;
-       }
-       else
-       {
-               p->hdr.flags = 0;
-       }
-
-       if (p->hdr_resp.alloc_hint + 0x18 <= p->hdr_ba.bba.max_tsize)
-       {
-               p->hdr.flags |= RPC_FLG_LAST;
-               p->hdr.frag_len = p->hdr_resp.alloc_hint + 0x18;
-       }
-       else
-       {
-               p->hdr.frag_len = p->hdr_ba.bba.max_tsize;
-       }
-
-       p->rhdr.data->offset.start = 0;
-       p->rhdr.data->offset.end   = 0x18;
-
-       /* store the header in the data stream */
-       p->rhdr.offset = 0;
-       smb_io_rpc_hdr   ("hdr", &(p->hdr   ), &(p->rhdr), 0);
-       smb_io_rpc_hdr_resp("resp", &(p->hdr_resp), &(p->rhdr), 0);
-
-       return p->rhdr.data != NULL && p->rhdr.offset == 0x18;
-}
-
-
-/*******************************************************************
- receives a netlogon pipe and responds.
- ********************************************************************/
-static BOOL api_rpc_command(pipes_struct *p, 
-                               char *rpc_name, struct api_struct *api_rpc_cmds,
-                               prs_struct *data)
-{
-       int fn_num;
-       DEBUG(4,("api_rpc_command: %s op 0x%x - ", rpc_name, p->hdr_req.opnum));
-
-       for (fn_num = 0; api_rpc_cmds[fn_num].name; fn_num++)
-       {
-               if (api_rpc_cmds[fn_num].opnum == p->hdr_req.opnum && api_rpc_cmds[fn_num].fn != NULL)
-               {
-                       DEBUG(3,("api_rpc_command: %s\n", api_rpc_cmds[fn_num].name));
-                       break;
-               }
-       }
-
-       if (api_rpc_cmds[fn_num].name == NULL)
-       {
-               DEBUG(4, ("unknown\n"));
-               return False;
-       }
-
-       /* start off with 1024 bytes, and a large safety margin too */
-       mem_buf_init(&(p->rdata.data), SAFETY_MARGIN);
-       mem_alloc_data(p->rdata.data, 1024);
-
-       p->rdata.io = False;
-       p->rdata.align = 4;
-
-       p->rdata.data->offset.start = 0;
-       p->rdata.data->offset.end   = 0xffffffff;
-
-       /* do the actual command */
-       p->rdata.offset = 0; 
-       api_rpc_cmds[fn_num].fn(p->uid, data, &(p->rdata));
-
-       if (p->rdata.data == NULL || p->rdata.offset == 0)
-       {
-               mem_free_data(p->rdata.data);
-               return False;
-       }
-
-       mem_realloc_data(p->rdata.data, p->rdata.offset);
-
-    DEBUG(10,("called %s\n", rpc_name));
-
-       return True;
-}
-
-
-/*******************************************************************
- receives a netlogon pipe and responds.
- ********************************************************************/
-BOOL api_rpcTNP(pipes_struct *p, char *rpc_name, struct api_struct *api_rpc_cmds,
-                               prs_struct *data)
-{
-       if (data == NULL || data->data == NULL)
-       {
-               DEBUG(2,("%s: NULL data received\n", rpc_name));
-               return False;
-       }
-
-       /* read the rpc header */
-       smb_io_rpc_hdr_req("req", &(p->hdr_req), data, 0);
-
-       /* interpret the command */
-       if (!api_rpc_command(p, rpc_name, api_rpc_cmds, data))
-       {
-               return False;
-       }
-
-       /* create the rpc header */
-       if (!create_rpc_reply(p, 0, p->rdata.offset))
-       {
-               return False;
-       }
-
-       p->frag_len_left   = p->hdr.frag_len - p->file_offset;
-       p->next_frag_start = p->hdr.frag_len; 
-       
-       /* set up the data chain */
-       p->rhdr.data->offset.start = 0;
-       p->rhdr.data->offset.end   = p->rhdr.offset;
-       p->rhdr.data->next = p->rdata.data;
-
-       p->rdata.data->offset.start = p->rhdr.data->offset.end;
-       p->rdata.data->offset.end   = p->rhdr.data->offset.end + p->rdata.offset;
-       p->rdata.data->next = NULL;
-
-       return True;
-}
-
 
 /*******************************************************************
  gets a domain user's groups
@@ -373,14 +229,14 @@ uint32 lookup_alias_name(uint32 rid, char *alias_name, uint32 *type)
 
        DEBUG(5,("lookup_alias_name: rid: %d", rid));
 
-       while (domain_alias_rids[i].rid != rid && domain_alias_rids[i].rid != 0)
+       while (builtin_alias_rids[i].rid != rid && builtin_alias_rids[i].rid != 0)
        {
                i++;
        }
 
-       if (domain_alias_rids[i].rid != 0)
+       if (builtin_alias_rids[i].rid != 0)
        {
-               fstrcpy(alias_name, domain_alias_rids[i].name);
+               fstrcpy(alias_name, builtin_alias_rids[i].name);
                DEBUG(5,(" = %s\n", alias_name));
                return 0x0;
        }
@@ -459,8 +315,8 @@ uint32 lookup_alias_rid(char *alias_name, uint32 *rid)
        do /* find, if it exists, a alias rid for the alias name*/
        {
                i++;
-               (*rid) = domain_alias_rids[i].rid;
-               als_name = domain_alias_rids[i].name;
+               (*rid) = builtin_alias_rids[i].rid;
+               als_name = builtin_alias_rids[i].name;
 
        } while (als_name != NULL && !strequal(als_name, alias_name));
 
@@ -472,18 +328,17 @@ uint32 lookup_alias_rid(char *alias_name, uint32 *rid)
  ********************************************************************/
 uint32 lookup_user_rid(char *user_name, uint32 *rid)
 {
-       struct smb_passwd *smb_pass;
+       struct sam_passwd *sam_pass;
        (*rid) = 0;
 
        /* find the user account */
        become_root(True);
-       smb_pass = getsmbpwnam(user_name);
+       sam_pass = getsam21pwnam(user_name);
        unbecome_root(True);
 
-       if (smb_pass != NULL)
+       if (sam_pass != NULL)
        {
-               /* lkclXXXX SHOULD use name_to_rid() here! */
-               (*rid) = smb_pass->smb_userid;
+               (*rid) = sam_pass->user_rid;
                return 0x0;
        }