LCOV - code coverage report
Current view: top level - source3/utils - net_rpc_conf.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 693 1048 66.1 %
Date: 2024-04-21 15:09:00 Functions: 42 45 93.3 %

          Line data    Source code
       1             : /*
       2             :  *  Samba Unix/Linux SMB client library
       3             :  *  Distributed SMB/CIFS Server Management Utility
       4             :  *  Local configuration interface
       5             :  *  Copyright (C) Vicentiu Ciorbaru 2011
       6             :  *
       7             :  *  This program is free software; you can redistribute it and/or modify
       8             :  *  it under the terms of the GNU General Public License as published by
       9             :  *  the Free Software Foundation; either version 3 of the License, or
      10             :  *  (at your option) any later version.
      11             :  *
      12             :  *  This program is distributed in the hope that it will be useful,
      13             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             :  *  GNU General Public License for more details.
      16             :  *
      17             :  *  You should have received a copy of the GNU General Public License
      18             :  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
      19             :  */
      20             : 
      21             : /*
      22             :  * This is an interface to Samba's configuration.
      23             :  *
      24             :  * This tool supports local as well as remote interaction via rpc
      25             :  * with the configuration stored in the registry.
      26             :  */
      27             : 
      28             : 
      29             : #include "includes.h"
      30             : #include "utils/net.h"
      31             : #include "utils/net_conf_util.h"
      32             : #include "rpc_client/cli_pipe.h"
      33             : #include "../librpc/gen_ndr/ndr_samr_c.h"
      34             : #include "rpc_client/init_samr.h"
      35             : #include "../librpc/gen_ndr/ndr_winreg_c.h"
      36             : #include "../libcli/registry/util_reg.h"
      37             : #include "rpc_client/cli_winreg.h"
      38             : #include "lib/smbconf/smbconf.h"
      39             : #include "lib/smbconf/smbconf_init.h"
      40             : #include "lib/smbconf/smbconf_reg.h"
      41             : #include "lib/param/loadparm.h"
      42             : 
      43             : 
      44             : 
      45             : /* internal functions */
      46             : /**********************************************************
      47             :  *
      48             :  * usage functions
      49             :  *
      50             :  **********************************************************/
      51             : const char confpath[100] = "Software\\Samba\\smbconf";
      52             : 
      53           0 : static int rpc_conf_list_usage(struct net_context *c, int argc,
      54             :                                const char **argv)
      55             : {
      56           0 :         d_printf("%s net rpc conf list\n", _("Usage:"));
      57           0 :         return -1;
      58             : }
      59             : 
      60           0 : static int rpc_conf_listshares_usage(struct net_context *c, int argc,
      61             :                                      const char **argv)
      62             : {
      63           0 :         d_printf("%s net rpc conf listshares\n", _("Usage:"));
      64           0 :         return -1;
      65             : }
      66             : 
      67           2 : static int rpc_conf_delshare_usage(struct net_context *c, int argc,
      68             :                                    const char **argv)
      69             : {
      70           2 :         d_printf("%s\n%s",
      71             :                  _("Usage:"),
      72             :                  _("net rpc conf delshare <sharename>\n"));
      73           2 :         return -1;
      74             : }
      75             : 
      76           2 : static int rpc_conf_addshare_usage(struct net_context *c, int argc,
      77             :                                    const char **argv)
      78             : {
      79           2 :         d_printf("%s\n%s",
      80             :                  _("Usage:"),
      81             :                  _(" net rpc conf addshare <sharename> <path> "
      82             :                    "[writeable={y|N} [guest_ok={y|N} [<comment>]]]\n"
      83             :                    "\t<sharename>      the new share name.\n"
      84             :                    "\t<path>           the path on the filesystem to export.\n"
      85             :                    "\twriteable={y|N}  set \"writeable to \"yes\" or "
      86             :                    "\"no\" (default) on this share.\n"
      87             :                    "\tguest_ok={y|N}   set \"guest ok\" to \"yes\" or "
      88             :                    "\"no\" (default)   on this share.\n"
      89             :                    "\t<comment>        optional comment for the new share.\n"));
      90           2 :         return -1;
      91             : 
      92             : }
      93             : 
      94           2 : static int rpc_conf_import_usage(struct net_context *c, int argc,
      95             :                                  const char**argv)
      96             : {
      97           2 :         d_printf("%s\n%s",
      98             :                  _("Usage:"),
      99             :                  _(" net rpc conf import [--test|-T] <filename> "
     100             :                    "[<servicename>]\n"
     101             :                    "\t[--test|-T]    testmode - do not act, just print "
     102             :                         "what would be done\n"
     103             :                    "\t<servicename>  only import service <servicename>, "
     104             :                         "ignore the rest\n"));
     105           2 :         return -1;
     106             : }
     107             : 
     108           0 : static int rpc_conf_showshare_usage(struct net_context *c, int argc,
     109             :                                     const char **argv)
     110             : {
     111           0 :         d_printf("%s\n%s",
     112             :                  _("Usage:"),
     113             :                  _("net rpc conf showshare <sharename>\n"));
     114           0 :         return -1;
     115             : }
     116             : 
     117           2 : static int rpc_conf_drop_usage(struct net_context *c, int argc,
     118             :                                const char **argv)
     119             : {
     120           2 :         d_printf("%s\nnet rpc conf drop\n", _("Usage:"));
     121           2 :         return -1;
     122             : }
     123             : 
     124           2 : static int rpc_conf_getparm_usage(struct net_context *c, int argc,
     125             :                                const char **argv)
     126             : {
     127           2 :         d_printf("%s\nnet rpc conf getparm <sharename> <parameter>\n",
     128             :                         _("Usage:"));
     129           2 :         return -1;
     130             : }
     131             : 
     132           2 : static int rpc_conf_setparm_usage(struct net_context *c, int argc,
     133             :                                   const char **argv)
     134             : {
     135           2 :         d_printf("%s\n%s",
     136             :                  _("Usage:"),
     137             :                  _(" net rpc conf setparm <section> <param> <value>\n"));
     138           2 :         return -1;
     139             : }
     140             : 
     141           2 : static int rpc_conf_delparm_usage(struct net_context *c, int argc,
     142             :                                 const char **argv)
     143             : {
     144           2 :         d_printf("%s\nnet rpc conf delparm <sharename> <parameter>\n",
     145             :                         _("Usage:"));
     146           2 :         return -1;
     147             : }
     148             : 
     149           2 : static int rpc_conf_getincludes_usage(struct net_context *c, int argc,
     150             :                                 const char **argv)
     151             : {
     152           2 :         d_printf("%s\nnet rpc conf getincludes <sharename>\n",
     153             :                         _("Usage:"));
     154           2 :         return -1;
     155             : }
     156             : 
     157           2 : static int rpc_conf_setincludes_usage(struct net_context *c, int argc,
     158             :                                 const char **argv)
     159             : {
     160           2 :         d_printf("%s\nnet rpc conf setincludes <sharename> [<filename>]*\n",
     161             :                         _("Usage:"));
     162           2 :         return -1;
     163             : }
     164             : 
     165           2 : static int rpc_conf_delincludes_usage(struct net_context *c, int argc,
     166             :                                 const char **argv)
     167             : {
     168           2 :         d_printf("%s\nnet rpc conf delincludes <sharename>\n",
     169             :                         _("Usage:"));
     170           2 :         return -1;
     171             : }
     172             : 
     173             : /**********************************************************
     174             :  *
     175             :  * helper functions
     176             :  *
     177             :  **********************************************************/
     178             : 
     179             : /*
     180             :  * The function deletes a registry value with the name 'value' from the share
     181             :  * with the name 'share_name'. 'parent_hnd' is the handle for the smbconf key.
     182             :  */
     183          28 : static NTSTATUS rpc_conf_del_value(TALLOC_CTX *mem_ctx,
     184             :                                    struct dcerpc_binding_handle *b,
     185             :                                    struct policy_handle *parent_hnd,
     186             :                                    const char *share_name,
     187             :                                    const char *value,
     188             :                                    WERROR *werr)
     189             : {
     190             : 
     191          28 :         TALLOC_CTX *frame = talloc_stackframe();
     192          28 :         NTSTATUS status = NT_STATUS_OK;
     193          28 :         WERROR result = WERR_OK;
     194           0 :         WERROR _werr;
     195             : 
     196           0 :         struct winreg_String keyname, valuename;
     197           0 :         struct policy_handle child_hnd;
     198             : 
     199          28 :         ZERO_STRUCT(child_hnd);
     200          28 :         ZERO_STRUCT(keyname);
     201          28 :         ZERO_STRUCT(valuename);
     202             : 
     203          28 :         keyname.name = share_name;
     204          28 :         valuename.name = value;
     205             : 
     206          28 :         status = dcerpc_winreg_OpenKey(b, frame, parent_hnd, keyname, 0,
     207             :                                        REG_KEY_WRITE, &child_hnd, &result);
     208             : 
     209          28 :         if (!(NT_STATUS_IS_OK(status))) {
     210           0 :                 d_fprintf(stderr, _("Failed to open key '%s': %s\n"),
     211             :                                 keyname.name, nt_errstr(status));
     212           0 :                 goto error;
     213             :         }
     214             : 
     215          28 :         if (!(W_ERROR_IS_OK(result))) {
     216           4 :                 d_fprintf(stderr, _("Failed to open key '%s': %s\n"),
     217             :                                 keyname.name, win_errstr(result));
     218           4 :                 goto error;
     219             :         }
     220             : 
     221          24 :         status = dcerpc_winreg_DeleteValue(b,
     222             :                                            frame,
     223             :                                            &child_hnd,
     224             :                                            valuename,
     225             :                                            &result);
     226             : 
     227          24 :         if (!(NT_STATUS_IS_OK(status))) {
     228           0 :                 d_fprintf(stderr, _("Failed to delete value %s\n"),
     229             :                                 nt_errstr(status));
     230           0 :                 goto error;
     231             :         }
     232             : 
     233          24 :         if (!(W_ERROR_IS_OK(result))) {
     234          14 :                 if (W_ERROR_EQUAL(result, WERR_FILE_NOT_FOUND)){
     235          14 :                         result = WERR_OK;
     236          14 :                         goto error;
     237             :                 }
     238             : 
     239           0 :                 d_fprintf(stderr, _("Failed to delete value  %s\n"),
     240             :                                 win_errstr(result));
     241           0 :                 goto error;
     242             :         }
     243             : 
     244          10 : error:
     245          28 :         *werr = result;
     246             : 
     247          28 :         dcerpc_winreg_CloseKey(b, frame, &child_hnd, &_werr);
     248             : 
     249          28 :         TALLOC_FREE(frame);
     250          28 :         return status;;
     251             : 
     252             : }
     253             : 
     254             : /*
     255             :  * The function sets a share in the registry with the parameters
     256             :  * held in the smbconf_service struct
     257             :  */
     258         202 : static NTSTATUS rpc_conf_set_share(TALLOC_CTX *mem_ctx,
     259             :                                    struct dcerpc_binding_handle *b,
     260             :                                    struct policy_handle *parent_hnd,
     261             :                                    struct smbconf_service *service,
     262             :                                    WERROR *werr)
     263             : {
     264         202 :         TALLOC_CTX *frame = talloc_stackframe();
     265             : 
     266         202 :         NTSTATUS status = NT_STATUS_OK;
     267         202 :         WERROR result = WERR_OK;
     268           0 :         WERROR _werr;
     269           0 :         enum winreg_CreateAction action;
     270           0 :         uint32_t i, j;
     271             : 
     272           0 :         const char **includes;
     273             : 
     274           0 :         struct winreg_String wkey, wkeyclass;
     275           0 :         struct policy_handle share_hnd;
     276             : 
     277         202 :         ZERO_STRUCT(share_hnd);
     278         202 :         ZERO_STRUCT(wkey);
     279         202 :         ZERO_STRUCT(wkeyclass);
     280             : 
     281         202 :         wkey.name = service->name;
     282         202 :         wkeyclass.name = "";
     283         202 :         action = REG_ACTION_NONE;
     284             : 
     285         202 :         status = dcerpc_winreg_CreateKey(b,
     286             :                                          frame,
     287             :                                          parent_hnd,
     288             :                                          wkey,
     289             :                                          wkeyclass,
     290             :                                          0,
     291             :                                          REG_KEY_ALL,
     292             :                                          NULL,
     293             :                                          &share_hnd,
     294             :                                          &action,
     295             :                                          &result);
     296             : 
     297         202 :         if (!NT_STATUS_IS_OK(status)) {
     298           0 :                 d_printf("winreg_CreateKey: Could not create smbconf key\n");
     299           0 :                 goto error;
     300             :         }
     301             : 
     302         202 :         if (!W_ERROR_IS_OK(result)) {
     303           0 :                 d_printf("winreg_CreateKey: Could not create smbconf key\n");
     304           0 :                 goto error;
     305             :         }
     306             : 
     307        1048 :         for (i = 0; i < service->num_params; i++) {
     308         846 :                 if (strequal(service->param_names[i], "include") == 0)
     309             :                 {
     310             : 
     311         846 :                         status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
     312         846 :                                                       service->param_names[i],
     313         846 :                                                       service->param_values[i],
     314             :                                                       &result);
     315             : 
     316         846 :                         if (!(NT_STATUS_IS_OK(status))) {
     317           0 :                                 d_fprintf(stderr,
     318             :                                           "ERROR: Share: '%s'\n"
     319             :                                           "Could not set parameter '%s'"
     320             :                                           " with value %s\n %s\n",
     321             :                                           service->name,
     322           0 :                                           service->param_names[i],
     323           0 :                                           service->param_values[i],
     324             :                                           nt_errstr(status));
     325           0 :                                 goto error;
     326             :                         }
     327             : 
     328         846 :                         if (!(W_ERROR_IS_OK(result))) {
     329           0 :                                 d_fprintf(stderr,
     330             :                                           "ERROR: Share: '%s'\n"
     331             :                                           "Could not set parameter '%s'"
     332             :                                           " with value %s\n %s\n",
     333             :                                           service->name,
     334           0 :                                           service->param_names[i],
     335           0 :                                           service->param_values[i],
     336             :                                           win_errstr(result));
     337           0 :                                 goto error;
     338             :                         }
     339             :                 } else {
     340             : 
     341           0 :                         includes = talloc_zero_array(frame,
     342             :                                                      const char *,
     343             :                                                      service->num_params + 1);
     344           0 :                         if (includes == NULL) {
     345           0 :                                 result = WERR_NOT_ENOUGH_MEMORY;
     346           0 :                                 d_fprintf(stderr, "ERROR: out of memory\n");
     347           0 :                                 goto error;
     348             :                         }
     349             : 
     350           0 :                         for (j = i; j < service->num_params; j++) {
     351             : 
     352           0 :                                 includes[j - i] = talloc_strdup(
     353             :                                                         frame,
     354           0 :                                                         service->param_values[j]);
     355             : 
     356           0 :                                 if (includes[j-i] == NULL) {
     357           0 :                                         result = WERR_NOT_ENOUGH_MEMORY;
     358           0 :                                         d_fprintf(stderr, "ERROR: out of memory\n");
     359           0 :                                         goto error;
     360             :                                 }
     361             :                         }
     362             : 
     363           0 :                         status = dcerpc_winreg_set_multi_sz(frame, b, &share_hnd,
     364             :                                                 "includes",
     365             :                                                 includes,
     366             :                                                 &result);
     367             : 
     368           0 :                         if (!(NT_STATUS_IS_OK(status))) {
     369           0 :                                 d_fprintf(stderr, "ERROR: Share: '%s'\n"
     370             :                                                 "Could not set includes\n %s\n",
     371             :                                                 service->name,
     372             :                                                 nt_errstr(status));
     373           0 :                                 goto error;
     374             :                         }
     375             : 
     376           0 :                         if (!(W_ERROR_IS_OK(result))) {
     377           0 :                                 d_fprintf(stderr, "ERROR: Share: '%s'\n"
     378             :                                                 "Could not set includes\n %s\n",
     379             :                                                 service->name,
     380             :                                                 win_errstr(result));
     381           0 :                                 goto error;
     382             :                         }
     383             : 
     384           0 :                         i = service->num_params;
     385             :                 }
     386             :         }
     387             : 
     388         202 : error:
     389             :         /* in case of error, should it delete the created key? */
     390         202 :         if (!(W_ERROR_IS_OK(result))) {
     391           0 :                 status =  werror_to_ntstatus(result);
     392             : 
     393             :         }
     394             : 
     395         202 :         dcerpc_winreg_CloseKey(b, frame, &share_hnd, &_werr);
     396             : 
     397         202 :         TALLOC_FREE(frame);
     398         202 :         return status;
     399             : 
     400             : }
     401             : 
     402             : /*
     403             :  * The function opens the registry database and retrieves
     404             :  * as a smbconf_service struct the share with the name
     405             :  * 'share_name'
     406             :  */
     407         628 : static NTSTATUS rpc_conf_get_share(TALLOC_CTX *mem_ctx,
     408             :                                    struct dcerpc_binding_handle *b,
     409             :                                    struct policy_handle *parent_hnd,
     410             :                                    const char *share_name,
     411             :                                    struct smbconf_service *share,
     412             :                                    WERROR *werr)
     413             : {
     414         628 :         TALLOC_CTX *frame = talloc_stackframe();
     415             : 
     416         628 :         NTSTATUS status = NT_STATUS_OK;
     417         628 :         WERROR result = WERR_OK;
     418           0 :         WERROR _werr;
     419           0 :         struct policy_handle child_hnd;
     420         628 :         int32_t includes_cnt, includes_idx = -1;
     421         628 :         uint32_t num_vals, num_subkeys, i, param_cnt = 0;
     422           0 :         const char **val_names;
     423         628 :         const char **subkeys = NULL;
     424           0 :         enum winreg_Type *types;
     425           0 :         DATA_BLOB *data;
     426         628 :         struct winreg_String key = { 0, };
     427         628 :         const char **multi_s = NULL;
     428         628 :         const char *s = NULL;
     429           0 :         struct smbconf_service tmp_share;
     430             : 
     431         628 :         ZERO_STRUCT(tmp_share);
     432             : 
     433             :         /*
     434             :          * Determine correct upper/lowercase.
     435             :          */
     436         628 :         status = dcerpc_winreg_enum_keys(frame,
     437             :                                          b,
     438             :                                          parent_hnd,
     439             :                                          &num_subkeys,
     440             :                                          &subkeys,
     441             :                                          &result);
     442         628 :         if (!(NT_STATUS_IS_OK(status))) {
     443           0 :                 d_fprintf(stderr, _("Failed to enumerate shares: %s\n"),
     444             :                                 nt_errstr(status));
     445           0 :                 goto error;
     446             :         }
     447         628 :         if (!(W_ERROR_IS_OK(result))) {
     448           0 :                 d_fprintf(stderr, _("Failed to enumerate shares: %s\n"),
     449             :                                 win_errstr(result));
     450           0 :                 goto error;
     451             :         }
     452             : 
     453       60658 :         for (i = 0; i < num_subkeys; i++) {
     454       60030 :                 if (!strequal(share_name, subkeys[i])) {
     455       59402 :                         continue;
     456             :                 }
     457             : 
     458         628 :                 key.name = subkeys[i];
     459             :         }
     460             : 
     461         628 :         if (key.name == NULL) {
     462           0 :                 d_fprintf(stderr, _("Could not find share.\n"));
     463           0 :                 goto error;
     464             :         }
     465             : 
     466         628 :         status = dcerpc_winreg_OpenKey(b, frame, parent_hnd, key, 0,
     467             :                                REG_KEY_READ, &child_hnd, &result);
     468             : 
     469         628 :         if (!(NT_STATUS_IS_OK(status))) {
     470           0 :                 d_fprintf(stderr, _("Failed to open subkey: %s\n"),
     471             :                                 nt_errstr(status));
     472           0 :                 goto error;
     473             :         }
     474         628 :         if (!(W_ERROR_IS_OK(result))) {
     475           0 :                 d_fprintf(stderr, _("Failed to open subkey: %s\n"),
     476             :                                 win_errstr(result));
     477           0 :                 goto error;
     478             :         }
     479             :         /* get all the info from the share key */
     480         628 :         status = dcerpc_winreg_enumvals(frame,
     481             :                         b,
     482             :                         &child_hnd,
     483             :                         &num_vals,
     484             :                         &val_names,
     485             :                         &types,
     486             :                         &data,
     487             :                         &result);
     488             : 
     489         628 :         if (!(NT_STATUS_IS_OK(status))) {
     490           0 :                 d_fprintf(stderr, _("Failed to enumerate values: %s\n"),
     491             :                                 nt_errstr(status));
     492           0 :                 goto error;
     493             :         }
     494         628 :         if (!(W_ERROR_IS_OK(result))) {
     495           0 :                 d_fprintf(stderr, _("Failed to enumerate values: %s\n"),
     496             :                                 win_errstr(result));
     497           0 :                 goto error;
     498             :         }
     499             :         /* check for includes */
     500        3196 :         for (i = 0; i < num_vals; i++) {
     501        2568 :                 if (strcmp(val_names[i], "includes") == 0){
     502           4 :                         if (!pull_reg_multi_sz(frame,
     503           4 :                                                &data[i],
     504             :                                                &multi_s))
     505             :                         {
     506           0 :                                 result = WERR_NOT_ENOUGH_MEMORY;
     507           0 :                                 d_fprintf(stderr,
     508           0 :                                           _("Failed to enumerate values: %s\n"),
     509             :                                           win_errstr(result));
     510           0 :                                 goto error;
     511             :                         }
     512           4 :                         includes_idx = i;
     513             :                 }
     514             :         }
     515             :         /* count the number of includes */
     516         628 :         includes_cnt = 0;
     517         628 :         if (includes_idx != -1) {
     518           4 :                 for (includes_cnt = 0;
     519          16 :                      multi_s[includes_cnt] != NULL;
     520          12 :                      includes_cnt ++);
     521             :         }
     522             :         /* place the name of the share in the smbconf_service struct */
     523         628 :         tmp_share.name = talloc_strdup(frame, key.name);
     524         628 :         if (tmp_share.name == NULL) {
     525           0 :                 result = WERR_NOT_ENOUGH_MEMORY;
     526           0 :                 d_fprintf(stderr, _("Failed to create share: %s\n"),
     527             :                                 win_errstr(result));
     528           0 :                 goto error;
     529             :         }
     530             :         /* place the number of parameters in the smbconf_service struct */
     531         628 :         tmp_share.num_params = num_vals;
     532         628 :         if (includes_idx != -1) {
     533           4 :                 tmp_share.num_params = num_vals + includes_cnt - 1;
     534             :         }
     535             :         /* allocate memory for the param_names and param_values lists */
     536         628 :         tmp_share.param_names = talloc_zero_array(frame, char *, tmp_share.num_params);
     537         628 :         if (tmp_share.param_names == NULL) {
     538           0 :                 result = WERR_NOT_ENOUGH_MEMORY;
     539           0 :                 d_fprintf(stderr, _("Failed to create share: %s\n"),
     540             :                                 win_errstr(result));
     541           0 :                 goto error;
     542             :         }
     543         628 :         tmp_share.param_values = talloc_zero_array(frame, char *, tmp_share.num_params);
     544         628 :         if (tmp_share.param_values == NULL) {
     545           0 :                 result = WERR_NOT_ENOUGH_MEMORY;
     546           0 :                 d_fprintf(stderr, _("Failed to create share: %s\n"),
     547             :                                 win_errstr(result));
     548           0 :                 goto error;
     549             :         }
     550             :         /* place all params except includes */
     551        3196 :         for (i = 0; i < num_vals; i++) {
     552        2568 :                 if (strcmp(val_names[i], "includes") != 0) {
     553        2564 :                         if (!pull_reg_sz(frame, &data[i], &s)) {
     554           0 :                                 result = WERR_NOT_ENOUGH_MEMORY;
     555           0 :                                 d_fprintf(stderr,
     556           0 :                                           _("Failed to enumerate values: %s\n"),
     557             :                                           win_errstr(result));
     558           0 :                                 goto error;
     559             :                         }
     560             :                         /* place param_names */
     561        2564 :                         tmp_share.param_names[param_cnt] = talloc_strdup(frame, val_names[i]);
     562        2564 :                         if (tmp_share.param_names[param_cnt] == NULL) {
     563           0 :                                 result = WERR_NOT_ENOUGH_MEMORY;
     564           0 :                                 d_fprintf(stderr, _("Failed to create share: %s\n"),
     565             :                                                 win_errstr(result));
     566           0 :                                 goto error;
     567             :                         }
     568             : 
     569             :                         /* place param_values */
     570        2564 :                         tmp_share.param_values[param_cnt++] = talloc_strdup(frame, s);
     571        2564 :                         if (tmp_share.param_values[param_cnt - 1] == NULL) {
     572           0 :                                 result = WERR_NOT_ENOUGH_MEMORY;
     573           0 :                                 d_fprintf(stderr, _("Failed to create share: %s\n"),
     574             :                                                 win_errstr(result));
     575           0 :                                 goto error;
     576             :                         }
     577             :                 }
     578             :         }
     579             :         /* place the includes last */
     580         640 :         for (i = 0; i < includes_cnt; i++) {
     581          12 :                 tmp_share.param_names[param_cnt] = talloc_strdup(frame, "include");
     582          12 :                 if (tmp_share.param_names[param_cnt] == NULL) {
     583           0 :                                 result = WERR_NOT_ENOUGH_MEMORY;
     584           0 :                                 d_fprintf(stderr, _("Failed to create share: %s\n"),
     585             :                                                 win_errstr(result));
     586           0 :                                 goto error;
     587             :                 }
     588             : 
     589          12 :                 tmp_share.param_values[param_cnt++] = talloc_strdup(frame, multi_s[i]);
     590          12 :                 if (tmp_share.param_values[param_cnt - 1] == NULL) {
     591           0 :                                 result = WERR_NOT_ENOUGH_MEMORY;
     592           0 :                                 d_fprintf(stderr, _("Failed to create share: %s\n"),
     593             :                                                 win_errstr(result));
     594           0 :                                 goto error;
     595             :                 }
     596             :         }
     597             : 
     598             :         /* move everything to the main memory ctx */
     599        3204 :         for (i = 0; i < param_cnt; i++) {
     600        2576 :                 tmp_share.param_names[i] = talloc_move(mem_ctx, &tmp_share.param_names[i]);
     601        2576 :                 tmp_share.param_values[i] = talloc_move(mem_ctx, &tmp_share.param_values[i]);
     602             :         }
     603             : 
     604         628 :         tmp_share.name = talloc_move(mem_ctx, &tmp_share.name);
     605         628 :         tmp_share.param_names = talloc_move(mem_ctx, &tmp_share.param_names);
     606         628 :         tmp_share.param_values = talloc_move(mem_ctx, &tmp_share.param_values);
     607             :         /* out parameter */
     608         628 :         *share = tmp_share;
     609         628 : error:
     610             :         /* close child */
     611         628 :         dcerpc_winreg_CloseKey(b, frame, &child_hnd, &_werr);
     612         628 :         *werr = result;
     613         628 :         TALLOC_FREE(frame);
     614         628 :         return status;
     615             : }
     616             : 
     617             : /*
     618             :  * The function prints the shares held as smbconf_service structs
     619             :  * in a smbconf file format.
     620             :  */
     621         224 : static int rpc_conf_print_shares(uint32_t num_shares,
     622             :                                  struct smbconf_service *shares)
     623             : {
     624             : 
     625           0 :         uint32_t share_count, param_count;
     626         224 :         const char *indent = "\t";
     627             : 
     628         224 :         if (num_shares == 0) {
     629           0 :                 return 0;
     630             :         }
     631             : 
     632         844 :         for (share_count = 0; share_count < num_shares; share_count++) {
     633         620 :                 d_printf("\n");
     634         620 :                 if (shares[share_count].name != NULL) {
     635         620 :                 d_printf("[%s]\n", shares[share_count].name);
     636             :                 }
     637             : 
     638         620 :                 for (param_count = 0;
     639        3160 :                      param_count < shares[share_count].num_params;
     640        2540 :                      param_count++)
     641             :                 {
     642        2540 :                         d_printf("%s%s = %s\n",
     643             :                                  indent,
     644        2540 :                                  shares[share_count].param_names[param_count],
     645        2540 :                                  shares[share_count].param_values[param_count]);
     646             :                 }
     647             :         }
     648         224 :         d_printf("\n");
     649             : 
     650         224 :         return 0;
     651             : 
     652             : }
     653             : 
     654             : /*
     655             :  * The function opens the registry key
     656             :  * HKLM/Software/Samba/smbconf with the give access_mask
     657             :  */
     658         526 : static NTSTATUS rpc_conf_open_conf(TALLOC_CTX *mem_ctx,
     659             :                                    struct dcerpc_binding_handle *b,
     660             :                                    uint32_t access_mask,
     661             :                                    struct policy_handle *hive_hnd,
     662             :                                    struct policy_handle *key_hnd,
     663             :                                    WERROR *werr)
     664             : {
     665         526 :         TALLOC_CTX *frame = talloc_stackframe();
     666         526 :         NTSTATUS status = NT_STATUS_OK;
     667         526 :         WERROR result = WERR_OK;
     668           0 :         WERROR _werr;
     669           0 :         struct policy_handle tmp_hive_hnd, tmp_key_hnd;
     670           0 :         struct winreg_String key;
     671             : 
     672         526 :         ZERO_STRUCT(key);
     673             : 
     674         526 :         status = dcerpc_winreg_OpenHKLM(b, frame, NULL,
     675             :                         access_mask, &tmp_hive_hnd, &result);
     676             : 
     677             :         /*
     678             :          * print no error messages if it is a read only open
     679             :          * and key does not exist
     680             :          * error still gets returned
     681             :          */
     682             : 
     683         526 :         if (access_mask == REG_KEY_READ &&
     684         492 :             W_ERROR_EQUAL(result, WERR_FILE_NOT_FOUND))
     685             :         {
     686           0 :                 goto error;
     687             :         }
     688             : 
     689         526 :         if (!(NT_STATUS_IS_OK(status))) {
     690           0 :                 d_fprintf(stderr, _("Failed to open hive: %s\n"),
     691             :                                 nt_errstr(status));
     692           0 :                 goto error;
     693             :         }
     694         526 :         if (!W_ERROR_IS_OK(result)) {
     695           0 :                 d_fprintf(stderr, _("Failed to open hive: %s\n"),
     696             :                                 win_errstr(result));
     697           0 :                 goto error;
     698             :         }
     699             : 
     700         526 :         key.name = confpath;
     701         526 :         status = dcerpc_winreg_OpenKey(b, frame, &tmp_hive_hnd, key, 0,
     702             :                                        access_mask, &tmp_key_hnd, &result);
     703             : 
     704             :         /*
     705             :          * print no error messages if it is a read only open
     706             :          * and key does not exist
     707             :          * error still gets returned
     708             :          */
     709             : 
     710         526 :         if (access_mask == REG_KEY_READ &&
     711         492 :             W_ERROR_EQUAL(result, WERR_FILE_NOT_FOUND))
     712             :         {
     713           0 :                 goto error;
     714             :         }
     715             : 
     716         526 :         if (!(NT_STATUS_IS_OK(status))) {
     717           0 :                 d_fprintf(stderr, _("Failed to open smbconf key: %s\n"),
     718             :                                 nt_errstr(status));
     719           0 :                 dcerpc_winreg_CloseKey(b, frame, &tmp_hive_hnd, &_werr);
     720           0 :                 goto error;
     721             :         }
     722         526 :         if (!(W_ERROR_IS_OK(result))) {
     723           0 :                 d_fprintf(stderr, _("Failed to open smbconf key: %s\n"),
     724             :                         win_errstr(result));
     725           0 :                 dcerpc_winreg_CloseKey(b, frame, &tmp_hive_hnd, &_werr);
     726           0 :                 goto error;
     727             :         }
     728             : 
     729         526 :         *hive_hnd = tmp_hive_hnd;
     730         526 :         *key_hnd = tmp_key_hnd;
     731             : 
     732         526 : error:
     733         526 :         TALLOC_FREE(frame);
     734         526 :         *werr = result;
     735             : 
     736         526 :         return status;
     737             : }
     738             : 
     739             : /**********************************************************
     740             :  *
     741             :  * internal functions that provide the functionality
     742             :  * net rpc conf
     743             :  *
     744             :  **********************************************************/
     745             : 
     746           4 : static NTSTATUS rpc_conf_listshares_internal(struct net_context *c,
     747             :                                              const struct dom_sid *domain_sid,
     748             :                                              const char *domain_name,
     749             :                                              struct cli_state *cli,
     750             :                                              struct rpc_pipe_client *pipe_hnd,
     751             :                                              TALLOC_CTX *mem_ctx,
     752             :                                              int argc,
     753             :                                              const char **argv )
     754             : {
     755             : 
     756           4 :         TALLOC_CTX *frame = talloc_stackframe();
     757           4 :         NTSTATUS status = NT_STATUS_OK;
     758           4 :         WERROR werr = WERR_OK;
     759           0 :         WERROR _werr;
     760             : 
     761           4 :         struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
     762             : 
     763             :         /* key info */
     764           0 :         struct policy_handle hive_hnd, key_hnd;
     765           0 :         uint32_t num_subkeys;
     766           0 :         uint32_t i;
     767           4 :         const char **subkeys = NULL;
     768             : 
     769             : 
     770           4 :         ZERO_STRUCT(hive_hnd);
     771           4 :         ZERO_STRUCT(key_hnd);
     772             : 
     773             : 
     774           4 :         if (argc != 0 || c->display_usage) {
     775           0 :                 rpc_conf_listshares_usage(c, argc, argv);
     776           0 :                 status = NT_STATUS_INVALID_PARAMETER;
     777           0 :                 goto error;
     778             :         }
     779             : 
     780             : 
     781           4 :         status = rpc_conf_open_conf(frame,
     782             :                                     b,
     783             :                                     REG_KEY_READ,
     784             :                                     &hive_hnd,
     785             :                                     &key_hnd,
     786             :                                     &werr);
     787             : 
     788           4 :         if (!(NT_STATUS_IS_OK(status))) {
     789           0 :                 goto error;
     790             :         }
     791             : 
     792           4 :         if (!(W_ERROR_IS_OK(werr))) {
     793           0 :                 goto error;
     794             :         }
     795             : 
     796           4 :         status = dcerpc_winreg_enum_keys(frame,
     797             :                                          b,
     798             :                                          &key_hnd,
     799             :                                          &num_subkeys,
     800             :                                          &subkeys,
     801             :                                          &werr);
     802             : 
     803           4 :         if (!(NT_STATUS_IS_OK(status))) {
     804           0 :                 d_fprintf(stderr, _("Failed to enumerate keys: %s\n"),
     805             :                                 nt_errstr(status));
     806           0 :                 goto error;
     807             :         }
     808             : 
     809           4 :         if (!(W_ERROR_IS_OK(werr))) {
     810           0 :                 d_fprintf(stderr, _("Failed to enumerate keys: %s\n"),
     811             :                                 win_errstr(werr));
     812           0 :                 goto error;
     813             :         }
     814             : 
     815         402 :         for (i = 0; i < num_subkeys; i++) {
     816         398 :                 d_printf("%s\n", subkeys[i]);
     817             :         }
     818             : 
     819           4 : error:
     820           4 :         if (!(W_ERROR_IS_OK(werr))) {
     821           0 :                 status =  werror_to_ntstatus(werr);
     822             :         }
     823             : 
     824           4 :         dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
     825           4 :         dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
     826             : 
     827           4 :         TALLOC_FREE(frame);
     828           4 :         return status;;
     829             : }
     830             : 
     831           6 : static NTSTATUS rpc_conf_delshare_internal(struct net_context *c,
     832             :                                            const struct dom_sid *domain_sid,
     833             :                                            const char *domain_name,
     834             :                                            struct cli_state *cli,
     835             :                                            struct rpc_pipe_client *pipe_hnd,
     836             :                                            TALLOC_CTX *mem_ctx,
     837             :                                            int argc,
     838             :                                            const char **argv )
     839             : {
     840             : 
     841           6 :         TALLOC_CTX *frame = talloc_stackframe();
     842           6 :         NTSTATUS status = NT_STATUS_OK;
     843           6 :         WERROR werr = WERR_OK;
     844           0 :         WERROR _werr;
     845             : 
     846           6 :         struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
     847             : 
     848             :         /* key info */
     849           0 :         struct policy_handle hive_hnd, key_hnd;
     850             : 
     851           6 :         ZERO_STRUCT(hive_hnd);
     852           6 :         ZERO_STRUCT(key_hnd);
     853             : 
     854             : 
     855           6 :         if (argc != 1 || c->display_usage) {
     856           2 :                 rpc_conf_delshare_usage(c, argc, argv);
     857           2 :                 status = NT_STATUS_INVALID_PARAMETER;
     858           2 :                 goto error;
     859             :         }
     860             : 
     861           4 :         status = rpc_conf_open_conf(frame,
     862             :                                     b,
     863             :                                     REG_KEY_ALL,
     864             :                                     &hive_hnd,
     865             :                                     &key_hnd,
     866             :                                     &werr);
     867             : 
     868           4 :         if (!(NT_STATUS_IS_OK(status))) {
     869           0 :                 goto error;
     870             :         }
     871             : 
     872           4 :         if (!(W_ERROR_IS_OK(werr))) {
     873           0 :                 goto error;
     874             :         }
     875             : 
     876           4 :         status = dcerpc_winreg_delete_subkeys_recursive(frame,
     877             :                                                         b,
     878             :                                                         &key_hnd,
     879             :                                                         REG_KEY_ALL,
     880             :                                                         argv[0],
     881             :                                                         &werr);
     882             : 
     883           4 :         if (!NT_STATUS_IS_OK(status)) {
     884           0 :                 d_fprintf(stderr,
     885             :                           "winreg_delete_subkeys: Could not delete key %s: %s\n",
     886             :                           argv[0], nt_errstr(status));
     887           0 :                 goto error;
     888             :         }
     889             : 
     890           4 :         if (W_ERROR_EQUAL(werr, WERR_FILE_NOT_FOUND)){
     891           2 :                 d_fprintf(stderr, _("ERROR: Key does not exist\n"));
     892             :         }
     893             : 
     894             : 
     895           4 :         if (!W_ERROR_IS_OK(werr)) {
     896           2 :                 d_fprintf(stderr,
     897             :                           "winreg_delete_subkeys: Could not delete key %s: %s\n",
     898             :                           argv[0], win_errstr(werr));
     899           2 :                 goto error;
     900             :         }
     901             : 
     902           2 : error:
     903           6 :         if (!(W_ERROR_IS_OK(werr))) {
     904           2 :                 status =  werror_to_ntstatus(werr);
     905             :         }
     906             : 
     907           6 :         dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
     908           6 :         dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
     909             : 
     910           6 :         TALLOC_FREE(frame);
     911             : 
     912           6 :         return status;
     913             : }
     914             : 
     915          20 : static NTSTATUS rpc_conf_list_internal(struct net_context *c,
     916             :                                        const struct dom_sid *domain_sid,
     917             :                                        const char *domain_name,
     918             :                                        struct cli_state *cli,
     919             :                                        struct rpc_pipe_client *pipe_hnd,
     920             :                                        TALLOC_CTX *mem_ctx,
     921             :                                        int argc,
     922             :                                        const char **argv )
     923             : {
     924             : 
     925          20 :         TALLOC_CTX *frame = talloc_stackframe();
     926          20 :         NTSTATUS status = NT_STATUS_OK;
     927          20 :         WERROR werr = WERR_OK;
     928           0 :         WERROR _werr;
     929             : 
     930          20 :         struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
     931             : 
     932             :         /* key info */
     933           0 :         struct policy_handle hive_hnd, key_hnd;
     934           0 :         uint32_t num_subkeys;
     935           0 :         uint32_t i;
     936           0 :         struct smbconf_service *shares;
     937          20 :         const char **subkeys = NULL;
     938             : 
     939             : 
     940          20 :         ZERO_STRUCT(hive_hnd);
     941          20 :         ZERO_STRUCT(key_hnd);
     942             : 
     943             : 
     944          20 :         if (argc != 0 || c->display_usage) {
     945           0 :                 rpc_conf_list_usage(c, argc, argv);
     946           0 :                 status = NT_STATUS_INVALID_PARAMETER;
     947           0 :                 goto error;
     948             :         }
     949             : 
     950          20 :         status = rpc_conf_open_conf(frame,
     951             :                                     b,
     952             :                                     REG_KEY_READ,
     953             :                                     &hive_hnd,
     954             :                                     &key_hnd,
     955             :                                     &werr);
     956             : 
     957          20 :         if (!(NT_STATUS_IS_OK(status))) {
     958           0 :                 goto error;
     959             :         }
     960             : 
     961          20 :         if (!(W_ERROR_IS_OK(werr))) {
     962           0 :                 goto error;
     963             :         }
     964             : 
     965          20 :         status = dcerpc_winreg_enum_keys(frame,
     966             :                                          b,
     967             :                                          &key_hnd,
     968             :                                          &num_subkeys,
     969             :                                          &subkeys,
     970             :                                          &werr);
     971             : 
     972          20 :         if (!(NT_STATUS_IS_OK(status))) {
     973           0 :                 d_fprintf(stderr, _("Failed to enumerate keys: %s\n"),
     974             :                                 nt_errstr(status));
     975           0 :                 goto error;
     976             :         }
     977             : 
     978          20 :         if (!(W_ERROR_IS_OK(werr))) {
     979           0 :                 d_fprintf(stderr, _("Failed to enumerate keys: %s\n"),
     980             :                                 win_errstr(werr));
     981           0 :                 goto error;
     982             :         }
     983             : 
     984          20 :         if (num_subkeys == 0) {
     985           8 :                 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
     986           8 :                 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
     987           8 :                 TALLOC_FREE(frame);
     988           8 :                 return NT_STATUS_OK;
     989             :         }
     990             : 
     991             :         /* get info from each subkey */
     992          12 :         shares = talloc_zero_array(frame, struct smbconf_service, num_subkeys);
     993          12 :         if (shares == NULL) {
     994           0 :                 werr = WERR_NOT_ENOUGH_MEMORY;
     995           0 :                 d_fprintf(stderr, _("Failed to create shares: %s\n"),
     996             :                                 win_errstr(werr));
     997           0 :                 goto error;
     998             : 
     999             :         }
    1000             : 
    1001         420 :         for (i = 0; i < num_subkeys; i++) {
    1002             :                 /* get each share and place it in the shares array */
    1003         408 :                 status = rpc_conf_get_share(frame,
    1004             :                                 b,
    1005             :                                 &key_hnd,
    1006         408 :                                 subkeys[i],
    1007         408 :                                 &shares[i],
    1008             :                                 &werr);
    1009         408 :                 if (!(NT_STATUS_IS_OK(status))) {
    1010           0 :                         goto error;
    1011             :                 }
    1012         408 :                 if (!(W_ERROR_IS_OK(werr))) {
    1013           0 :                         goto error;
    1014             :                 }
    1015             : 
    1016             :         }
    1017             :         /* print the shares array */
    1018          12 :         rpc_conf_print_shares(num_subkeys, shares);
    1019             : 
    1020          12 : error:
    1021          12 :         if (!(W_ERROR_IS_OK(werr))) {
    1022           0 :                 status =  werror_to_ntstatus(werr);
    1023             :         }
    1024             : 
    1025          12 :         dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
    1026          12 :         dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
    1027             : 
    1028          12 :         TALLOC_FREE(frame);
    1029          12 :         return status;
    1030             : 
    1031             : }
    1032             : 
    1033          32 : static NTSTATUS rpc_conf_drop_internal(struct net_context *c,
    1034             :                                        const struct dom_sid *domain_sid,
    1035             :                                        const char *domain_name,
    1036             :                                        struct cli_state *cli,
    1037             :                                        struct rpc_pipe_client *pipe_hnd,
    1038             :                                        TALLOC_CTX *mem_ctx,
    1039             :                                        int argc,
    1040             :                                        const char **argv )
    1041             : {
    1042          32 :         TALLOC_CTX *frame = talloc_stackframe();
    1043          32 :         NTSTATUS status = NT_STATUS_OK;
    1044          32 :         WERROR werr = WERR_OK;
    1045           0 :         WERROR _werr;
    1046             : 
    1047          32 :         struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    1048             : 
    1049             :         /* key info */
    1050           0 :         struct policy_handle hive_hnd, key_hnd;
    1051          32 :         const char *keyname = confpath;
    1052           0 :         struct winreg_String wkey, wkeyclass;
    1053          32 :         enum winreg_CreateAction action = REG_ACTION_NONE;
    1054             : 
    1055             : 
    1056          32 :         ZERO_STRUCT(hive_hnd);
    1057          32 :         ZERO_STRUCT(key_hnd);
    1058             : 
    1059             : 
    1060          32 :         if (argc != 0 || c->display_usage) {
    1061           2 :                 rpc_conf_drop_usage(c, argc, argv);
    1062           2 :                 status = NT_STATUS_INVALID_PARAMETER;
    1063           2 :                 goto error;
    1064             :         }
    1065             : 
    1066          30 :         status = rpc_conf_open_conf(frame,
    1067             :                                     b,
    1068             :                                     REG_KEY_ALL,
    1069             :                                     &hive_hnd,
    1070             :                                     &key_hnd,
    1071             :                                     &werr);
    1072             : 
    1073          30 :         if (!(NT_STATUS_IS_OK(status))) {
    1074           0 :                 goto error;
    1075             :         }
    1076             : 
    1077          30 :         if (!(W_ERROR_IS_OK(werr))) {
    1078           0 :                 goto error;
    1079             :         }
    1080             : 
    1081          30 :         status = dcerpc_winreg_delete_subkeys_recursive(frame,
    1082             :                                                         b,
    1083             :                                                         &hive_hnd,
    1084             :                                                         REG_KEY_ALL,
    1085             :                                                         keyname,
    1086             :                                                         &werr);
    1087             : 
    1088          30 :         if (!NT_STATUS_IS_OK(status)) {
    1089           0 :                 d_printf("winreg_delete_subkeys: Could not delete key %s: %s\n",
    1090             :                           keyname, nt_errstr(status));
    1091           0 :                 goto error;
    1092             :         }
    1093             : 
    1094          30 :         if (!W_ERROR_IS_OK(werr)) {
    1095           0 :                 d_printf("winreg_delete_subkeys: Could not delete key %s: %s\n",
    1096             :                           keyname, win_errstr(werr));
    1097           0 :                 goto error;
    1098             :         }
    1099             : 
    1100          30 :         ZERO_STRUCT(wkey);
    1101          30 :         wkey.name = keyname;
    1102          30 :         ZERO_STRUCT(wkeyclass);
    1103          30 :         wkeyclass.name = "";
    1104          30 :         action = REG_ACTION_NONE;
    1105             : 
    1106          30 :         status = dcerpc_winreg_CreateKey(b,
    1107             :                                          frame,
    1108             :                                          &hive_hnd,
    1109             :                                          wkey,
    1110             :                                          wkeyclass,
    1111             :                                          0,
    1112             :                                          REG_KEY_ALL,
    1113             :                                          NULL,
    1114             :                                          &key_hnd,
    1115             :                                          &action,
    1116             :                                          &werr);
    1117             : 
    1118          30 :         if (!NT_STATUS_IS_OK(status)) {
    1119           0 :                 d_printf("winreg_CreateKey: Could not create smbconf key\n");
    1120           0 :                 goto error;
    1121             :         }
    1122             : 
    1123          30 :         if (!W_ERROR_IS_OK(werr)) {
    1124           0 :                 d_printf("winreg_CreateKey: Could not create smbconf key\n");
    1125           0 :                 goto error;
    1126             :         }
    1127             : 
    1128             : 
    1129          30 : error:
    1130          32 :         if (!(W_ERROR_IS_OK(werr))) {
    1131           0 :                 status =  werror_to_ntstatus(werr);
    1132             :         }
    1133             : 
    1134          32 :         dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
    1135          32 :         dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
    1136             : 
    1137          32 :         TALLOC_FREE(frame);
    1138          32 :         return status;
    1139             : }
    1140             : 
    1141           6 : static NTSTATUS rpc_conf_import_internal(struct net_context *c,
    1142             :                                          const struct dom_sid *domain_sid,
    1143             :                                          const char *domain_name,
    1144             :                                          struct cli_state *cli,
    1145             :                                          struct rpc_pipe_client *pipe_hnd,
    1146             :                                          TALLOC_CTX *mem_ctx,
    1147             :                                          int argc,
    1148             :                                          const char **argv )
    1149             : {
    1150             : 
    1151           6 :         struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    1152             : 
    1153           0 :         struct policy_handle hive_hnd, key_hnd;
    1154             : 
    1155           6 :         const char *filename = NULL;
    1156           6 :         const char *servicename = NULL;
    1157           6 :         char *conf_source = NULL;
    1158           0 :         TALLOC_CTX *frame;
    1159           0 :         struct smbconf_ctx *txt_ctx;
    1160           6 :         struct smbconf_service *service = NULL;
    1161           6 :         struct smbconf_service **services = NULL;
    1162           0 :         uint32_t num_shares, i;
    1163           6 :         sbcErr err = SBC_ERR_UNKNOWN_FAILURE;
    1164             : 
    1165           6 :         WERROR werr = WERR_OK;
    1166           6 :         NTSTATUS status = NT_STATUS_OK;
    1167             : 
    1168           6 :         ZERO_STRUCT(hive_hnd);
    1169           6 :         ZERO_STRUCT(key_hnd);
    1170             : 
    1171           6 :         frame = talloc_stackframe();
    1172             : 
    1173           6 :         if (c->display_usage) {
    1174           0 :                 rpc_conf_import_usage(c, argc, argv);
    1175           0 :                 status = NT_STATUS_INVALID_PARAMETER;
    1176           0 :                 goto error;
    1177             :         }
    1178             : 
    1179           6 :         switch (argc) {
    1180           2 :                 case 0:
    1181             :                 default:
    1182           2 :                         rpc_conf_import_usage(c, argc, argv);
    1183           2 :                         status = NT_STATUS_INVALID_PARAMETER;
    1184           2 :                         goto error;
    1185           0 :                 case 2:
    1186           0 :                         servicename = talloc_strdup(frame, argv[1]);
    1187           0 :                         if (servicename == NULL) {
    1188           0 :                                 d_printf(_("error: out of memory!\n"));
    1189           0 :                                 goto error;
    1190             :                         }
    1191             : 
    1192           0 :                         FALL_THROUGH;
    1193             :                 case 1:
    1194           4 :                         filename = argv[0];
    1195           4 :                         break;
    1196             :         }
    1197             : 
    1198           4 :         DEBUG(3,("rpc_conf_import: reading configuration from file %s.\n",
    1199             :                 filename));
    1200             : 
    1201           4 :         conf_source = talloc_asprintf(frame, "file:%s", filename);
    1202           4 :         if (conf_source == NULL) {
    1203           0 :                 d_fprintf(stderr, _("error: out of memory!\n"));
    1204           0 :                 goto error;
    1205             :         }
    1206             : 
    1207           4 :         err = smbconf_init(frame, &txt_ctx, conf_source);
    1208           4 :         if (!SBC_ERROR_IS_OK(err)) {
    1209           0 :                 d_fprintf(stderr, _("error loading file '%s': %s\n"), filename,
    1210             :                          sbcErrorString(err));
    1211           0 :                 goto error;
    1212             :         }
    1213             : 
    1214           4 :         if (c->opt_testmode) {
    1215           0 :                 d_printf(_("\nTEST MODE - "
    1216             :                          "would import the following configuration:\n\n"));
    1217             :         }
    1218             : 
    1219           4 :         if (servicename != NULL) {
    1220           0 :                 err = smbconf_get_share(txt_ctx, frame,
    1221             :                                         servicename,
    1222             :                                         &service);
    1223           0 :                 if (!SBC_ERROR_IS_OK(err)) {
    1224           0 :                         goto error;
    1225             :                 }
    1226             : 
    1227           0 :                 num_shares = 1;
    1228             : 
    1229             :         } else {
    1230             : 
    1231           4 :                 err = smbconf_get_config(txt_ctx, frame,
    1232             :                                           &num_shares,
    1233             :                                           &services);
    1234           4 :                 if (!SBC_ERROR_IS_OK(err)) {
    1235           0 :                         goto error;
    1236             :                 }
    1237             :         }
    1238             : 
    1239           4 :         if (c->opt_testmode) {
    1240           0 :                 if (servicename != NULL) {
    1241           0 :                         rpc_conf_print_shares(1, service);
    1242             :                 }
    1243           0 :                 for (i = 0; i < num_shares; i++) {
    1244           0 :                         rpc_conf_print_shares(1, services[i]);
    1245             :                 }
    1246           0 :                 goto error;
    1247             :         }
    1248             : 
    1249           4 :         status = rpc_conf_drop_internal(c,
    1250             :                                domain_sid,
    1251             :                                domain_name,
    1252             :                                cli,
    1253             :                                pipe_hnd,
    1254             :                                frame,
    1255             :                                0,
    1256             :                                NULL );
    1257             : 
    1258           4 :         if (!(NT_STATUS_IS_OK(status))) {
    1259           0 :                 goto error;
    1260             :         }
    1261             : 
    1262           4 :         status = rpc_conf_open_conf(frame,
    1263             :                                     b,
    1264             :                                     REG_KEY_READ,
    1265             :                                     &hive_hnd,
    1266             :                                     &key_hnd,
    1267             :                                     &werr);
    1268             : 
    1269           4 :         if (!(NT_STATUS_IS_OK(status))) {
    1270           0 :                 goto error;
    1271             :         }
    1272             : 
    1273           4 :         if (!(W_ERROR_IS_OK(werr))) {
    1274           0 :                 goto error;
    1275             :         }
    1276             : 
    1277           4 :         if (servicename != NULL) {
    1278           0 :                 status = rpc_conf_set_share(frame,
    1279             :                                             b,
    1280             :                                             &key_hnd,
    1281             :                                             service,
    1282             :                                             &werr);
    1283             : 
    1284           0 :                 if (!(NT_STATUS_IS_OK(status))) {
    1285           0 :                         goto error;
    1286             :                 }
    1287             : 
    1288           0 :                 if (!(W_ERROR_IS_OK(werr))) {
    1289           0 :                         goto error;
    1290             :                 }
    1291             : 
    1292             :         } else {
    1293             : 
    1294         206 :                 for (i = 0; i < num_shares; i++) {
    1295         202 :                         status = rpc_conf_set_share(frame,
    1296             :                                         b,
    1297             :                                         &key_hnd,
    1298         202 :                                         services[i],
    1299             :                                         &werr);
    1300             : 
    1301         202 :                         if (!(NT_STATUS_IS_OK(status))) {
    1302           0 :                                 goto error;
    1303             :                         }
    1304             : 
    1305         202 :                         if (!(W_ERROR_IS_OK(werr))) {
    1306           0 :                                 goto error;
    1307             :                         }
    1308             : 
    1309             :                 }
    1310             :         }
    1311             : 
    1312           4 : error:
    1313           6 :         if (!SBC_ERROR_IS_OK(err)) {
    1314           2 :                 d_fprintf(stderr, "ERROR: %s\n", sbcErrorString(err));
    1315             :         }
    1316             : 
    1317           6 :         if (!(W_ERROR_IS_OK(werr))) {
    1318           0 :                 status =  werror_to_ntstatus(werr);
    1319             :         }
    1320           6 :         TALLOC_FREE(frame);
    1321           6 :         return status;
    1322             : }
    1323             : 
    1324         212 : static NTSTATUS rpc_conf_showshare_internal(struct net_context *c,
    1325             :                                             const struct dom_sid *domain_sid,
    1326             :                                             const char *domain_name,
    1327             :                                             struct cli_state *cli,
    1328             :                                             struct rpc_pipe_client *pipe_hnd,
    1329             :                                             TALLOC_CTX *mem_ctx,
    1330             :                                             int argc,
    1331             :                                             const char **argv )
    1332             : {
    1333         212 :         TALLOC_CTX *frame = talloc_stackframe();
    1334         212 :         NTSTATUS status = NT_STATUS_OK;
    1335         212 :         WERROR werr = WERR_OK;
    1336           0 :         WERROR _werr;
    1337             : 
    1338         212 :         struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    1339             : 
    1340             :         /* key info */
    1341           0 :         struct policy_handle hive_hnd, key_hnd;
    1342         212 :         struct smbconf_service *service = NULL;
    1343         212 :         const char *sharename = NULL;
    1344             : 
    1345             : 
    1346         212 :         ZERO_STRUCT(hive_hnd);
    1347         212 :         ZERO_STRUCT(key_hnd);
    1348             : 
    1349             : 
    1350         212 :         if (argc != 1 || c->display_usage) {
    1351           0 :                 rpc_conf_showshare_usage(c, argc, argv);
    1352           0 :                 status = NT_STATUS_INVALID_PARAMETER;
    1353           0 :                 goto error;
    1354             :         }
    1355             : 
    1356         212 :         status = rpc_conf_open_conf(frame,
    1357             :                                     b,
    1358             :                                     REG_KEY_READ,
    1359             :                                     &hive_hnd,
    1360             :                                     &key_hnd,
    1361             :                                     &werr);
    1362             : 
    1363         212 :         if (!(NT_STATUS_IS_OK(status))) {
    1364           0 :                 goto error;
    1365             :         }
    1366             : 
    1367         212 :         if (!(W_ERROR_IS_OK(werr))) {
    1368           0 :                 goto error;
    1369             :         }
    1370             : 
    1371         212 :         sharename = talloc_strdup(frame, argv[0]);
    1372         212 :         if (sharename == NULL) {
    1373           0 :                 werr = WERR_NOT_ENOUGH_MEMORY;
    1374           0 :                 d_fprintf(stderr, _("Failed to create share: %s\n"),
    1375             :                                 win_errstr(werr));
    1376           0 :                 goto error;
    1377             :         }
    1378             : 
    1379         212 :         service = talloc(frame, struct smbconf_service);
    1380         212 :         if (service == NULL) {
    1381           0 :                 werr = WERR_NOT_ENOUGH_MEMORY;
    1382           0 :                 d_fprintf(stderr, _("Failed to create share: %s\n"),
    1383             :                                 win_errstr(werr));
    1384           0 :                 goto error;
    1385             :         }
    1386             : 
    1387         212 :         status = rpc_conf_get_share(frame,
    1388             :                         b,
    1389             :                         &key_hnd,
    1390             :                         sharename,
    1391             :                         service,
    1392             :                         &werr);
    1393             : 
    1394         212 :         if (!(NT_STATUS_IS_OK(status))) {
    1395           0 :                 goto error;
    1396             :         }
    1397         212 :         if (!(W_ERROR_IS_OK(werr))) {
    1398           0 :                 goto error;
    1399             :         }
    1400             : 
    1401         212 :         rpc_conf_print_shares(1, service);
    1402             : 
    1403         212 : error:
    1404         212 :         if (!(W_ERROR_IS_OK(werr))) {
    1405           0 :                 status =  werror_to_ntstatus(werr);
    1406             :         }
    1407             : 
    1408         212 :         dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
    1409         212 :         dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
    1410             : 
    1411         212 :         TALLOC_FREE(frame);
    1412         212 :         return status;
    1413             : }
    1414             : 
    1415         214 : static NTSTATUS rpc_conf_addshare_internal(struct net_context *c,
    1416             :                                            const struct dom_sid *domain_sid,
    1417             :                                            const char *domain_name,
    1418             :                                            struct cli_state *cli,
    1419             :                                            struct rpc_pipe_client *pipe_hnd,
    1420             :                                            TALLOC_CTX *mem_ctx,
    1421             :                                            int argc,
    1422             :                                            const char **argv )
    1423             : {
    1424         214 :         TALLOC_CTX *frame = talloc_stackframe();
    1425         214 :         NTSTATUS status = NT_STATUS_OK;
    1426         214 :         WERROR werr = WERR_OK;
    1427           0 :         WERROR _werr;
    1428             : 
    1429         214 :         struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    1430             : 
    1431             :         /* key info */
    1432           0 :         struct policy_handle hive_hnd, key_hnd, share_hnd;
    1433         214 :         char *sharename = NULL;
    1434         214 :         const char *path = NULL;
    1435         214 :         const char *comment = NULL;
    1436         214 :         const char *guest_ok = "no";
    1437         214 :         const char *read_only = "yes";
    1438           0 :         struct winreg_String key, keyclass;
    1439         214 :         enum winreg_CreateAction action = 0;
    1440             : 
    1441             : 
    1442         214 :         ZERO_STRUCT(hive_hnd);
    1443         214 :         ZERO_STRUCT(key_hnd);
    1444         214 :         ZERO_STRUCT(share_hnd);
    1445             : 
    1446         214 :         ZERO_STRUCT(key);
    1447         214 :         ZERO_STRUCT(keyclass);
    1448             : 
    1449         214 :         if (c->display_usage) {
    1450           0 :                 rpc_conf_addshare_usage(c, argc, argv);
    1451           0 :                 status = NT_STATUS_INVALID_PARAMETER;
    1452           0 :                 goto error;
    1453             :         }
    1454             : 
    1455         214 :         switch (argc) {
    1456           2 :                 case 0:
    1457             :                 case 1:
    1458             :                 default:
    1459           2 :                         rpc_conf_addshare_usage(c, argc, argv);
    1460           2 :                         status = NT_STATUS_INVALID_PARAMETER;
    1461           2 :                         goto error;
    1462         206 :                 case 5:
    1463         206 :                         comment = argv[4];
    1464             : 
    1465           0 :                         FALL_THROUGH;
    1466         206 :                 case 4:
    1467         206 :                         if (!strnequal(argv[3], "guest_ok=", 9)) {
    1468           0 :                                 rpc_conf_addshare_usage(c, argc, argv);
    1469           0 :                                 status = NT_STATUS_INVALID_PARAMETER;
    1470           0 :                                 goto error;
    1471             :                         }
    1472         206 :                         switch (argv[3][9]) {
    1473         102 :                                 case 'y':
    1474             :                                 case 'Y':
    1475         102 :                                         guest_ok = "yes";
    1476         206 :                                         break;
    1477         104 :                                 case 'n':
    1478             :                                 case 'N':
    1479         104 :                                         guest_ok = "no";
    1480         104 :                                         break;
    1481           0 :                                 default:
    1482           0 :                                         rpc_conf_addshare_usage(c, argc, argv);
    1483           0 :                                         status = NT_STATUS_INVALID_PARAMETER;
    1484           0 :                                         goto error;
    1485             :                         }
    1486             : 
    1487           0 :                         FALL_THROUGH;
    1488             :                 case 3:
    1489         206 :                         if (!strnequal(argv[2], "writeable=", 10)) {
    1490           0 :                                 rpc_conf_addshare_usage(c, argc, argv);
    1491           0 :                                 status = NT_STATUS_INVALID_PARAMETER;
    1492           0 :                                 goto error;
    1493             :                         }
    1494         206 :                         switch (argv[2][10]) {
    1495         102 :                                 case 'y':
    1496             :                                 case 'Y':
    1497         102 :                                         read_only = "no";
    1498         206 :                                         break;
    1499         104 :                                 case 'n':
    1500             :                                 case 'N':
    1501         104 :                                         read_only = "yes";
    1502         104 :                                         break;
    1503           0 :                                 default:
    1504           0 :                                         rpc_conf_addshare_usage(c, argc, argv);
    1505           0 :                                         status = NT_STATUS_INVALID_PARAMETER;
    1506           0 :                                         goto error;
    1507             :                         }
    1508             : 
    1509           0 :                         FALL_THROUGH;
    1510             :                 case 2:
    1511         212 :                         path = argv[1];
    1512         212 :                         sharename = talloc_strdup(frame, argv[0]);
    1513         212 :                         if (sharename == NULL) {
    1514           0 :                                 d_printf(_("error: out of memory!\n"));
    1515           0 :                                 goto error;
    1516             :                         }
    1517             : 
    1518         212 :                         break;
    1519             :         }
    1520             : 
    1521         212 :         status = rpc_conf_open_conf(frame,
    1522             :                                     b,
    1523             :                                     REG_KEY_READ,
    1524             :                                     &hive_hnd,
    1525             :                                     &key_hnd,
    1526             :                                     &werr);
    1527             : 
    1528         212 :         if (!(NT_STATUS_IS_OK(status))) {
    1529           0 :                 goto error;
    1530             :         }
    1531             : 
    1532         212 :         if (!(W_ERROR_IS_OK(werr))) {
    1533           0 :                 goto error;
    1534             :         }
    1535             : 
    1536         212 :         key.name = argv[0];
    1537         212 :         keyclass.name = "";
    1538             : 
    1539         212 :         status = dcerpc_winreg_CreateKey(b, frame, &key_hnd, key, keyclass,
    1540             :                         0, REG_KEY_READ, NULL, &share_hnd,
    1541             :                         &action, &werr);
    1542             : 
    1543         212 :         if (!(NT_STATUS_IS_OK(status))) {
    1544           0 :                 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
    1545             :                                 argv[0], nt_errstr(status));
    1546           0 :                 goto error;
    1547             :         }
    1548             : 
    1549         212 :         if (!W_ERROR_IS_OK(werr)) {
    1550           0 :                 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
    1551             :                                 argv[0], win_errstr(werr));
    1552           0 :                 goto error;
    1553             :         }
    1554             : 
    1555         212 :         switch (action) {
    1556           0 :                 case REG_ACTION_NONE:
    1557           0 :                         werr = WERR_CREATE_FAILED;
    1558           0 :                         d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
    1559             :                                 argv[0], win_errstr(werr));
    1560           2 :                         goto error;
    1561         210 :                 case REG_CREATED_NEW_KEY:
    1562         210 :                         DEBUG(5, ("net rpc conf setincludes:"
    1563             :                                         "createkey created %s\n", argv[0]));
    1564         210 :                         break;
    1565           2 :                 case REG_OPENED_EXISTING_KEY:
    1566           2 :                         d_fprintf(stderr, _("ERROR: Share '%s' already exists\n"), argv[0]);
    1567           2 :                         status = NT_STATUS_INVALID_PARAMETER;
    1568           2 :                         goto error;
    1569             :         }
    1570             : 
    1571             :         /* set the path parameter */
    1572         210 :         status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
    1573             :                                         "path", path, &werr);
    1574             : 
    1575         210 :         if (!(NT_STATUS_IS_OK(status))) {
    1576           0 :                 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
    1577             :                                 " with value %s\n %s\n",
    1578             :                                 "path", path, nt_errstr(status));
    1579           0 :                 goto error;
    1580             :         }
    1581             : 
    1582         210 :         if (!(W_ERROR_IS_OK(werr))) {
    1583           0 :                 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
    1584             :                                 " with value %s\n %s\n",
    1585             :                                 "path", path, win_errstr(werr));
    1586           0 :                 goto error;
    1587             :         }
    1588             : 
    1589             :         /* set the writeable parameter */
    1590         210 :         status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
    1591             :                                         "read only", read_only, &werr);
    1592             : 
    1593         210 :         if (!(NT_STATUS_IS_OK(status))) {
    1594           0 :                 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
    1595             :                                 " with value %s\n %s\n",
    1596             :                                 "read only", read_only, nt_errstr(status));
    1597           0 :                 goto error;
    1598             :         }
    1599             : 
    1600         210 :         if (!(W_ERROR_IS_OK(werr))) {
    1601           0 :                 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
    1602             :                                 " with value %s\n %s\n",
    1603             :                                 "read only", read_only, win_errstr(werr));
    1604           0 :                 goto error;
    1605             :         }
    1606             : 
    1607             :         /* set the guest ok parameter */
    1608         210 :         status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
    1609             :                                         "guest ok", guest_ok, &werr);
    1610             : 
    1611         210 :         if (!(NT_STATUS_IS_OK(status))) {
    1612           0 :                 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
    1613             :                                 " with value %s\n %s\n",
    1614             :                                 "guest ok", guest_ok, nt_errstr(status));
    1615           0 :                 goto error;
    1616             :         }
    1617             : 
    1618         210 :         if (!(W_ERROR_IS_OK(werr))) {
    1619           0 :                 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
    1620             :                                 " with value %s\n %s\n",
    1621             :                                 "guest ok", guest_ok, win_errstr(werr));
    1622           0 :                 goto error;
    1623             :         }
    1624             : 
    1625         210 :         if (argc == 5) {
    1626             :                 /* set the comment parameter */
    1627         204 :                 status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
    1628             :                                                 "comment", comment, &werr);
    1629             : 
    1630         204 :                 if (!(NT_STATUS_IS_OK(status))) {
    1631           0 :                         d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
    1632             :                                         " with value %s\n %s\n",
    1633             :                                         "comment", comment, nt_errstr(status));
    1634           0 :                         goto error;
    1635             :                 }
    1636             : 
    1637         204 :                 if (!(W_ERROR_IS_OK(werr))) {
    1638           0 :                         d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
    1639             :                                         " with value %s\n %s\n",
    1640             :                                         "comment", comment, win_errstr(werr));
    1641           0 :                         goto error;
    1642             :                 }
    1643             :         }
    1644         210 : error:
    1645         214 :         if (!(W_ERROR_IS_OK(werr))) {
    1646           0 :                 status =  werror_to_ntstatus(werr);
    1647             :         }
    1648             : 
    1649         214 :         dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
    1650         214 :         dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
    1651         214 :         dcerpc_winreg_CloseKey(b, frame, &share_hnd, &_werr);
    1652             : 
    1653         214 :         TALLOC_FREE(frame);
    1654         214 :         return status;
    1655             : }
    1656             : 
    1657           8 : static NTSTATUS rpc_conf_getparm_internal(struct net_context *c,
    1658             :                                           const struct dom_sid *domain_sid,
    1659             :                                           const char *domain_name,
    1660             :                                           struct cli_state *cli,
    1661             :                                           struct rpc_pipe_client *pipe_hnd,
    1662             :                                           TALLOC_CTX *mem_ctx,
    1663             :                                           int argc,
    1664             :                                           const char **argv )
    1665             : {
    1666           8 :         TALLOC_CTX *frame = talloc_stackframe();
    1667           8 :         NTSTATUS status = NT_STATUS_OK;
    1668           8 :         WERROR werr = WERR_OK;
    1669           0 :         WERROR _werr;
    1670             : 
    1671           8 :         struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    1672             : 
    1673             :         /* key info */
    1674           0 :         struct policy_handle hive_hnd, key_hnd;
    1675           8 :         struct smbconf_service *service = NULL;
    1676             : 
    1677           8 :         bool param_is_set = false;
    1678           0 :         uint32_t param_count;
    1679             : 
    1680           8 :         ZERO_STRUCT(hive_hnd);
    1681           8 :         ZERO_STRUCT(key_hnd);
    1682             : 
    1683             : 
    1684           8 :         if (argc != 2 || c->display_usage) {
    1685           2 :                 rpc_conf_getparm_usage(c, argc, argv);
    1686           2 :                 status = NT_STATUS_INVALID_PARAMETER;
    1687           2 :                 goto error;
    1688             :         }
    1689             : 
    1690           6 :         status = rpc_conf_open_conf(frame,
    1691             :                                     b,
    1692             :                                     REG_KEY_READ,
    1693             :                                     &hive_hnd,
    1694             :                                     &key_hnd,
    1695             :                                     &werr);
    1696             : 
    1697           6 :         if (!(NT_STATUS_IS_OK(status))) {
    1698           0 :                 goto error;
    1699             :         }
    1700             : 
    1701           6 :         if (!(W_ERROR_IS_OK(werr))) {
    1702           0 :                 goto error;
    1703             :         }
    1704             : 
    1705             : 
    1706           6 :         service = talloc(frame, struct smbconf_service);
    1707             : 
    1708           6 :         status = rpc_conf_get_share(frame,
    1709             :                                     b,
    1710             :                                     &key_hnd,
    1711             :                                     argv[0],
    1712             :                                     service,
    1713             :                                     &werr);
    1714             : 
    1715           6 :         if (!(NT_STATUS_IS_OK(status))) {
    1716           0 :                         goto error;
    1717             :         }
    1718             : 
    1719           6 :         if (W_ERROR_EQUAL(werr, WERR_FILE_NOT_FOUND)) {
    1720           0 :                 d_fprintf(stderr, _("ERROR: Share %s does not exist\n"),
    1721             :                                 argv[0]);
    1722           0 :                 goto error;
    1723             :         }
    1724             : 
    1725           6 :         if (!(W_ERROR_IS_OK(werr))) {
    1726           0 :                         goto error;
    1727             :         }
    1728             : 
    1729           6 :         for (param_count = 0;
    1730          30 :              param_count < service->num_params;
    1731          24 :              param_count++)
    1732             :         {
    1733             :                 /* should includes also be printed? */
    1734          24 :                 if (strcmp(service->param_names[param_count], argv[1]) == 0) {
    1735           6 :                         d_printf(_("%s\n"),
    1736           6 :                                 service->param_values[param_count]);
    1737           6 :                         param_is_set = true;
    1738             :                 }
    1739             :         }
    1740             : 
    1741           6 :         if (!param_is_set) {
    1742           0 :                 d_fprintf(stderr, _("ERROR: Given parameter '%s' has not been set\n"),
    1743           0 :                                 argv[1]);
    1744           0 :                 werr = WERR_FILE_NOT_FOUND;
    1745           0 :                 goto error;
    1746             :         }
    1747             : 
    1748           6 : error:
    1749             : 
    1750           8 :         if (!(W_ERROR_IS_OK(werr))) {
    1751           0 :                 status =  werror_to_ntstatus(werr);
    1752             :         }
    1753             : 
    1754           8 :         dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
    1755           8 :         dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
    1756             : 
    1757           8 :         TALLOC_FREE(frame);
    1758           8 :         return status;
    1759             : 
    1760             : }
    1761             : 
    1762          22 : static NTSTATUS rpc_conf_setparm_internal(struct net_context *c,
    1763             :                                           const struct dom_sid *domain_sid,
    1764             :                                           const char *domain_name,
    1765             :                                           struct cli_state *cli,
    1766             :                                           struct rpc_pipe_client *pipe_hnd,
    1767             :                                           TALLOC_CTX *mem_ctx,
    1768             :                                           int argc,
    1769             :                                           const char **argv )
    1770             : {
    1771          22 :         TALLOC_CTX *frame = talloc_stackframe();
    1772          22 :         NTSTATUS status = NT_STATUS_OK;
    1773          22 :         WERROR werr = WERR_OK;
    1774           0 :         WERROR _werr;
    1775             : 
    1776          22 :         struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    1777             : 
    1778             :         /* key info */
    1779           0 :         struct policy_handle hive_hnd, key_hnd, share_hnd;
    1780             : 
    1781           0 :         struct winreg_String key, keyclass;
    1782          22 :         enum winreg_CreateAction action = 0;
    1783             : 
    1784           0 :         const char *service_name, *param_name, *valstr;
    1785             : 
    1786          22 :         ZERO_STRUCT(hive_hnd);
    1787          22 :         ZERO_STRUCT(key_hnd);
    1788          22 :         ZERO_STRUCT(share_hnd);
    1789             : 
    1790          22 :         ZERO_STRUCT(key);
    1791          22 :         ZERO_STRUCT(keyclass);
    1792             : 
    1793          22 :         if (argc != 3 || c->display_usage) {
    1794           2 :                 rpc_conf_setparm_usage(c, argc, argv);
    1795           2 :                 status = NT_STATUS_INVALID_PARAMETER;
    1796           2 :                 goto error;
    1797             :         }
    1798             : 
    1799          20 :         status = rpc_conf_open_conf(frame,
    1800             :                                     b,
    1801             :                                     REG_KEY_READ,
    1802             :                                     &hive_hnd,
    1803             :                                     &key_hnd,
    1804             :                                     &werr);
    1805             : 
    1806          20 :         if (!(NT_STATUS_IS_OK(status))) {
    1807           0 :                 goto error;
    1808             :         }
    1809             : 
    1810          20 :         if (!(W_ERROR_IS_OK(werr))) {
    1811           0 :                 goto error;
    1812             :         }
    1813             : 
    1814          20 :         service_name = argv[0];
    1815          20 :         param_name = argv[1];
    1816          20 :         valstr = argv[2];
    1817             : 
    1818          20 :         key.name = service_name;
    1819          20 :         keyclass.name = "";
    1820             : 
    1821          20 :         status = dcerpc_winreg_CreateKey(b, frame, &key_hnd, key, keyclass,
    1822             :                         0, REG_KEY_READ, NULL, &share_hnd,
    1823             :                         &action, &werr);
    1824             : 
    1825          20 :         if (!(NT_STATUS_IS_OK(status))) {
    1826           0 :                 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
    1827             :                           service_name, nt_errstr(status));
    1828           0 :                 goto error;
    1829             :         }
    1830             : 
    1831          20 :         if (!W_ERROR_IS_OK(werr)) {
    1832           0 :                 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
    1833             :                           service_name, win_errstr(werr));
    1834           0 :                 goto error;
    1835             :         }
    1836             : 
    1837          20 :         switch (action) {
    1838           0 :                 case REG_ACTION_NONE:
    1839           0 :                         werr = WERR_CREATE_FAILED;
    1840           0 :                         d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
    1841             :                                   service_name, win_errstr(werr));
    1842           0 :                         goto error;
    1843           4 :                 case REG_CREATED_NEW_KEY:
    1844           4 :                         DEBUG(5, ("net rpc conf setparm:"
    1845             :                                   "createkey created %s\n", service_name));
    1846          20 :                         break;
    1847          16 :                 case REG_OPENED_EXISTING_KEY:
    1848          16 :                         DEBUG(5, ("net rpc conf setparm:"
    1849             :                                   "createkey opened existing %s\n",
    1850             :                                   service_name));
    1851             : 
    1852             :                         /* delete possibly existing value */
    1853          16 :                         status = rpc_conf_del_value(frame,
    1854             :                                                     b,
    1855             :                                                     &key_hnd,
    1856             :                                                     service_name,
    1857             :                                                     param_name,
    1858             :                                                     &werr);
    1859             : 
    1860          16 :                         if (!(NT_STATUS_IS_OK(status))) {
    1861           0 :                                 goto error;
    1862             :                         }
    1863             : 
    1864          16 :                         if (!(W_ERROR_IS_OK(werr))) {
    1865           0 :                                 goto error;
    1866             :                         }
    1867             : 
    1868          16 :                         break;
    1869             :         }
    1870             : 
    1871             :         /*
    1872             :          * check if parameter is valid for writing
    1873             :          */
    1874             : 
    1875          20 :         if (!net_conf_param_valid(service_name, param_name, valstr)) {
    1876          10 :                 werr = WERR_INVALID_PARAMETER;
    1877          10 :                 goto error;
    1878             :         }
    1879             : 
    1880             :         /* set the parameter */
    1881          10 :         status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
    1882             :                                       param_name, valstr, &werr);
    1883             : 
    1884          10 :         if (!(NT_STATUS_IS_OK(status))) {
    1885           0 :                 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
    1886             :                                 " with value %s\n %s\n",
    1887             :                                 param_name, valstr, nt_errstr(status));
    1888           0 :                 goto error;
    1889             :         }
    1890             : 
    1891          10 :         if (!(W_ERROR_IS_OK(werr))) {
    1892           0 :                 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
    1893             :                                 " with value %s\n %s\n",
    1894             :                                 param_name, valstr, win_errstr(werr));
    1895           0 :                 goto error;
    1896             :         }
    1897             : 
    1898          10 : error:
    1899             : 
    1900          22 :         if (!(W_ERROR_IS_OK(werr))) {
    1901          10 :                 status =  werror_to_ntstatus(werr);
    1902             :         }
    1903             : 
    1904          22 :         dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
    1905          22 :         dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
    1906          22 :         dcerpc_winreg_CloseKey(b, frame, &share_hnd, &_werr);
    1907             : 
    1908          22 :         TALLOC_FREE(frame);
    1909          22 :         return status;
    1910             : }
    1911             : 
    1912           6 : static NTSTATUS rpc_conf_delparm_internal(struct net_context *c,
    1913             :                                           const struct dom_sid *domain_sid,
    1914             :                                           const char *domain_name,
    1915             :                                           struct cli_state *cli,
    1916             :                                           struct rpc_pipe_client *pipe_hnd,
    1917             :                                           TALLOC_CTX *mem_ctx,
    1918             :                                           int argc,
    1919             :                                           const char **argv )
    1920             : {
    1921           6 :         TALLOC_CTX *frame = talloc_stackframe();
    1922           6 :         NTSTATUS status = NT_STATUS_OK;
    1923           6 :         WERROR werr = WERR_OK;
    1924           0 :         WERROR _werr;
    1925             : 
    1926           6 :         struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    1927             : 
    1928             :         /* key info */
    1929           0 :         struct policy_handle hive_hnd, key_hnd;
    1930             : 
    1931             : 
    1932           6 :         ZERO_STRUCT(hive_hnd);
    1933           6 :         ZERO_STRUCT(key_hnd);
    1934             : 
    1935             : 
    1936           6 :         if (argc != 2 || c->display_usage) {
    1937           2 :                 rpc_conf_delparm_usage(c, argc, argv);
    1938           2 :                 status = NT_STATUS_INVALID_PARAMETER;
    1939           2 :                 goto error;
    1940             :         }
    1941             : 
    1942           4 :         status = rpc_conf_open_conf(frame,
    1943             :                                     b,
    1944             :                                     REG_KEY_READ,
    1945             :                                     &hive_hnd,
    1946             :                                     &key_hnd,
    1947             :                                     &werr);
    1948             : 
    1949           4 :         if (!(NT_STATUS_IS_OK(status))) {
    1950           0 :                 goto error;
    1951             :         }
    1952             : 
    1953           4 :         if (!(W_ERROR_IS_OK(werr))) {
    1954           0 :                 goto error;
    1955             :         }
    1956             : 
    1957           4 :         status = rpc_conf_del_value(frame,
    1958             :                                     b,
    1959             :                                     &key_hnd,
    1960             :                                     argv[0],
    1961           4 :                                     argv[1],
    1962             :                                     &werr);
    1963             : 
    1964           6 : error:
    1965             : 
    1966           6 :         if (!(W_ERROR_IS_OK(werr))) {
    1967           2 :                 status =  werror_to_ntstatus(werr);
    1968             :         }
    1969             : 
    1970           6 :         dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
    1971           6 :         dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
    1972             : 
    1973           6 :         TALLOC_FREE(frame);
    1974           6 :         return status;
    1975             : 
    1976             : }
    1977             : 
    1978           4 : static NTSTATUS rpc_conf_getincludes_internal(struct net_context *c,
    1979             :                                               const struct dom_sid *domain_sid,
    1980             :                                               const char *domain_name,
    1981             :                                               struct cli_state *cli,
    1982             :                                               struct rpc_pipe_client *pipe_hnd,
    1983             :                                               TALLOC_CTX *mem_ctx,
    1984             :                                               int argc,
    1985             :                                               const char **argv )
    1986             : {
    1987           4 :         TALLOC_CTX *frame = talloc_stackframe();
    1988           4 :         NTSTATUS status = NT_STATUS_OK;
    1989           4 :         WERROR werr = WERR_OK;
    1990           0 :         WERROR _werr;
    1991             : 
    1992           4 :         struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    1993             : 
    1994             :         /* key info */
    1995           0 :         struct policy_handle hive_hnd, key_hnd;
    1996           4 :         struct smbconf_service *service = NULL;
    1997             : 
    1998           0 :         uint32_t param_count;
    1999             : 
    2000             : 
    2001           4 :         ZERO_STRUCT(hive_hnd);
    2002           4 :         ZERO_STRUCT(key_hnd);
    2003             : 
    2004             : 
    2005           4 :         if (argc != 1 || c->display_usage) {
    2006           2 :                 rpc_conf_getincludes_usage(c, argc, argv);
    2007           2 :                 status = NT_STATUS_INVALID_PARAMETER;
    2008           2 :                 goto error;
    2009             :         }
    2010             : 
    2011           2 :         status = rpc_conf_open_conf(frame,
    2012             :                                     b,
    2013             :                                     REG_KEY_READ,
    2014             :                                     &hive_hnd,
    2015             :                                     &key_hnd,
    2016             :                                     &werr);
    2017             : 
    2018           2 :         if (!(NT_STATUS_IS_OK(status))) {
    2019           0 :                 goto error;
    2020             :         }
    2021             : 
    2022           2 :         if (!(W_ERROR_IS_OK(werr))) {
    2023           0 :                 goto error;
    2024             :         }
    2025             : 
    2026           2 :         service = talloc(frame, struct smbconf_service);
    2027             : 
    2028           2 :         status = rpc_conf_get_share(frame,
    2029             :                                     b,
    2030             :                                     &key_hnd,
    2031             :                                     argv[0],
    2032             :                                     service,
    2033             :                                     &werr);
    2034             : 
    2035           2 :         if (!(NT_STATUS_IS_OK(status))) {
    2036           0 :                         goto error;
    2037             :         }
    2038             : 
    2039           2 :         if (!(W_ERROR_IS_OK(werr))) {
    2040           0 :                         goto error;
    2041             :         }
    2042             : 
    2043           2 :         for (param_count = 0;
    2044          14 :              param_count < service->num_params;
    2045          12 :              param_count++)
    2046             :         {
    2047          12 :                 if (strcmp(service->param_names[param_count], "include") == 0) {
    2048           6 :                         d_printf(_("%s = %s\n"),
    2049           6 :                                 service->param_names[param_count],
    2050           6 :                                 service->param_values[param_count]);
    2051             :                 }
    2052             :         }
    2053             : 
    2054           2 : error:
    2055             : 
    2056           4 :         if (!(W_ERROR_IS_OK(werr))) {
    2057           0 :                 status =  werror_to_ntstatus(werr);
    2058             :         }
    2059             : 
    2060           4 :         dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
    2061           4 :         dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
    2062             : 
    2063           4 :         TALLOC_FREE(frame);
    2064           4 :         return status;
    2065             : 
    2066             : }
    2067             : 
    2068           4 : static NTSTATUS rpc_conf_setincludes_internal(struct net_context *c,
    2069             :                                               const struct dom_sid *domain_sid,
    2070             :                                               const char *domain_name,
    2071             :                                               struct cli_state *cli,
    2072             :                                               struct rpc_pipe_client *pipe_hnd,
    2073             :                                               TALLOC_CTX *mem_ctx,
    2074             :                                               int argc,
    2075             :                                               const char **argv )
    2076             : {
    2077           4 :         TALLOC_CTX *frame = talloc_stackframe();
    2078           4 :         NTSTATUS status = NT_STATUS_OK;
    2079           4 :         WERROR werr = WERR_OK;
    2080           0 :         WERROR _werr;
    2081             : 
    2082           4 :         struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    2083             : 
    2084             :         /* key info */
    2085           0 :         struct policy_handle hive_hnd, key_hnd, share_hnd;
    2086             : 
    2087           0 :         struct winreg_String key, keyclass;
    2088           4 :         enum winreg_CreateAction action = 0;
    2089             : 
    2090           4 :         ZERO_STRUCT(hive_hnd);
    2091           4 :         ZERO_STRUCT(key_hnd);
    2092           4 :         ZERO_STRUCT(share_hnd);
    2093             : 
    2094           4 :         ZERO_STRUCT(key);
    2095           4 :         ZERO_STRUCT(keyclass);
    2096             : 
    2097           4 :         if (argc < 1 || c->display_usage) {
    2098           2 :                 rpc_conf_setincludes_usage(c, argc, argv);
    2099           2 :                 status = NT_STATUS_INVALID_PARAMETER;
    2100           2 :                 goto error;
    2101             :         }
    2102             : 
    2103           2 :         status = rpc_conf_open_conf(frame,
    2104             :                                     b,
    2105             :                                     REG_KEY_READ,
    2106             :                                     &hive_hnd,
    2107             :                                     &key_hnd,
    2108             :                                     &werr);
    2109             : 
    2110           2 :         if (!(NT_STATUS_IS_OK(status))) {
    2111           0 :                 goto error;
    2112             :         }
    2113             : 
    2114           2 :         if (!(W_ERROR_IS_OK(werr))) {
    2115           0 :                 goto error;
    2116             :         }
    2117             : 
    2118           2 :         key.name = argv[0];
    2119           2 :         keyclass.name = "";
    2120             : 
    2121           2 :         status = dcerpc_winreg_CreateKey(b, frame, &key_hnd, key, keyclass,
    2122             :                         0, REG_KEY_READ, NULL, &share_hnd,
    2123             :                         &action, &werr);
    2124             : 
    2125           2 :         if (!(NT_STATUS_IS_OK(status))) {
    2126           0 :                 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
    2127             :                                 argv[0], nt_errstr(status));
    2128           0 :                 goto error;
    2129             :         }
    2130             : 
    2131           2 :         if (!W_ERROR_IS_OK(werr)) {
    2132           0 :                 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
    2133             :                                 argv[0], win_errstr(werr));
    2134           0 :                 goto error;
    2135             :         }
    2136             : 
    2137           2 :         switch (action) {
    2138           0 :                 case REG_ACTION_NONE:
    2139             :                         /* Is there any other way to treat this? */
    2140           0 :                         werr = WERR_CREATE_FAILED;
    2141           0 :                         d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
    2142             :                                 argv[0], win_errstr(werr));
    2143           0 :                         goto error;
    2144           0 :                 case REG_CREATED_NEW_KEY:
    2145           0 :                         DEBUG(5, ("net rpc conf setincludes:"
    2146             :                                         "createkey created %s\n", argv[0]));
    2147           2 :                         break;
    2148           2 :                 case REG_OPENED_EXISTING_KEY:
    2149           2 :                         DEBUG(5, ("net rpc conf setincludes:"
    2150             :                                         "createkey opened existing %s\n", argv[0]));
    2151             : 
    2152             :                         /* delete possibly existing value */
    2153           2 :                         status = rpc_conf_del_value(frame,
    2154             :                                                     b,
    2155             :                                                     &key_hnd,
    2156             :                                                     argv[0],
    2157             :                                                     "includes",
    2158             :                                                     &werr);
    2159             : 
    2160           2 :                         if (!(NT_STATUS_IS_OK(status))) {
    2161           0 :                                 goto error;
    2162             :                         }
    2163             : 
    2164           2 :                         if (!(W_ERROR_IS_OK(werr))) {
    2165           0 :                                 goto error;
    2166             :                         }
    2167           2 :                         break;
    2168             :         }
    2169             : 
    2170             :         /* set the 'includes' values */
    2171           2 :         status = dcerpc_winreg_set_multi_sz(frame, b, &share_hnd,
    2172             :                                             "includes", argv + 1, &werr);
    2173           2 :         if (!(NT_STATUS_IS_OK(status))) {
    2174           0 :                 d_fprintf(stderr, "ERROR: Could not set includes\n %s\n",
    2175             :                                 nt_errstr(status));
    2176           0 :                 goto error;
    2177             :         }
    2178             : 
    2179           2 :         if (!(W_ERROR_IS_OK(werr))) {
    2180           0 :                 d_fprintf(stderr, "ERROR: Could not set includes\n %s\n",
    2181             :                                 win_errstr(werr));
    2182           0 :                 goto error;
    2183             :         }
    2184             : 
    2185           2 : error:
    2186             : 
    2187           4 :         if (!(W_ERROR_IS_OK(werr))) {
    2188           0 :                 status =  werror_to_ntstatus(werr);
    2189             :         }
    2190             : 
    2191           4 :         dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
    2192           4 :         dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
    2193           4 :         dcerpc_winreg_CloseKey(b, frame, &share_hnd, &_werr);
    2194             : 
    2195           4 :         TALLOC_FREE(frame);
    2196           4 :         return status;
    2197             : }
    2198             : 
    2199           8 : static NTSTATUS rpc_conf_delincludes_internal(struct net_context *c,
    2200             :                                               const struct dom_sid *domain_sid,
    2201             :                                               const char *domain_name,
    2202             :                                               struct cli_state *cli,
    2203             :                                               struct rpc_pipe_client *pipe_hnd,
    2204             :                                               TALLOC_CTX *mem_ctx,
    2205             :                                               int argc,
    2206             :                                               const char **argv )
    2207             : {
    2208           8 :         TALLOC_CTX *frame = talloc_stackframe();
    2209           8 :         NTSTATUS status = NT_STATUS_OK;
    2210           8 :         WERROR werr = WERR_OK;
    2211           0 :         WERROR _werr;
    2212             : 
    2213           8 :         struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    2214             : 
    2215             :         /* key info */
    2216           0 :         struct policy_handle hive_hnd, key_hnd;
    2217             : 
    2218             : 
    2219           8 :         ZERO_STRUCT(hive_hnd);
    2220           8 :         ZERO_STRUCT(key_hnd);
    2221             : 
    2222             : 
    2223           8 :         if (argc != 1 || c->display_usage) {
    2224           2 :                 rpc_conf_delincludes_usage(c, argc, argv);
    2225           2 :                 status = NT_STATUS_INVALID_PARAMETER;
    2226           2 :                 goto error;
    2227             :         }
    2228             : 
    2229           6 :         status = rpc_conf_open_conf(frame,
    2230             :                                     b,
    2231             :                                     REG_KEY_READ,
    2232             :                                     &hive_hnd,
    2233             :                                     &key_hnd,
    2234             :                                     &werr);
    2235             : 
    2236           6 :         if (!(NT_STATUS_IS_OK(status))) {
    2237           0 :                 goto error;
    2238             :         }
    2239             : 
    2240           6 :         if (!(W_ERROR_IS_OK(werr))) {
    2241           0 :                 goto error;
    2242             :         }
    2243             : 
    2244           6 :         status = rpc_conf_del_value(frame,
    2245             :                                     b,
    2246             :                                     &key_hnd,
    2247             :                                     argv[0],
    2248             :                                     "includes",
    2249             :                                     &werr);
    2250             : 
    2251           8 : error:
    2252             : 
    2253           8 :         if (!(W_ERROR_IS_OK(werr))) {
    2254           2 :                 status =  werror_to_ntstatus(werr);
    2255             :         }
    2256             : 
    2257           8 :         dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
    2258           8 :         dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
    2259             : 
    2260           8 :         TALLOC_FREE(frame);
    2261           8 :         return status;
    2262             : 
    2263             : }
    2264             : 
    2265             : /**********************************************************
    2266             :  *
    2267             :  * Functions that run the rpc commands for net rpc conf modules
    2268             :  *
    2269             :  **********************************************************/
    2270             : 
    2271          28 : static int rpc_conf_drop(struct net_context *c, int argc,
    2272             :                                 const char **argv)
    2273             : {
    2274          28 :         return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
    2275             :                 rpc_conf_drop_internal, argc, argv );
    2276             : 
    2277             : }
    2278             : 
    2279         212 : static int rpc_conf_showshare(struct net_context *c, int argc,
    2280             :                                 const char **argv)
    2281             : {
    2282         212 :         return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
    2283             :                 rpc_conf_showshare_internal, argc, argv );
    2284             : }
    2285             : 
    2286         214 : static int rpc_conf_addshare(struct net_context *c, int argc,
    2287             :                                 const char **argv)
    2288             : {
    2289         214 :         return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
    2290             :                 rpc_conf_addshare_internal, argc, argv );
    2291             : }
    2292             : 
    2293           4 : static int rpc_conf_listshares(struct net_context *c, int argc,
    2294             :                                 const char **argv)
    2295             : {
    2296           4 :         return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
    2297             :                 rpc_conf_listshares_internal, argc, argv );
    2298             : }
    2299             : 
    2300          20 : static int rpc_conf_list(struct net_context *c, int argc,
    2301             :                              const char **argv)
    2302             : {
    2303          20 :         return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
    2304             :                 rpc_conf_list_internal, argc, argv );
    2305             : }
    2306             : 
    2307           6 : static int rpc_conf_import(struct net_context *c, int argc,
    2308             :                                 const char **argv)
    2309             : {
    2310           6 :         return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
    2311             :                 rpc_conf_import_internal, argc, argv );
    2312             : }
    2313           6 : static int rpc_conf_delshare(struct net_context *c, int argc,
    2314             :                              const char **argv)
    2315             : {
    2316           6 :         return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
    2317             :                 rpc_conf_delshare_internal, argc, argv );
    2318             : }
    2319             : 
    2320           8 : static int rpc_conf_getparm(struct net_context *c, int argc,
    2321             :                              const char **argv)
    2322             : {
    2323           8 :         return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
    2324             :                 rpc_conf_getparm_internal, argc, argv );
    2325             : }
    2326             : 
    2327          22 : static int rpc_conf_setparm(struct net_context *c, int argc,
    2328             :                                 const char **argv)
    2329             : {
    2330          22 :         return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
    2331             :                 rpc_conf_setparm_internal, argc, argv );
    2332             : }
    2333           6 : static int rpc_conf_delparm(struct net_context *c, int argc,
    2334             :                                 const char **argv)
    2335             : {
    2336           6 :         return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
    2337             :                 rpc_conf_delparm_internal, argc, argv );
    2338             : }
    2339             : 
    2340           4 : static int rpc_conf_getincludes(struct net_context *c, int argc,
    2341             :                              const char **argv)
    2342             : {
    2343           4 :         return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
    2344             :                 rpc_conf_getincludes_internal, argc, argv );
    2345             : }
    2346             : 
    2347           4 : static int rpc_conf_setincludes(struct net_context *c, int argc,
    2348             :                                 const char **argv)
    2349             : {
    2350           4 :         return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
    2351             :                 rpc_conf_setincludes_internal, argc, argv );
    2352             : }
    2353             : 
    2354           8 : static int rpc_conf_delincludes(struct net_context *c, int argc,
    2355             :                                 const char **argv)
    2356             : {
    2357           8 :         return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
    2358             :                 rpc_conf_delincludes_internal, argc, argv );
    2359             : }
    2360             : 
    2361             : /* function calls */
    2362         542 : int net_rpc_conf(struct net_context *c, int argc,
    2363             :                  const char **argv)
    2364             : {
    2365         542 :         struct functable func_table[] = {
    2366             :                 {
    2367             :                         "list",
    2368             :                         rpc_conf_list,
    2369             :                         NET_TRANSPORT_RPC,
    2370             :                         N_("Dump the complete remote configuration in smb.conf like "
    2371             :                            "format."),
    2372             :                         N_("net rpc conf list\n"
    2373             :                            "    Dump the complete remote configuration in smb.conf "
    2374             :                            "like format.")
    2375             : 
    2376             :                 },
    2377             :                 {
    2378             :                         "import",
    2379             :                         rpc_conf_import,
    2380             :                         NET_TRANSPORT_RPC,
    2381             :                         N_("Import configuration from file in smb.conf "
    2382             :                            "format."),
    2383             :                         N_("net rpc conf import\n"
    2384             :                            "    Import configuration from file in smb.conf "
    2385             :                            "format.")
    2386             :                 },
    2387             :                 {
    2388             :                         "listshares",
    2389             :                         rpc_conf_listshares,
    2390             :                         NET_TRANSPORT_RPC,
    2391             :                         N_("List the remote share names."),
    2392             :                         N_("net rpc conf list\n"
    2393             :                            "    List the remote share names.")
    2394             : 
    2395             :                 },
    2396             :                 {
    2397             :                         "drop",
    2398             :                         rpc_conf_drop,
    2399             :                         NET_TRANSPORT_RPC,
    2400             :                         N_("Delete the complete remote configuration."),
    2401             :                         N_("net rpc conf drop\n"
    2402             :                            "    Delete the complete remote configuration.")
    2403             : 
    2404             :                 },
    2405             :                 {
    2406             :                         "showshare",
    2407             :                         rpc_conf_showshare,
    2408             :                         NET_TRANSPORT_RPC,
    2409             :                         N_("Show the definition of a remote share."),
    2410             :                         N_("net rpc conf showshare\n"
    2411             :                            "    Show the definition of a remote share.")
    2412             : 
    2413             :                 },
    2414             :                 {
    2415             :                         "addshare",
    2416             :                         rpc_conf_addshare,
    2417             :                         NET_TRANSPORT_RPC,
    2418             :                         N_("Create a new remote share."),
    2419             :                         N_("net rpc conf addshare\n"
    2420             :                            "    Create a new remote share.")
    2421             :                 },
    2422             :                 {
    2423             :                         "delshare",
    2424             :                         rpc_conf_delshare,
    2425             :                         NET_TRANSPORT_RPC,
    2426             :                         N_("Delete a remote share."),
    2427             :                         N_("net rpc conf delshare\n"
    2428             :                            "    Delete a remote share.")
    2429             :                 },
    2430             :                 {
    2431             :                         "getparm",
    2432             :                         rpc_conf_getparm,
    2433             :                         NET_TRANSPORT_RPC,
    2434             :                         N_("Retrieve the value of a parameter."),
    2435             :                         N_("net rpc conf getparm\n"
    2436             :                            "    Retrieve the value of a parameter.")
    2437             :                 },
    2438             :                 {
    2439             :                         "setparm",
    2440             :                         rpc_conf_setparm,
    2441             :                         NET_TRANSPORT_RPC,
    2442             :                         N_("Store a parameter."),
    2443             :                         N_("net rpc conf setparm\n"
    2444             :                            "    Store a parameter.")
    2445             :                 },
    2446             :                 {
    2447             :                         "delparm",
    2448             :                         rpc_conf_delparm,
    2449             :                         NET_TRANSPORT_RPC,
    2450             :                         N_("Delete a parameter."),
    2451             :                         N_("net rpc conf delparm\n"
    2452             :                            "    Delete a parameter.")
    2453             :                 },
    2454             :                 {
    2455             :                         "getincludes",
    2456             :                         rpc_conf_getincludes,
    2457             :                         NET_TRANSPORT_RPC,
    2458             :                         N_("Show the includes of a share definition."),
    2459             :                         N_("net rpc conf getincludes\n"
    2460             :                            "    Show the includes of a share definition.")
    2461             :                 },
    2462             :                 {
    2463             :                         "setincludes",
    2464             :                         rpc_conf_setincludes,
    2465             :                         NET_TRANSPORT_RPC,
    2466             :                         N_("Set includes for a share."),
    2467             :                         N_("net rpc conf setincludes\n"
    2468             :                            "    Set includes for a share.")
    2469             :                 },
    2470             :                 {
    2471             :                         "delincludes",
    2472             :                         rpc_conf_delincludes,
    2473             :                         NET_TRANSPORT_RPC,
    2474             :                         N_("Delete includes from a share definition."),
    2475             :                         N_("net rpc conf delincludes\n"
    2476             :                            "    Delete includes from a share definition.")
    2477             :                 },
    2478             :                 {NULL, NULL, 0, NULL, NULL}
    2479             :         };
    2480             : 
    2481         542 :         return net_run_function(c, argc, argv, "net rpc conf", func_table);
    2482             : 
    2483             : }

Generated by: LCOV version 1.14