Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/utils/net_rpc.c

    r480 r745  
    2323#include "includes.h"
    2424#include "utils/net.h"
     25#include "rpc_client/cli_pipe.h"
    2526#include "../libcli/auth/libcli_auth.h"
    26 #include "../librpc/gen_ndr/cli_samr.h"
    27 #include "../librpc/gen_ndr/cli_lsa.h"
    28 #include "../librpc/gen_ndr/cli_netlogon.h"
    29 #include "../librpc/gen_ndr/cli_srvsvc.h"
    30 #include "../librpc/gen_ndr/cli_spoolss.h"
    31 #include "../librpc/gen_ndr/cli_initshutdown.h"
    32 #include "../librpc/gen_ndr/cli_winreg.h"
     27#include "../librpc/gen_ndr/ndr_samr_c.h"
     28#include "rpc_client/cli_samr.h"
     29#include "rpc_client/init_samr.h"
     30#include "../librpc/gen_ndr/ndr_lsa_c.h"
     31#include "rpc_client/cli_lsarpc.h"
     32#include "../librpc/gen_ndr/ndr_netlogon_c.h"
     33#include "../librpc/gen_ndr/ndr_srvsvc_c.h"
     34#include "../librpc/gen_ndr/ndr_spoolss.h"
     35#include "../librpc/gen_ndr/ndr_initshutdown_c.h"
     36#include "../librpc/gen_ndr/ndr_winreg_c.h"
     37#include "secrets.h"
     38#include "lib/netapi/netapi.h"
     39#include "lib/netapi/netapi_net.h"
     40#include "rpc_client/init_lsa.h"
     41#include "../libcli/security/security.h"
     42#include "libsmb/libsmb.h"
     43#include "libsmb/clirap.h"
     44#include "nsswitch/libwbclient/wbclient.h"
     45#include "passdb.h"
    3346
    3447static int net_mode_share;
    35 static bool sync_files(struct copy_clistate *cp_clistate, const char *mask);
     48static NTSTATUS sync_files(struct copy_clistate *cp_clistate, const char *mask);
    3649
    3750/**
     
    6073
    6174NTSTATUS net_get_remote_domain_sid(struct cli_state *cli, TALLOC_CTX *mem_ctx,
    62                                    DOM_SID **domain_sid,
     75                                   struct dom_sid **domain_sid,
    6376                                   const char **domain_name)
    6477{
    6578        struct rpc_pipe_client *lsa_pipe = NULL;
    6679        struct policy_handle pol;
    67         NTSTATUS result = NT_STATUS_OK;
     80        NTSTATUS status, result;
    6881        union lsa_PolicyInformation *info = NULL;
    69 
    70         result = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc.syntax_id,
     82        struct dcerpc_binding_handle *b;
     83
     84        status = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc.syntax_id,
    7185                                          &lsa_pipe);
    72         if (!NT_STATUS_IS_OK(result)) {
     86        if (!NT_STATUS_IS_OK(status)) {
    7387                d_fprintf(stderr, _("Could not initialise lsa pipe\n"));
    74                 return result;
    75         }
    76 
    77         result = rpccli_lsa_open_policy(lsa_pipe, mem_ctx, false,
     88                return status;
     89        }
     90
     91        b = lsa_pipe->binding_handle;
     92
     93        status = rpccli_lsa_open_policy(lsa_pipe, mem_ctx, false,
    7894                                     SEC_FLAG_MAXIMUM_ALLOWED,
    7995                                     &pol);
    80         if (!NT_STATUS_IS_OK(result)) {
     96        if (!NT_STATUS_IS_OK(status)) {
    8197                d_fprintf(stderr, "open_policy %s: %s\n",
    8298                          _("failed"),
    83                           nt_errstr(result));
    84                 return result;
    85         }
    86 
    87         result = rpccli_lsa_QueryInfoPolicy(lsa_pipe, mem_ctx,
     99                          nt_errstr(status));
     100                return status;
     101        }
     102
     103        status = dcerpc_lsa_QueryInfoPolicy(b, mem_ctx,
    88104                                            &pol,
    89105                                            LSA_POLICY_INFO_ACCOUNT_DOMAIN,
    90                                             &info);
     106                                            &info,
     107                                            &result);
     108        if (!NT_STATUS_IS_OK(status)) {
     109                d_fprintf(stderr, "lsaquery %s: %s\n",
     110                          _("failed"),
     111                          nt_errstr(status));
     112                return status;
     113        }
    91114        if (!NT_STATUS_IS_OK(result)) {
    92115                d_fprintf(stderr, "lsaquery %s: %s\n",
     
    99122        *domain_sid = info->account_domain.sid;
    100123
    101         rpccli_lsa_Close(lsa_pipe, mem_ctx, &pol);
     124        dcerpc_lsa_Close(b, mem_ctx, &pol, &result);
    102125        TALLOC_FREE(lsa_pipe);
    103126
     
    129152        TALLOC_CTX *mem_ctx;
    130153        NTSTATUS nt_status;
    131         DOM_SID *domain_sid;
     154        struct dom_sid *domain_sid;
    132155        const char *domain_name;
    133156        int ret = -1;
     
    242265
    243266static NTSTATUS rpc_changetrustpw_internals(struct net_context *c,
    244                                         const DOM_SID *domain_sid,
     267                                        const struct dom_sid *domain_sid,
    245268                                        const char *domain_name,
    246269                                        struct cli_state *cli,
     
    310333
    311334static NTSTATUS rpc_oldjoin_internals(struct net_context *c,
    312                                         const DOM_SID *domain_sid,
     335                                        const struct dom_sid *domain_sid,
    313336                                        const char *domain_name,
    314337                                        struct cli_state *cli,
     
    489512
    490513NTSTATUS rpc_info_internals(struct net_context *c,
    491                         const DOM_SID *domain_sid,
     514                        const struct dom_sid *domain_sid,
    492515                        const char *domain_name,
    493516                        struct cli_state *cli,
     
    498521{
    499522        struct policy_handle connect_pol, domain_pol;
    500         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
     523        NTSTATUS status, result;
    501524        union samr_DomainInfo *info = NULL;
    502525        fstring sid_str;
     526        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    503527
    504528        sid_to_fstring(sid_str, domain_sid);
    505529
    506530        /* Get sam policy handle */
    507         result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
     531        status = dcerpc_samr_Connect2(b, mem_ctx,
    508532                                      pipe_hnd->desthost,
    509533                                      MAXIMUM_ALLOWED_ACCESS,
    510                                       &connect_pol);
     534                                      &connect_pol,
     535                                      &result);
     536        if (!NT_STATUS_IS_OK(status)) {
     537                d_fprintf(stderr, _("Could not connect to SAM: %s\n"),
     538                          nt_errstr(status));
     539                goto done;
     540        }
     541
    511542        if (!NT_STATUS_IS_OK(result)) {
     543                status = result;
    512544                d_fprintf(stderr, _("Could not connect to SAM: %s\n"),
    513545                          nt_errstr(result));
     
    516548
    517549        /* Get domain policy handle */
    518         result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
     550        status = dcerpc_samr_OpenDomain(b, mem_ctx,
    519551                                        &connect_pol,
    520552                                        MAXIMUM_ALLOWED_ACCESS,
    521553                                        CONST_DISCARD(struct dom_sid2 *, domain_sid),
    522                                         &domain_pol);
     554                                        &domain_pol,
     555                                        &result);
     556        if (!NT_STATUS_IS_OK(status)) {
     557                d_fprintf(stderr, _("Could not open domain: %s\n"),
     558                          nt_errstr(status));
     559                goto done;
     560        }
    523561        if (!NT_STATUS_IS_OK(result)) {
     562                status = result;
    524563                d_fprintf(stderr, _("Could not open domain: %s\n"),
    525564                          nt_errstr(result));
     
    527566        }
    528567
    529         result = rpccli_samr_QueryDomainInfo(pipe_hnd, mem_ctx,
     568        status = dcerpc_samr_QueryDomainInfo(b, mem_ctx,
    530569                                             &domain_pol,
    531570                                             2,
    532                                              &info);
     571                                             &info,
     572                                             &result);
     573        if (!NT_STATUS_IS_OK(status)) {
     574                goto done;
     575        }
     576        status = result;
    533577        if (NT_STATUS_IS_OK(result)) {
    534578                d_printf(_("Domain Name: %s\n"),
     
    543587
    544588 done:
    545         return result;
     589        return status;
    546590}
    547591
     
    586630
    587631static NTSTATUS rpc_getsid_internals(struct net_context *c,
    588                         const DOM_SID *domain_sid,
     632                        const struct dom_sid *domain_sid,
    589633                        const char *domain_name,
    590634                        struct cli_state *cli,
     
    728772        }
    729773
     774        return status;
     775}
     776
     777/**
     778 * Set a user's primary group
     779 *
     780 * @param argc  Standard main() style argc.
     781 * @param argv  Standard main() style argv. Initial components are already
     782 *              stripped.
     783 *
     784 * @return A shell status integer (0 for success).
     785 **/
     786
     787static int rpc_user_setprimarygroup(struct net_context *c, int argc,
     788                                    const char **argv)
     789{
     790        NET_API_STATUS status;
     791        uint8_t *buffer;
     792        struct GROUP_INFO_2 *g2;
     793        struct USER_INFO_1051 u1051;
     794        uint32_t parm_err = 0;
     795
     796        if (argc != 2 || c->display_usage) {
     797                rpc_user_usage(c, argc, argv);
     798                return 0;
     799        }
     800
     801        status = NetGroupGetInfo(c->opt_host, argv[1], 2, &buffer);
     802        if (status) {
     803                d_fprintf(stderr, _("Failed to find group name %s -- %s\n"),
     804                          argv[1],
     805                          libnetapi_get_error_string(c->netapi_ctx, status));
     806                return status;
     807        }
     808        g2 = (struct GROUP_INFO_2 *)buffer;
     809
     810        u1051.usri1051_primary_group_id = g2->grpi2_group_id;
     811
     812        NetApiBufferFree(buffer);
     813
     814        status = NetUserSetInfo(c->opt_host, argv[0], 1051,
     815                                (uint8_t *)&u1051, &parm_err);
     816        if (status) {
     817                d_fprintf(stderr,
     818                          _("Failed to set user's primary group %s to %s - "
     819                            "%s\n"), argv[0], argv[1],
     820                          libnetapi_get_error_string(c->netapi_ctx, status));
     821        } else {
     822                d_printf(_("Set primary group of user %s to %s\n"), argv[0],
     823                         argv[1]);
     824        }
    730825        return status;
    731826}
     
    894989                uint32_t max_entries, max_size;
    895990
    896                 get_query_dispinfo_params(
     991                dcerpc_get_query_dispinfo_params(
    897992                        loop_count, &max_entries, &max_size);
    898993
     
    9561051                        N_("List domain groups of user"),
    9571052                        N_("net rpc user info\n"
    958                            "    Lis domain groups of user")
     1053                           "    List domain groups of user")
    9591054                },
    9601055                {
     
    9821077                           "    Rename specified user")
    9831078                },
     1079                {
     1080                        "setprimarygroup",
     1081                        rpc_user_setprimarygroup,
     1082                        NET_TRANSPORT_RPC,
     1083                        "Set a user's primary group",
     1084                        "net rpc user setprimarygroup\n"
     1085                        "    Set a user's primary group"
     1086                },
    9841087                {NULL, NULL, 0, NULL, NULL}
    9851088        };
    9861089
    987         status = libnetapi_init(&c->netapi_ctx);
     1090        status = libnetapi_net_init(&c->netapi_ctx);
    9881091        if (status != 0) {
    9891092                return -1;
     
    10441147{
    10451148        struct policy_handle connect_pol, domain_pol, user_pol;
    1046         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
    1047         DOM_SID sid;
     1149        NTSTATUS status, result;
     1150        struct dom_sid sid;
    10481151        uint32 rid;
    10491152        enum lsa_SidType type;
     1153        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    10501154
    10511155        if (argc == 0) {
     
    10591163        ZERO_STRUCT(user_pol);
    10601164
    1061         result = net_rpc_lookup_name(c, mem_ctx, rpc_pipe_np_smb_conn(pipe_hnd),
     1165        status = net_rpc_lookup_name(c, mem_ctx, rpc_pipe_np_smb_conn(pipe_hnd),
    10621166                                     argv[0], NULL, NULL, &sid, &type);
    1063         if (!NT_STATUS_IS_OK(result)) {
     1167        if (!NT_STATUS_IS_OK(status)) {
    10641168                d_fprintf(stderr, _("Could not lookup %s: %s\n"), argv[0],
    1065                           nt_errstr(result));
     1169                          nt_errstr(status));
    10661170                goto done;
    10671171        }
     
    10701174                d_fprintf(stderr, _("%s is a %s, not a user\n"), argv[0],
    10711175                          sid_type_lookup(type));
    1072                 result = NT_STATUS_NO_SUCH_USER;
     1176                status = NT_STATUS_NO_SUCH_USER;
    10731177                goto done;
    10741178        }
     
    10761180        if (!sid_peek_check_rid(ctx->domain_sid, &sid, &rid)) {
    10771181                d_fprintf(stderr, _("%s is not in our domain\n"), argv[0]);
    1078                 result = NT_STATUS_NO_SUCH_USER;
    1079                 goto done;
    1080         }
    1081 
    1082         result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
     1182                status = NT_STATUS_NO_SUCH_USER;
     1183                goto done;
     1184        }
     1185
     1186        status = dcerpc_samr_Connect2(b, mem_ctx,
    10831187                                      pipe_hnd->desthost,
    10841188                                      MAXIMUM_ALLOWED_ACCESS,
    1085                                       &connect_pol);
     1189                                      &connect_pol,
     1190                                      &result);
     1191        if (!NT_STATUS_IS_OK(status)) {
     1192                goto done;
     1193        }
    10861194        if (!NT_STATUS_IS_OK(result)) {
    1087                 goto done;
    1088         }
    1089 
    1090         result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
     1195                status = result;
     1196                goto done;
     1197        }
     1198
     1199        status = dcerpc_samr_OpenDomain(b, mem_ctx,
    10911200                                        &connect_pol,
    10921201                                        MAXIMUM_ALLOWED_ACCESS,
    10931202                                        ctx->domain_sid,
    1094                                         &domain_pol);
     1203                                        &domain_pol,
     1204                                        &result);
     1205        if (!NT_STATUS_IS_OK(status)) {
     1206                goto done;
     1207        }
    10951208        if (!NT_STATUS_IS_OK(result)) {
    1096                 goto done;
    1097         }
    1098 
    1099         result = rpccli_samr_OpenUser(pipe_hnd, mem_ctx,
     1209                status = result;
     1210                goto done;
     1211        }
     1212
     1213        status = dcerpc_samr_OpenUser(b, mem_ctx,
    11001214                                      &domain_pol,
    11011215                                      MAXIMUM_ALLOWED_ACCESS,
    11021216                                      rid,
    1103                                       &user_pol);
     1217                                      &user_pol,
     1218                                      &result);
     1219        if (!NT_STATUS_IS_OK(status)) {
     1220                goto done;
     1221        }
    11041222        if (!NT_STATUS_IS_OK(result)) {
    1105                 goto done;
    1106         }
    1107 
    1108         result = fn(c, mem_ctx, ctx, pipe_hnd, &user_pol, argc-1, argv+1);
     1223                status = result;
     1224                goto done;
     1225        }
     1226
     1227        status = fn(c, mem_ctx, ctx, pipe_hnd, &user_pol, argc-1, argv+1);
    11091228
    11101229 done:
    11111230        if (is_valid_policy_hnd(&user_pol)) {
    1112                 rpccli_samr_Close(pipe_hnd, mem_ctx, &user_pol);
     1231                dcerpc_samr_Close(b, mem_ctx, &user_pol, &result);
    11131232        }
    11141233        if (is_valid_policy_hnd(&domain_pol)) {
    1115                 rpccli_samr_Close(pipe_hnd, mem_ctx, &domain_pol);
     1234                dcerpc_samr_Close(b, mem_ctx, &domain_pol, &result);
    11161235        }
    11171236        if (is_valid_policy_hnd(&connect_pol)) {
    1118                 rpccli_samr_Close(pipe_hnd, mem_ctx, &connect_pol);
    1119         }
    1120         return result;
     1237                dcerpc_samr_Close(b, mem_ctx, &connect_pol, &result);
     1238        }
     1239        return status;
    11211240}
    11221241
     
    11281247                                           int argc, const char **argv)
    11291248{
    1130         NTSTATUS result;
     1249        NTSTATUS status, result;
    11311250        union samr_UserInfo *info = NULL;
     1251        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    11321252
    11331253        if (argc != 0) {
     
    11371257        }
    11381258
    1139         result = rpccli_samr_QueryUserInfo(pipe_hnd, mem_ctx,
     1259        status = dcerpc_samr_QueryUserInfo(b, mem_ctx,
    11401260                                           user_hnd,
    11411261                                           21,
    1142                                            &info);
     1262                                           &info,
     1263                                           &result);
     1264        if (!NT_STATUS_IS_OK(status)) {
     1265                return status;
     1266        }
    11431267        if (!NT_STATUS_IS_OK(result)) {
    11441268                return result;
     
    11801304                                               int argc, const char **argv)
    11811305{
    1182         NTSTATUS result;
     1306        NTSTATUS status, result;
    11831307        const char *username;
    11841308        const char *oldval = "";
    11851309        union samr_UserInfo *info = NULL;
     1310        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    11861311
    11871312        if (argc > 1) {
     
    11911316        }
    11921317
    1193         result = rpccli_samr_QueryUserInfo(pipe_hnd, mem_ctx,
     1318        status = dcerpc_samr_QueryUserInfo(b, mem_ctx,
    11941319                                           user_hnd,
    11951320                                           21,
    1196                                            &info);
     1321                                           &info,
     1322                                           &result);
     1323        if (!NT_STATUS_IS_OK(status)) {
     1324                return status;
     1325        }
    11971326        if (!NT_STATUS_IS_OK(result)) {
    11981327                return result;
     
    12261355        SETSTR("description", description, DESCRIPTION);
    12271356
    1228         result = rpccli_samr_SetUserInfo(pipe_hnd, mem_ctx,
     1357        status = dcerpc_samr_SetUserInfo(b, mem_ctx,
    12291358                                         user_hnd,
    12301359                                         21,
    1231                                          info);
     1360                                         info,
     1361                                         &result);
     1362        if (!NT_STATUS_IS_OK(status)) {
     1363                return status;
     1364        }
     1365
     1366        status = result;
    12321367
    12331368        d_printf(_("Set %s's %s from [%s] to [%s]\n"), username,
     
    12361371 done:
    12371372
    1238         return result;
     1373        return status;
    12391374}
    12401375
     
    12651400                                                int argc, const char **argv)
    12661401{
    1267         NTSTATUS result;
     1402        NTSTATUS status, result;
    12681403        const char *username;
    12691404        const char *oldval = "unknown";
     
    12711406        bool newval;
    12721407        union samr_UserInfo *info = NULL;
     1408        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    12731409
    12741410        if ((argc > 1) ||
     
    12841420        newval = strequal(argv[0], "yes");
    12851421
    1286         result = rpccli_samr_QueryUserInfo(pipe_hnd, mem_ctx,
     1422        status = dcerpc_samr_QueryUserInfo(b, mem_ctx,
    12871423                                           user_hnd,
    12881424                                           21,
    1289                                            &info);
     1425                                           &info,
     1426                                           &result);
     1427        if (!NT_STATUS_IS_OK(status)) {
     1428                return status;
     1429        }
    12901430        if (!NT_STATUS_IS_OK(result)) {
    12911431                return result;
     
    13121452        info->info21.fields_present = SAMR_FIELD_ACCT_FLAGS;
    13131453
    1314         result = rpccli_samr_SetUserInfo(pipe_hnd, mem_ctx,
     1454        status = dcerpc_samr_SetUserInfo(b, mem_ctx,
    13151455                                         user_hnd,
    13161456                                         21,
    1317                                          info);
    1318 
     1457                                         info,
     1458                                         &result);
     1459        if (!NT_STATUS_IS_OK(status)) {
     1460                goto done;
     1461        }
     1462        status = result;
    13191463        if (NT_STATUS_IS_OK(result)) {
    13201464                d_printf(_("Set %s's %s flag from [%s] to [%s]\n"), username,
     
    13241468 done:
    13251469
    1326         return result;
     1470        return status;
    13271471}
    13281472
     
    14341578
    14351579static NTSTATUS rpc_group_delete_internals(struct net_context *c,
    1436                                         const DOM_SID *domain_sid,
     1580                                        const struct dom_sid *domain_sid,
    14371581                                        const char *domain_name,
    14381582                                        struct cli_state *cli,
     
    14441588        struct policy_handle connect_pol, domain_pol, group_pol, user_pol;
    14451589        bool group_is_primary = false;
    1446         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
     1590        NTSTATUS status, result;
    14471591        uint32_t group_rid;
    1448         struct samr_RidTypeArray *rids = NULL;
     1592        struct samr_RidAttrArray *rids = NULL;
    14491593        /* char **names; */
    14501594        int i;
    14511595        /* struct samr_RidWithAttribute *user_gids; */
     1596        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    14521597
    14531598        struct samr_Ids group_rids, name_types;
     
    14601605        }
    14611606
    1462         result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
     1607        status = dcerpc_samr_Connect2(b, mem_ctx,
    14631608                                      pipe_hnd->desthost,
    14641609                                      MAXIMUM_ALLOWED_ACCESS,
    1465                                       &connect_pol);
     1610                                      &connect_pol,
     1611                                      &result);
     1612        if (!NT_STATUS_IS_OK(status)) {
     1613                d_fprintf(stderr, _("Request samr_Connect2 failed\n"));
     1614                goto done;
     1615        }
    14661616
    14671617        if (!NT_STATUS_IS_OK(result)) {
     1618                status = result;
    14681619                d_fprintf(stderr, _("Request samr_Connect2 failed\n"));
    1469                 goto done;
     1620                goto done;
    14701621        }
    14711622
    1472         result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
     1623        status = dcerpc_samr_OpenDomain(b, mem_ctx,
    14731624                                        &connect_pol,
    14741625                                        MAXIMUM_ALLOWED_ACCESS,
    14751626                                        CONST_DISCARD(struct dom_sid2 *, domain_sid),
    1476                                         &domain_pol);
     1627                                        &domain_pol,
     1628                                        &result);
     1629        if (!NT_STATUS_IS_OK(status)) {
     1630                d_fprintf(stderr, _("Request open_domain failed\n"));
     1631                goto done;
     1632        }
    14771633
    14781634        if (!NT_STATUS_IS_OK(result)) {
     1635                status = result;
    14791636                d_fprintf(stderr, _("Request open_domain failed\n"));
    1480                 goto done;
     1637                goto done;
    14811638        }
    14821639
    14831640        init_lsa_String(&lsa_acct_name, argv[0]);
    14841641
    1485         result = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,
     1642        status = dcerpc_samr_LookupNames(b, mem_ctx,
    14861643                                         &domain_pol,
    14871644                                         1,
    14881645                                         &lsa_acct_name,
    14891646                                         &group_rids,
    1490                                          &name_types);
     1647                                         &name_types,
     1648                                         &result);
     1649        if (!NT_STATUS_IS_OK(status)) {
     1650                d_fprintf(stderr, _("Lookup of '%s' failed\n"),argv[0]);
     1651                goto done;
     1652        }
     1653
    14911654        if (!NT_STATUS_IS_OK(result)) {
     1655                status = result;
    14921656                d_fprintf(stderr, _("Lookup of '%s' failed\n"),argv[0]);
    1493                 goto done;
     1657                goto done;
    14941658        }
    14951659
     
    14971661        {
    14981662        case SID_NAME_DOM_GRP:
    1499                 result = rpccli_samr_OpenGroup(pipe_hnd, mem_ctx,
     1663                status = dcerpc_samr_OpenGroup(b, mem_ctx,
    15001664                                               &domain_pol,
    15011665                                               MAXIMUM_ALLOWED_ACCESS,
    15021666                                               group_rids.ids[0],
    1503                                                &group_pol);
     1667                                               &group_pol,
     1668                                               &result);
     1669                if (!NT_STATUS_IS_OK(status)) {
     1670                        d_fprintf(stderr, _("Request open_group failed"));
     1671                        goto done;
     1672                }
     1673
    15041674                if (!NT_STATUS_IS_OK(result)) {
     1675                        status = result;
    15051676                        d_fprintf(stderr, _("Request open_group failed"));
    1506                         goto done;
     1677                        goto done;
    15071678                }
    15081679
    15091680                group_rid = group_rids.ids[0];
    15101681
    1511                 result = rpccli_samr_QueryGroupMember(pipe_hnd, mem_ctx,
     1682                status = dcerpc_samr_QueryGroupMember(b, mem_ctx,
    15121683                                                      &group_pol,
    1513                                                       &rids);
    1514 
    1515                 if (!NT_STATUS_IS_OK(result)) {
     1684                                                      &rids,
     1685                                                      &result);
     1686                if (!NT_STATUS_IS_OK(status)) {
    15161687                        d_fprintf(stderr,
    15171688                                  _("Unable to query group members of %s"),
    15181689                                  argv[0]);
    1519                         goto done;
     1690                        goto done;
     1691                }
     1692
     1693                if (!NT_STATUS_IS_OK(result)) {
     1694                        status = result;
     1695                        d_fprintf(stderr,
     1696                                  _("Unable to query group members of %s"),
     1697                                  argv[0]);
     1698                        goto done;
    15201699                }
    15211700
     
    15291708                for (i = 0; i < rids->count; i++)
    15301709                {
    1531                         result = rpccli_samr_OpenUser(pipe_hnd, mem_ctx,
     1710                        status = dcerpc_samr_OpenUser(b, mem_ctx,
    15321711                                                      &domain_pol,
    15331712                                                      MAXIMUM_ALLOWED_ACCESS,
    15341713                                                      rids->rids[i],
    1535                                                       &user_pol);
    1536 
    1537                         if (!NT_STATUS_IS_OK(result)) {
     1714                                                      &user_pol,
     1715                                                      &result);
     1716                        if (!NT_STATUS_IS_OK(status)) {
    15381717                                d_fprintf(stderr,
    15391718                                        _("Unable to open group member %d\n"),
    15401719                                        rids->rids[i]);
    1541                                 goto done;
    1542                         }
    1543 
    1544                         result = rpccli_samr_QueryUserInfo(pipe_hnd, mem_ctx,
     1720                                goto done;
     1721                        }
     1722
     1723                        if (!NT_STATUS_IS_OK(result)) {
     1724                                status = result;
     1725                                d_fprintf(stderr,
     1726                                        _("Unable to open group member %d\n"),
     1727                                        rids->rids[i]);
     1728                                goto done;
     1729                        }
     1730
     1731                        status = dcerpc_samr_QueryUserInfo(b, mem_ctx,
    15451732                                                           &user_pol,
    15461733                                                           21,
    1547                                                            &info);
    1548 
    1549                         if (!NT_STATUS_IS_OK(result)) {
     1734                                                           &info,
     1735                                                           &result);
     1736                        if (!NT_STATUS_IS_OK(status)) {
    15501737                                d_fprintf(stderr,
    15511738                                        _("Unable to lookup userinfo for group "
    15521739                                          "member %d\n"),
    15531740                                        rids->rids[i]);
    1554                                 goto done;
    1555                         }
     1741                                goto done;
     1742                        }
     1743
     1744                        if (!NT_STATUS_IS_OK(result)) {
     1745                                status = result;
     1746                                d_fprintf(stderr,
     1747                                        _("Unable to lookup userinfo for group "
     1748                                          "member %d\n"),
     1749                                        rids->rids[i]);
     1750                                goto done;
     1751                        }
    15561752
    15571753                        if (info->info21.primary_gid == group_rid) {
     
    15641760                        }
    15651761
    1566                         rpccli_samr_Close(pipe_hnd, mem_ctx, &user_pol);
     1762                        dcerpc_samr_Close(b, mem_ctx, &user_pol, &result);
    15671763                }
    15681764
     
    15711767                                 "some of it's members have it as primary "
    15721768                                 "group\n"));
    1573                         result = NT_STATUS_MEMBERS_PRIMARY_GROUP;
     1769                        status = NT_STATUS_MEMBERS_PRIMARY_GROUP;
    15741770                        goto done;
    15751771                }
     
    15811777                                d_printf(_("Remove group member %d..."),
    15821778                                        rids->rids[i]);
    1583                         result = rpccli_samr_DeleteGroupMember(pipe_hnd, mem_ctx,
     1779                        status = dcerpc_samr_DeleteGroupMember(b, mem_ctx,
    15841780                                                               &group_pol,
    1585                                                                rids->rids[i]);
    1586 
     1781                                                               rids->rids[i],
     1782                                                               &result);
     1783                        if (!NT_STATUS_IS_OK(status)) {
     1784                                goto done;
     1785                        }
     1786                        status = result;
    15871787                        if (NT_STATUS_IS_OK(result)) {
    15881788                                if (c->opt_verbose)
     
    15951795                }
    15961796
    1597                 result = rpccli_samr_DeleteDomainGroup(pipe_hnd, mem_ctx,
    1598                                                        &group_pol);
     1797                status = dcerpc_samr_DeleteDomainGroup(b, mem_ctx,
     1798                                                       &group_pol,
     1799                                                       &result);
     1800                if (!NT_STATUS_IS_OK(status)) {
     1801                        break;
     1802                }
     1803
     1804                status = result;
    15991805
    16001806                break;
    16011807        /* removing a local group is easier... */
    16021808        case SID_NAME_ALIAS:
    1603                 result = rpccli_samr_OpenAlias(pipe_hnd, mem_ctx,
     1809                status = dcerpc_samr_OpenAlias(b, mem_ctx,
    16041810                                               &domain_pol,
    16051811                                               MAXIMUM_ALLOWED_ACCESS,
    16061812                                               group_rids.ids[0],
    1607                                                &group_pol);
    1608 
     1813                                               &group_pol,
     1814                                               &result);
     1815                if (!NT_STATUS_IS_OK(status)) {
     1816                        d_fprintf(stderr, _("Request open_alias failed\n"));
     1817                        goto done;
     1818                }
    16091819                if (!NT_STATUS_IS_OK(result)) {
     1820                        status = result;
    16101821                        d_fprintf(stderr, _("Request open_alias failed\n"));
    1611                         goto done;
     1822                        goto done;
    16121823                }
    16131824
    1614                 result = rpccli_samr_DeleteDomAlias(pipe_hnd, mem_ctx,
    1615                                                     &group_pol);
     1825                status = dcerpc_samr_DeleteDomAlias(b, mem_ctx,
     1826                                                    &group_pol,
     1827                                                    &result);
     1828                if (!NT_STATUS_IS_OK(status)) {
     1829                        break;
     1830                }
     1831
     1832                status = result;
     1833
    16161834                break;
    16171835        default:
     
    16191837                                    "for deleting local or global groups\n"),
    16201838                        argv[0],sid_type_lookup(name_types.ids[0]));
    1621                 result = NT_STATUS_UNSUCCESSFUL;
    1622                 goto done;
    1623         }
    1624 
    1625         if (NT_STATUS_IS_OK(result)) {
     1839                status = NT_STATUS_UNSUCCESSFUL;
     1840                goto done;
     1841        }
     1842
     1843        if (NT_STATUS_IS_OK(status)) {
    16261844                if (c->opt_verbose)
    16271845                        d_printf(_("Deleted %s '%s'\n"),
     
    16291847        } else {
    16301848                d_fprintf(stderr, _("Deleting of %s failed: %s\n"), argv[0],
    1631                         get_friendly_nt_error_msg(result));
     1849                        get_friendly_nt_error_msg(status));
    16321850        }
    16331851
    16341852 done:
    1635         return result;
     1853        return status;
    16361854
    16371855}
     
    17201938                                TALLOC_CTX *mem_ctx,
    17211939                                const char *name,
    1722                                 DOM_SID *sid,
     1940                                struct dom_sid *sid,
    17231941                                enum lsa_SidType *type)
    17241942{
    1725         DOM_SID *sids = NULL;
     1943        struct dom_sid *sids = NULL;
    17261944        enum lsa_SidType *types = NULL;
    17271945        struct rpc_pipe_client *pipe_hnd = NULL;
    17281946        struct policy_handle lsa_pol;
    1729         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
    1730 
    1731         result = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc.syntax_id,
     1947        NTSTATUS status, result;
     1948        struct dcerpc_binding_handle *b;
     1949
     1950        status = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc.syntax_id,
    17321951                                          &pipe_hnd);
    1733         if (!NT_STATUS_IS_OK(result)) {
    1734                 goto done;
    1735         }
    1736 
    1737         result = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, false,
     1952        if (!NT_STATUS_IS_OK(status)) {
     1953                goto done;
     1954        }
     1955
     1956        b = pipe_hnd->binding_handle;
     1957
     1958        status = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, false,
    17381959                                     SEC_FLAG_MAXIMUM_ALLOWED, &lsa_pol);
    17391960
    1740         if (!NT_STATUS_IS_OK(result)) {
    1741                 goto done;
    1742         }
    1743 
    1744         result = rpccli_lsa_lookup_names(pipe_hnd, mem_ctx, &lsa_pol, 1,
     1961        if (!NT_STATUS_IS_OK(status)) {
     1962                goto done;
     1963        }
     1964
     1965        status = rpccli_lsa_lookup_names(pipe_hnd, mem_ctx, &lsa_pol, 1,
    17451966                                      &name, NULL, 1, &sids, &types);
    17461967
    1747         if (NT_STATUS_IS_OK(result)) {
     1968        if (NT_STATUS_IS_OK(status)) {
    17481969                sid_copy(sid, &sids[0]);
    17491970                *type = types[0];
    17501971        }
    17511972
    1752         rpccli_lsa_Close(pipe_hnd, mem_ctx, &lsa_pol);
     1973        dcerpc_lsa_Close(b, mem_ctx, &lsa_pol, &result);
    17531974
    17541975 done:
     
    17571978        }
    17581979
    1759         if (!NT_STATUS_IS_OK(result) && (StrnCaseCmp(name, "S-", 2) == 0)) {
     1980        if (!NT_STATUS_IS_OK(status) && (StrnCaseCmp(name, "S-", 2) == 0)) {
    17601981
    17611982                /* Try as S-1-5-whatever */
    17621983
    1763                 DOM_SID tmp_sid;
     1984                struct dom_sid tmp_sid;
    17641985
    17651986                if (string_to_sid(&tmp_sid, name)) {
    17661987                        sid_copy(sid, &tmp_sid);
    17671988                        *type = SID_NAME_UNKNOWN;
    1768                         result = NT_STATUS_OK;
     1989                        status = NT_STATUS_OK;
    17691990                }
    17701991        }
    17711992
    1772         return result;
     1993        return status;
    17731994}
    17741995
    17751996static NTSTATUS rpc_add_groupmem(struct rpc_pipe_client *pipe_hnd,
    17761997                                TALLOC_CTX *mem_ctx,
    1777                                 const DOM_SID *group_sid,
     1998                                const struct dom_sid *group_sid,
    17781999                                const char *member)
    17792000{
    17802001        struct policy_handle connect_pol, domain_pol;
    1781         NTSTATUS result;
     2002        NTSTATUS status, result;
    17822003        uint32 group_rid;
    17832004        struct policy_handle group_pol;
     2005        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    17842006
    17852007        struct samr_Ids rids, rid_types;
    17862008        struct lsa_String lsa_acct_name;
    17872009
    1788         DOM_SID sid;
     2010        struct dom_sid sid;
    17892011
    17902012        sid_copy(&sid, group_sid);
     
    17952017
    17962018        /* Get sam policy handle */
    1797         result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
     2019        status = dcerpc_samr_Connect2(b, mem_ctx,
    17982020                                      pipe_hnd->desthost,
    17992021                                      MAXIMUM_ALLOWED_ACCESS,
    1800                                       &connect_pol);
     2022                                      &connect_pol,
     2023                                      &result);
     2024        if (!NT_STATUS_IS_OK(status)) {
     2025                return status;
     2026        }
    18012027        if (!NT_STATUS_IS_OK(result)) {
    18022028                return result;
     
    18042030
    18052031        /* Get domain policy handle */
    1806         result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
     2032        status = dcerpc_samr_OpenDomain(b, mem_ctx,
    18072033                                        &connect_pol,
    18082034                                        MAXIMUM_ALLOWED_ACCESS,
    18092035                                        &sid,
    1810                                         &domain_pol);
     2036                                        &domain_pol,
     2037                                        &result);
     2038        if (!NT_STATUS_IS_OK(status)) {
     2039                return status;
     2040        }
    18112041        if (!NT_STATUS_IS_OK(result)) {
    18122042                return result;
     
    18152045        init_lsa_String(&lsa_acct_name, member);
    18162046
    1817         result = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,
     2047        status = dcerpc_samr_LookupNames(b, mem_ctx,
    18182048                                         &domain_pol,
    18192049                                         1,
    18202050                                         &lsa_acct_name,
    18212051                                         &rids,
    1822                                          &rid_types);
    1823 
    1824         if (!NT_STATUS_IS_OK(result)) {
     2052                                         &rid_types,
     2053                                         &result);
     2054        if (!NT_STATUS_IS_OK(status)) {
    18252055                d_fprintf(stderr, _("Could not lookup up group member %s\n"),
    18262056                          member);
     
    18282058        }
    18292059
    1830         result = rpccli_samr_OpenGroup(pipe_hnd, mem_ctx,
     2060        if (!NT_STATUS_IS_OK(result)) {
     2061                status = result;
     2062                d_fprintf(stderr, _("Could not lookup up group member %s\n"),
     2063                          member);
     2064                goto done;
     2065        }
     2066
     2067        status = dcerpc_samr_OpenGroup(b, mem_ctx,
    18312068                                       &domain_pol,
    18322069                                       MAXIMUM_ALLOWED_ACCESS,
    18332070                                       group_rid,
    1834                                        &group_pol);
     2071                                       &group_pol,
     2072                                       &result);
     2073        if (!NT_STATUS_IS_OK(status)) {
     2074                goto done;
     2075        }
    18352076
    18362077        if (!NT_STATUS_IS_OK(result)) {
    1837                 goto done;
    1838         }
    1839 
    1840         result = rpccli_samr_AddGroupMember(pipe_hnd, mem_ctx,
     2078                status = result;
     2079                goto done;
     2080        }
     2081
     2082        status = dcerpc_samr_AddGroupMember(b, mem_ctx,
    18412083                                            &group_pol,
    18422084                                            rids.ids[0],
    1843                                             0x0005); /* unknown flags */
     2085                                            0x0005, /* unknown flags */
     2086                                            &result);
     2087        if (!NT_STATUS_IS_OK(status)) {
     2088                goto done;
     2089        }
     2090
     2091        status = result;
    18442092
    18452093 done:
    1846         rpccli_samr_Close(pipe_hnd, mem_ctx, &connect_pol);
    1847         return result;
     2094        dcerpc_samr_Close(b, mem_ctx, &connect_pol, &result);
     2095        return status;
    18482096}
    18492097
    18502098static NTSTATUS rpc_add_aliasmem(struct rpc_pipe_client *pipe_hnd,
    18512099                                TALLOC_CTX *mem_ctx,
    1852                                 const DOM_SID *alias_sid,
     2100                                const struct dom_sid *alias_sid,
    18532101                                const char *member)
    18542102{
    18552103        struct policy_handle connect_pol, domain_pol;
    1856         NTSTATUS result;
     2104        NTSTATUS status, result;
    18572105        uint32 alias_rid;
    18582106        struct policy_handle alias_pol;
    1859 
    1860         DOM_SID member_sid;
     2107        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
     2108
     2109        struct dom_sid member_sid;
    18612110        enum lsa_SidType member_type;
    18622111
    1863         DOM_SID sid;
     2112        struct dom_sid sid;
    18642113
    18652114        sid_copy(&sid, alias_sid);
     
    18792128
    18802129        /* Get sam policy handle */
    1881         result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
     2130        status = dcerpc_samr_Connect2(b, mem_ctx,
    18822131                                      pipe_hnd->desthost,
    18832132                                      MAXIMUM_ALLOWED_ACCESS,
    1884                                       &connect_pol);
     2133                                      &connect_pol,
     2134                                      &result);
     2135        if (!NT_STATUS_IS_OK(status)) {
     2136                goto done;
     2137        }
    18852138        if (!NT_STATUS_IS_OK(result)) {
     2139                status = result;
    18862140                goto done;
    18872141        }
    18882142
    18892143        /* Get domain policy handle */
    1890         result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
     2144        status = dcerpc_samr_OpenDomain(b, mem_ctx,
    18912145                                        &connect_pol,
    18922146                                        MAXIMUM_ALLOWED_ACCESS,
    18932147                                        &sid,
    1894                                         &domain_pol);
     2148                                        &domain_pol,
     2149                                        &result);
     2150        if (!NT_STATUS_IS_OK(status)) {
     2151                goto done;
     2152        }
    18952153        if (!NT_STATUS_IS_OK(result)) {
    1896                 goto done;
    1897         }
    1898 
    1899         result = rpccli_samr_OpenAlias(pipe_hnd, mem_ctx,
     2154                status = result;
     2155                goto done;
     2156        }
     2157
     2158        status = dcerpc_samr_OpenAlias(b, mem_ctx,
    19002159                                       &domain_pol,
    19012160                                       MAXIMUM_ALLOWED_ACCESS,
    19022161                                       alias_rid,
    1903                                        &alias_pol);
    1904 
     2162                                       &alias_pol,
     2163                                       &result);
     2164        if (!NT_STATUS_IS_OK(status)) {
     2165                return status;
     2166        }
    19052167        if (!NT_STATUS_IS_OK(result)) {
    19062168                return result;
    19072169        }
    19082170
    1909         result = rpccli_samr_AddAliasMember(pipe_hnd, mem_ctx,
     2171        status = dcerpc_samr_AddAliasMember(b, mem_ctx,
    19102172                                            &alias_pol,
    1911                                             &member_sid);
    1912 
    1913         if (!NT_STATUS_IS_OK(result)) {
    1914                 return result;
    1915         }
     2173                                            &member_sid,
     2174                                            &result);
     2175        if (!NT_STATUS_IS_OK(status)) {
     2176                return status;
     2177        }
     2178
     2179        status = result;
    19162180
    19172181 done:
    1918         rpccli_samr_Close(pipe_hnd, mem_ctx, &connect_pol);
    1919         return result;
     2182        dcerpc_samr_Close(b, mem_ctx, &connect_pol, &result);
     2183        return status;
    19202184}
    19212185
    19222186static NTSTATUS rpc_group_addmem_internals(struct net_context *c,
    1923                                         const DOM_SID *domain_sid,
     2187                                        const struct dom_sid *domain_sid,
    19242188                                        const char *domain_name,
    19252189                                        struct cli_state *cli,
     
    19292193                                        const char **argv)
    19302194{
    1931         DOM_SID group_sid;
     2195        struct dom_sid group_sid;
    19322196        enum lsa_SidType group_type;
    19332197
     
    19872251                                struct rpc_pipe_client *pipe_hnd,
    19882252                                TALLOC_CTX *mem_ctx,
    1989                                 const DOM_SID *group_sid,
     2253                                const struct dom_sid *group_sid,
    19902254                                const char *member)
    19912255{
    19922256        struct policy_handle connect_pol, domain_pol;
    1993         NTSTATUS result;
     2257        NTSTATUS status, result;
    19942258        uint32 group_rid;
    19952259        struct policy_handle group_pol;
     2260        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    19962261
    19972262        struct samr_Ids rids, rid_types;
    19982263        struct lsa_String lsa_acct_name;
    19992264
    2000         DOM_SID sid;
     2265        struct dom_sid sid;
    20012266
    20022267        sid_copy(&sid, group_sid);
     
    20062271
    20072272        /* Get sam policy handle */
    2008         result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
     2273        status = dcerpc_samr_Connect2(b, mem_ctx,
    20092274                                      pipe_hnd->desthost,
    20102275                                      MAXIMUM_ALLOWED_ACCESS,
    2011                                       &connect_pol);
    2012         if (!NT_STATUS_IS_OK(result))
     2276                                      &connect_pol,
     2277                                      &result);
     2278        if (!NT_STATUS_IS_OK(status)) {
     2279                return status;
     2280        }
     2281        if (!NT_STATUS_IS_OK(result)) {
    20132282                return result;
     2283        }
     2284
    20142285
    20152286        /* Get domain policy handle */
    2016         result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
     2287        status = dcerpc_samr_OpenDomain(b, mem_ctx,
    20172288                                        &connect_pol,
    20182289                                        MAXIMUM_ALLOWED_ACCESS,
    20192290                                        &sid,
    2020                                         &domain_pol);
    2021         if (!NT_STATUS_IS_OK(result))
     2291                                        &domain_pol,
     2292                                        &result);
     2293        if (!NT_STATUS_IS_OK(status)) {
     2294                return status;
     2295        }
     2296        if (!NT_STATUS_IS_OK(result)) {
    20222297                return result;
     2298        }
    20232299
    20242300        init_lsa_String(&lsa_acct_name, member);
    20252301
    2026         result = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,
     2302        status = dcerpc_samr_LookupNames(b, mem_ctx,
    20272303                                         &domain_pol,
    20282304                                         1,
    20292305                                         &lsa_acct_name,
    20302306                                         &rids,
    2031                                          &rid_types);
    2032         if (!NT_STATUS_IS_OK(result)) {
     2307                                         &rid_types,
     2308                                         &result);
     2309        if (!NT_STATUS_IS_OK(status)) {
    20332310                d_fprintf(stderr, _("Could not lookup up group member %s\n"),
    20342311                          member);
     
    20362313        }
    20372314
    2038         result = rpccli_samr_OpenGroup(pipe_hnd, mem_ctx,
     2315        if (!NT_STATUS_IS_OK(result)) {
     2316                status = result;
     2317                d_fprintf(stderr, _("Could not lookup up group member %s\n"),
     2318                          member);
     2319                goto done;
     2320        }
     2321
     2322        status = dcerpc_samr_OpenGroup(b, mem_ctx,
    20392323                                       &domain_pol,
    20402324                                       MAXIMUM_ALLOWED_ACCESS,
    20412325                                       group_rid,
    2042                                        &group_pol);
    2043 
    2044         if (!NT_STATUS_IS_OK(result))
    2045                 goto done;
    2046 
    2047         result = rpccli_samr_DeleteGroupMember(pipe_hnd, mem_ctx,
     2326                                       &group_pol,
     2327                                       &result);
     2328        if (!NT_STATUS_IS_OK(status)) {
     2329                goto done;
     2330        }
     2331        if (!NT_STATUS_IS_OK(result)) {
     2332                status = result;
     2333                goto done;
     2334        }
     2335
     2336        status = dcerpc_samr_DeleteGroupMember(b, mem_ctx,
    20482337                                               &group_pol,
    2049                                                rids.ids[0]);
    2050 
     2338                                               rids.ids[0],
     2339                                               &result);
     2340        if (!NT_STATUS_IS_OK(status)) {
     2341                goto done;
     2342        }
     2343
     2344        status = result;
    20512345 done:
    2052         rpccli_samr_Close(pipe_hnd, mem_ctx, &connect_pol);
    2053         return result;
     2346        dcerpc_samr_Close(b, mem_ctx, &connect_pol, &result);
     2347        return status;
    20542348}
    20552349
    20562350static NTSTATUS rpc_del_aliasmem(struct rpc_pipe_client *pipe_hnd,
    20572351                                TALLOC_CTX *mem_ctx,
    2058                                 const DOM_SID *alias_sid,
     2352                                const struct dom_sid *alias_sid,
    20592353                                const char *member)
    20602354{
    20612355        struct policy_handle connect_pol, domain_pol;
    2062         NTSTATUS result;
     2356        NTSTATUS status, result;
    20632357        uint32 alias_rid;
    20642358        struct policy_handle alias_pol;
    2065 
    2066         DOM_SID member_sid;
     2359        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
     2360
     2361        struct dom_sid member_sid;
    20672362        enum lsa_SidType member_type;
    20682363
    2069         DOM_SID sid;
     2364        struct dom_sid sid;
    20702365
    20712366        sid_copy(&sid, alias_sid);
     
    20842379
    20852380        /* Get sam policy handle */
    2086         result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
     2381        status = dcerpc_samr_Connect2(b, mem_ctx,
    20872382                                      pipe_hnd->desthost,
    20882383                                      MAXIMUM_ALLOWED_ACCESS,
    2089                                       &connect_pol);
     2384                                      &connect_pol,
     2385                                      &result);
     2386        if (!NT_STATUS_IS_OK(status)) {
     2387                goto done;
     2388        }
    20902389        if (!NT_STATUS_IS_OK(result)) {
     2390                status = result;
    20912391                goto done;
    20922392        }
    20932393
    20942394        /* Get domain policy handle */
    2095         result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
     2395        status = dcerpc_samr_OpenDomain(b, mem_ctx,
    20962396                                        &connect_pol,
    20972397                                        MAXIMUM_ALLOWED_ACCESS,
    20982398                                        &sid,
    2099                                         &domain_pol);
     2399                                        &domain_pol,
     2400                                        &result);
     2401        if (!NT_STATUS_IS_OK(status)) {
     2402                goto done;
     2403        }
    21002404        if (!NT_STATUS_IS_OK(result)) {
    2101                 goto done;
    2102         }
    2103 
    2104         result = rpccli_samr_OpenAlias(pipe_hnd, mem_ctx,
     2405                status = result;
     2406                goto done;
     2407        }
     2408
     2409        status = dcerpc_samr_OpenAlias(b, mem_ctx,
    21052410                                       &domain_pol,
    21062411                                       MAXIMUM_ALLOWED_ACCESS,
    21072412                                       alias_rid,
    2108                                        &alias_pol);
    2109 
    2110         if (!NT_STATUS_IS_OK(result))
     2413                                       &alias_pol,
     2414                                       &result);
     2415        if (!NT_STATUS_IS_OK(status)) {
     2416                return status;
     2417        }
     2418
     2419        if (!NT_STATUS_IS_OK(result)) {
    21112420                return result;
    2112 
    2113         result = rpccli_samr_DeleteAliasMember(pipe_hnd, mem_ctx,
     2421        }
     2422
     2423        status = dcerpc_samr_DeleteAliasMember(b, mem_ctx,
    21142424                                               &alias_pol,
    2115                                                &member_sid);
    2116 
    2117         if (!NT_STATUS_IS_OK(result))
    2118                 return result;
     2425                                               &member_sid,
     2426                                               &result);
     2427
     2428        if (!NT_STATUS_IS_OK(status)) {
     2429                return status;
     2430        }
     2431
     2432        status = result;
    21192433
    21202434 done:
    2121         rpccli_samr_Close(pipe_hnd, mem_ctx, &connect_pol);
    2122         return result;
     2435        dcerpc_samr_Close(b, mem_ctx, &connect_pol, &result);
     2436        return status;
    21232437}
    21242438
    21252439static NTSTATUS rpc_group_delmem_internals(struct net_context *c,
    2126                                         const DOM_SID *domain_sid,
     2440                                        const struct dom_sid *domain_sid,
    21272441                                        const char *domain_name,
    21282442                                        struct cli_state *cli,
     
    21322446                                        const char **argv)
    21332447{
    2134         DOM_SID group_sid;
     2448        struct dom_sid group_sid;
    21352449        enum lsa_SidType group_type;
    21362450
     
    22042518
    22052519static NTSTATUS rpc_group_list_internals(struct net_context *c,
    2206                                         const DOM_SID *domain_sid,
     2520                                        const struct dom_sid *domain_sid,
    22072521                                        const char *domain_name,
    22082522                                        struct cli_state *cli,
     
    22132527{
    22142528        struct policy_handle connect_pol, domain_pol;
    2215         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
     2529        NTSTATUS status, result;
    22162530        uint32 start_idx=0, max_entries=250, num_entries, i, loop_count = 0;
    22172531        struct samr_SamArray *groups = NULL;
     
    22192533        bool local = false;
    22202534        bool builtin = false;
     2535        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    22212536
    22222537        if (c->display_usage) {
     
    22532568        /* Get sam policy handle */
    22542569
    2255         result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
     2570        status = dcerpc_samr_Connect2(b, mem_ctx,
    22562571                                      pipe_hnd->desthost,
    22572572                                      MAXIMUM_ALLOWED_ACCESS,
    2258                                       &connect_pol);
     2573                                      &connect_pol,
     2574                                      &result);
     2575        if (!NT_STATUS_IS_OK(status)) {
     2576                goto done;
     2577        }
    22592578        if (!NT_STATUS_IS_OK(result)) {
     2579                status = result;
    22602580                goto done;
    22612581        }
     
    22632583        /* Get domain policy handle */
    22642584
    2265         result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
     2585        status = dcerpc_samr_OpenDomain(b, mem_ctx,
    22662586                                        &connect_pol,
    22672587                                        MAXIMUM_ALLOWED_ACCESS,
    22682588                                        CONST_DISCARD(struct dom_sid2 *, domain_sid),
    2269                                         &domain_pol);
     2589                                        &domain_pol,
     2590                                        &result);
     2591        if (!NT_STATUS_IS_OK(status)) {
     2592                goto done;
     2593        }
    22702594        if (!NT_STATUS_IS_OK(result)) {
     2595                status = result;
    22712596                goto done;
    22722597        }
     
    22822607                if (!global) break;
    22832608
    2284                 get_query_dispinfo_params(
     2609                dcerpc_get_query_dispinfo_params(
    22852610                        loop_count, &max_entries, &max_size);
    22862611
    2287                 result = rpccli_samr_QueryDisplayInfo(pipe_hnd, mem_ctx,
     2612                status = dcerpc_samr_QueryDisplayInfo(b, mem_ctx,
    22882613                                                      &domain_pol,
    22892614                                                      3,
     
    22932618                                                      &total_size,
    22942619                                                      &returned_size,
    2295                                                       &info);
     2620                                                      &info,
     2621                                                      &result);
     2622                if (!NT_STATUS_IS_OK(status)) {
     2623                        goto done;
     2624                }
    22962625                num_entries = info.info3.count;
    22972626                start_idx += info.info3.count;
     
    23212650                if (!local) break;
    23222651
    2323                 result = rpccli_samr_EnumDomainAliases(pipe_hnd, mem_ctx,
     2652                status = dcerpc_samr_EnumDomainAliases(b, mem_ctx,
    23242653                                                       &domain_pol,
    23252654                                                       &start_idx,
    23262655                                                       &groups,
    23272656                                                       0xffff,
    2328                                                        &num_entries);
     2657                                                       &num_entries,
     2658                                                       &result);
     2659                if (!NT_STATUS_IS_OK(status)) {
     2660                        goto done;
     2661                }
    23292662                if (!NT_STATUS_IS_OK(result) &&
    23302663                    !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES))
     
    23392672                                struct policy_handle alias_pol;
    23402673                                union samr_AliasInfo *info = NULL;
    2341 
    2342                                 if ((NT_STATUS_IS_OK(rpccli_samr_OpenAlias(pipe_hnd, mem_ctx,
    2343                                                                            &domain_pol,
    2344                                                                            0x8,
    2345                                                                            groups->entries[i].idx,
    2346                                                                            &alias_pol))) &&
    2347                                     (NT_STATUS_IS_OK(rpccli_samr_QueryAliasInfo(pipe_hnd, mem_ctx,
    2348                                                                                 &alias_pol,
    2349                                                                                 3,
    2350                                                                                 &info))) &&
    2351                                     (NT_STATUS_IS_OK(rpccli_samr_Close(pipe_hnd, mem_ctx,
    2352                                                                     &alias_pol)))) {
    2353                                         description = info->description.string;
     2674                                NTSTATUS _result;
     2675
     2676                                status = dcerpc_samr_OpenAlias(b, mem_ctx,
     2677                                                               &domain_pol,
     2678                                                               0x8,
     2679                                                               groups->entries[i].idx,
     2680                                                               &alias_pol,
     2681                                                               &_result);
     2682                                if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(_result)) {
     2683                                        status = dcerpc_samr_QueryAliasInfo(b, mem_ctx,
     2684                                                                            &alias_pol,
     2685                                                                            3,
     2686                                                                            &info,
     2687                                                                            &_result);
     2688                                        if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(_result)) {
     2689                                                status = dcerpc_samr_Close(b, mem_ctx,
     2690                                                                           &alias_pol,
     2691                                                                           &_result);
     2692                                                if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(_result)) {
     2693                                                        description = info->description.string;
     2694                                                }
     2695                                        }
    23542696                                }
    23552697                        }
     
    23642706                }
    23652707        } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
    2366         rpccli_samr_Close(pipe_hnd, mem_ctx, &domain_pol);
     2708        dcerpc_samr_Close(b, mem_ctx, &domain_pol, &result);
    23672709        /* Get builtin policy handle */
    23682710
    2369         result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
     2711        status = dcerpc_samr_OpenDomain(b, mem_ctx,
    23702712                                        &connect_pol,
    23712713                                        MAXIMUM_ALLOWED_ACCESS,
    23722714                                        CONST_DISCARD(struct dom_sid2 *, &global_sid_Builtin),
    2373                                         &domain_pol);
     2715                                        &domain_pol,
     2716                                        &result);
     2717        if (!NT_STATUS_IS_OK(status)) {
     2718                goto done;
     2719        }
    23742720        if (!NT_STATUS_IS_OK(result)) {
    2375                 goto done;
    2376         }
     2721                status = result;
     2722                goto done;
     2723        }
     2724
    23772725        /* query builtin aliases */
    23782726        start_idx = 0;
     
    23802728                if (!builtin) break;
    23812729
    2382                 result = rpccli_samr_EnumDomainAliases(pipe_hnd, mem_ctx,
     2730                status = dcerpc_samr_EnumDomainAliases(b, mem_ctx,
    23832731                                                       &domain_pol,
    23842732                                                       &start_idx,
    23852733                                                       &groups,
    23862734                                                       max_entries,
    2387                                                        &num_entries);
     2735                                                       &num_entries,
     2736                                                       &result);
     2737                if (!NT_STATUS_IS_OK(status)) {
     2738                        break;
     2739                }
    23882740                if (!NT_STATUS_IS_OK(result) &&
    2389                     !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES))
     2741                    !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES)) {
     2742                        status = result;
    23902743                        break;
     2744                }
    23912745
    23922746                for (i = 0; i < num_entries; i++) {
     
    23982752                                struct policy_handle alias_pol;
    23992753                                union samr_AliasInfo *info = NULL;
    2400 
    2401                                 if ((NT_STATUS_IS_OK(rpccli_samr_OpenAlias(pipe_hnd, mem_ctx,
    2402                                                                            &domain_pol,
    2403                                                                            0x8,
    2404                                                                            groups->entries[i].idx,
    2405                                                                            &alias_pol))) &&
    2406                                     (NT_STATUS_IS_OK(rpccli_samr_QueryAliasInfo(pipe_hnd, mem_ctx,
    2407                                                                                 &alias_pol,
    2408                                                                                 3,
    2409                                                                                 &info))) &&
    2410                                     (NT_STATUS_IS_OK(rpccli_samr_Close(pipe_hnd, mem_ctx,
    2411                                                                     &alias_pol)))) {
    2412                                         description = info->description.string;
     2754                                NTSTATUS _result;
     2755
     2756                                status = dcerpc_samr_OpenAlias(b, mem_ctx,
     2757                                                               &domain_pol,
     2758                                                               0x8,
     2759                                                               groups->entries[i].idx,
     2760                                                               &alias_pol,
     2761                                                               &_result);
     2762                                if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(_result)) {
     2763                                        status = dcerpc_samr_QueryAliasInfo(b, mem_ctx,
     2764                                                                            &alias_pol,
     2765                                                                            3,
     2766                                                                            &info,
     2767                                                                            &_result);
     2768                                        if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(_result)) {
     2769                                                status = dcerpc_samr_Close(b, mem_ctx,
     2770                                                                           &alias_pol,
     2771                                                                           &_result);
     2772                                                if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(_result)) {
     2773                                                        description = info->description.string;
     2774                                                }
     2775                                        }
    24132776                                }
    24142777                        }
     
    24242787        } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
    24252788
     2789        status = result;
     2790
    24262791 done:
    2427         return result;
     2792        return status;
    24282793}
    24292794
     
    24392804                                        TALLOC_CTX *mem_ctx,
    24402805                                        const char *domain_name,
    2441                                         const DOM_SID *domain_sid,
     2806                                        const struct dom_sid *domain_sid,
    24422807                                        struct policy_handle *domain_pol,
    24432808                                        uint32 rid)
    24442809{
    2445         NTSTATUS result;
     2810        NTSTATUS result, status;
    24462811        struct policy_handle group_pol;
    24472812        uint32 num_members, *group_rids;
    24482813        int i;
    2449         struct samr_RidTypeArray *rids = NULL;
     2814        struct samr_RidAttrArray *rids = NULL;
    24502815        struct lsa_Strings names;
    24512816        struct samr_Ids types;
     2817        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    24522818
    24532819        fstring sid_str;
    24542820        sid_to_fstring(sid_str, domain_sid);
    24552821
    2456         result = rpccli_samr_OpenGroup(pipe_hnd, mem_ctx,
     2822        status = dcerpc_samr_OpenGroup(b, mem_ctx,
    24572823                                       domain_pol,
    24582824                                       MAXIMUM_ALLOWED_ACCESS,
    24592825                                       rid,
    2460                                        &group_pol);
    2461 
    2462         if (!NT_STATUS_IS_OK(result))
     2826                                       &group_pol,
     2827                                       &result);
     2828        if (!NT_STATUS_IS_OK(status)) {
     2829                return status;
     2830        }
     2831        if (!NT_STATUS_IS_OK(result)) {
    24632832                return result;
    2464 
    2465         result = rpccli_samr_QueryGroupMember(pipe_hnd, mem_ctx,
     2833        }
     2834
     2835        status = dcerpc_samr_QueryGroupMember(b, mem_ctx,
    24662836                                              &group_pol,
    2467                                               &rids);
    2468 
    2469         if (!NT_STATUS_IS_OK(result))
     2837                                              &rids,
     2838                                              &result);
     2839        if (!NT_STATUS_IS_OK(status)) {
     2840                return status;
     2841        }
     2842        if (!NT_STATUS_IS_OK(result)) {
    24702843                return result;
     2844        }
    24712845
    24722846        num_members = rids->count;
     
    24792853                        this_time = num_members;
    24802854
    2481                 result = rpccli_samr_LookupRids(pipe_hnd, mem_ctx,
     2855                status = dcerpc_samr_LookupRids(b, mem_ctx,
    24822856                                                domain_pol,
    24832857                                                this_time,
    24842858                                                group_rids,
    24852859                                                &names,
    2486                                                 &types);
    2487 
    2488                 if (!NT_STATUS_IS_OK(result))
     2860                                                &types,
     2861                                                &result);
     2862                if (!NT_STATUS_IS_OK(status)) {
     2863                        return status;
     2864                }
     2865                if (!NT_STATUS_IS_OK(result)) {
    24892866                        return result;
     2867                }
    24902868
    24912869                /* We only have users as members, but make the output
     
    25182896                                        uint32 rid)
    25192897{
    2520         NTSTATUS result;
     2898        NTSTATUS result, status;
    25212899        struct rpc_pipe_client *lsa_pipe;
    25222900        struct policy_handle alias_pol, lsa_pol;
    25232901        uint32 num_members;
    2524         DOM_SID *alias_sids;
     2902        struct dom_sid *alias_sids;
    25252903        char **domains;
    25262904        char **names;
     
    25282906        int i;
    25292907        struct lsa_SidArray sid_array;
    2530 
    2531         result = rpccli_samr_OpenAlias(pipe_hnd, mem_ctx,
     2908        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
     2909
     2910        status = dcerpc_samr_OpenAlias(b, mem_ctx,
    25322911                                       domain_pol,
    25332912                                       MAXIMUM_ALLOWED_ACCESS,
    25342913                                       rid,
    2535                                        &alias_pol);
    2536 
    2537         if (!NT_STATUS_IS_OK(result))
     2914                                       &alias_pol,
     2915                                       &result);
     2916        if (!NT_STATUS_IS_OK(status)) {
     2917                return status;
     2918        }
     2919        if (!NT_STATUS_IS_OK(result)) {
    25382920                return result;
    2539 
    2540         result = rpccli_samr_GetMembersInAlias(pipe_hnd, mem_ctx,
     2921        }
     2922
     2923        status = dcerpc_samr_GetMembersInAlias(b, mem_ctx,
    25412924                                               &alias_pol,
    2542                                                &sid_array);
    2543 
     2925                                               &sid_array,
     2926                                               &result);
     2927        if (!NT_STATUS_IS_OK(status)) {
     2928                d_fprintf(stderr, _("Couldn't list alias members\n"));
     2929                return status;
     2930        }
    25442931        if (!NT_STATUS_IS_OK(result)) {
    25452932                d_fprintf(stderr, _("Couldn't list alias members\n"));
     
    25712958        }
    25722959
    2573         alias_sids = TALLOC_ZERO_ARRAY(mem_ctx, DOM_SID, num_members);
     2960        alias_sids = TALLOC_ZERO_ARRAY(mem_ctx, struct dom_sid, num_members);
    25742961        if (!alias_sids) {
    25752962                d_fprintf(stderr, _("Out of memory\n"));
     
    26143001
    26153002static NTSTATUS rpc_group_members_internals(struct net_context *c,
    2616                                         const DOM_SID *domain_sid,
     3003                                        const struct dom_sid *domain_sid,
    26173004                                        const char *domain_name,
    26183005                                        struct cli_state *cli,
     
    26223009                                        const char **argv)
    26233010{
    2624         NTSTATUS result;
     3011        NTSTATUS result, status;
    26253012        struct policy_handle connect_pol, domain_pol;
    26263013        struct samr_Ids rids, rid_types;
    26273014        struct lsa_String lsa_acct_name;
     3015        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    26283016
    26293017        /* Get sam policy handle */
    26303018
    2631         result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
     3019        status = dcerpc_samr_Connect2(b, mem_ctx,
    26323020                                      pipe_hnd->desthost,
    26333021                                      MAXIMUM_ALLOWED_ACCESS,
    2634                                       &connect_pol);
    2635 
    2636         if (!NT_STATUS_IS_OK(result))
     3022                                      &connect_pol,
     3023                                      &result);
     3024        if (!NT_STATUS_IS_OK(status)) {
     3025                return status;
     3026        }
     3027        if (!NT_STATUS_IS_OK(result)) {
    26373028                return result;
     3029        }
    26383030
    26393031        /* Get domain policy handle */
    26403032
    2641         result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
     3033        status = dcerpc_samr_OpenDomain(b, mem_ctx,
    26423034                                        &connect_pol,
    26433035                                        MAXIMUM_ALLOWED_ACCESS,
    26443036                                        CONST_DISCARD(struct dom_sid2 *, domain_sid),
    2645                                         &domain_pol);
    2646 
    2647         if (!NT_STATUS_IS_OK(result))
     3037                                        &domain_pol,
     3038                                        &result);
     3039        if (!NT_STATUS_IS_OK(status)) {
     3040                return status;
     3041        }
     3042        if (!NT_STATUS_IS_OK(result)) {
    26483043                return result;
     3044        }
    26493045
    26503046        init_lsa_String(&lsa_acct_name, argv[0]); /* sure? */
    26513047
    2652         result = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,
     3048        status = dcerpc_samr_LookupNames(b, mem_ctx,
    26533049                                         &domain_pol,
    26543050                                         1,
    26553051                                         &lsa_acct_name,
    26563052                                         &rids,
    2657                                          &rid_types);
     3053                                         &rid_types,
     3054                                         &result);
     3055        if (!NT_STATUS_IS_OK(status)) {
     3056                return status;
     3057        }
    26583058
    26593059        if (!NT_STATUS_IS_OK(result)) {
     
    26613061                /* Ok, did not find it in the global sam, try with builtin */
    26623062
    2663                 DOM_SID sid_Builtin;
    2664 
    2665                 rpccli_samr_Close(pipe_hnd, mem_ctx, &domain_pol);
     3063                struct dom_sid sid_Builtin;
     3064
     3065                dcerpc_samr_Close(b, mem_ctx, &domain_pol, &result);
    26663066
    26673067                sid_copy(&sid_Builtin, &global_sid_Builtin);
    26683068
    2669                 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
     3069                status = dcerpc_samr_OpenDomain(b, mem_ctx,
    26703070                                                &connect_pol,
    26713071                                                MAXIMUM_ALLOWED_ACCESS,
    26723072                                                &sid_Builtin,
    2673                                                 &domain_pol);
    2674 
     3073                                                &domain_pol,
     3074                                                &result);
     3075                if (!NT_STATUS_IS_OK(status)) {
     3076                        return status;
     3077                }
    26753078                if (!NT_STATUS_IS_OK(result)) {
    26763079                        d_fprintf(stderr, _("Couldn't find group %s\n"),
     
    26793082                }
    26803083
    2681                 result = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,
     3084                status = dcerpc_samr_LookupNames(b, mem_ctx,
    26823085                                                 &domain_pol,
    26833086                                                 1,
    26843087                                                 &lsa_acct_name,
    26853088                                                 &rids,
    2686                                                  &rid_types);
    2687 
     3089                                                 &rid_types,
     3090                                                 &result);
     3091                if (!NT_STATUS_IS_OK(status)) {
     3092                        return status;
     3093                }
    26883094                if (!NT_STATUS_IS_OK(result)) {
    26893095                        d_fprintf(stderr, _("Couldn't find group %s\n"),
     
    28343240        };
    28353241
    2836         status = libnetapi_init(&c->netapi_ctx);
     3242        status = libnetapi_net_init(&c->netapi_ctx);
    28373243        if (status != 0) {
    28383244                return -1;
     
    29753381        NTSTATUS status;
    29763382        union srvsvc_NetShareInfo info;
     3383        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    29773384
    29783385        /* no specific share requested, enumerate all */
     
    29853392                info_ctr->level = level;
    29863393
    2987                 status = rpccli_srvsvc_NetShareEnumAll(pipe_hnd, mem_ctx,
     3394                status = dcerpc_srvsvc_NetShareEnumAll(b, mem_ctx,
    29883395                                                       pipe_hnd->desthost,
    29893396                                                       info_ctr,
     
    29923399                                                       &resume_handle,
    29933400                                                       &result);
     3401                if (!NT_STATUS_IS_OK(status)) {
     3402                        return ntstatus_to_werror(status);
     3403                }
    29943404                return result;
    29953405        }
    29963406
    29973407        /* request just one share */
    2998         status = rpccli_srvsvc_NetShareGetInfo(pipe_hnd, mem_ctx,
     3408        status = dcerpc_srvsvc_NetShareGetInfo(b, mem_ctx,
    29993409                                               pipe_hnd->desthost,
    30003410                                               argv[0],
     
    30033413                                               &result);
    30043414
    3005         if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
     3415        if (!NT_STATUS_IS_OK(status)) {
     3416                result = ntstatus_to_werror(status);
     3417                goto done;
     3418        }
     3419
     3420        if (!W_ERROR_IS_OK(result)) {
    30063421                goto done;
    30073422        }
     
    30243439
    30253440                info_ctr->ctr.ctr1 = ctr1;
     3441
     3442                break;
    30263443        }
    30273444        case 2:
     
    30363453
    30373454                info_ctr->ctr.ctr2 = ctr2;
     3455
     3456                break;
    30383457        }
    30393458        case 502:
     
    30483467
    30493468                info_ctr->ctr.ctr502 = ctr502;
     3469
     3470                break;
    30503471        }
    30513472        } /* switch */
     
    31053526static bool check_share_availability(struct cli_state *cli, const char *netname)
    31063527{
    3107         if (!NT_STATUS_IS_OK(cli_tcon_andx(cli, netname, "A:", "", 0))) {
     3528        NTSTATUS status;
     3529
     3530        status = cli_tcon_andx(cli, netname, "A:", "", 0);
     3531        if (!NT_STATUS_IS_OK(status)) {
    31083532                d_printf(_("skipping   [%s]: not a file share.\n"), netname);
    31093533                return false;
    31103534        }
    31113535
    3112         if (!cli_tdis(cli))
     3536        status = cli_tdis(cli);
     3537        if (!NT_STATUS_IS_OK(status)) {
     3538                d_printf(_("cli_tdis returned %s\n"), nt_errstr(status));
    31133539                return false;
     3540        }
    31143541
    31153542        return true;
     
    31573584
    31583585static NTSTATUS rpc_share_migrate_shares_internals(struct net_context *c,
    3159                                                 const DOM_SID *domain_sid,
     3586                                                const struct dom_sid *domain_sid,
    31603587                                                const char *domain_name,
    31613588                                                struct cli_state *cli,
     
    31733600        uint32 level = 502; /* includes secdesc */
    31743601        uint32_t parm_error = 0;
     3602        struct dcerpc_binding_handle *b;
    31753603
    31763604        result = get_share_info(c, pipe_hnd, mem_ctx, level, argc, argv,
     
    31853613                return nt_status;
    31863614
     3615        b = srvsvc_pipe->binding_handle;
    31873616
    31883617        for (i = 0; i < ctr_src.ctr.ctr502->count; i++) {
     
    32063635                info.info502 = &info502;
    32073636
    3208                 nt_status = rpccli_srvsvc_NetShareAdd(srvsvc_pipe, mem_ctx,
     3637                nt_status = dcerpc_srvsvc_NetShareAdd(b, mem_ctx,
    32093638                                                      srvsvc_pipe->desthost,
    32103639                                                      502,
     
    32123641                                                      &parm_error,
    32133642                                                      &result);
    3214 
     3643                if (!NT_STATUS_IS_OK(nt_status)) {
     3644                        printf(_("cannot add share: %s\n"),
     3645                                nt_errstr(nt_status));
     3646                        goto done;
     3647                }
    32153648                if (W_ERROR_V(result) == W_ERROR_V(WERR_FILE_EXISTS)) {
    32163649                        printf(_("           [%s] does already exist\n"),
     
    32193652                }
    32203653
    3221                 if (!NT_STATUS_IS_OK(nt_status) || !W_ERROR_IS_OK(result)) {
    3222                         printf(_("cannot add share: %s\n"), win_errstr(result));
     3654                if (!W_ERROR_IS_OK(result)) {
     3655                        nt_status = werror_to_ntstatus(result);
     3656                        printf(_("cannot add share: %s\n"),
     3657                                win_errstr(result));
    32233658                        goto done;
    32243659                }
     
    32763711 *
    32773712 **/
    3278 static void copy_fn(const char *mnt, file_info *f,
     3713static NTSTATUS copy_fn(const char *mnt, struct file_info *f,
    32793714                    const char *mask, void *state)
    32803715{
     
    32923727
    32933728        if (strequal(f->name, ".") || strequal(f->name, ".."))
    3294                 return;
     3729                return NT_STATUS_OK;
    32953730
    32963731        DEBUG(3,("got mask: %s, name: %s\n", mask, f->name));
    32973732
    32983733        /* DIRECTORY */
    3299         if (f->mode & aDIR) {
     3734        if (f->mode & FILE_ATTRIBUTE_DIRECTORY) {
    33003735
    33013736                DEBUG(3,("got dir: %s\n", f->name));
     
    33203755                default:
    33213756                        d_fprintf(stderr, _("Unsupported mode %d\n"), net_mode_share);
    3322                         return;
     3757                        return NT_STATUS_INTERNAL_ERROR;
    33233758                }
    33243759
    3325                 if (!NT_STATUS_IS_OK(nt_status))
     3760                if (!NT_STATUS_IS_OK(nt_status)) {
    33263761                        printf(_("could not handle dir %s: %s\n"),
    33273762                                dir, nt_errstr(nt_status));
     3763                        return nt_status;
     3764                }
    33283765
    33293766                /* search below that directory */
     
    33333770                old_dir = local_state->cwd;
    33343771                local_state->cwd = dir;
    3335                 if (!sync_files(local_state, new_mask))
     3772                nt_status = sync_files(local_state, new_mask);
     3773                if (!NT_STATUS_IS_OK(nt_status)) {
    33363774                        printf(_("could not handle files\n"));
     3775                }
    33373776                local_state->cwd = old_dir;
    33383777
    3339                 return;
     3778                return nt_status;
    33403779        }
    33413780
     
    33633802                d_fprintf(stderr, _("Unsupported file mode %d\n"),
    33643803                          net_mode_share);
    3365                 return;
     3804                return NT_STATUS_INTERNAL_ERROR;
    33663805        }
    33673806
     
    33693808                printf(_("could not handle file %s: %s\n"),
    33703809                        filename, nt_errstr(nt_status));
    3371 
     3810        return nt_status;
    33723811}
    33733812
     
    33813820 * @return              Boolean result
    33823821 **/
    3383 static bool sync_files(struct copy_clistate *cp_clistate, const char *mask)
     3822static NTSTATUS sync_files(struct copy_clistate *cp_clistate, const char *mask)
    33843823{
    33853824        struct cli_state *targetcli;
    33863825        char *targetpath = NULL;
     3826        NTSTATUS status;
    33873827
    33883828        DEBUG(3,("calling cli_list with mask: %s\n", mask));
     
    33933833                                    "%s\n"),
    33943834                        mask, cli_errstr(cp_clistate->cli_share_src));
    3395                 return false;
    3396         }
    3397 
    3398         if (cli_list(targetcli, targetpath, cp_clistate->attribute, copy_fn, cp_clistate) == -1) {
     3835                return cli_nt_error(cp_clistate->cli_share_src);
     3836        }
     3837
     3838        status = cli_list(targetcli, targetpath, cp_clistate->attribute,
     3839                          copy_fn, cp_clistate);
     3840        if (!NT_STATUS_IS_OK(status)) {
    33993841                d_fprintf(stderr, _("listing %s failed with error: %s\n"),
    3400                         mask, cli_errstr(targetcli));
    3401                 return false;
    3402         }
    3403 
    3404         return true;
     3842                          mask, nt_errstr(status));
     3843        }
     3844
     3845        return status;
    34053846}
    34063847
     
    34623903
    34633904static NTSTATUS rpc_share_migrate_files_internals(struct net_context *c,
    3464                                                 const DOM_SID *domain_sid,
     3905                                                const struct dom_sid *domain_sid,
    34653906                                                const char *domain_name,
    34663907                                                struct cli_state *cli,
     
    35293970                cp_clistate.cli_share_dst = NULL;
    35303971                cp_clistate.cwd = NULL;
    3531                 cp_clistate.attribute = aSYSTEM | aHIDDEN | aDIR;
     3972                cp_clistate.attribute = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_DIRECTORY;
    35323973                cp_clistate.c = c;
    35333974
     
    35594000                }
    35604001
    3561                 if (!sync_files(&cp_clistate, mask)) {
     4002                nt_status = sync_files(&cp_clistate, mask);
     4003                if (!NT_STATUS_IS_OK(nt_status)) {
    35624004                        d_fprintf(stderr, _("could not handle files for share: "
    35634005                                            "%s\n"), info502.name);
    3564                         nt_status = NT_STATUS_UNSUCCESSFUL;
    35654006                        goto done;
    35664007                }
     
    36204061
    36214062static NTSTATUS rpc_share_migrate_security_internals(struct net_context *c,
    3622                                                 const DOM_SID *domain_sid,
     4063                                                const struct dom_sid *domain_sid,
    36234064                                                const char *domain_name,
    36244065                                                struct cli_state *cli,
     
    36374078        uint32 level = 502; /* includes secdesc */
    36384079        uint32_t parm_error = 0;
     4080        struct dcerpc_binding_handle *b;
    36394081
    36404082        result = get_share_info(c, pipe_hnd, mem_ctx, level, argc, argv,
     
    36504092                return nt_status;
    36514093
     4094        b = srvsvc_pipe->binding_handle;
    36524095
    36534096        for (i = 0; i < ctr_src.ctr.ctr502->count; i++) {
     
    36734116
    36744117                /* finally modify the share on the dst server */
    3675                 nt_status = rpccli_srvsvc_NetShareSetInfo(srvsvc_pipe, mem_ctx,
     4118                nt_status = dcerpc_srvsvc_NetShareSetInfo(b, mem_ctx,
    36764119                                                          srvsvc_pipe->desthost,
    36774120                                                          info502.name,
     
    36804123                                                          &parm_error,
    36814124                                                          &result);
    3682                 if (!NT_STATUS_IS_OK(nt_status) || !W_ERROR_IS_OK(result)) {
     4125                if (!NT_STATUS_IS_OK(nt_status)) {
     4126                        printf(_("cannot set share-acl: %s\n"),
     4127                               nt_errstr(nt_status));
     4128                        goto done;
     4129                }
     4130                if (!W_ERROR_IS_OK(result)) {
     4131                        nt_status = werror_to_ntstatus(result);
    36834132                        printf(_("cannot set share-acl: %s\n"),
    36844133                               win_errstr(result));
     
    38304279
    38314280struct full_alias {
    3832         DOM_SID sid;
     4281        struct dom_sid sid;
    38334282        uint32 num_members;
    3834         DOM_SID *members;
     4283        struct dom_sid *members;
    38354284};
    38364285
     
    38584307                                        TALLOC_CTX *mem_ctx,
    38594308                                        struct policy_handle *connect_pol,
    3860                                         const DOM_SID *domain_sid)
     4309                                        const struct dom_sid *domain_sid)
    38614310{
    38624311        uint32 start_idx, max_entries, num_entries, i;
    38634312        struct samr_SamArray *groups = NULL;
    3864         NTSTATUS result;
     4313        NTSTATUS result, status;
    38654314        struct policy_handle domain_pol;
     4315        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    38664316
    38674317        /* Get domain policy handle */
    38684318
    3869         result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
     4319        status = dcerpc_samr_OpenDomain(b, mem_ctx,
    38704320                                        connect_pol,
    38714321                                        MAXIMUM_ALLOWED_ACCESS,
    38724322                                        CONST_DISCARD(struct dom_sid2 *, domain_sid),
    3873                                         &domain_pol);
    3874         if (!NT_STATUS_IS_OK(result))
     4323                                        &domain_pol,
     4324                                        &result);
     4325        if (!NT_STATUS_IS_OK(status)) {
     4326                return status;
     4327        }
     4328        if (!NT_STATUS_IS_OK(result)) {
    38754329                return result;
     4330        }
    38764331
    38774332        start_idx = 0;
     
    38794334
    38804335        do {
    3881                 result = rpccli_samr_EnumDomainAliases(pipe_hnd, mem_ctx,
     4336                status = dcerpc_samr_EnumDomainAliases(b, mem_ctx,
    38824337                                                       &domain_pol,
    38834338                                                       &start_idx,
    38844339                                                       &groups,
    38854340                                                       max_entries,
    3886                                                        &num_entries);
     4341                                                       &num_entries,
     4342                                                       &result);
     4343                if (!NT_STATUS_IS_OK(status)) {
     4344                        goto done;
     4345                }
    38874346                for (i = 0; i < num_entries; i++) {
    38884347
     
    38914350                        struct lsa_SidArray sid_array;
    38924351                        int j;
    3893 
    3894                         result = rpccli_samr_OpenAlias(pipe_hnd, mem_ctx,
     4352                        NTSTATUS _result;
     4353
     4354                        status = dcerpc_samr_OpenAlias(b, mem_ctx,
    38954355                                                       &domain_pol,
    38964356                                                       MAXIMUM_ALLOWED_ACCESS,
    38974357                                                       groups->entries[i].idx,
    3898                                                        &alias_pol);
    3899                         if (!NT_STATUS_IS_OK(result))
     4358                                                       &alias_pol,
     4359                                                       &_result);
     4360                        if (!NT_STATUS_IS_OK(status)) {
    39004361                                goto done;
    3901 
    3902                         result = rpccli_samr_GetMembersInAlias(pipe_hnd, mem_ctx,
     4362                        }
     4363                        if (!NT_STATUS_IS_OK(_result)) {
     4364                                status = _result;
     4365                                goto done;
     4366                        }
     4367
     4368                        status = dcerpc_samr_GetMembersInAlias(b, mem_ctx,
    39034369                                                               &alias_pol,
    3904                                                                &sid_array);
    3905                         if (!NT_STATUS_IS_OK(result))
     4370                                                               &sid_array,
     4371                                                               &_result);
     4372                        if (!NT_STATUS_IS_OK(status)) {
    39064373                                goto done;
     4374                        }
     4375                        if (!NT_STATUS_IS_OK(_result)) {
     4376                                status = _result;
     4377                                goto done;
     4378                        }
    39074379
    39084380                        alias.num_members = sid_array.num_sids;
    39094381
    3910                         result = rpccli_samr_Close(pipe_hnd, mem_ctx, &alias_pol);
    3911                         if (!NT_STATUS_IS_OK(result))
     4382                        status = dcerpc_samr_Close(b, mem_ctx, &alias_pol, &_result);
     4383                        if (!NT_STATUS_IS_OK(status)) {
    39124384                                goto done;
     4385                        }
     4386                        if (!NT_STATUS_IS_OK(_result)) {
     4387                                status = _result;
     4388                                goto done;
     4389                        }
    39134390
    39144391                        alias.members = NULL;
    39154392
    39164393                        if (alias.num_members > 0) {
    3917                                 alias.members = SMB_MALLOC_ARRAY(DOM_SID, alias.num_members);
     4394                                alias.members = SMB_MALLOC_ARRAY(struct dom_sid, alias.num_members);
    39184395
    39194396                                for (j = 0; j < alias.num_members; j++)
     
    39224399                        }
    39234400
    3924                         sid_copy(&alias.sid, domain_sid);
    3925                         sid_append_rid(&alias.sid, groups->entries[i].idx);
     4401                        sid_compose(&alias.sid, domain_sid,
     4402                                    groups->entries[i].idx);
    39264403
    39274404                        push_alias(mem_ctx, &alias);
     
    39294406        } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
    39304407
    3931         result = NT_STATUS_OK;
     4408        status = NT_STATUS_OK;
    39324409
    39334410 done:
    3934         rpccli_samr_Close(pipe_hnd, mem_ctx, &domain_pol);
    3935 
    3936         return result;
     4411        dcerpc_samr_Close(b, mem_ctx, &domain_pol, &result);
     4412
     4413        return status;
    39374414}
    39384415
     
    39424419
    39434420static NTSTATUS rpc_aliaslist_dump(struct net_context *c,
    3944                                 const DOM_SID *domain_sid,
     4421                                const struct dom_sid *domain_sid,
    39454422                                const char *domain_name,
    39464423                                struct cli_state *cli,
     
    39534430        NTSTATUS result;
    39544431        struct policy_handle lsa_pol;
     4432        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    39554433
    39564434        result = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,
     
    39974475        }
    39984476
    3999         rpccli_lsa_Close(pipe_hnd, mem_ctx, &lsa_pol);
     4477        dcerpc_lsa_Close(b, mem_ctx, &lsa_pol, &result);
    40004478
    40014479        return NT_STATUS_OK;
     
    40084486
    40094487static NTSTATUS rpc_aliaslist_internals(struct net_context *c,
    4010                                         const DOM_SID *domain_sid,
     4488                                        const struct dom_sid *domain_sid,
    40114489                                        const char *domain_name,
    40124490                                        struct cli_state *cli,
     
    40164494                                        const char **argv)
    40174495{
    4018         NTSTATUS result;
     4496        NTSTATUS result, status;
    40194497        struct policy_handle connect_pol;
    4020 
    4021         result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
     4498        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
     4499
     4500        status = dcerpc_samr_Connect2(b, mem_ctx,
    40224501                                      pipe_hnd->desthost,
    40234502                                      MAXIMUM_ALLOWED_ACCESS,
    4024                                       &connect_pol);
    4025 
    4026         if (!NT_STATUS_IS_OK(result))
    4027                 goto done;
    4028 
    4029         result = rpc_fetch_domain_aliases(pipe_hnd, mem_ctx, &connect_pol,
     4503                                      &connect_pol,
     4504                                      &result);
     4505        if (!NT_STATUS_IS_OK(status)) {
     4506                goto done;
     4507        }
     4508        if (!NT_STATUS_IS_OK(result)) {
     4509                status = result;
     4510                goto done;
     4511        }
     4512
     4513        status = rpc_fetch_domain_aliases(pipe_hnd, mem_ctx, &connect_pol,
    40304514                                          &global_sid_Builtin);
    4031 
    4032         if (!NT_STATUS_IS_OK(result))
    4033                 goto done;
    4034 
    4035         result = rpc_fetch_domain_aliases(pipe_hnd, mem_ctx, &connect_pol,
     4515        if (!NT_STATUS_IS_OK(status)) {
     4516                goto done;
     4517        }
     4518
     4519        status = rpc_fetch_domain_aliases(pipe_hnd, mem_ctx, &connect_pol,
    40364520                                          domain_sid);
    40374521
    4038         rpccli_samr_Close(pipe_hnd, mem_ctx, &connect_pol);
     4522        dcerpc_samr_Close(b, mem_ctx, &connect_pol, &result);
    40394523 done:
    4040         return result;
    4041 }
    4042 
    4043 static void init_user_token(NT_USER_TOKEN *token, DOM_SID *user_sid)
     4524        return status;
     4525}
     4526
     4527static void init_user_token(struct security_token *token, struct dom_sid *user_sid)
    40444528{
    40454529        token->num_sids = 4;
    40464530
    4047         if (!(token->user_sids = SMB_MALLOC_ARRAY(DOM_SID, 4))) {
     4531        if (!(token->sids = SMB_MALLOC_ARRAY(struct dom_sid, 4))) {
    40484532                d_fprintf(stderr, "malloc %s\n",_("failed"));
    40494533                token->num_sids = 0;
     
    40514535        }
    40524536
    4053         token->user_sids[0] = *user_sid;
    4054         sid_copy(&token->user_sids[1], &global_sid_World);
    4055         sid_copy(&token->user_sids[2], &global_sid_Network);
    4056         sid_copy(&token->user_sids[3], &global_sid_Authenticated_Users);
    4057 }
    4058 
    4059 static void free_user_token(NT_USER_TOKEN *token)
    4060 {
    4061         SAFE_FREE(token->user_sids);
    4062 }
    4063 
    4064 static void add_sid_to_token(NT_USER_TOKEN *token, DOM_SID *sid)
    4065 {
    4066         if (is_sid_in_token(token, sid))
     4537        token->sids[0] = *user_sid;
     4538        sid_copy(&token->sids[1], &global_sid_World);
     4539        sid_copy(&token->sids[2], &global_sid_Network);
     4540        sid_copy(&token->sids[3], &global_sid_Authenticated_Users);
     4541}
     4542
     4543static void free_user_token(struct security_token *token)
     4544{
     4545        SAFE_FREE(token->sids);
     4546}
     4547
     4548static void add_sid_to_token(struct security_token *token, struct dom_sid *sid)
     4549{
     4550        if (security_token_has_sid(token, sid))
    40674551                return;
    40684552
    4069         token->user_sids = SMB_REALLOC_ARRAY(token->user_sids, DOM_SID, token->num_sids+1);
    4070         if (!token->user_sids) {
     4553        token->sids = SMB_REALLOC_ARRAY(token->sids, struct dom_sid, token->num_sids+1);
     4554        if (!token->sids) {
    40714555                return;
    40724556        }
    40734557
    4074         sid_copy(&token->user_sids[token->num_sids], sid);
     4558        sid_copy(&token->sids[token->num_sids], sid);
    40754559
    40764560        token->num_sids += 1;
     
    40794563struct user_token {
    40804564        fstring name;
    4081         NT_USER_TOKEN token;
     4565        struct security_token token;
    40824566};
    40834567
     
    40894573
    40904574        for (i=0; i<token->token.num_sids; i++) {
    4091                 d_printf(" %s\n", sid_string_tos(&token->token.user_sids[i]));
    4092         }
    4093 }
    4094 
    4095 static bool is_alias_member(DOM_SID *sid, struct full_alias *alias)
     4575                d_printf(" %s\n", sid_string_tos(&token->token.sids[i]));
     4576        }
     4577}
     4578
     4579static bool is_alias_member(struct dom_sid *sid, struct full_alias *alias)
    40964580{
    40974581        int i;
    40984582
    40994583        for (i=0; i<alias->num_members; i++) {
    4100                 if (sid_compare(sid, &alias->members[i]) == 0)
     4584                if (dom_sid_compare(sid, &alias->members[i]) == 0)
    41014585                        return true;
    41024586        }
     
    41054589}
    41064590
    4107 static void collect_sid_memberships(NT_USER_TOKEN *token, DOM_SID sid)
     4591static void collect_sid_memberships(struct security_token *token, struct dom_sid sid)
    41084592{
    41094593        int i;
     
    41224606 */
    41234607
    4124 static void collect_alias_memberships(NT_USER_TOKEN *token)
     4608static void collect_alias_memberships(struct security_token *token)
    41254609{
    41264610        int num_global_sids = token->num_sids;
     
    41284612
    41294613        for (i=0; i<num_global_sids; i++) {
    4130                 collect_sid_memberships(token, token->user_sids[i]);
    4131         }
    4132 }
    4133 
    4134 static bool get_user_sids(const char *domain, const char *user, NT_USER_TOKEN *token)
     4614                collect_sid_memberships(token, token->sids[i]);
     4615        }
     4616}
     4617
     4618static bool get_user_sids(const char *domain, const char *user, struct security_token *token)
    41354619{
    41364620        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
     
    41384622        fstring full_name;
    41394623        struct wbcDomainSid wsid;
    4140         char *sid_str = NULL;
    4141         DOM_SID user_sid;
     4624        char sid_str[WBC_SID_STRING_BUFLEN];
     4625        struct dom_sid user_sid;
    41424626        uint32_t num_groups;
    41434627        gid_t *groups = NULL;
     
    41574641        }
    41584642
    4159         wbc_status = wbcSidToString(&wsid, &sid_str);
    4160         if (!WBC_ERROR_IS_OK(wbc_status)) {
    4161                 return false;
    4162         }
    4163 
    4164         if (type != SID_NAME_USER) {
    4165                 wbcFreeMemory(sid_str);
     4643        wbcSidToStringBuf(&wsid, sid_str, sizeof(sid_str));
     4644
     4645        if (type != WBC_SID_NAME_USER) {
    41664646                DEBUG(1, ("%s is not a user\n", full_name));
    41674647                return false;
     
    41724652                return false;
    41734653        }
    4174 
    4175         wbcFreeMemory(sid_str);
    4176         sid_str = NULL;
    41774654
    41784655        init_user_token(token, &user_sid);
     
    41894666        for (i = 0; i < num_groups; i++) {
    41904667                gid_t gid = groups[i];
    4191                 DOM_SID sid;
     4668                struct dom_sid sid;
    41924669
    41934670                wbc_status = wbcGidToSid(gid, &wsid);
     
    41994676                }
    42004677
    4201                 wbc_status = wbcSidToString(&wsid, &sid_str);
    4202                 if (!WBC_ERROR_IS_OK(wbc_status)) {
    4203                         wbcFreeMemory(groups);
    4204                         return false;
    4205                 }
     4678                wbcSidToStringBuf(&wsid, sid_str, sizeof(sid_str));
    42064679
    42074680                DEBUG(3, (" %s\n", sid_str));
    42084681
    42094682                string_to_sid(&sid, sid_str);
    4210                 wbcFreeMemory(sid_str);
    4211                 sid_str = NULL;
    4212 
    42134683                add_sid_to_token(token, &sid);
    42144684        }
     
    42774747
    42784748                get_user_sids(domain, user, &(result[i].token));
    4279                 i+=1;
    42804749        }
    42814750        TALLOC_FREE(frame);
     
    43084777                        /* We have a SID */
    43094778
    4310                         DOM_SID sid;
     4779                        struct dom_sid sid;
    43114780                        if(!string_to_sid(&sid, &line[1])) {
    43124781                                DEBUG(1,("get_user_tokens_from_file: Could "
     
    43374806                fstrcpy(token->name, line);
    43384807                token->token.num_sids = 0;
    4339                 token->token.user_sids = NULL;
     4808                token->token.sids = NULL;
    43404809                continue;
    43414810        }
     
    43564825{
    43574826        uint16_t fnum;
    4358         SEC_DESC *share_sd = NULL;
    4359         SEC_DESC *root_sd = NULL;
     4827        struct security_descriptor *share_sd = NULL;
     4828        struct security_descriptor *root_sd = NULL;
    43604829        struct cli_state *cli = rpc_pipe_np_smb_conn(pipe_hnd);
    43614830        int i;
     
    43644833        NTSTATUS status;
    43654834        uint16 cnum;
    4366 
    4367         status = rpccli_srvsvc_NetShareGetInfo(pipe_hnd, mem_ctx,
     4835        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
     4836
     4837        status = dcerpc_srvsvc_NetShareGetInfo(b, mem_ctx,
    43684838                                               pipe_hnd->desthost,
    43694839                                               netname,
     
    44724942
    44734943static NTSTATUS rpc_share_allowedusers_internals(struct net_context *c,
    4474                                                 const DOM_SID *domain_sid,
     4944                                                const struct dom_sid *domain_sid,
    44754945                                                const char *domain_name,
    44764946                                                struct cli_state *cli,
     
    46685138        };
    46695139
    4670         status = libnetapi_init(&c->netapi_ctx);
     5140        status = libnetapi_net_init(&c->netapi_ctx);
    46715141        if (status != 0) {
    46725142                return -1;
     
    47615231        WERROR result;
    47625232        NTSTATUS status;
     5233        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    47635234
    47645235        if (argc != 1) {
     
    47675238        }
    47685239
    4769         status = rpccli_srvsvc_NetShareGetInfo(pipe_hnd, mem_ctx,
     5240        status = dcerpc_srvsvc_NetShareGetInfo(b, mem_ctx,
    47705241                                               pipe_hnd->desthost,
    47715242                                               argv[0],
     
    47735244                                               &info,
    47745245                                               &result);
    4775         if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
     5246        if (!NT_STATUS_IS_OK(status)) {
     5247                result = ntstatus_to_werror(status);
     5248                goto done;
     5249        }
     5250        if (!W_ERROR_IS_OK(result)) {
    47765251                goto done;
    47775252        }
     
    49445419        };
    49455420
    4946         status = libnetapi_init(&c->netapi_ctx);
     5421        status = libnetapi_net_init(&c->netapi_ctx);
    49475422        if (status != 0) {
    49485423                return -1;
     
    49875462
    49885463static NTSTATUS rpc_shutdown_abort_internals(struct net_context *c,
    4989                                         const DOM_SID *domain_sid,
     5464                                        const struct dom_sid *domain_sid,
    49905465                                        const char *domain_name,
    49915466                                        struct cli_state *cli,
     
    49955470                                        const char **argv)
    49965471{
    4997         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
    4998 
    4999         result = rpccli_initshutdown_Abort(pipe_hnd, mem_ctx, NULL, NULL);
    5000 
    5001         if (NT_STATUS_IS_OK(result)) {
     5472        NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
     5473        WERROR result;
     5474        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
     5475
     5476        status = dcerpc_initshutdown_Abort(b, mem_ctx, NULL, &result);
     5477        if (!NT_STATUS_IS_OK(status)) {
     5478                return status;
     5479        }
     5480        if (W_ERROR_IS_OK(result)) {
    50025481                d_printf(_("\nShutdown successfully aborted\n"));
    50035482                DEBUG(5,("cmd_shutdown_abort: query succeeded\n"));
     
    50055484                DEBUG(5,("cmd_shutdown_abort: query failed\n"));
    50065485
    5007         return result;
     5486        return werror_to_ntstatus(result);
    50085487}
    50095488
     
    50265505
    50275506static NTSTATUS rpc_reg_shutdown_abort_internals(struct net_context *c,
    5028                                                 const DOM_SID *domain_sid,
     5507                                                const struct dom_sid *domain_sid,
    50295508                                                const char *domain_name,
    50305509                                                struct cli_state *cli,
     
    50355514{
    50365515        NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
    5037 
    5038         result = rpccli_winreg_AbortSystemShutdown(pipe_hnd, mem_ctx, NULL, NULL);
    5039 
    5040         if (NT_STATUS_IS_OK(result)) {
     5516        WERROR werr;
     5517        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
     5518
     5519        result = dcerpc_winreg_AbortSystemShutdown(b, mem_ctx, NULL, &werr);
     5520
     5521        if (!NT_STATUS_IS_OK(result)) {
     5522                DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
     5523                return result;
     5524        }
     5525        if (W_ERROR_IS_OK(werr)) {
    50415526                d_printf(_("\nShutdown successfully aborted\n"));
    50425527                DEBUG(5,("cmd_reg_abort_shutdown: query succeeded\n"));
     
    50445529                DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
    50455530
    5046         return result;
     5531        return werror_to_ntstatus(werr);
    50475532}
    50485533
     
    51025587
    51035588NTSTATUS rpc_init_shutdown_internals(struct net_context *c,
    5104                                      const DOM_SID *domain_sid,
     5589                                     const struct dom_sid *domain_sid,
    51055590                                     const char *domain_name,
    51065591                                     struct cli_state *cli,
     
    51105595                                     const char **argv)
    51115596{
    5112         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
     5597        NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
     5598        WERROR result;
    51135599        const char *msg = N_("This machine will be shutdown shortly");
    51145600        uint32 timeout = 20;
    51155601        struct lsa_StringLarge msg_string;
     5602        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    51165603
    51175604        if (c->opt_comment) {
     
    51255612
    51265613        /* create an entry */
    5127         result = rpccli_initshutdown_Init(pipe_hnd, mem_ctx, NULL,
     5614        status = dcerpc_initshutdown_Init(b, mem_ctx, NULL,
    51285615                        &msg_string, timeout, c->opt_force, c->opt_reboot,
    5129                         NULL);
    5130 
    5131         if (NT_STATUS_IS_OK(result)) {
     5616                        &result);
     5617        if (!NT_STATUS_IS_OK(status)) {
     5618                return status;
     5619        }
     5620        if (W_ERROR_IS_OK(result)) {
    51325621                d_printf(_("\nShutdown of remote machine succeeded\n"));
    51335622                DEBUG(5,("Shutdown of remote machine succeeded\n"));
     
    51355624                DEBUG(1,("Shutdown of remote machine failed!\n"));
    51365625        }
    5137         return result;
     5626        return werror_to_ntstatus(result);
    51385627}
    51395628
     
    51565645
    51575646NTSTATUS rpc_reg_shutdown_internals(struct net_context *c,
    5158                                     const DOM_SID *domain_sid,
     5647                                    const struct dom_sid *domain_sid,
    51595648                                    const char *domain_name,
    51605649                                    struct cli_state *cli,
     
    51695658        NTSTATUS result;
    51705659        WERROR werr;
     5660        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    51715661
    51725662        if (c->opt_comment) {
     
    51805670
    51815671        /* create an entry */
    5182         result = rpccli_winreg_InitiateSystemShutdown(pipe_hnd, mem_ctx, NULL,
     5672        result = dcerpc_winreg_InitiateSystemShutdown(b, mem_ctx, NULL,
    51835673                        &msg_string, timeout, c->opt_force, c->opt_reboot,
    51845674                        &werr);
    5185 
    5186         if (NT_STATUS_IS_OK(result)) {
     5675        if (!NT_STATUS_IS_OK(result)) {
     5676                d_fprintf(stderr, "\nShutdown of remote machine failed\n");
     5677                return result;
     5678        }
     5679
     5680        if (W_ERROR_IS_OK(werr)) {
    51875681                d_printf(_("\nShutdown of remote machine succeeded\n"));
    51885682        } else {
     
    51945688        }
    51955689
    5196         return result;
     5690        return werror_to_ntstatus(werr);
    51975691}
    51985692
     
    52535747
    52545748static NTSTATUS rpc_trustdom_add_internals(struct net_context *c,
    5255                                                 const DOM_SID *domain_sid,
     5749                                                const struct dom_sid *domain_sid,
    52565750                                                const char *domain_name,
    52575751                                                struct cli_state *cli,
     
    52625756{
    52635757        struct policy_handle connect_pol, domain_pol, user_pol;
    5264         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
     5758        NTSTATUS status, result;
    52655759        char *acct_name;
    52665760        struct lsa_String lsa_acct_name;
     
    52715765        union samr_UserInfo info;
    52725766        unsigned int orig_timeout;
     5767        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    52735768
    52745769        if (argc != 2) {
     
    52935788
    52945789        /* Get samr policy handle */
    5295         result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
     5790        status = dcerpc_samr_Connect2(b, mem_ctx,
    52965791                                      pipe_hnd->desthost,
    52975792                                      MAXIMUM_ALLOWED_ACCESS,
    5298                                       &connect_pol);
     5793                                      &connect_pol,
     5794                                      &result);
     5795        if (!NT_STATUS_IS_OK(status)) {
     5796                goto done;
     5797        }
    52995798        if (!NT_STATUS_IS_OK(result)) {
     5799                status = result;
    53005800                goto done;
    53015801        }
    53025802
    53035803        /* Get domain policy handle */
    5304         result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
     5804        status = dcerpc_samr_OpenDomain(b, mem_ctx,
    53055805                                        &connect_pol,
    53065806                                        MAXIMUM_ALLOWED_ACCESS,
    53075807                                        CONST_DISCARD(struct dom_sid2 *, domain_sid),
    5308                                         &domain_pol);
     5808                                        &domain_pol,
     5809                                        &result);
     5810        if (!NT_STATUS_IS_OK(status)) {
     5811                goto done;
     5812        }
    53095813        if (!NT_STATUS_IS_OK(result)) {
     5814                status = result;
    53105815                goto done;
    53115816        }
     
    53245829                     SAMR_USER_ACCESS_SET_ATTRIBUTES;
    53255830
    5326         result = rpccli_samr_CreateUser2(pipe_hnd, mem_ctx,
     5831        status = dcerpc_samr_CreateUser2(b, mem_ctx,
    53275832                                         &domain_pol,
    53285833                                         &lsa_acct_name,
     
    53315836                                         &user_pol,
    53325837                                         &access_granted,
    5333                                          &user_rid);
    5334 
     5838                                         &user_rid,
     5839                                         &result);
     5840        if (!NT_STATUS_IS_OK(status)) {
     5841                goto done;
     5842        }
    53355843        /* And restore our original timeout. */
    53365844        rpccli_set_timeout(pipe_hnd, orig_timeout);
    53375845
    53385846        if (!NT_STATUS_IS_OK(result)) {
     5847                status = result;
    53395848                d_printf(_("net rpc trustdom add: create user %s failed %s\n"),
    53405849                        acct_name, nt_errstr(result));
     
    53565865                info.info23.password = crypt_pwd;
    53575866
    5358                 result = rpccli_samr_SetUserInfo2(pipe_hnd, mem_ctx,
     5867                status = dcerpc_samr_SetUserInfo2(b, mem_ctx,
    53595868                                                  &user_pol,
    53605869                                                  23,
    5361                                                   &info);
     5870                                                  &info,
     5871                                                  &result);
     5872                if (!NT_STATUS_IS_OK(status)) {
     5873                        goto done;
     5874                }
    53625875
    53635876                if (!NT_STATUS_IS_OK(result)) {
     5877                        status = result;
    53645878                        DEBUG(0,("Could not set trust account password: %s\n",
    53655879                                 nt_errstr(result)));
     
    53705884 done:
    53715885        SAFE_FREE(acct_name);
    5372         return result;
     5886        return status;
    53735887}
    53745888
     
    54145928
    54155929static NTSTATUS rpc_trustdom_del_internals(struct net_context *c,
    5416                                         const DOM_SID *domain_sid,
     5930                                        const struct dom_sid *domain_sid,
    54175931                                        const char *domain_name,
    54185932                                        struct cli_state *cli,
     
    54235937{
    54245938        struct policy_handle connect_pol, domain_pol, user_pol;
    5425         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
     5939        NTSTATUS status, result;
    54265940        char *acct_name;
    5427         DOM_SID trust_acct_sid;
     5941        struct dom_sid trust_acct_sid;
    54285942        struct samr_Ids user_rids, name_types;
    54295943        struct lsa_String lsa_acct_name;
     5944        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    54305945
    54315946        if (argc != 1) {
     
    54475962
    54485963        /* Get samr policy handle */
    5449         result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
     5964        status = dcerpc_samr_Connect2(b, mem_ctx,
    54505965                                      pipe_hnd->desthost,
    54515966                                      MAXIMUM_ALLOWED_ACCESS,
    5452                                       &connect_pol);
     5967                                      &connect_pol,
     5968                                      &result);
     5969        if (!NT_STATUS_IS_OK(status)) {
     5970                goto done;
     5971        }
    54535972        if (!NT_STATUS_IS_OK(result)) {
     5973                status = result;
    54545974                goto done;
    54555975        }
    54565976
    54575977        /* Get domain policy handle */
    5458         result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
     5978        status = dcerpc_samr_OpenDomain(b, mem_ctx,
    54595979                                        &connect_pol,
    54605980                                        MAXIMUM_ALLOWED_ACCESS,
    54615981                                        CONST_DISCARD(struct dom_sid2 *, domain_sid),
    5462                                         &domain_pol);
     5982                                        &domain_pol,
     5983                                        &result);
     5984        if (!NT_STATUS_IS_OK(status)) {
     5985                goto done;
     5986        }
    54635987        if (!NT_STATUS_IS_OK(result)) {
     5988                status = result;
    54645989                goto done;
    54655990        }
     
    54675992        init_lsa_String(&lsa_acct_name, acct_name);
    54685993
    5469         result = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,
     5994        status = dcerpc_samr_LookupNames(b, mem_ctx,
    54705995                                         &domain_pol,
    54715996                                         1,
    54725997                                         &lsa_acct_name,
    54735998                                         &user_rids,
    5474                                          &name_types);
    5475 
     5999                                         &name_types,
     6000                                         &result);
     6001        if (!NT_STATUS_IS_OK(status)) {
     6002                d_printf(_("net rpc trustdom del: LookupNames on user %s "
     6003                           "failed %s\n"),
     6004                        acct_name, nt_errstr(status));
     6005                goto done;
     6006        }
    54766007        if (!NT_STATUS_IS_OK(result)) {
     6008                status = result;
    54776009                d_printf(_("net rpc trustdom del: LookupNames on user %s "
    54786010                           "failed %s\n"),
     
    54816013        }
    54826014
    5483         result = rpccli_samr_OpenUser(pipe_hnd, mem_ctx,
     6015        status = dcerpc_samr_OpenUser(b, mem_ctx,
    54846016                                      &domain_pol,
    54856017                                      MAXIMUM_ALLOWED_ACCESS,
    54866018                                      user_rids.ids[0],
    5487                                       &user_pol);
     6019                                      &user_pol,
     6020                                      &result);
     6021        if (!NT_STATUS_IS_OK(status)) {
     6022                d_printf(_("net rpc trustdom del: OpenUser on user %s failed "
     6023                           "%s\n"),
     6024                        acct_name, nt_errstr(status) );
     6025                goto done;
     6026        }
    54886027
    54896028        if (!NT_STATUS_IS_OK(result)) {
     6029                status = result;
    54906030                d_printf(_("net rpc trustdom del: OpenUser on user %s failed "
    54916031                           "%s\n"),
     
    54956035
    54966036        /* append the rid to the domain sid */
    5497         sid_copy(&trust_acct_sid, domain_sid);
    5498         if (!sid_append_rid(&trust_acct_sid, user_rids.ids[0])) {
     6037        if (!sid_compose(&trust_acct_sid, domain_sid, user_rids.ids[0])) {
    54996038                goto done;
    55006039        }
     
    55026041        /* remove the sid */
    55036042
    5504         result = rpccli_samr_RemoveMemberFromForeignDomain(pipe_hnd, mem_ctx,
     6043        status = dcerpc_samr_RemoveMemberFromForeignDomain(b, mem_ctx,
    55056044                                                           &user_pol,
    5506                                                            &trust_acct_sid);
     6045                                                           &trust_acct_sid,
     6046                                                           &result);
     6047        if (!NT_STATUS_IS_OK(status)) {
     6048                d_printf(_("net rpc trustdom del: RemoveMemberFromForeignDomain"
     6049                           " on user %s failed %s\n"),
     6050                        acct_name, nt_errstr(status));
     6051                goto done;
     6052        }
    55076053        if (!NT_STATUS_IS_OK(result)) {
     6054                status = result;
    55086055                d_printf(_("net rpc trustdom del: RemoveMemberFromForeignDomain"
    55096056                           " on user %s failed %s\n"),
     
    55126059        }
    55136060
     6061
    55146062        /* Delete user */
    55156063
    5516         result = rpccli_samr_DeleteUser(pipe_hnd, mem_ctx,
    5517                                         &user_pol);
     6064        status = dcerpc_samr_DeleteUser(b, mem_ctx,
     6065                                        &user_pol,
     6066                                        &result);
     6067        if (!NT_STATUS_IS_OK(status)) {
     6068                d_printf(_("net rpc trustdom del: DeleteUser on user %s failed "
     6069                           "%s\n"),
     6070                        acct_name, nt_errstr(status));
     6071                goto done;
     6072        }
    55186073
    55196074        if (!NT_STATUS_IS_OK(result)) {
     6075                result = status;
    55206076                d_printf(_("net rpc trustdom del: DeleteUser on user %s failed "
    55216077                           "%s\n"),
     
    55316087
    55326088 done:
    5533         return result;
     6089        return status;
    55346090}
    55356091
     
    55656121        struct rpc_pipe_client *netr;
    55666122        NTSTATUS status;
     6123        WERROR result;
     6124        struct dcerpc_binding_handle *b;
    55676125
    55686126        /* Use NetServerEnum2 */
     
    55846142        }
    55856143
    5586         status = rpccli_netr_GetDcName(netr, mem_ctx,
     6144        b = netr->binding_handle;
     6145
     6146        status = dcerpc_netr_GetDcName(b, mem_ctx,
    55876147                                       cli->desthost,
    55886148                                       domain_name,
    55896149                                       &buffer,
    5590                                        NULL);
     6150                                       &result);
    55916151        TALLOC_FREE(netr);
    55926152
    5593         if (NT_STATUS_IS_OK(status)) {
     6153        if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(result)) {
    55946154                return status;
    55956155        }
     
    55986158                 for domain %s\n", domain_name));
    55996159
    5600         return status;
     6160        if (!NT_STATUS_IS_OK(status)) {
     6161                return status;
     6162        }
     6163
     6164        return werror_to_ntstatus(result);
    56016165}
    56026166
     
    56206184        struct policy_handle connect_hnd;
    56216185        TALLOC_CTX *mem_ctx;
    5622         NTSTATUS nt_status;
    5623         DOM_SID *domain_sid;
     6186        NTSTATUS nt_status, result;
     6187        struct dom_sid *domain_sid;
    56246188
    56256189        char* domain_name;
     
    56276191        fstring pdc_name;
    56286192        union lsa_PolicyInformation *info = NULL;
     6193        struct dcerpc_binding_handle *b;
    56296194
    56306195        /*
     
    57196284                return -1;
    57206285        }
     6286
     6287        b = pipe_hnd->binding_handle;
    57216288
    57226289        nt_status = rpccli_lsa_open_policy2(pipe_hnd, mem_ctx, true, KEY_QUERY_VALUE,
     
    57326299        /* Querying info level 5 */
    57336300
    5734         nt_status = rpccli_lsa_QueryInfoPolicy(pipe_hnd, mem_ctx,
     6301        nt_status = dcerpc_lsa_QueryInfoPolicy(b, mem_ctx,
    57356302                                               &connect_hnd,
    57366303                                               LSA_POLICY_INFO_ACCOUNT_DOMAIN,
    5737                                                &info);
     6304                                               &info,
     6305                                               &result);
    57386306        if (NT_STATUS_IS_ERR(nt_status)) {
    57396307                DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
     
    57436311                return -1;
    57446312        }
     6313        if (NT_STATUS_IS_ERR(result)) {
     6314                DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
     6315                        nt_errstr(result)));
     6316                cli_shutdown(cli);
     6317                talloc_destroy(mem_ctx);
     6318                return -1;
     6319        }
    57456320
    57466321        domain_sid = info->account_domain.sid;
     
    57646339         */
    57656340
    5766         nt_status = rpccli_lsa_Close(pipe_hnd, mem_ctx, &connect_hnd);
     6341        nt_status = dcerpc_lsa_Close(b, mem_ctx, &connect_hnd, &result);
    57676342        if (NT_STATUS_IS_ERR(nt_status)) {
    57686343                DEBUG(0, ("Couldn't close LSA pipe. Error was %s\n",
     
    58246399
    58256400static NTSTATUS rpc_query_domain_sid(struct net_context *c,
    5826                                         const DOM_SID *domain_sid,
     6401                                        const struct dom_sid *domain_sid,
    58276402                                        const char *domain_name,
    58286403                                        struct cli_state *cli,
     
    58406415}
    58416416
    5842 static void print_trusted_domain(DOM_SID *dom_sid, const char *trusted_dom_name)
     6417static void print_trusted_domain(struct dom_sid *dom_sid, const char *trusted_dom_name)
    58436418{
    58446419        fstring ascii_sid;
     
    58536428                                      TALLOC_CTX *mem_ctx,
    58546429                                      struct policy_handle *pol,
    5855                                       DOM_SID dom_sid,
     6430                                      struct dom_sid dom_sid,
    58566431                                      const char *trusted_dom_name)
    58576432{
    5858         NTSTATUS nt_status;
     6433        NTSTATUS nt_status, result;
    58596434        union lsa_TrustedDomainInfo *info = NULL;
    58606435        char *cleartextpwd = NULL;
     
    58626437        DATA_BLOB session_key_blob;
    58636438        DATA_BLOB data = data_blob_null;
    5864 
    5865         nt_status = rpccli_lsa_QueryTrustedDomainInfoBySid(pipe_hnd, mem_ctx,
     6439        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
     6440
     6441        nt_status = dcerpc_lsa_QueryTrustedDomainInfoBySid(b, mem_ctx,
    58666442                                                           pol,
    58676443                                                           &dom_sid,
    58686444                                                           LSA_TRUSTED_DOMAIN_INFO_PASSWORD,
    5869                                                            &info);
     6445                                                           &info,
     6446                                                           &result);
    58706447        if (NT_STATUS_IS_ERR(nt_status)) {
    58716448                DEBUG(0,("Could not query trusted domain info. Error was %s\n",
    58726449                nt_errstr(nt_status)));
     6450                goto done;
     6451        }
     6452        if (NT_STATUS_IS_ERR(result)) {
     6453                nt_status = result;
     6454                DEBUG(0,("Could not query trusted domain info. Error was %s\n",
     6455                nt_errstr(result)));
    58736456                goto done;
    58746457        }
     
    59176500        struct cli_state *cli = NULL;
    59186501        struct rpc_pipe_client *pipe_hnd = NULL;
    5919         NTSTATUS nt_status;
     6502        NTSTATUS nt_status, result;
    59206503        const char *domain_name = NULL;
    5921         DOM_SID *queried_dom_sid;
     6504        struct dom_sid *queried_dom_sid;
    59226505        struct policy_handle connect_hnd;
    59236506        union lsa_PolicyInformation *info = NULL;
     
    59286511        struct lsa_DomainList dom_list;
    59296512        fstring pdc_name;
     6513        struct dcerpc_binding_handle *b;
    59306514
    59316515        if (c->display_usage) {
     
    59776561        };
    59786562
     6563        b = pipe_hnd->binding_handle;
     6564
    59796565        nt_status = rpccli_lsa_open_policy2(pipe_hnd, mem_ctx, false, KEY_QUERY_VALUE,
    59806566                                        &connect_hnd);
     
    59886574
    59896575        /* query info level 5 to obtain sid of a domain being queried */
    5990         nt_status = rpccli_lsa_QueryInfoPolicy(pipe_hnd, mem_ctx,
     6576        nt_status = dcerpc_lsa_QueryInfoPolicy(b, mem_ctx,
    59916577                                               &connect_hnd,
    59926578                                               LSA_POLICY_INFO_ACCOUNT_DOMAIN,
    5993                                                &info);
     6579                                               &info,
     6580                                               &result);
    59946581
    59956582        if (NT_STATUS_IS_ERR(nt_status)) {
     
    60006587                return -1;
    60016588        }
     6589        if (NT_STATUS_IS_ERR(result)) {
     6590                DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
     6591                        nt_errstr(result)));
     6592                cli_shutdown(cli);
     6593                talloc_destroy(mem_ctx);
     6594                return -1;
     6595        }
    60026596
    60036597        queried_dom_sid = info->account_domain.sid;
     
    60116605
    60126606        do {
    6013                 nt_status = rpccli_lsa_EnumTrustDom(pipe_hnd, mem_ctx,
     6607                nt_status = dcerpc_lsa_EnumTrustDom(b, mem_ctx,
    60146608                                                    &connect_hnd,
    60156609                                                    &enum_ctx,
    60166610                                                    &dom_list,
    6017                                                     (uint32_t)-1);
     6611                                                    (uint32_t)-1,
     6612                                                    &result);
    60186613                if (NT_STATUS_IS_ERR(nt_status)) {
    60196614                        DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
     
    60236618                        return -1;
    60246619                };
     6620                if (NT_STATUS_IS_ERR(result)) {
     6621                        nt_status = result;
     6622                        DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
     6623                                nt_errstr(result)));
     6624                        cli_shutdown(cli);
     6625                        talloc_destroy(mem_ctx);
     6626                        return -1;
     6627                };
     6628
    60256629
    60266630                for (i = 0; i < dom_list.count; i++) {
     
    60486652
    60496653        /* close this connection before doing next one */
    6050         nt_status = rpccli_lsa_Close(pipe_hnd, mem_ctx, &connect_hnd);
     6654        nt_status = dcerpc_lsa_Close(b, mem_ctx, &connect_hnd, &result);
    60516655        if (NT_STATUS_IS_ERR(nt_status)) {
    60526656                DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
     
    60706674        struct cli_state *cli = NULL, *remote_cli = NULL;
    60716675        struct rpc_pipe_client *pipe_hnd = NULL;
    6072         NTSTATUS nt_status;
     6676        NTSTATUS nt_status, result;
    60736677        const char *domain_name = NULL;
    6074         DOM_SID *queried_dom_sid;
     6678        struct dom_sid *queried_dom_sid;
    60756679        int ascii_dom_name_len;
    60766680        struct policy_handle connect_hnd;
    60776681        union lsa_PolicyInformation *info = NULL;
     6682        struct dcerpc_binding_handle *b = NULL;
    60786683
    60796684        /* trusted domains listing variables */
     
    61356740                return -1;
    61366741        };
     6742
     6743        b = pipe_hnd->binding_handle;
    61376744
    61386745        nt_status = rpccli_lsa_open_policy2(pipe_hnd, mem_ctx, false, KEY_QUERY_VALUE,
     
    61476754       
    61486755        /* query info level 5 to obtain sid of a domain being queried */
    6149         nt_status = rpccli_lsa_QueryInfoPolicy(pipe_hnd, mem_ctx,
     6756        nt_status = dcerpc_lsa_QueryInfoPolicy(b, mem_ctx,
    61506757                                               &connect_hnd,
    61516758                                               LSA_POLICY_INFO_ACCOUNT_DOMAIN,
    6152                                                &info);
     6759                                               &info,
     6760                                               &result);
    61536761
    61546762        if (NT_STATUS_IS_ERR(nt_status)) {
     
    61596767                return -1;
    61606768        }
     6769        if (NT_STATUS_IS_ERR(result)) {
     6770                DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
     6771                        nt_errstr(result)));
     6772                cli_shutdown(cli);
     6773                talloc_destroy(mem_ctx);
     6774                return -1;
     6775        }
    61616776
    61626777        queried_dom_sid = info->account_domain.sid;
     
    61726787
    61736788        do {
    6174                 nt_status = rpccli_lsa_EnumTrustDom(pipe_hnd, mem_ctx,
     6789                nt_status = dcerpc_lsa_EnumTrustDom(b, mem_ctx,
    61756790                                                    &connect_hnd,
    61766791                                                    &enum_ctx,
    61776792                                                    &dom_list,
    6178                                                     (uint32_t)-1);
     6793                                                    (uint32_t)-1,
     6794                                                    &result);
    61796795                if (NT_STATUS_IS_ERR(nt_status)) {
    61806796                        DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
     
    61846800                        return -1;
    61856801                };
     6802                if (NT_STATUS_IS_ERR(result)) {
     6803                        DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
     6804                                nt_errstr(result)));
     6805                        cli_shutdown(cli);
     6806                        talloc_destroy(mem_ctx);
     6807                        return -1;
     6808                };
     6809
    61866810
    61876811                for (i = 0; i < dom_list.count; i++) {
     
    62036827
    62046828        /* close this connection before doing next one */
    6205         nt_status = rpccli_lsa_Close(pipe_hnd, mem_ctx, &connect_hnd);
     6829        nt_status = dcerpc_lsa_Close(b, mem_ctx, &connect_hnd, &result);
    62066830        if (NT_STATUS_IS_ERR(nt_status)) {
    62076831                DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
     
    62326856        };
    62336857
     6858        b = pipe_hnd->binding_handle;
     6859
    62346860        /* SamrConnect2 */
    6235         nt_status = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
     6861        nt_status = dcerpc_samr_Connect2(b, mem_ctx,
    62366862                                         pipe_hnd->desthost,
    62376863                                         SAMR_ACCESS_LOOKUP_DOMAIN,
    6238                                          &connect_hnd);
     6864                                         &connect_hnd,
     6865                                         &result);
    62396866        if (!NT_STATUS_IS_OK(nt_status)) {
    62406867                DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
     
    62446871                return -1;
    62456872        };
     6873        if (!NT_STATUS_IS_OK(result)) {
     6874                nt_status = result;
     6875                DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
     6876                        nt_errstr(result)));
     6877                cli_shutdown(cli);
     6878                talloc_destroy(mem_ctx);
     6879                return -1;
     6880        };
    62466881
    62476882        /* SamrOpenDomain - we have to open domain policy handle in order to be
    62486883           able to enumerate accounts*/
    6249         nt_status = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
     6884        nt_status = dcerpc_samr_OpenDomain(b, mem_ctx,
    62506885                                           &connect_hnd,
    62516886                                           SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
    62526887                                           queried_dom_sid,
    6253                                            &domain_hnd);
     6888                                           &domain_hnd,
     6889                                           &result);
    62546890        if (!NT_STATUS_IS_OK(nt_status)) {
    62556891                DEBUG(0, ("Couldn't open domain object. Error was %s\n",
     
    62596895                return -1;
    62606896        };
     6897        if (!NT_STATUS_IS_OK(result)) {
     6898                nt_status = result;
     6899                DEBUG(0, ("Couldn't open domain object. Error was %s\n",
     6900                        nt_errstr(result)));
     6901                cli_shutdown(cli);
     6902                talloc_destroy(mem_ctx);
     6903                return -1;
     6904        };
    62616905
    62626906        /*
     
    62696913        do {
    62706914
    6271                 nt_status = rpccli_samr_EnumDomainUsers(pipe_hnd, mem_ctx,
     6915                nt_status = dcerpc_samr_EnumDomainUsers(b, mem_ctx,
    62726916                                                        &domain_hnd,
    62736917                                                        &enum_ctx,
     
    62756919                                                        &trusts,
    62766920                                                        0xffff,
    6277                                                         &num_domains);
     6921                                                        &num_domains,
     6922                                                        &result);
    62786923                if (NT_STATUS_IS_ERR(nt_status)) {
    62796924                        DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n",
    62806925                                nt_errstr(nt_status)));
     6926                        cli_shutdown(cli);
     6927                        talloc_destroy(mem_ctx);
     6928                        return -1;
     6929                };
     6930                if (NT_STATUS_IS_ERR(result)) {
     6931                        nt_status = result;
     6932                        DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n",
     6933                                nt_errstr(result)));
    62816934                        cli_shutdown(cli);
    62826935                        talloc_destroy(mem_ctx);
     
    63316984                }
    63326985
    6333         } while (NT_STATUS_EQUAL(nt_status, STATUS_MORE_ENTRIES));
     6986        } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
    63346987
    63356988        if (!found_domain) {
     
    63386991
    63396992        /* close opened samr and domain policy handles */
    6340         nt_status = rpccli_samr_Close(pipe_hnd, mem_ctx, &domain_hnd);
     6993        nt_status = dcerpc_samr_Close(b, mem_ctx, &domain_hnd, &result);
    63416994        if (!NT_STATUS_IS_OK(nt_status)) {
    63426995                DEBUG(0, ("Couldn't properly close domain policy handle for domain %s\n", domain_name));
    63436996        };
    63446997
    6345         nt_status = rpccli_samr_Close(pipe_hnd, mem_ctx, &connect_hnd);
     6998        nt_status = dcerpc_samr_Close(b, mem_ctx, &connect_hnd, &result);
    63466999        if (!NT_STATUS_IS_OK(nt_status)) {
    63477000                DEBUG(0, ("Couldn't properly close samr policy handle for domain %s\n", domain_name));
     
    65217174                }
    65227175
    6523                 return run_rpc_command(c, NULL, &ndr_table_netlogon.syntax_id,
    6524                                        NET_FLAGS_ANONYMOUS,
    6525                                        rpc_vampire_internals,
    6526                                        argc, argv);
     7176                return rpc_vampire_passdb(c, argc, argv);
    65277177        }
    65287178
     
    73497999                           "    Open interactive shell on remote server")
    73508000                },
     8001                {
     8002                        "trust",
     8003                        net_rpc_trust,
     8004                        NET_TRANSPORT_RPC,
     8005                        N_("Manage trusts"),
     8006                        N_("net rpc trust\n"
     8007                           "    Manage trusts")
     8008                },
    73518009                {NULL, NULL, 0, NULL, NULL}
    73528010        };
    73538011
    7354         status = libnetapi_init(&c->netapi_ctx);
     8012        status = libnetapi_net_init(&c->netapi_ctx);
    73558013        if (status != 0) {
    73568014                return -1;
Note: See TracChangeset for help on using the changeset viewer.