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 / pipentlsa.c < prev    next >
C/C++ Source or Header  |  1997-11-04  |  13KB  |  462 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. #include "../nterr.h"
  29.  
  30. extern int DEBUGLEVEL;
  31.  
  32. #ifdef NTDOMAIN
  33.  
  34. /***************************************************************************
  35. lsa_reply_open_policy
  36.  ***************************************************************************/
  37. static int lsa_reply_open_policy(char *q, char *base)
  38. {
  39.     int i;
  40.     LSA_R_OPEN_POL r_o;
  41.  
  42.     /* set up the LSA QUERY INFO response */
  43.     bzero(&(r_o.pol.data), POL_HND_SIZE);
  44.     for (i = 4; i < POL_HND_SIZE; i++)
  45.     {
  46.         r_o.pol.data[i] = i;
  47.     }
  48.     r_o.status = 0x0;
  49.  
  50.     /* store the response in the SMB stream */
  51.     q = lsa_io_r_open_pol(False, &r_o, q, base, 4, 0);
  52.  
  53.     /* return length of SMB data stored */
  54.     return PTR_DIFF(q, base);
  55. }
  56.  
  57. /***************************************************************************
  58. make_dom_query
  59.  ***************************************************************************/
  60. static void make_dom_query(DOM_QUERY *d_q, char *dom_name, char *dom_sid)
  61. {
  62.     int domlen = strlen(dom_name);
  63.  
  64.     d_q->uni_dom_max_len = domlen * 2;
  65.     d_q->uni_dom_str_len = domlen * 2;
  66.  
  67.     d_q->buffer_dom_name = 4; /* domain buffer pointer */
  68.     d_q->buffer_dom_sid  = 2; /* domain sid pointer */
  69.  
  70.     /* this string is supposed to be character short */
  71.     make_unistr2(&(d_q->uni_domain_name), dom_name, domlen);
  72.  
  73.     make_dom_sid(&(d_q->dom_sid), dom_sid);
  74. }
  75.  
  76. /***************************************************************************
  77. lsa_reply_query_info
  78.  ***************************************************************************/
  79. static int lsa_reply_query_info(LSA_Q_QUERY_INFO *q_q, char *q, char *base,
  80.                 char *dom_name, char *dom_sid)
  81. {
  82.     LSA_R_QUERY_INFO r_q;
  83.  
  84.     /* set up the LSA QUERY INFO response */
  85.  
  86.     r_q.undoc_buffer = 0x22000000; /* bizarre */
  87.     r_q.info_class = q_q->info_class;
  88.  
  89.     make_dom_query(&r_q.dom.id5, dom_name, dom_sid);
  90.  
  91.     r_q.status = 0x0;
  92.  
  93.     /* store the response in the SMB stream */
  94.     q = lsa_io_r_query(False, &r_q, q, base, 4, 0);
  95.  
  96.     /* return length of SMB data stored */
  97.     return PTR_DIFF(q, base);
  98. }
  99.  
  100. /***************************************************************************
  101. make_dom_ref
  102.  
  103.  pretty much hard-coded choice of "other" sids, unfortunately...
  104.  
  105.  ***************************************************************************/
  106. static void make_dom_ref(DOM_R_REF *ref,
  107.                 char *dom_name, char *dom_sid,
  108.                 char *other_sid1, char *other_sid2, char *other_sid3)
  109. {
  110.     int len_dom_name   = strlen(dom_name);
  111.     int len_other_sid1 = strlen(other_sid1);
  112.     int len_other_sid2 = strlen(other_sid2);
  113.     int len_other_sid3 = strlen(other_sid3);
  114.  
  115.     ref->undoc_buffer = 1;
  116.     ref->num_ref_doms_1 = 4;
  117.     ref->buffer_dom_name = 1;
  118.     ref->max_entries = 32;
  119.     ref->num_ref_doms_2 = 4;
  120.  
  121.     make_uni_hdr2(&(ref->hdr_dom_name  ), len_dom_name  , len_dom_name  , 0);
  122.     make_uni_hdr2(&(ref->hdr_ref_dom[0]), len_other_sid1, len_other_sid1, 0);
  123.     make_uni_hdr2(&(ref->hdr_ref_dom[1]), len_other_sid2, len_other_sid2, 0);
  124.     make_uni_hdr2(&(ref->hdr_ref_dom[2]), len_other_sid3, len_other_sid3, 0);
  125.  
  126.     if (dom_name != NULL)
  127.     {
  128.         make_unistr(&(ref->uni_dom_name), dom_name);
  129.     }
  130.  
  131.     make_dom_sid(&(ref->ref_dom[0]), dom_sid   );
  132.     make_dom_sid(&(ref->ref_dom[1]), other_sid1);
  133.     make_dom_sid(&(ref->ref_dom[2]), other_sid2);
  134.     make_dom_sid(&(ref->ref_dom[3]), other_sid3);
  135. }
  136.  
  137. /***************************************************************************
  138. make_reply_lookup_rids
  139.  ***************************************************************************/
  140. static void make_reply_lookup_rids(LSA_R_LOOKUP_RIDS *r_l,
  141.                 int num_entries, uint32 dom_rids[MAX_LOOKUP_SIDS],
  142.                 char *dom_name, char *dom_sid,
  143.                 char *other_sid1, char *other_sid2, char *other_sid3)
  144. {
  145.     int i;
  146.  
  147.     make_dom_ref(&(r_l->dom_ref), dom_name, dom_sid,
  148.                  other_sid1, other_sid2, other_sid3);
  149.  
  150.     r_l->num_entries = num_entries;
  151.     r_l->undoc_buffer = 1;
  152.     r_l->num_entries2 = num_entries;
  153.  
  154.     for (i = 0; i < num_entries; i++)
  155.     {
  156.         make_dom_rid2(&(r_l->dom_rid[i]), dom_rids[i]);
  157.     }
  158.  
  159.     r_l->num_entries3 = num_entries;
  160. }
  161.  
  162. /***************************************************************************
  163. make_reply_lookup_sids
  164.  ***************************************************************************/
  165. static void make_reply_lookup_sids(LSA_R_LOOKUP_SIDS *r_l,
  166.                 int num_entries, fstring dom_sids[MAX_LOOKUP_SIDS],
  167.                 char *dom_name, char *dom_sid,
  168.                 char *other_sid1, char *other_sid2, char *other_sid3)
  169. {
  170.     int i;
  171.  
  172.     make_dom_ref(&(r_l->dom_ref), dom_name, dom_sid,
  173.                  other_sid1, other_sid2, other_sid3);
  174.  
  175.     r_l->num_entries = num_entries;
  176.     r_l->undoc_buffer = 1;
  177.     r_l->num_entries2 = num_entries;
  178.  
  179.     for (i = 0; i < num_entries; i++)
  180.     {
  181.         make_dom_sid2(&(r_l->dom_sid[i]), dom_sids[i]);
  182.     }
  183.  
  184.     r_l->num_entries3 = num_entries;
  185. }
  186.  
  187. /***************************************************************************
  188. lsa_reply_lookup_sids
  189.  ***************************************************************************/
  190. static int lsa_reply_lookup_sids(char *q, char *base,
  191.                 int num_entries, fstring dom_sids[MAX_LOOKUP_SIDS],
  192.                 char *dom_name, char *dom_sid,
  193.                 char *other_sid1, char *other_sid2, char *other_sid3)
  194. {
  195.     LSA_R_LOOKUP_SIDS r_l;
  196.  
  197.     /* set up the LSA Lookup SIDs response */
  198.     make_reply_lookup_sids(&r_l, num_entries, dom_sids,
  199.                 dom_name, dom_sid, other_sid1, other_sid2, other_sid3);
  200.     r_l.status = 0x0;
  201.  
  202.     /* store the response in the SMB stream */
  203.     q = lsa_io_r_lookup_sids(False, &r_l, q, base, 4, 0);
  204.  
  205.     /* return length of SMB data stored */
  206.     return PTR_DIFF(q, base);
  207. }
  208.  
  209. /***************************************************************************
  210. lsa_reply_lookup_rids
  211.  ***************************************************************************/
  212. static int lsa_reply_lookup_rids(char *q, char *base,
  213.                 int num_entries, uint32 dom_rids[MAX_LOOKUP_SIDS],
  214.                 char *dom_name, char *dom_sid,
  215.                 char *other_sid1, char *other_sid2, char *other_sid3)
  216. {
  217.     LSA_R_LOOKUP_RIDS r_l;
  218.  
  219.     /* set up the LSA Lookup RIDs response */
  220.     make_reply_lookup_rids(&r_l, num_entries, dom_rids,
  221.                 dom_name, dom_sid, other_sid1, other_sid2, other_sid3);
  222.     r_l.status = 0x0;
  223.  
  224.     /* store the response in the SMB stream */
  225.     q = lsa_io_r_lookup_rids(False, &r_l, q, base, 4, 0);
  226.  
  227.     /* return length of SMB data stored */
  228.     return PTR_DIFF(q, base);
  229. }
  230.  
  231. /***************************************************************************
  232. api_lsa_open_policy
  233.  ***************************************************************************/
  234. static void api_lsa_open_policy( char *param, char *data,
  235.                              char **rdata, int *rdata_len )
  236. {
  237.     LSA_Q_OPEN_POL q_o;
  238.  
  239.     /* grab the server, object attributes and desired access flag...*/
  240.     lsa_io_q_open_pol(True, &q_o, data + 0x18, data, 4, 0);
  241.  
  242.     /* lkclXXXX having decoded it, ignore all fields in the open policy! */
  243.  
  244.     /* return a 20 byte policy handle */
  245.     *rdata_len = lsa_reply_open_policy(*rdata + 0x18, *rdata);
  246. }
  247.  
  248. /***************************************************************************
  249. api_lsa_query_info
  250.  ***************************************************************************/
  251. static void api_lsa_query_info( char *param, char *data,
  252.                                 char **rdata, int *rdata_len )
  253. {
  254.     LSA_Q_QUERY_INFO q_i;
  255.     pstring dom_name;
  256.     pstring dom_sid;
  257.  
  258.     /* grab the info class and policy handle */
  259.     lsa_io_q_query(True, &q_i, data + 0x18, data, 4, 0);
  260.  
  261.     pstrcpy(dom_name, lp_workgroup());
  262.     pstrcpy(dom_sid , lp_domain_sid());
  263.  
  264.     /* construct reply.  return status is always 0x0 */
  265.     *rdata_len = lsa_reply_query_info(&q_i, *rdata + 0x18, *rdata, 
  266.                                      dom_name, dom_sid);
  267. }
  268.  
  269. /***************************************************************************
  270. api_lsa_lookup_sids
  271.  ***************************************************************************/
  272. static void api_lsa_lookup_sids( char *param, char *data,
  273.                                  char **rdata, int *rdata_len )
  274. {
  275.     int i;
  276.     LSA_Q_LOOKUP_SIDS q_l;
  277.     pstring dom_name;
  278.     pstring dom_sid;
  279.     fstring dom_sids[MAX_LOOKUP_SIDS];
  280.  
  281.     /* grab the info class and policy handle */
  282.     lsa_io_q_lookup_sids(True, &q_l, data + 0x18, data, 4, 0);
  283.  
  284.     pstrcpy(dom_name, lp_workgroup());
  285.     pstrcpy(dom_sid , lp_domain_sid());
  286.  
  287.     /* convert received SIDs to strings, so we can do them. */
  288.     for (i = 0; i < q_l.num_entries; i++)
  289.     {
  290.         fstrcpy(dom_sids[i], dom_sid_to_string(&(q_l.dom_sids[i])));
  291.     }
  292.  
  293.     /* construct reply.  return status is always 0x0 */
  294.     *rdata_len = lsa_reply_lookup_sids(*rdata + 0x18, *rdata,
  295.                 q_l.num_entries, dom_sids, /* text-converted SIDs */
  296.                 dom_name, dom_sid, /* domain name, domain SID */
  297.                 "S-1-1", "S-1-3", "S-1-5"); /* the three other SIDs */
  298. }
  299.  
  300. /***************************************************************************
  301. api_lsa_lookup_names
  302.  ***************************************************************************/
  303. static void api_lsa_lookup_names( char *param, char *data,
  304.                                   char **rdata, int *rdata_len )
  305. {
  306.     int i;
  307.     LSA_Q_LOOKUP_RIDS q_l;
  308.     pstring dom_name;
  309.     pstring dom_sid;
  310.     uint32 dom_rids[MAX_LOOKUP_SIDS];
  311.     uint32 dummy_g_rid;
  312.  
  313.     /* grab the info class and policy handle */
  314.     lsa_io_q_lookup_rids(True, &q_l, data + 0x18, data, 4, 0);
  315.  
  316.     pstrcpy(dom_name, lp_workgroup());
  317.     pstrcpy(dom_sid , lp_domain_sid());
  318.  
  319.     /* convert received RIDs to strings, so we can do them. */
  320.     for (i = 0; i < q_l.num_entries; i++)
  321.     {
  322.         char *user_name = unistr2(q_l.lookup_name[i].str.buffer);
  323.         if (!name_to_rid(user_name, &dom_rids[i], &dummy_g_rid))
  324.         {
  325.             /* WHOOPS!  we should really do something about this... */
  326.             dom_rids[i] = 0;
  327.         }
  328.     }
  329.  
  330.     /* construct reply.  return status is always 0x0 */
  331.     *rdata_len = lsa_reply_lookup_rids(*rdata + 0x18, *rdata,
  332.                 q_l.num_entries, dom_rids, /* text-converted SIDs */
  333.                 dom_name, dom_sid, /* domain name, domain SID */
  334.                 "S-1-1", "S-1-3", "S-1-5"); /* the three other SIDs */
  335. }
  336.  
  337. /***************************************************************************
  338. api_ntLsarpcTNP
  339.  ***************************************************************************/
  340. BOOL api_ntLsarpcTNP(int cnum,int uid, char *param,char *data,
  341.              int mdrcnt,int mprcnt,
  342.              char **rdata,char **rparam,
  343.              int *rdata_len,int *rparam_len)
  344. {
  345.     RPC_HDR_RR hdr;
  346.  
  347.     if (data == NULL)
  348.     {
  349.         DEBUG(2,("api_ntLsarpcTNP: NULL data received\n"));
  350.         return False;
  351.     }
  352.  
  353.     smb_io_rpc_hdr_rr(True, &hdr, data, data, 4, 0);
  354.  
  355.     DEBUG(4,("lsarpc TransactNamedPipe op %x\n",hdr.opnum));
  356.  
  357.     switch (hdr.opnum)
  358.     {
  359.         case LSA_OPENPOLICY:
  360.         {
  361.             DEBUG(3,("LSA_OPENPOLICY\n"));
  362.             api_lsa_open_policy(param, data, rdata, rdata_len);
  363.             create_rpc_reply(hdr.hdr.call_id, *rdata, *rdata_len);
  364.             break;
  365.         }
  366.  
  367.         case LSA_QUERYINFOPOLICY:
  368.         {
  369.             DEBUG(3,("LSA_QUERYINFOPOLICY\n"));
  370.  
  371.             api_lsa_query_info(param, data, rdata, rdata_len);
  372.             create_rpc_reply(hdr.hdr.call_id, *rdata, *rdata_len);
  373.             break;
  374.         }
  375.  
  376.         case LSA_ENUMTRUSTDOM:
  377.         {
  378.             char *q = *rdata + 0x18;
  379.  
  380.             DEBUG(3,("LSA_ENUMTRUSTDOM\n"));
  381.  
  382.             initrpcreply(data, *rdata);
  383.  
  384.             SIVAL(q, 0, 0); /* enumeration context */
  385.             SIVAL(q, 0, 4); /* entries read */
  386.             SIVAL(q, 0, 8); /* trust information */
  387.  
  388.             q += 12;
  389.  
  390.             endrpcreply(data, *rdata, q-*rdata, 0x8000001a, rdata_len);
  391.  
  392.             break;
  393.         }
  394.  
  395.         case LSA_CLOSE:
  396.         {
  397.             char *q;
  398.  
  399.             DEBUG(3,("LSA_CLOSE\n"));
  400.  
  401.             initrpcreply(data, *rdata);
  402.  
  403.             q = *rdata + 0x18;
  404.  
  405.             SIVAL(q, 0, 0); q += 4;
  406.             SIVAL(q, 0, 0); q += 4;
  407.             SIVAL(q, 0, 0); q += 4;
  408.             SIVAL(q, 0, 0); q += 4;
  409.             SIVAL(q, 0, 0); q += 4;
  410.  
  411.             endrpcreply(data, *rdata, q-*rdata, 0, rdata_len);
  412.  
  413.             break;
  414.         }
  415.  
  416.         case LSA_OPENSECRET:
  417.         {
  418.             char *q = *rdata + 0x18;
  419.             DEBUG(3,("LSA_OPENSECRET\n"));
  420.  
  421.             initrpcreply(data, *rdata);
  422.  
  423.             SIVAL(q, 0, 0);
  424.             SIVAL(q, 0, 4);
  425.             SIVAL(q, 0, 8);
  426.             SIVAL(q, 0, 12);
  427.             SIVAL(q, 0, 16);
  428.  
  429.             q += 20;
  430.  
  431.             endrpcreply(data, *rdata, q-*rdata, 0xc000034, rdata_len);
  432.  
  433.             break;
  434.         }
  435.  
  436.         case LSA_LOOKUPSIDS:
  437.         {
  438.             DEBUG(3,("LSA_OPENSECRET\n"));
  439.             api_lsa_lookup_sids(param, data, rdata, rdata_len);
  440.             create_rpc_reply(hdr.hdr.call_id, *rdata, *rdata_len);
  441.             break;
  442.         }
  443.  
  444.         case LSA_LOOKUPNAMES:
  445.         {
  446.             DEBUG(3,("LSA_LOOKUPNAMES\n"));
  447.             api_lsa_lookup_names(param, data, rdata, rdata_len);
  448.             create_rpc_reply(hdr.hdr.call_id, *rdata, *rdata_len);
  449.             break;
  450.         }
  451.  
  452.         default:
  453.         {
  454.             DEBUG(4, ("NTLSARPC, unknown code: %lx\n", hdr.opnum));
  455.             break;
  456.         }
  457.     }
  458.     return True;
  459. }
  460.  
  461. #endif /* NTDOMAIN */
  462.