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 / pipeutil.c < prev    next >
C/C++ Source or Header  |  1998-05-12  |  6KB  |  235 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.  *  Copyright (C) Paul Ashton                       1997.
  9.  *  
  10.  *  This program is free software; you can redistribute it and/or modify
  11.  *  it under the terms of the GNU General Public License as published by
  12.  *  the Free Software Foundation; either version 2 of the License, or
  13.  *  (at your option) any later version.
  14.  *  
  15.  *  This program is distributed in the hope that it will be useful,
  16.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  *  GNU General Public License for more details.
  19.  *  
  20.  *  You should have received a copy of the GNU General Public License
  21.  *  along with this program; if not, write to the Free Software
  22.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  */
  24.  
  25.  
  26. #include "../includes.h"
  27. #include "../trans2.h"
  28.  
  29. extern int DEBUGLEVEL;
  30.  
  31.  
  32. #ifdef NTDOMAIN
  33.  
  34. /* this function is due to be replaced */
  35. void initrpcreply(char *inbuf, char *q)
  36. {
  37.     uint32 callid;
  38.  
  39.     SCVAL(q, 0, 5); q++; /* RPC version 5 */
  40.     SCVAL(q, 0, 0); q++; /* minor version 0 */
  41.     SCVAL(q, 0, 2); q++; /* RPC response packet */
  42.     SCVAL(q, 0, 3); q++; /* first frag + last frag */
  43.     RSIVAL(q, 0, 0x10000000); q += 4; /* packed data representation */
  44.     RSSVAL(q, 0, 0); q += 2; /* fragment length, fill in later */
  45.     SSVAL(q, 0, 0); q += 2; /* authentication length */
  46.     callid = RIVAL(inbuf, 12);
  47.     RSIVAL(q, 0, callid); q += 4; /* call identifier - match incoming RPC */
  48.     SIVAL(q, 0, 0x18); q += 4; /* allocation hint (no idea) */
  49.     SSVAL(q, 0, 0); q += 2; /* presentation context identifier */
  50.     SCVAL(q, 0, 0); q++; /* cancel count */
  51.     SCVAL(q, 0, 0); q++; /* reserved */
  52. }
  53.  
  54. /* this function is due to be replaced */
  55. void endrpcreply(char *inbuf, char *q, int datalen, int rtnval, int *rlen)
  56. {
  57.     SSVAL(q, 8, datalen + 4);
  58.     SIVAL(q,0x10,datalen+4-0x18); /* allocation hint */
  59.     SIVAL(q, datalen, rtnval);
  60.     *rlen = datalen + 4;
  61. }
  62.  
  63. /* Group and User RID username mapping function */
  64. BOOL name_to_rid(char *user_name, uint32 *u_rid, uint32 *g_rid)
  65. {
  66.     struct passwd *pw = Get_Pwnam(user_name, False);
  67.  
  68.     if (u_rid == NULL || g_rid == NULL || user_name == NULL)
  69.     {
  70.         return False;
  71.     }
  72.  
  73.     if (!pw)
  74.     {
  75.       DEBUG(1,("Username %s is invalid on this system\n", user_name));
  76.       return False;
  77.     }
  78.  
  79.     if (user_in_list(user_name, lp_domain_guest_users()))
  80.     {
  81.         *u_rid = DOMAIN_USER_RID_GUEST;
  82.     }
  83.     else if (user_in_list(user_name, lp_domain_admin_users()))
  84.     {
  85.         *u_rid = DOMAIN_USER_RID_ADMIN;
  86.     }
  87.     else
  88.     {
  89.         /* turn the unix UID into a Domain RID.  this is what the posix
  90.            sub-system does (adds 1000 to the uid) */
  91.         *u_rid = (uint32)(pw->pw_uid + 1000);
  92.     }
  93.  
  94.     /* absolutely no idea what to do about the unix GID to Domain RID mapping */
  95.     *g_rid = (uint32)(pw->pw_gid + 1000);
  96.  
  97.     return True;
  98. }
  99.  
  100.  
  101. /* BIG NOTE: this function only does SIDS where the identauth is not >= 2^32 */
  102. char *dom_sid_to_string(DOM_SID *sid)
  103. {
  104.   static pstring sidstr;
  105.   char subauth[16];
  106.   int i;
  107.   uint32 ia = (sid->id_auth[5]) +
  108.               (sid->id_auth[4] << 8 ) +
  109.               (sid->id_auth[3] << 16) +
  110.               (sid->id_auth[2] << 24);
  111.  
  112.   slprintf(sidstr, sizeof(sidstr) -1, "S-%d-%d", sid->sid_rev_num, ia);
  113.  
  114.   for (i = 0; i < sid->num_auths; i++)
  115.   {
  116.     slprintf(subauth, sizeof(subauth)-1, "-%d", sid->sub_auths[i]);
  117.     pstrcat(sidstr, subauth);
  118.   }
  119.  
  120.   DEBUG(5,("dom_sid_to_string returning %s\n", sidstr));
  121.   return sidstr;
  122. }
  123.  
  124. int make_dom_sids(char *sids_str, DOM_SID *sids, int max_sids)
  125. {
  126.     char *ptr;
  127.     pstring s2;
  128.     int count;
  129.  
  130.     DEBUG(4,("make_dom_sids: %s\n", sids_str));
  131.  
  132.     if (sids_str == NULL || *sids_str == 0) return 0;
  133.  
  134.     for (count = 0, ptr = sids_str; next_token(&ptr, s2, NULL) && count < max_sids; count++) 
  135.     {
  136.         make_dom_sid(&sids[count], s2);
  137.     }
  138.  
  139.     return count;
  140. }
  141.  
  142. /* array lookup of well-known RID aliases.  the purpose of these escapes me.. */
  143. /* XXXX this structure should not have the well-known RID groups added to it,
  144.    i.e the DOMAIN_GROUP_RID_ADMIN/USER/GUEST.  */
  145. static struct
  146. {
  147.     uint32 rid;
  148.     char   *rid_name;
  149.  
  150. } rid_lookups[] = 
  151. {
  152.     { DOMAIN_ALIAS_RID_ADMINS       , "admins" },
  153.     { DOMAIN_ALIAS_RID_USERS        , "users" },
  154.     { DOMAIN_ALIAS_RID_GUESTS       , "guests" },
  155.     { DOMAIN_ALIAS_RID_POWER_USERS  , "power_users" },
  156.  
  157.     { DOMAIN_ALIAS_RID_ACCOUNT_OPS  , "account_ops" },
  158.     { DOMAIN_ALIAS_RID_SYSTEM_OPS   , "system_ops" },
  159.     { DOMAIN_ALIAS_RID_PRINT_OPS    , "print_ops" },
  160.     { DOMAIN_ALIAS_RID_BACKUP_OPS   , "backup_ops" },
  161.     { DOMAIN_ALIAS_RID_REPLICATOR   , "replicator" },
  162.     { 0                             , NULL }
  163. };
  164.  
  165. int make_dom_gids(char *gids_str, DOM_GID *gids)
  166. {
  167.     char *ptr;
  168.     pstring s2;
  169.     int count;
  170.  
  171.     DEBUG(4,("make_dom_gids: %s\n", gids_str));
  172.  
  173.     if (gids_str == NULL || *gids_str == 0) return 0;
  174.  
  175.     for (count = 0, ptr = gids_str; next_token(&ptr, s2, NULL) && count < LSA_MAX_GROUPS; count++) 
  176.     {
  177.         /* the entries are of the form GID/ATTR, ATTR being optional.*/
  178.         char *attr;
  179.         uint32 rid = 0;
  180.         int i;
  181.  
  182.         attr = strchr(s2,'/');
  183.         if (attr) *attr++ = 0;
  184.         if (!attr || !*attr) attr = "7"; /* default value for attribute is 7 */
  185.  
  186.         /* look up the RID string and see if we can turn it into a rid number */
  187.         for (i = 0; rid_lookups[i].rid_name != NULL; i++)
  188.         {
  189.             if (strequal(rid_lookups[i].rid_name, s2))
  190.             {
  191.                 rid = rid_lookups[i].rid;
  192.                 break;
  193.             }
  194.         }
  195.  
  196.         if (rid == 0) rid = atoi(s2);
  197.  
  198.         if (rid == 0)
  199.         {
  200.             DEBUG(1,("make_dom_gids: unknown well-known alias RID %s/%s\n",
  201.                       s2, attr));
  202.             count--;
  203.         }
  204.         else
  205.         {
  206.             gids[count].g_rid = rid;
  207.             gids[count].attr  = atoi(attr);
  208.  
  209.             DEBUG(5,("group id: %d attr: %d\n",
  210.                       gids[count].g_rid,
  211.                       gids[count].attr));
  212.         }
  213.     }
  214.  
  215.     return count;
  216. }
  217.  
  218. int create_rpc_request(uint32 call_id, uint8 op_num, char *q, int data_len)
  219. {
  220.     RPC_HDR_RR hdr;
  221.  
  222.     make_rpc_hdr_rr(&hdr, RPC_REQUEST, call_id, data_len, op_num);
  223.     return smb_io_rpc_hdr_rr(False, &hdr, q, q, 4, 0) - q;
  224. }
  225.  
  226. int create_rpc_reply(uint32 call_id, char *q, int data_len)
  227. {
  228.     RPC_HDR_RR hdr;
  229.  
  230.     make_rpc_hdr_rr(&hdr, RPC_RESPONSE, call_id, data_len, 0);
  231.     return smb_io_rpc_hdr_rr(False, &hdr, q, q, 4, 0) - q;
  232. }
  233.  
  234. #endif
  235.