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 / pipesrvsvc.c < prev    next >
C/C++ Source or Header  |  1997-11-04  |  8KB  |  268 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. ********************************************************************/
  36. static void make_srv_share_info1_str(SH_INFO_1_STR *sh1, char *net_name, char *remark)
  37. {
  38.     if (sh1 == NULL) return;
  39.  
  40.     DEBUG(5,("make_srv_share_info1_str: %s %s\n", net_name, remark));
  41.  
  42.     make_unistr2(&(sh1->uni_netname), net_name, strlen(net_name)+1);
  43.     make_unistr2(&(sh1->uni_remark ), remark  , strlen(remark  )+1);
  44. }
  45.  
  46. /*******************************************************************
  47. ********************************************************************/
  48. static void make_srv_share_info1(SH_INFO_1 *sh1, char *net_name, uint32 type, char *remark)
  49. {
  50.     if (sh1 == NULL) return;
  51.  
  52.     DEBUG(5,("make_srv_share_info1_str: %s %8x %s\n", net_name, type, remark));
  53.  
  54.     sh1->ptr_netname = net_name != NULL ? 1 : 0;
  55.     sh1->type        = type;
  56.     sh1->ptr_remark  = remark   != NULL ? 1 : 0;
  57. }
  58.  
  59. /*******************************************************************
  60. fill in a share info level 1 structure.
  61.  
  62. this function breaks the rule that i'd like to be in place, namely
  63. it doesn't receive its data as arguments: it has to call lp_xxxx()
  64. functions itself.  yuck.
  65.  
  66. this function is identical to api_RNetShareEnum().  maybe it even
  67. generates the same output!  (too much to hope for, really...)
  68.  
  69. ********************************************************************/
  70. static void make_srv_share_1_ctr(SHARE_INFO_1_CTR *ctr)
  71. {
  72.     int snum;
  73.     int num_entries = 0;
  74.     int svcs = lp_numservices();
  75.  
  76.     if (ctr == NULL) return;
  77.  
  78.     DEBUG(5,("make_srv_share_1_ctr\n"));
  79.  
  80.     for (snum = 0; snum < svcs && num_entries < MAX_SHARE_ENTRIES; num_entries++, snum++)
  81.     {
  82.         int len_net_name;
  83.         pstring net_name;
  84.         pstring remark;
  85.         uint32 type;
  86.  
  87.         if (lp_browseable(snum) && lp_snum_ok(snum))
  88.         {
  89.             /* see ipc.c:fill_share_info() */
  90.  
  91.             pstrcpy(net_name, lp_servicename(snum));
  92.             pstrcpy(remark  , lp_comment    (snum));
  93.             len_net_name = strlen(net_name);
  94.  
  95.             /* work out the share type */
  96.             type = STYPE_DISKTREE;
  97.             
  98.             if (lp_print_ok(snum))             type = STYPE_PRINTQ;
  99.             if (strequal("IPC$", net_name))    type = STYPE_IPC;
  100.             if (net_name[len_net_name] == '$') type |= STYPE_HIDDEN;
  101.  
  102.             make_srv_share_info1    (&(ctr->info_1    [num_entries]), net_name, type, remark);
  103.             make_srv_share_info1_str(&(ctr->info_1_str[num_entries]), net_name,       remark);
  104.         }
  105.     }
  106.  
  107.     ctr->num_entries_read  = num_entries;
  108.     ctr->ptr_share_info    = num_entries > 0 ? 1 : 0;
  109.     ctr->num_entries_read2 = num_entries;
  110.     ctr->num_entries_read3 = num_entries;
  111.     ctr->padding           = 0;
  112. }
  113.  
  114. /*******************************************************************
  115. ********************************************************************/
  116. static void make_srv_net_share_enum(SRV_R_NET_SHARE_ENUM *r_n,
  117.                              int share_level, int switch_value, int status)  
  118. {
  119.     DEBUG(5,("make_srv_net_share_enum: %d\n", __LINE__));
  120.  
  121.     r_n->share_level  = share_level;
  122.     r_n->switch_value = switch_value;
  123.     r_n->status       = status;
  124.  
  125.     switch (switch_value)
  126.     {
  127.         case 1:
  128.         {
  129.             make_srv_share_1_ctr(&(r_n->share.info1));
  130.             r_n->ptr_share_info = r_n->share.info1.num_entries_read > 0 ? 1 : 0;
  131.             break;
  132.         }
  133.         default:
  134.         {
  135.             DEBUG(5,("make_srv_net_share_enum: unsupported switch value %d\n",
  136.                       switch_value));
  137.             r_n->ptr_share_info = 0;
  138.             break;
  139.         }
  140.     }
  141. }
  142.  
  143. /*******************************************************************
  144. ********************************************************************/
  145. static int srv_reply_net_share_enum(SRV_Q_NET_SHARE_ENUM *q_n,
  146.                 char *q, char *base,
  147.                 int status)
  148. {
  149.     SRV_R_NET_SHARE_ENUM r_n;
  150.  
  151.     DEBUG(5,("srv_net_share_enum: %d\n", __LINE__));
  152.  
  153.     /* set up the */
  154.     make_srv_net_share_enum(&r_n, q_n->share_level, q_n->switch_value, status);
  155.  
  156.     /* store the response in the SMB stream */
  157.     q = srv_io_r_net_share_enum(False, &r_n, q, base, 4, 0);
  158.  
  159.     DEBUG(5,("srv_srv_pwset: %d\n", __LINE__));
  160.  
  161.     /* return length of SMB data stored */
  162.     return PTR_DIFF(q, base);
  163. }
  164.  
  165. /*******************************************************************
  166. ********************************************************************/
  167. static void api_srv_net_share_info( char *param, char *data,
  168.                                     char **rdata, int *rdata_len )
  169. {
  170.     SRV_Q_NET_SHARE_ENUM q_n;
  171.  
  172.     /* grab the net share enum */
  173.     srv_io_q_net_share_enum(True, &q_n, data + 0x18, data, 4, 0);
  174.  
  175.     /* XXXX push the reply buffer size up a bit, and hope it's sufficient */
  176.     /* for the current maximum limit of 32 share entries */
  177.     *rdata_len = 4096;
  178.     *rdata = REALLOC(*rdata, *rdata_len);
  179.  
  180.     /* construct reply.  always indicate success */
  181.     *rdata_len = srv_reply_net_share_enum(&q_n, *rdata + 0x18, *rdata, 0x0);
  182. }
  183.  
  184.  
  185. /*******************************************************************
  186. receives a srvsvc pipe and responds.
  187. ********************************************************************/
  188. BOOL api_srvsvcTNP(int cnum,int uid, char *param,char *data,
  189.              int mdrcnt,int mprcnt,
  190.              char **rdata,char **rparam,
  191.              int *rdata_len,int *rparam_len)
  192. {
  193.     RPC_HDR_RR hdr;
  194.  
  195.     if (data == NULL)
  196.     {
  197.         DEBUG(2,("api_srvsvcTNP: NULL data received\n"));
  198.         return False;
  199.     }
  200.  
  201.     smb_io_rpc_hdr_rr(True, &hdr, data, data, 4, 0);
  202.  
  203.     DEBUG(4,("srvsvc TransactNamedPipe op %x\n",hdr.opnum));
  204.  
  205.     switch (hdr.opnum)
  206.     {
  207.         case NETSHAREENUM:
  208.         {
  209.             api_srv_net_share_info( param, data, rdata, rdata_len);
  210.             create_rpc_reply(hdr.hdr.call_id, *rdata, *rdata_len);
  211.             break;
  212.         }
  213.  
  214.         case NETSERVERGETINFO:
  215.         {
  216.             extern pstring myname;
  217.             char *q;
  218.             char *servername;
  219.             uint32 level;
  220.             UNISTR2 uni_str;
  221.  
  222.             q = data + 0x18;
  223.  
  224.             servername = q + 16;
  225.             q = skip_unicode_string(servername,1);
  226.             if (strlen(unistr(servername)) % 2 == 0)
  227.             q += 2;
  228.             level = IVAL(q, 0); q += 4;
  229.  
  230.             /* ignore the rest for the moment */
  231.             initrpcreply(data, *rdata);
  232.             q = *rdata + 0x18;
  233.  
  234.             SIVAL(q, 0, 101); q += 4; /* switch value */
  235.             SIVAL(q, 0, 2); q += 4; /* bufptr */
  236.             SIVAL(q, 0, 0x1f4); q += 4; /* platform id */
  237.             SIVAL(q, 0, 2); q += 4; /* bufptr for name */
  238.             SIVAL(q, 0, 5); q += 4; /* major version */
  239.             SIVAL(q, 0, 4); q += 4; /* minor version == 5.4 */
  240.             SIVAL(q, 0, 0x4100B); q += 4; /* type */
  241.             SIVAL(q, 0, 2); q += 4; /* comment */
  242.  
  243.             get_myname(myname,NULL);
  244.  
  245.             make_unistr2(&uni_str, myname, strlen(myname));
  246.             q = smb_io_unistr2(False, &uni_str, q, *rdata, 4, 0);
  247.  
  248.             make_unistr2(&uni_str, lp_serverstring(), strlen(lp_serverstring()));
  249.             q = smb_io_unistr2(False, &uni_str, q, *rdata, 4, 0);
  250.  
  251.             q = align_offset(q, *rdata, 4);
  252.  
  253.             endrpcreply(data, *rdata, q-*rdata, 0, rdata_len);
  254.             break;
  255.         }
  256.  
  257.         default:
  258.         {
  259.             DEBUG(4, ("srvsvc, unknown code: %lx\n", hdr.opnum));
  260.             break;
  261.         }
  262.     }
  263.  
  264.     return(True);
  265. }
  266.  
  267. #endif
  268.