Ignore:
Timestamp:
Nov 14, 2012, 12:59:34 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to 3.6.0

Location:
vendor/current/source3/utils
Files:
8 added
1 deleted
55 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/utils/dbwrap_tool.c

    r414 r740  
    2121
    2222#include "includes.h"
    23 
    24 extern bool AllowDebugChange;
     23#include "system/filesys.h"
     24#include "dbwrap.h"
     25#include "messages.h"
    2526
    2627typedef enum { OP_FETCH, OP_STORE, OP_DELETE, OP_ERASE, OP_LISTKEYS } dbwrap_op;
     
    214215
    215216        load_case_tables();
    216         DEBUGLEVEL_CLASS[DBGC_ALL] = 0;
    217         dbf = x_stderr;
    218         AllowDebugChange = false;
     217        lp_set_cmdline("log level", "0");
     218        setup_logging(argv[0], DEBUG_STDERR);
    219219        lp_load(get_dyn_CONFIGFILE(), true, false, false, true);
    220220
     
    299299        }
    300300
    301         msg_ctx = messaging_init(mem_ctx, server_id_self(), evt_ctx);
     301        msg_ctx = messaging_init(mem_ctx, procid_self(), evt_ctx);
    302302        if (msg_ctx == NULL) {
    303303                d_fprintf(stderr, "ERROR: could not init messaging context\n");
  • vendor/current/source3/utils/eventlogadm.c

    r414 r740  
    2424
    2525#include "includes.h"
    26 
    27 #undef  DBGC_CLASS
    28 #define DBGC_CLASS DBGC_UTIL_EVENTLOG
    29 
     26#include "lib/eventlog/eventlog.h"
     27#include "registry.h"
     28#include "registry/reg_backend_db.h"
     29#include "registry/reg_objects.h"
     30#include "../libcli/registry/util_reg.h"
    3031
    3132extern int optind;
     
    4142        printf( " -o dump <Eventlog Name> <starting_record>\t\t\t\t\tDump stored eventlog entries on STDOUT\n" );
    4243        printf( "\nMiscellaneous options:\n" );
     44        printf( " -s <filename>\t\t\t\t\t\t\tUse configuration file <filename>.\n");
    4345        printf( " -d\t\t\t\t\t\t\t\tturn debug on\n" );
    4446        printf( " -h\t\t\t\t\t\t\t\tdisplay help\n\n" );
     
    5153
    5254        elogs = lp_eventlog_list(  );
    53         printf( "Active eventlog names (from smb.conf):\n" );
     55        printf( "Active eventlog names:\n" );
    5456        printf( "--------------------------------------\n" );
    5557        if ( elogs ) {
     
    6062        else
    6163                printf( "\t<None specified>\n");
     64}
     65
     66/*********************************************************************
     67 for an eventlog, add in a source name. If the eventlog doesn't
     68 exist (not in the list) do nothing.   If a source for the log
     69 already exists, change the information (remove, replace)
     70*********************************************************************/
     71static bool eventlog_add_source( const char *eventlog, const char *sourcename,
     72                                 const char *messagefile )
     73{
     74        /* Find all of the eventlogs, add keys for each of them */
     75        /* need to add to the value KEY_EVENTLOG/<eventlog>/Sources string (Creating if necessary)
     76           need to add KEY of source to KEY_EVENTLOG/<eventlog>/<source> */
     77
     78        const char **elogs = lp_eventlog_list(  );
     79        const char **wrklist, **wp;
     80        char *evtlogpath = NULL;
     81        struct regsubkey_ctr *subkeys;
     82        struct regval_ctr *values;
     83        struct regval_blob *rval;
     84        int ii = 0;
     85        bool already_in;
     86        int i;
     87        int numsources = 0;
     88        TALLOC_CTX *ctx = talloc_tos();
     89        WERROR werr;
     90        DATA_BLOB blob;
     91
     92        if (!elogs) {
     93                return False;
     94        }
     95
     96        for ( i = 0; elogs[i]; i++ ) {
     97                if ( strequal( elogs[i], eventlog ) )
     98                        break;
     99        }
     100
     101        if ( !elogs[i] ) {
     102                d_printf("Eventlog [%s] not found in list of valid event logs\n",
     103                         eventlog);
     104                return false;   /* invalid named passed in */
     105        }
     106
     107        /* have to assume that the evenlog key itself exists at this point */
     108        /* add in a key of [sourcename] under the eventlog key */
     109
     110        /* todo add to Sources */
     111
     112        werr = regval_ctr_init(ctx, &values);
     113        if(!W_ERROR_IS_OK(werr)) {
     114                d_printf("talloc() failure!\n");
     115                return false;
     116        }
     117
     118        evtlogpath = talloc_asprintf(ctx, "%s\\%s", KEY_EVENTLOG, eventlog);
     119        if (!evtlogpath) {
     120                TALLOC_FREE(values);
     121                return false;
     122        }
     123
     124        regdb_fetch_values( evtlogpath, values );
     125
     126
     127        if ( !( rval = regval_ctr_getvalue( values, "Sources" ) ) ) {
     128                d_printf("No Sources value for [%s]!\n", eventlog);
     129                return False;
     130        }
     131        /* perhaps this adding a new string to a multi_sz should be a fn? */
     132        /* check to see if it's there already */
     133
     134        if ( regval_type(rval) != REG_MULTI_SZ ) {
     135                d_printf("Wrong type for Sources, should be REG_MULTI_SZ\n");
     136                return False;
     137        }
     138        /* convert to a 'regulah' chars to do some comparisons */
     139
     140        already_in = False;
     141        wrklist = NULL;
     142        dump_data(1, regval_data_p(rval), regval_size(rval));
     143
     144        blob = data_blob_const(regval_data_p(rval), regval_size(rval));
     145        if (!pull_reg_multi_sz(talloc_tos(), &blob, &wrklist)) {
     146                return false;
     147        }
     148
     149        for (ii=0; wrklist[ii]; ii++) {
     150                numsources++;
     151        }
     152
     153        if (numsources > 0) {
     154                /* see if it's in there already */
     155                wp = wrklist;
     156
     157                while (wp && *wp ) {
     158                        if ( strequal( *wp, sourcename ) ) {
     159                                d_printf("Source name [%s] already in list for [%s] \n",
     160                                         sourcename, eventlog);
     161                                already_in = True;
     162                                break;
     163                        }
     164                        wp++;
     165                }
     166        } else {
     167                d_printf("Nothing in the sources list, this might be a problem\n");
     168        }
     169
     170        wp = wrklist;
     171
     172        if ( !already_in ) {
     173                /* make a new list with an additional entry; copy values, add another */
     174                wp = TALLOC_ARRAY(ctx, const char *, numsources + 2 );
     175
     176                if ( !wp ) {
     177                        d_printf("talloc() failed \n");
     178                        return False;
     179                }
     180                memcpy( wp, wrklist, sizeof( char * ) * numsources );
     181                *( wp + numsources ) = ( char * ) sourcename;
     182                *( wp + numsources + 1 ) = NULL;
     183                if (!push_reg_multi_sz(ctx, &blob, wp)) {
     184                        return false;
     185                }
     186                dump_data( 1, blob.data, blob.length);
     187                regval_ctr_addvalue( values, "Sources", REG_MULTI_SZ,
     188                                     blob.data, blob.length);
     189                regdb_store_values( evtlogpath, values );
     190                data_blob_free(&blob);
     191        } else {
     192                d_printf("Source name [%s] found in existing list of sources\n",
     193                         sourcename);
     194        }
     195        TALLOC_FREE(values);
     196        TALLOC_FREE(wrklist);   /*  */
     197
     198        werr = regsubkey_ctr_init(ctx, &subkeys);
     199        if (!W_ERROR_IS_OK(werr)) {
     200                d_printf("talloc() failure!\n");
     201                return False;
     202        }
     203        TALLOC_FREE(evtlogpath);
     204        evtlogpath = talloc_asprintf(ctx, "%s\\%s", KEY_EVENTLOG, eventlog );
     205        if (!evtlogpath) {
     206                TALLOC_FREE(subkeys);
     207                return false;
     208        }
     209
     210        regdb_fetch_keys( evtlogpath, subkeys );
     211
     212        if ( !regsubkey_ctr_key_exists( subkeys, sourcename ) ) {
     213                d_printf(" Source name [%s] for eventlog [%s] didn't exist, adding \n",
     214                         sourcename, eventlog);
     215                regsubkey_ctr_addkey( subkeys, sourcename );
     216                if ( !regdb_store_keys( evtlogpath, subkeys ) )
     217                        return False;
     218        }
     219        TALLOC_FREE(subkeys);
     220
     221        /* at this point KEY_EVENTLOG/<eventlog>/<sourcename> key is in there. Now need to add EventMessageFile */
     222
     223        /* now allocate room for the source's subkeys */
     224
     225        werr = regsubkey_ctr_init(ctx, &subkeys);
     226        if (!W_ERROR_IS_OK(werr)) {
     227                d_printf("talloc() failure!\n");
     228                return False;
     229        }
     230        TALLOC_FREE(evtlogpath);
     231        evtlogpath = talloc_asprintf(ctx, "%s\\%s\\%s",
     232                  KEY_EVENTLOG, eventlog, sourcename);
     233        if (!evtlogpath) {
     234                TALLOC_FREE(subkeys);
     235                return false;
     236        }
     237
     238        regdb_fetch_keys( evtlogpath, subkeys );
     239
     240        /* now add the values to the KEY_EVENTLOG/Application form key */
     241        werr = regval_ctr_init(ctx, &values);
     242        if (!W_ERROR_IS_OK(werr)) {
     243                d_printf("talloc() failure!\n");
     244                return False;
     245        }
     246        d_printf("Storing EventMessageFile [%s] to eventlog path of [%s]\n",
     247                 messagefile, evtlogpath);
     248
     249        regdb_fetch_values( evtlogpath, values );
     250
     251        regval_ctr_addvalue_sz(values, "EventMessageFile", messagefile);
     252        regdb_store_values( evtlogpath, values );
     253
     254        TALLOC_FREE(values);
     255
     256        return True;
    62257}
    63258
     
    221416        int opt, rc;
    222417        char *exename;
     418        char *configfile = NULL;
    223419        TALLOC_CTX *frame = talloc_stackframe();
    224420
     
    229425
    230426        opt_debug = 0;          /* todo set this from getopts */
    231 
    232         lp_load(get_dyn_CONFIGFILE(), True, False, False, True);
    233427
    234428        exename = argv[0];
     
    241435        eventlog_add_source( "System", "TestSourceX", "SomeTestPathX" );
    242436#endif
    243         while ( ( opt = getopt( argc, argv, "dho:" ) ) != EOF ) {
     437        while ( ( opt = getopt( argc, argv, "dho:s:" ) ) != EOF ) {
    244438                switch ( opt ) {
    245439
     
    257451                        opt_debug = 1;
    258452                        break;
     453                case 's':
     454                        configfile = talloc_strdup(frame, optarg);
     455                        break;
     456
    259457                }
    260458        }
     
    266464                printf( "\nNot enough arguments!\n" );
    267465                usage( exename );
     466                exit( 1 );
     467        }
     468
     469        if ( configfile == NULL ) {
     470                lp_load(get_dyn_CONFIGFILE(), True, False, False, True);
     471        } else if (!lp_load(configfile, True, False, False, True)) {
     472                printf("Unable to parse configfile '%s'\n",configfile);
    268473                exit( 1 );
    269474        }
  • vendor/current/source3/utils/log2pcaphex.c

    r414 r740  
    5252
    5353#include "includes.h"
     54#include "popt_common.h"
    5455
    5556/* We don't care about the paranoid malloc checker in this standalone
  • vendor/current/source3/utils/net.c

    r427 r740  
    4242
    4343#include "includes.h"
     44#include "popt_common.h"
    4445#include "utils/net.h"
    45 
    46 extern bool AllowDebugChange;
     46#include "secrets.h"
     47#include "lib/netapi/netapi.h"
     48#include "../libcli/security/security.h"
     49#include "passdb.h"
     50#include "messages.h"
    4751
    4852#ifdef WITH_FAKE_KASERVER
     
    232236static int net_getlocalsid(struct net_context *c, int argc, const char **argv)
    233237{
    234         DOM_SID sid;
     238        struct dom_sid sid;
    235239        const char *name;
    236240        fstring sid_str;
     
    272276static int net_setlocalsid(struct net_context *c, int argc, const char **argv)
    273277{
    274         DOM_SID sid;
     278        struct dom_sid sid;
    275279
    276280        if ( (argc != 1)
     
    293297static int net_setdomainsid(struct net_context *c, int argc, const char **argv)
    294298{
    295         DOM_SID sid;
     299        struct dom_sid sid;
    296300
    297301        if ( (argc != 1)
     
    314318static int net_getdomainsid(struct net_context *c, int argc, const char **argv)
    315319{
    316         DOM_SID domain_sid;
     320        struct dom_sid domain_sid;
    317321        fstring sid_str;
    318322
     
    668672                net_maxrid,
    669673                NET_TRANSPORT_LOCAL,
    670                 N_("Display the maximul RID currently used"),
     674                N_("Display the maximum RID currently used"),
    671675                N_("  net maxrid")
    672676        },
     
    719723                N_("  Use 'net help eventlog' to get more information about "
    720724                   "'net eventlog' commands.")
     725        },
     726        {       "printing",
     727                net_printing,
     728                NET_TRANSPORT_LOCAL,
     729                N_("Process tdb printer files"),
     730                N_("  Use 'net help printing' to get more information about "
     731                   "'net printing' commands.")
     732        },
     733
     734        {       "serverid",
     735                net_serverid,
     736                NET_TRANSPORT_LOCAL,
     737                N_("Manage the serverid tdb"),
     738                N_("  Use 'net help serverid' to get more information about "
     739                   "'net serverid' commands.")
    721740        },
    722741
     
    797816                {"single-obj-repl", 0, POPT_ARG_NONE, &c->opt_single_obj_repl},
    798817                {"clean-old-entries", 0, POPT_ARG_NONE, &c->opt_clean_old_entries},
    799 
     818                /* Options for 'net idmap'*/
     819                {"db", 0, POPT_ARG_STRING, &c->opt_db},
     820                {"lock", 0, POPT_ARG_NONE,   &c->opt_lock},
     821                {"auto", 'a', POPT_ARG_NONE,   &c->opt_auto},
     822                {"repair", 0, POPT_ARG_NONE,   &c->opt_repair},
    800823                POPT_COMMON_SAMBA
    801824                { 0, 0, 0, 0}
     
    804827        zero_sockaddr(&c->opt_dest_ip);
    805828
     829        setup_logging(argv[0], DEBUG_STDERR);
     830
    806831        load_case_tables();
    807832
    808833        setlocale(LC_ALL, "");
    809834#if defined(HAVE_BINDTEXTDOMAIN)
    810         bindtextdomain(MODULE_NAME, dyn_LOCALEDIR);
     835        bindtextdomain(MODULE_NAME, get_dyn_LOCALEDIR());
    811836#endif
    812837#if defined(HAVE_TEXTDOMAIN)
     
    815840
    816841        /* set default debug level to 0 regardless of what smb.conf sets */
    817         DEBUGLEVEL_CLASS[DBGC_ALL] = 0;
    818         dbf = x_stderr;
     842        lp_set_cmdline("log level", "0");
    819843        c->private_data = net_func;
    820844
     
    855879        }
    856880
    857         /*
    858          * Don't load debug level from smb.conf. It should be
    859          * set by cmdline arg or remain default (0)
    860          */
    861         AllowDebugChange = false;
    862881        lp_load(get_dyn_CONFIGFILE(), true, false, false, true);
    863882
     
    898917
    899918        /* this makes sure that when we do things like call scripts,
    900            that it won't assert becouse we are not root */
     919           that it won't assert because we are not root */
    901920        sec_init();
    902921
     
    912931        }
    913932
     933        /* Failing to init the msg_ctx isn't a fatal error. Only
     934           root-level things (joining/leaving domains etc.) will be denied. */
     935
     936        c->msg_ctx = messaging_init(c, procid_self(),
     937                                    event_context_init(c));
     938
    914939        rc = net_run_function(c, argc_new-1, argv_new+1, "net", net_func);
    915940
  • vendor/current/source3/utils/net.h

    r414 r740  
    2323 */
    2424
    25 #include "lib/netapi/netapi.h"
    26 #include "libnet/libnet.h"
    27 #include "localedir.h"
     25struct cli_state;
    2826
     27#include "../librpc/gen_ndr/lsa.h"
     28
     29#include "intl.h"
    2930#ifdef HAVE_LIBINTL_H
    3031#include <libintl.h>
     
    7677        int opt_single_obj_repl;
    7778        int opt_clean_old_entries;
     79        const char *opt_db;
     80        int opt_lock;
     81        int opt_auto;
     82        int opt_repair;
    7883
    7984        int opt_have_ip;
     
    8186        bool smb_encrypt;
    8287        struct libnetapi_ctx *netapi_ctx;
     88        struct messaging_context *msg_ctx;
    8389
    8490        bool display_usage;
     
    110116
    111117typedef NTSTATUS (*rpc_command_fn)(struct net_context *c,
    112                                 const DOM_SID *,
     118                                const struct dom_sid *,
    113119                                const char *,
    114120                                struct cli_state *cli,
     
    130136        struct cli_state *cli;
    131137
    132         DOM_SID *domain_sid;
     138        struct dom_sid *domain_sid;
    133139        const char *domain_name;
    134140
  • vendor/current/source3/utils/net_ads.c

    r594 r740  
    2323#include "includes.h"
    2424#include "utils/net.h"
     25#include "rpc_client/cli_pipe.h"
    2526#include "librpc/gen_ndr/ndr_krb5pac.h"
    26 #include "../librpc/gen_ndr/cli_spoolss.h"
     27#include "../librpc/gen_ndr/ndr_spoolss.h"
    2728#include "nsswitch/libwbclient/wbclient.h"
     29#include "ads.h"
     30#include "libads/cldap.h"
     31#include "libads/dns.h"
     32#include "../libds/common/flags.h"
     33#include "librpc/gen_ndr/libnet_join.h"
     34#include "libnet/libnet_join.h"
     35#include "smb_krb5.h"
     36#include "secrets.h"
     37#include "krb5_env.h"
     38#include "../libcli/security/security.h"
     39#include "libsmb/libsmb.h"
    2840
    2941#ifdef HAVE_ADS
     
    104116        printf(_("Domain Controller:\t%s\n"), reply.pdc_dns_name);
    105117
    106         printf(_("Pre-Win2k Domain:\t%s\n"), reply.domain);
     118        printf(_("Pre-Win2k Domain:\t%s\n"), reply.domain_name);
    107119        printf(_("Pre-Win2k Hostname:\t%s\n"), reply.pdc_name);
    108120
     
    402414        }
    403415
    404         d_printf(_("Workgroup: %s\n"), reply.domain);
     416        d_printf(_("Workgroup: %s\n"), reply.domain_name);
    405417
    406418        ads_destroy(&ads);
     
    476488                ou_str = SMB_STRDUP(c->opt_container);
    477489        } else {
    478                 ou_str = ads_default_ou_string(ads, WELL_KNOWN_GUID_USERS);
     490                ou_str = ads_default_ou_string(ads, DS_GUID_USERS_CONTAINER);
    479491        }
    480492
     
    540552        char *primary_group;
    541553        char *escaped_user;
    542         DOM_SID primary_group_sid;
     554        struct dom_sid primary_group_sid;
    543555        uint32_t group_rid;
    544556        enum wbcSidType type;
     
    770782                ou_str = SMB_STRDUP(c->opt_container);
    771783        } else {
    772                 ou_str = ads_default_ou_string(ads, WELL_KNOWN_GUID_USERS);
     784                ou_str = ads_default_ou_string(ads, DS_GUID_USERS_CONTAINER);
    773785        }
    774786
     
    959971        }
    960972
     973        if (!c->msg_ctx) {
     974                d_fprintf(stderr, _("Could not initialise message context. "
     975                        "Try running as root\n"));
     976                return -1;
     977        }
     978
    961979        werr = libnet_init_UnjoinCtx(ctx, &r);
    962980        if (!W_ERROR_IS_OK(werr)) {
     
    978996                                  WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE;
    979997        r->in.delete_machine_account = true;
     998        r->in.msg_ctx           = c->msg_ctx;
    980999
    9811000        werr = libnet_Unjoin(ctx, r);
     
    11041123
    11051124#if defined(WITH_DNS_UPDATES)
    1106 #include "dns.h"
     1125#include "../lib/addns/dns.h"
    11071126DNS_ERROR DoDNSUpdate(char *pszServerName,
    11081127                      const char *pszDomainName, const char *pszHostName,
     
    11161135{
    11171136        struct dns_rr_ns *nameservers = NULL;
    1118         int ns_count = 0;
     1137        int ns_count = 0, i;
    11191138        NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
    11201139        DNS_ERROR dns_err;
     
    11811200        }
    11821201
    1183         /* Now perform the dns update - we'll try non-secure and if we fail,
    1184            we'll follow it up with a secure update */
    1185 
    1186         fstrcpy( dns_server, nameservers[0].hostname );
    1187 
    1188         dns_err = DoDNSUpdate(dns_server, dnsdomain, machine_name, addrs, num_addrs);
    1189         if (!ERR_DNS_IS_OK(dns_err)) {
     1202        for (i=0; i < ns_count; i++) {
     1203
     1204                /* Now perform the dns update - we'll try non-secure and if we fail,
     1205                   we'll follow it up with a secure update */
     1206
     1207                fstrcpy( dns_server, nameservers[i].hostname );
     1208
     1209                dns_err = DoDNSUpdate(dns_server, dnsdomain, machine_name, addrs, num_addrs);
     1210                if (ERR_DNS_IS_OK(dns_err)) {
     1211                        status = NT_STATUS_OK;
     1212                        goto done;
     1213                }
     1214
     1215                if (ERR_DNS_EQUAL(dns_err, ERROR_DNS_INVALID_NAME_SERVER) ||
     1216                    ERR_DNS_EQUAL(dns_err, ERROR_DNS_CONNECTION_FAILED) ||
     1217                    ERR_DNS_EQUAL(dns_err, ERROR_DNS_SOCKET_ERROR)) {
     1218                        DEBUG(1,("retrying DNS update with next nameserver after receiving %s\n",
     1219                                dns_errstr(dns_err)));
     1220                        continue;
     1221                }
     1222
     1223                d_printf(_("DNS Update for %s failed: %s\n"),
     1224                        machine_name, dns_errstr(dns_err));
    11901225                status = NT_STATUS_UNSUCCESSFUL;
     1226                goto done;
    11911227        }
    11921228
     
    13481384                d_fprintf(stderr, _("Please supply a valid domain name\n"));
    13491385                werr = WERR_INVALID_PARAM;
     1386                goto fail;
     1387        }
     1388
     1389        if (!c->msg_ctx) {
     1390                d_fprintf(stderr, _("Could not initialise message context. "
     1391                        "Try running as root\n"));
     1392                werr = WERR_ACCESS_DENIED;
    13501393                goto fail;
    13511394        }
     
    13681411                                  WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE |
    13691412                                  WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED;
     1413        r->in.msg_ctx           = c->msg_ctx;
    13701414
    13711415        werr = libnet_Join(ctx, r);
     1416        if (W_ERROR_EQUAL(werr, WERR_DCNOTFOUND) &&
     1417            strequal(domain, lp_realm())) {
     1418                r->in.domain_name = lp_workgroup();
     1419                werr = libnet_Join(ctx, r);
     1420        }
    13721421        if (!W_ERROR_IS_OK(werr)) {
    13731422                goto fail;
     
    14381487                ads_destroy(&ads_dns);
    14391488        }
     1489
     1490done:
    14401491#endif
    14411492
    1442 done:
    14431493        TALLOC_FREE(r);
    14441494        TALLOC_FREE( ctx );
     
    15831633        err = do_gethostbyname(argv[0], argv[1]);
    15841634
    1585         d_printf(_("do_gethostbyname returned %d\n"), ERROR_DNS_V(err));
     1635        d_printf(_("do_gethostbyname returned %s (%d)\n"),
     1636                dns_errstr(err), ERROR_DNS_V(err));
    15861637#endif
    15871638        return 0;
     
    17831834                                        c->opt_password ? c->opt_password : "",
    17841835                                        CLI_FULL_CONNECTION_USE_KERBEROS,
    1785                                         Undefined, NULL);
     1836                                        Undefined);
    17861837
    17871838        if (NT_STATUS_IS_ERR(nt_status)) {
    1788                 d_fprintf(stderr, _("Unable to open a connnection to %s to "
     1839                d_fprintf(stderr, _("Unable to open a connection to %s to "
    17891840                                    "obtain data for %s\n"),
    17901841                          servername, printername);
     
    18351886        nt_status = cli_rpc_pipe_open_noauth(cli, &ndr_table_spoolss.syntax_id, &pipe_hnd);
    18361887        if (!NT_STATUS_IS_OK(nt_status)) {
    1837                 d_fprintf(stderr, _("Unable to open a connnection to the spoolss pipe on %s\n"),
     1888                d_fprintf(stderr, _("Unable to open a connection to the spoolss pipe on %s\n"),
    18381889                         servername);
    18391890                SAFE_FREE(prt_dn);
     
    22652316        const char **attrs;
    22662317        LDAPMessage *res = NULL;
    2267         DOM_SID sid;
     2318        struct dom_sid sid;
    22682319
    22692320        if (argc < 1 || c->display_usage) {
     
    24632514static int net_ads_kerberos_pac(struct net_context *c, int argc, const char **argv)
    24642515{
    2465         struct PAC_DATA *pac = NULL;
    24662516        struct PAC_LOGON_INFO *info = NULL;
    24672517        TALLOC_CTX *mem_ctx = NULL;
     
    24932543                                     c->opt_user_name,
    24942544                                     c->opt_password,
    2495                                      0,
     2545                                     0,
    24962546                                     NULL,
    24972547                                     NULL,
     
    25012551                                     2592000, /* one month */
    25022552                                     impersonate_princ_s,
    2503                                      &pac);
     2553                                     &info);
    25042554        if (!NT_STATUS_IS_OK(status)) {
    25052555                d_printf(_("failed to query kerberos PAC: %s\n"),
     
    25082558        }
    25092559
    2510         info = get_logon_info_from_pac(pac);
    25112560        if (info) {
    25122561                const char *s;
     
    27942843}
    27952844
     2845int net_ads_gpo(struct net_context *c, int argc, const char **argv)
     2846{
     2847        return net_ads_noads();
     2848}
     2849
    27962850/* this one shouldn't display a message */
    27972851int net_ads_check(struct net_context *c)
  • vendor/current/source3/utils/net_ads_gpo.c

    r414 r740  
    2020#include "includes.h"
    2121#include "utils/net.h"
     22#include "ads.h"
     23#include "../libgpo/gpo.h"
     24#include "libgpo/gpo_proto.h"
     25#include "../libds/common/flags.h"
    2226
    2327#ifdef HAVE_ADS
     
    3539        struct GROUP_POLICY_OBJECT *gpo;
    3640        NTSTATUS result;
    37         struct nt_user_token *token = NULL;
     41        struct security_token *token = NULL;
    3842
    3943        if (argc < 1 || c->display_usage) {
     
    154158        {
    155159                WERROR werr = gp_reg_state_read(mem_ctx, flags,
    156                                                 &token->user_sids[0],
     160                                                &token->sids[0],
    157161                                                &read_list);
    158162                if (!W_ERROR_IS_OK(werr)) {
     
    247251                                            "(objectclass=groupPolicyContainer)",
    248252                                            attrs,
    249                                             DACL_SECURITY_INFORMATION,
     253                                            SECINFO_DACL,
    250254                                            &res);
    251255
     
    290294static int net_ads_gpo_list(struct net_context *c, int argc, const char **argv)
    291295{
    292         ADS_STRUCT *ads;
     296        ADS_STRUCT *ads = NULL;
    293297        ADS_STATUS status;
    294298        LDAPMessage *res = NULL;
     
    298302        uint32 flags = 0;
    299303        struct GROUP_POLICY_OBJECT *gpo_list;
    300         struct nt_user_token *token = NULL;
     304        struct security_token *token = NULL;
    301305
    302306        if (argc < 1 || c->display_usage) {
     
    359363}
    360364
    361 #if 0
    362365static int net_ads_gpo_apply(struct net_context *c, int argc, const char **argv)
    363366{
     
    369372        uint32 uac = 0;
    370373        uint32 flags = 0;
    371         struct nt_user_token *token = NULL;
     374        struct security_token *token = NULL;
    372375        const char *filter = NULL;
    373376
     
    391394
    392395        status = ads_startup(c, false, &ads);
     396        /* filter = cse_gpo_name_to_guid_string("Security"); */
     397
    393398        if (!ADS_ERR_OK(status)) {
    394399                d_printf("got: %s\n", ads_errstr(status));
     
    443448        return 0;
    444449}
    445 #endif
    446450
    447451static int net_ads_gpo_link_get(struct net_context *c, int argc, const char **argv)
     
    625629{
    626630        struct functable func[] = {
    627 #if 0
    628631                {
    629632                        "apply",
     
    634637                        "    Apply GPO to container"
    635638                },
    636 #endif
    637639                {
    638640                        "getgpo",
  • vendor/current/source3/utils/net_afs.c

    r427 r740  
    2020#include "includes.h"
    2121#include "utils/net.h"
     22#include "secrets.h"
     23#include "system/filesys.h"
    2224
    2325int net_afs_usage(struct net_context *c, int argc, const char **argv)
     
    3638
    3739        if (argc != 2) {
    38                 d_printf(_("Usage:")," net afs key <keyfile> cell\n");
     40                d_printf("%s net afs key <keyfile> cell\n", _("Usage:"));
    3941                return -1;
    4042        }
     
    5254        if (read(fd, &keyfile, sizeof(keyfile)) != sizeof(keyfile)) {
    5355                d_fprintf(stderr, _("Could not read keyfile\n"));
     56                close(fd);
    5457                return -1;
    5558        }
     59        close(fd);
    5660
    5761        if (!secrets_store_afs_keyfile(argv[1], &keyfile)) {
     
    6973
    7074        if (argc != 2) {
    71                 fprintf(stderr, _("Usage:")," net afs impersonate <user> <cell>\n");
     75                d_fprintf(stderr, "%s net afs impersonate <user> <cell>\n",
     76                          _("Usage:"));
    7277                exit(1);
    7378        }
  • vendor/current/source3/utils/net_cache.c

    r414 r740  
    3434 * Both of them are defined by first arg of gencache_iterate() routine.
    3535 */
    36 static void print_cache_entry(const char* keystr, const char* datastr,
     36static void print_cache_entry(const char* keystr, DATA_BLOB value,
    3737                              const time_t timeout, void* dptr)
    3838{
    3939        char *timeout_str;
    4040        char *alloc_str = NULL;
     41        const char *datastr;
     42        char *datastr_free = NULL;
    4143        time_t now_t = time(NULL);
    42         struct tm timeout_tm, *now_tm;
    43         /* localtime returns statically allocated pointer, so timeout_tm
    44            has to be copied somewhere else */
    45 
    46         now_tm = localtime(&timeout);
    47         if (!now_tm) {
     44        struct tm timeout_tm, now_tm;
     45        struct tm *ptimeout_tm, *pnow_tm;
     46
     47        ptimeout_tm = localtime_r(&timeout, &timeout_tm);
     48        if (ptimeout_tm == NULL) {
    4849                return;
    4950        }
    50         memcpy(&timeout_tm, now_tm, sizeof(struct tm));
    51         now_tm = localtime(&now_t);
    52         if (!now_tm) {
     51        pnow_tm = localtime_r(&now_t, &now_tm);
     52        if (pnow_tm == NULL) {
    5353                return;
    5454        }
    5555
    5656        /* form up timeout string depending whether it's today's date or not */
    57         if (timeout_tm.tm_year != now_tm->tm_year ||
    58                         timeout_tm.tm_mon != now_tm->tm_mon ||
    59                         timeout_tm.tm_mday != now_tm->tm_mday) {
     57        if (timeout_tm.tm_year != now_tm.tm_year ||
     58                        timeout_tm.tm_mon != now_tm.tm_mon ||
     59                        timeout_tm.tm_mday != now_tm.tm_mday) {
    6060
    6161                timeout_str = asctime(&timeout_tm);
     
    7272        }
    7373
     74        datastr = (char *)value.data;
     75
     76        if ((value.length > 0) && (value.data[value.length-1] != '\0')) {
     77                datastr_free = talloc_asprintf(
     78                        talloc_tos(), "<binary length %d>",
     79                        (int)value.length);
     80                datastr = datastr_free;
     81                if (datastr == NULL) {
     82                        datastr = "<binary>";
     83                }
     84        }
     85
    7486        d_printf(_("Key: %s\t Timeout: %s\t Value: %s  %s\n"), keystr,
    7587                 timeout_str, datastr, timeout > now_t ? "": _("(expired)"));
     
    221233{
    222234        const char* keystr = argv[0];
    223         char* valuestr = NULL;
     235        DATA_BLOB value;
    224236        time_t timeout;
    225237
     
    231243        }
    232244
    233         if (gencache_get(keystr, &valuestr, &timeout)) {
    234                 print_cache_entry(keystr, valuestr, timeout, NULL);
    235                 SAFE_FREE(valuestr);
     245        if (gencache_get_data_blob(keystr, &value, &timeout, NULL)) {
     246                print_cache_entry(keystr, value, timeout, NULL);
     247                data_blob_free(&value);
    236248                return 0;
    237249        }
     
    261273
    262274        pattern = argv[0];
    263         gencache_iterate(print_cache_entry, NULL, pattern);
     275        gencache_iterate_blobs(print_cache_entry, NULL, pattern);
    264276        return 0;
    265277}
     
    285297                return 0;
    286298        }
    287         gencache_iterate(print_cache_entry, NULL, pattern);
     299        gencache_iterate_blobs(print_cache_entry, NULL, pattern);
    288300        return 0;
    289301}
  • vendor/current/source3/utils/net_conf.c

    r478 r740  
    2929
    3030#include "includes.h"
     31#include "system/filesys.h"
    3132#include "utils/net.h"
     33#include "lib/smbconf/smbconf.h"
     34#include "lib/smbconf/smbconf_init.h"
     35#include "lib/smbconf/smbconf_reg.h"
    3236
    3337/**********************************************************************
     
    171175 * This functions process a service previously loaded with libsmbconf.
    172176 */
    173 static WERROR import_process_service(struct net_context *c,
     177static sbcErr import_process_service(struct net_context *c,
    174178                                     struct smbconf_ctx *conf_ctx,
    175179                                     struct smbconf_service *service)
    176180{
    177181        uint32_t idx;
    178         WERROR werr = WERR_OK;
     182        sbcErr err = SBC_ERR_OK;
    179183        uint32_t num_includes = 0;
    180184        char **includes = NULL;
     
    197201
    198202        if (smbconf_share_exists(conf_ctx, service->name)) {
    199                 werr = smbconf_delete_share(conf_ctx, service->name);
    200                 if (!W_ERROR_IS_OK(werr)) {
     203                err = smbconf_delete_share(conf_ctx, service->name);
     204                if (!SBC_ERROR_IS_OK(err)) {
    201205                        goto done;
    202206                }
    203207        }
    204         werr = smbconf_create_share(conf_ctx, service->name);
    205         if (!W_ERROR_IS_OK(werr)) {
     208        err = smbconf_create_share(conf_ctx, service->name);
     209        if (!SBC_ERROR_IS_OK(err)) {
    206210                goto done;
    207211        }
     
    214218                                                        num_includes+1);
    215219                        if (includes == NULL) {
    216                                 werr = WERR_NOMEM;
     220                                err = SBC_ERR_NOMEM;
    217221                                goto done;
    218222                        }
     
    220224                                                service->param_values[idx]);
    221225                        if (includes[num_includes] == NULL) {
    222                                 werr = WERR_NOMEM;
     226                                err = SBC_ERR_NOMEM;
    223227                                goto done;
    224228                        }
    225229                        num_includes++;
    226230                } else {
    227                         werr = smbconf_set_parameter(conf_ctx,
     231                        err = smbconf_set_parameter(conf_ctx,
    228232                                                     service->name,
    229233                                                     service->param_names[idx],
    230234                                                     service->param_values[idx]);
    231                         if (!W_ERROR_IS_OK(werr)) {
     235                        if (!SBC_ERROR_IS_OK(err)) {
    232236                                d_fprintf(stderr,
    233237                                          _("Error in section [%s], parameter \"%s\": %s\n"),
    234238                                          service->name, service->param_names[idx],
    235                                           win_errstr(werr));
     239                                          sbcErrorString(err));
    236240                                goto done;
    237241                        }
     
    239243        }
    240244
    241         werr = smbconf_set_includes(conf_ctx, service->name, num_includes,
    242                                     (const char **)includes);
    243 
     245        err = smbconf_set_includes(conf_ctx, service->name, num_includes,
     246                                   (const char **)includes);
     247        if (!SBC_ERROR_IS_OK(err)) {
     248                goto done;
     249        }
     250
     251        err = SBC_ERR_OK;
    244252done:
    245253        TALLOC_FREE(mem_ctx);
    246         return werr;
     254        return err;
    247255}
    248256
     
    257265                         int argc, const char **argv)
    258266{
    259         WERROR werr = WERR_OK;
     267        sbcErr err;
    260268        int ret = -1;
    261269        TALLOC_CTX *mem_ctx;
     
    271279        }
    272280
    273         werr = smbconf_get_config(conf_ctx, mem_ctx, &num_shares, &shares);
    274         if (!W_ERROR_IS_OK(werr)) {
     281        err = smbconf_get_config(conf_ctx, mem_ctx, &num_shares, &shares);
     282        if (!SBC_ERROR_IS_OK(err)) {
    275283                d_fprintf(stderr, _("Error getting config: %s\n"),
    276                           win_errstr(werr));
     284                          sbcErrorString(err));
    277285                goto done;
    278286        }
     
    312320        TALLOC_CTX *mem_ctx;
    313321        struct smbconf_ctx *txt_ctx;
    314         WERROR werr;
     322        sbcErr err;
    315323
    316324        if (c->display_usage)
     
    344352        }
    345353
    346         werr = smbconf_init(mem_ctx, &txt_ctx, conf_source);
    347         if (!W_ERROR_IS_OK(werr)) {
     354        err = smbconf_init(mem_ctx, &txt_ctx, conf_source);
     355        if (!SBC_ERROR_IS_OK(err)) {
    348356                d_printf(_("error loading file '%s': %s\n"), filename,
    349                          win_errstr(werr));
     357                         sbcErrorString(err));
    350358                goto done;
    351359        }
     
    359367                struct smbconf_service *service = NULL;
    360368
    361                 werr = smbconf_get_share(txt_ctx, mem_ctx,
    362                                          servicename,
    363                                          &service);
    364                 if (!W_ERROR_IS_OK(werr)) {
     369                err = smbconf_get_share(txt_ctx, mem_ctx,
     370                                        servicename,
     371                                        &service);
     372                if (!SBC_ERROR_IS_OK(err)) {
    365373                        goto cancel;
    366374                }
    367375
    368                 werr = smbconf_transaction_start(conf_ctx);
    369                 if (!W_ERROR_IS_OK(werr)) {
     376                err = smbconf_transaction_start(conf_ctx);
     377                if (!SBC_ERROR_IS_OK(err)) {
    370378                        d_printf(_("error starting transaction: %s\n"),
    371                                  win_errstr(werr));
     379                                 sbcErrorString(err));
    372380                        goto done;
    373381                }
    374382
    375                 werr = import_process_service(c, conf_ctx, service);
    376                 if (!W_ERROR_IS_OK(werr)) {
     383                err = import_process_service(c, conf_ctx, service);
     384                if (!SBC_ERROR_IS_OK(err)) {
    377385                        goto cancel;
    378386                }
     
    381389                uint32_t num_shares, sidx;
    382390
    383                 werr = smbconf_get_config(txt_ctx, mem_ctx,
     391                err = smbconf_get_config(txt_ctx, mem_ctx,
    384392                                          &num_shares,
    385393                                          &services);
    386                 if (!W_ERROR_IS_OK(werr)) {
     394                if (!SBC_ERROR_IS_OK(err)) {
    387395                        goto cancel;
    388396                }
    389397                if (!c->opt_testmode) {
    390                         werr = smbconf_drop(conf_ctx);
    391                         if (!W_ERROR_IS_OK(werr)) {
     398                        if (!SBC_ERROR_IS_OK(smbconf_drop(conf_ctx))) {
    392399                                goto cancel;
    393400                        }
     
    396403                /*
    397404                 * Wrap the importing of shares into a transaction,
    398                  * but only 100 at a time, in order to serve memory.
     405                 * but only 100 at a time, in order to save memory.
    399406                 * The allocated memory accumulates across the actions
    400407                 * within the transaction, and for me, some 1500
     
    402409                 * was exceeded.
    403410                 */
    404                 werr = smbconf_transaction_start(conf_ctx);
    405                 if (!W_ERROR_IS_OK(werr)) {
     411                err = smbconf_transaction_start(conf_ctx);
     412                if (!SBC_ERROR_IS_OK(err)) {
    406413                        d_printf(_("error starting transaction: %s\n"),
    407                                  win_errstr(werr));
     414                                 sbcErrorString(err));
    408415                        goto done;
    409416                }
    410417
    411418                for (sidx = 0; sidx < num_shares; sidx++) {
    412                         werr = import_process_service(c, conf_ctx,
    413                                                       services[sidx]);
    414                         if (!W_ERROR_IS_OK(werr)) {
     419                        err = import_process_service(c, conf_ctx,
     420                                                     services[sidx]);
     421                        if (!SBC_ERROR_IS_OK(err)) {
    415422                                goto cancel;
    416423                        }
     
    420427                        }
    421428
    422                         werr = smbconf_transaction_commit(conf_ctx);
    423                         if (!W_ERROR_IS_OK(werr)) {
     429                        err = smbconf_transaction_commit(conf_ctx);
     430                        if (!SBC_ERROR_IS_OK(err)) {
    424431                                d_printf(_("error committing transaction: "
    425432                                           "%s\n"),
    426                                          win_errstr(werr));
     433                                         sbcErrorString(err));
    427434                                goto done;
    428435                        }
    429                         werr = smbconf_transaction_start(conf_ctx);
    430                         if (!W_ERROR_IS_OK(werr)) {
     436                        err = smbconf_transaction_start(conf_ctx);
     437                        if (!SBC_ERROR_IS_OK(err)) {
    431438                                d_printf(_("error starting transaction: %s\n"),
    432                                          win_errstr(werr));
     439                                         sbcErrorString(err));
    433440                                goto done;
    434441                        }
     
    436443        }
    437444
    438         werr = smbconf_transaction_commit(conf_ctx);
    439         if (!W_ERROR_IS_OK(werr)) {
     445        err = smbconf_transaction_commit(conf_ctx);
     446        if (!SBC_ERROR_IS_OK(err)) {
    440447                d_printf(_("error committing transaction: %s\n"),
    441                          win_errstr(werr));
     448                         sbcErrorString(err));
    442449        } else {
    443450                ret = 0;
     
    447454
    448455cancel:
    449         werr = smbconf_transaction_cancel(conf_ctx);
    450         if (!W_ERROR_IS_OK(werr)) {
     456        err = smbconf_transaction_cancel(conf_ctx);
     457        if (!SBC_ERROR_IS_OK(err)) {
    451458                d_printf(_("error cancelling transaction: %s\n"),
    452                          win_errstr(werr));
     459                         sbcErrorString(err));
    453460        }
    454461
     
    462469                               const char **argv)
    463470{
    464         WERROR werr = WERR_OK;
     471        sbcErr err;
    465472        int ret = -1;
    466473        uint32_t count, num_shares = 0;
     
    475482        }
    476483
    477         werr = smbconf_get_share_names(conf_ctx, mem_ctx, &num_shares,
    478                                        &share_names);
    479         if (!W_ERROR_IS_OK(werr)) {
     484        err = smbconf_get_share_names(conf_ctx, mem_ctx, &num_shares,
     485                                      &share_names);
     486        if (!SBC_ERROR_IS_OK(err)) {
    480487                goto done;
    481488        }
     
    497504{
    498505        int ret = -1;
    499         WERROR werr;
     506        sbcErr err;
    500507
    501508        if (argc != 0 || c->display_usage) {
     
    504511        }
    505512
    506         werr = smbconf_drop(conf_ctx);
    507         if (!W_ERROR_IS_OK(werr)) {
     513        err = smbconf_drop(conf_ctx);
     514        if (!SBC_ERROR_IS_OK(err)) {
    508515                d_fprintf(stderr, _("Error deleting configuration: %s\n"),
    509                           win_errstr(werr));
     516                          sbcErrorString(err));
    510517                goto done;
    511518        }
     
    522529{
    523530        int ret = -1;
    524         WERROR werr = WERR_OK;
     531        sbcErr err;
    525532        const char *sharename = NULL;
    526533        TALLOC_CTX *mem_ctx;
     
    541548        }
    542549
    543         werr = smbconf_get_share(conf_ctx, mem_ctx, sharename, &service);
    544         if (!W_ERROR_IS_OK(werr)) {
     550        err = smbconf_get_share(conf_ctx, mem_ctx, sharename, &service);
     551        if (!SBC_ERROR_IS_OK(err)) {
    545552                d_printf(_("error getting share parameters: %s\n"),
    546                          win_errstr(werr));
     553                         sbcErrorString(err));
    547554                goto done;
    548555        }
     
    573580{
    574581        int ret = -1;
    575         WERROR werr = WERR_OK;
     582        sbcErr err;
    576583        char *sharename = NULL;
    577584        const char *path = NULL;
     
    579586        const char *guest_ok = "no";
    580587        const char *writeable = "no";
    581         SMB_STRUCT_STAT sbuf;
    582588        TALLOC_CTX *mem_ctx = talloc_stackframe();
    583589
     
    679685        }
    680686
    681         if (sys_stat(path, &sbuf, false) != 0) {
    682                 d_fprintf(stderr,
    683                           _("ERROR: cannot stat path '%s' to ensure "
    684                             "this is a directory.\n"
    685                             "Error was '%s'.\n"),
    686                           path, strerror(errno));
    687                 goto done;
    688         }
    689 
    690         if (!S_ISDIR(sbuf.st_ex_mode)) {
    691                 d_fprintf(stderr,
    692                           _("ERROR: path '%s' is not a directory.\n"),
    693                           path);
    694                 goto done;
    695         }
    696 
    697687        /*
    698688         * start a transaction
    699689         */
    700690
    701         werr = smbconf_transaction_start(conf_ctx);
    702         if (!W_ERROR_IS_OK(werr)) {
     691        err = smbconf_transaction_start(conf_ctx);
     692        if (!SBC_ERROR_IS_OK(err)) {
    703693                d_printf("error starting transaction: %s\n",
    704                          win_errstr(werr));
     694                         sbcErrorString(err));
    705695                goto done;
    706696        }
     
    710700         */
    711701
    712         werr = smbconf_create_share(conf_ctx, sharename);
    713         if (!W_ERROR_IS_OK(werr)) {
     702        err = smbconf_create_share(conf_ctx, sharename);
     703        if (!SBC_ERROR_IS_OK(err)) {
    714704                d_fprintf(stderr, _("Error creating share %s: %s\n"),
    715                           sharename, win_errstr(werr));
     705                          sharename, sbcErrorString(err));
    716706                goto cancel;
    717707        }
     
    721711         */
    722712
    723         werr = smbconf_set_parameter(conf_ctx, sharename, "path", path);
    724         if (!W_ERROR_IS_OK(werr)) {
     713        err = smbconf_set_parameter(conf_ctx, sharename, "path", path);
     714        if (!SBC_ERROR_IS_OK(err)) {
    725715                d_fprintf(stderr, _("Error setting parameter %s: %s\n"),
    726                           "path", win_errstr(werr));
     716                          "path", sbcErrorString(err));
    727717                goto cancel;
    728718        }
    729719
    730720        if (comment != NULL) {
    731                 werr = smbconf_set_parameter(conf_ctx, sharename, "comment",
    732                                              comment);
    733                 if (!W_ERROR_IS_OK(werr)) {
     721                err = smbconf_set_parameter(conf_ctx, sharename, "comment",
     722                                            comment);
     723                if (!SBC_ERROR_IS_OK(err)) {
    734724                        d_fprintf(stderr, _("Error setting parameter %s: %s\n"),
    735                                   "comment", win_errstr(werr));
     725                                  "comment", sbcErrorString(err));
    736726                        goto cancel;
    737727                }
    738728        }
    739729
    740         werr = smbconf_set_parameter(conf_ctx, sharename, "guest ok", guest_ok);
    741         if (!W_ERROR_IS_OK(werr)) {
     730        err = smbconf_set_parameter(conf_ctx, sharename, "guest ok", guest_ok);
     731        if (!SBC_ERROR_IS_OK(err)) {
    742732                d_fprintf(stderr, _("Error setting parameter %s: %s\n"),
    743                           "'guest ok'", win_errstr(werr));
     733                          "'guest ok'", sbcErrorString(err));
    744734                goto cancel;
    745735        }
    746736
    747         werr = smbconf_set_parameter(conf_ctx, sharename, "writeable",
    748                                      writeable);
    749         if (!W_ERROR_IS_OK(werr)) {
     737        err = smbconf_set_parameter(conf_ctx, sharename, "writeable",
     738                                    writeable);
     739        if (!SBC_ERROR_IS_OK(err)) {
    750740                d_fprintf(stderr, _("Error setting parameter %s: %s\n"),
    751                           "writeable", win_errstr(werr));
     741                          "writeable", sbcErrorString(err));
    752742                goto cancel;
    753743        }
     
    757747         */
    758748
    759         werr = smbconf_transaction_commit(conf_ctx);
    760         if (!W_ERROR_IS_OK(werr)) {
     749        err = smbconf_transaction_commit(conf_ctx);
     750        if (!SBC_ERROR_IS_OK(err)) {
    761751                d_printf("error committing transaction: %s\n",
    762                          win_errstr(werr));
     752                         sbcErrorString(err));
    763753        } else {
    764754                ret = 0;
     
    768758
    769759cancel:
    770         werr = smbconf_transaction_cancel(conf_ctx);
    771         if (!W_ERROR_IS_OK(werr)) {
     760        err = smbconf_transaction_cancel(conf_ctx);
     761        if (!SBC_ERROR_IS_OK(err)) {
    772762                d_printf("error cancelling transaction: %s\n",
    773                          win_errstr(werr));
     763                         sbcErrorString(err));
    774764        }
    775765
     
    785775        int ret = -1;
    786776        const char *sharename = NULL;
    787         WERROR werr = WERR_OK;
     777        sbcErr err;
    788778        TALLOC_CTX *mem_ctx = talloc_stackframe();
    789779
     
    798788        }
    799789
    800         werr = smbconf_delete_share(conf_ctx, sharename);
    801         if (!W_ERROR_IS_OK(werr)) {
     790        err = smbconf_delete_share(conf_ctx, sharename);
     791        if (!SBC_ERROR_IS_OK(err)) {
    802792                d_fprintf(stderr, _("Error deleting share %s: %s\n"),
    803                           sharename, win_errstr(werr));
     793                          sharename, sbcErrorString(err));
    804794                goto done;
    805795        }
     
    815805{
    816806        int ret = -1;
    817         WERROR werr = WERR_OK;
     807        sbcErr err;
    818808        char *service = NULL;
    819809        char *param = NULL;
     
    843833        value_str = argv[2];
    844834
    845         werr = smbconf_transaction_start(conf_ctx);
    846         if (!W_ERROR_IS_OK(werr)) {
     835        err = smbconf_transaction_start(conf_ctx);
     836        if (!SBC_ERROR_IS_OK(err)) {
    847837                d_printf(_("error starting transaction: %s\n"),
    848                          win_errstr(werr));
     838                         sbcErrorString(err));
    849839                goto done;
    850840        }
    851841
    852842        if (!smbconf_share_exists(conf_ctx, service)) {
    853                 werr = smbconf_create_share(conf_ctx, service);
    854                 if (!W_ERROR_IS_OK(werr)) {
     843                err = smbconf_create_share(conf_ctx, service);
     844                if (!SBC_ERROR_IS_OK(err)) {
    855845                        d_fprintf(stderr, _("Error creating share '%s': %s\n"),
    856                                   service, win_errstr(werr));
     846                                  service, sbcErrorString(err));
    857847                        goto cancel;
    858848                }
    859849        }
    860850
    861         werr = smbconf_set_parameter(conf_ctx, service, param, value_str);
    862 
    863         if (!W_ERROR_IS_OK(werr)) {
     851        err = smbconf_set_parameter(conf_ctx, service, param, value_str);
     852        if (!SBC_ERROR_IS_OK(err)) {
    864853                d_fprintf(stderr, _("Error setting value '%s': %s\n"),
    865                           param, win_errstr(werr));
     854                          param, sbcErrorString(err));
    866855                goto cancel;
    867856        }
    868857
    869         werr = smbconf_transaction_commit(conf_ctx);
    870         if (!W_ERROR_IS_OK(werr)) {
     858        err = smbconf_transaction_commit(conf_ctx);
     859        if (!SBC_ERROR_IS_OK(err)) {
    871860                d_printf(_("error committing transaction: %s\n"),
    872                          win_errstr(werr));
     861                         sbcErrorString(err));
    873862        } else {
    874863                ret = 0;
     
    878867
    879868cancel:
    880         werr = smbconf_transaction_cancel(conf_ctx);
    881         if (!W_ERROR_IS_OK(werr)) {
     869        err = smbconf_transaction_cancel(conf_ctx);
     870        if (!SBC_ERROR_IS_OK(err)) {
    882871                d_printf(_("error cancelling transaction: %s\n"),
    883                          win_errstr(werr));
     872                         sbcErrorString(err));
    884873        }
    885874
     
    893882{
    894883        int ret = -1;
    895         WERROR werr = WERR_OK;
     884        sbcErr err;
    896885        char *service = NULL;
    897886        char *param = NULL;
     
    922911        }
    923912
    924         werr = smbconf_get_parameter(conf_ctx, mem_ctx, service, param, &valstr);
    925 
    926         if (W_ERROR_EQUAL(werr, WERR_NO_SUCH_SERVICE)) {
     913        err = smbconf_get_parameter(conf_ctx, mem_ctx, service, param, &valstr);
     914        if (SBC_ERROR_EQUAL(err, SBC_ERR_NO_SUCH_SERVICE)) {
    927915                d_fprintf(stderr,
    928916                          _("Error: given service '%s' does not exist.\n"),
    929917                          service);
    930918                goto done;
    931         } else if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
     919        } else if (SBC_ERROR_EQUAL(err, SBC_ERR_INVALID_PARAM)) {
    932920                d_fprintf(stderr,
    933921                          _("Error: given parameter '%s' is not set.\n"),
    934922                          param);
    935923                goto done;
    936         } else if (!W_ERROR_IS_OK(werr)) {
     924        } else if (!SBC_ERROR_IS_OK(err)) {
    937925                d_fprintf(stderr, _("Error getting value '%s': %s.\n"),
    938                           param, win_errstr(werr));
     926                          param, sbcErrorString(err));
    939927                goto done;
    940928        }
     
    952940{
    953941        int ret = -1;
    954         WERROR werr = WERR_OK;
     942        sbcErr err;
    955943        char *service = NULL;
    956944        char *param = NULL;
     
    978966        }
    979967
    980         werr = smbconf_delete_parameter(conf_ctx, service, param);
    981 
    982         if (W_ERROR_EQUAL(werr, WERR_NO_SUCH_SERVICE)) {
     968        err = smbconf_delete_parameter(conf_ctx, service, param);
     969        if (SBC_ERROR_EQUAL(err, SBC_ERR_NO_SUCH_SERVICE)) {
    983970                d_fprintf(stderr,
    984971                          _("Error: given service '%s' does not exist.\n"),
    985972                          service);
    986973                goto done;
    987         } else if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
     974        } else if (SBC_ERROR_EQUAL(err, SBC_ERR_INVALID_PARAM)) {
    988975                d_fprintf(stderr,
    989976                          _("Error: given parameter '%s' is not set.\n"),
    990977                          param);
    991978                goto done;
    992         } else if (!W_ERROR_IS_OK(werr)) {
     979        } else if (!SBC_ERROR_IS_OK(err)) {
    993980                d_fprintf(stderr, _("Error deleting value '%s': %s.\n"),
    994                           param, win_errstr(werr));
     981                          param, sbcErrorString(err));
    995982                goto done;
    996983        }
     
    1007994                                int argc, const char **argv)
    1008995{
    1009         WERROR werr;
     996        sbcErr err;
    1010997        uint32_t num_includes;
    1011998        uint32_t count;
     
    10261013        }
    10271014
    1028         werr = smbconf_get_includes(conf_ctx, mem_ctx, service,
     1015        err = smbconf_get_includes(conf_ctx, mem_ctx, service,
    10291016                                    &num_includes, &includes);
    1030         if (!W_ERROR_IS_OK(werr)) {
    1031                 d_printf(_("error getting includes: %s\n"), win_errstr(werr));
     1017        if (!SBC_ERROR_IS_OK(err)) {
     1018                d_printf(_("error getting includes: %s\n"), sbcErrorString(err));
    10321019                goto done;
    10331020        }
     
    10481035                                int argc, const char **argv)
    10491036{
    1050         WERROR werr;
     1037        sbcErr err;
    10511038        char *service;
    10521039        uint32_t num_includes;
     
    10731060        }
    10741061
    1075         werr = smbconf_set_includes(conf_ctx, service, num_includes, includes);
    1076         if (!W_ERROR_IS_OK(werr)) {
    1077                 d_printf(_("error setting includes: %s\n"), win_errstr(werr));
     1062        err = smbconf_set_includes(conf_ctx, service, num_includes, includes);
     1063        if (!SBC_ERROR_IS_OK(err)) {
     1064                d_printf(_("error setting includes: %s\n"), sbcErrorString(err));
    10781065                goto done;
    10791066        }
     
    10901077                                int argc, const char **argv)
    10911078{
    1092         WERROR werr;
     1079        sbcErr err;
    10931080        char *service;
    10941081        int ret = -1;
     
    11061093        }
    11071094
    1108         werr = smbconf_delete_includes(conf_ctx, service);
    1109         if (!W_ERROR_IS_OK(werr)) {
    1110                 d_printf(_("error deleting includes: %s\n"), win_errstr(werr));
     1095        err = smbconf_delete_includes(conf_ctx, service);
     1096        if (!SBC_ERROR_IS_OK(err)) {
     1097                d_printf(_("error deleting includes: %s\n"), sbcErrorString(err));
    11111098                goto done;
    11121099        }
     
    11371124                                  int argc, const char **argv)
    11381125{
    1139         WERROR werr;
     1126        sbcErr err;
    11401127        TALLOC_CTX *mem_ctx = talloc_stackframe();
    11411128        struct smbconf_ctx *conf_ctx;
    11421129        int ret = -1;
    11431130
    1144         werr = smbconf_init(mem_ctx, &conf_ctx, "registry:");
    1145 
    1146         if (!W_ERROR_IS_OK(werr)) {
     1131        err = smbconf_init(mem_ctx, &conf_ctx, "registry:");
     1132        if (!SBC_ERROR_IS_OK(err)) {
    11471133                return -1;
    11481134        }
  • vendor/current/source3/utils/net_dns.c

    r414 r740  
    1 
    21/*
    32   Samba Unix/Linux Dynamic DNS Update
     
    1110   the Free Software Foundation; either version 3 of the License, or
    1211   (at your option) any later version.
    13    
     12
    1413   This program is distributed in the hope that it will be useful,
    1514   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1615   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1716   GNU General Public License for more details.
    18    
     17
    1918   You should have received a copy of the GNU General Public License
    2019   along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    2322#include "includes.h"
    2423#include "utils/net.h"
    25 #include "dns.h"
     24#include "../lib/addns/dns.h"
    2625
    2726#if defined(WITH_DNS_UPDATES)
    28 
    2927/*
    3028 * Silly prototype to get rid of a warning
     
    5654                return ERROR_DNS_NO_MEMORY;
    5755        }
    58                
     56
    5957        err = dns_open_connection( pszServerName, DNS_TCP, mem_ctx, &conn );
    6058        if (!ERR_DNS_IS_OK(err)) {
     
    115113                                                     DNS_SRV_WIN2000 );
    116114                }
    117                
     115
    118116                if (!ERR_DNS_IS_OK(err))
    119117                        goto error;
    120                
    121118
    122119                err = dns_sign_update(req, gss_context, keyname,
  • vendor/current/source3/utils/net_dom.c

    r414 r740  
    2020#include "includes.h"
    2121#include "utils/net.h"
    22 #include "../librpc/gen_ndr/cli_initshutdown.h"
     22#include "../librpc/gen_ndr/ndr_initshutdown.h"
     23#include "../librpc/gen_ndr/ndr_winreg.h"
     24#include "lib/netapi/netapi.h"
     25#include "lib/netapi/netapi_net.h"
     26#include "libsmb/libsmb.h"
    2327
    2428int net_dom_usage(struct net_context *c, int argc, const char **argv)
     
    371375        };
    372376
    373         status = libnetapi_init(&c->netapi_ctx);
     377        status = libnetapi_net_init(&c->netapi_ctx);
    374378        if (status != 0) {
    375379                return -1;
  • vendor/current/source3/utils/net_eventlog.c

    r414 r740  
    2222#include "includes.h"
    2323#include "utils/net.h"
     24#include "lib/eventlog/eventlog.h"
    2425
    2526/**
     
    5556        }
    5657
    57         ndr_err = ndr_pull_struct_blob(&blob, ctx, NULL, &evt,
     58        ndr_err = ndr_pull_struct_blob(&blob, ctx, &evt,
    5859                   (ndr_pull_flags_fn_t)ndr_pull_EVENTLOG_EVT_FILE);
    5960        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     
    113114
    114115        /* dump_data(0, blob.data, blob.length); */
    115         ndr_err = ndr_pull_struct_blob(&blob, ctx, NULL, &evt_header,
     116        ndr_err = ndr_pull_struct_blob(&blob, ctx, &evt_header,
    116117                   (ndr_pull_flags_fn_t)ndr_pull_EVENTLOGHEADER);
    117118        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     
    126127        }
    127128
    128         ndr_err = ndr_pull_struct_blob(&blob, ctx, NULL, &evt,
     129        ndr_err = ndr_pull_struct_blob(&blob, ctx, &evt,
    129130                   (ndr_pull_flags_fn_t)ndr_pull_EVENTLOG_EVT_FILE);
    130131        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
  • vendor/current/source3/utils/net_g_lock.c

    r453 r740  
    2121#include "net.h"
    2222#include "g_lock.h"
     23#include "messages.h"
    2324
    2425static bool net_g_lock_init(TALLOC_CTX *mem_ctx,
     
    3132        struct g_lock_ctx *g_ctx = NULL;
    3233
    33         ev = tevent_context_init(talloc_tos());
     34        ev = tevent_context_init(mem_ctx);
    3435        if (ev == NULL) {
    3536                d_fprintf(stderr, "ERROR: could not init event context\n");
    3637                goto fail;
    3738        }
    38         msg = messaging_init(talloc_tos(), server_id_self(), ev);
     39        msg = messaging_init(mem_ctx, procid_self(), ev);
    3940        if (msg == NULL) {
    4041                d_fprintf(stderr, "ERROR: could not init messaging context\n");
    4142                goto fail;
    4243        }
    43         g_ctx = g_lock_ctx_init(talloc_tos(), msg);
     44        g_ctx = g_lock_ctx_init(mem_ctx, msg);
    4445        if (g_ctx == NULL) {
    4546                d_fprintf(stderr, "ERROR: could not init g_lock context\n");
     
    9192        status = g_lock_do(name, G_LOCK_WRITE,
    9293                           timeval_set(timeout / 1000, timeout % 1000),
    93                            net_g_lock_do_fn, &state);
     94                           procid_self(), net_g_lock_do_fn, &state);
    9495        if (!NT_STATUS_IS_OK(status)) {
    9596                d_fprintf(stderr, "ERROR: g_lock_do failed: %s\n",
  • vendor/current/source3/utils/net_group.c

    r414 r740  
    6464                return net_ads_group(c, argc, argv);
    6565
    66         if (argc == 0 && net_rpc_check(c, NET_FLAGS_PDC))
    67                 return net_rpc_group(c,argc, argv);
    68 
    6966        return net_rap_group(c, argc, argv);
    7067}
  • vendor/current/source3/utils/net_groupmap.c

    r414 r740  
    2323
    2424#include "includes.h"
     25#include "system/passwd.h"
    2526#include "utils/net.h"
     27#include "../libcli/security/security.h"
     28#include "passdb.h"
    2629
    2730/*********************************************************
     
    2932 Return the SID.
    3033**********************************************************/
    31 static bool get_sid_from_input(DOM_SID *sid, char *input)
     34static bool get_sid_from_input(struct dom_sid *sid, char *input)
    3235{
    3336        GROUP_MAP map;
     
    124127        /* list a single group is given a name */
    125128        if ( ntgroup[0] || sid_string[0] ) {
    126                 DOM_SID sid;
     129                struct dom_sid sid;
    127130                GROUP_MAP map;
    128131
     
    166169static int net_groupmap_add(struct net_context *c, int argc, const char **argv)
    167170{
    168         DOM_SID sid;
     171        struct dom_sid sid;
    169172        fstring ntgroup = "";
    170173        fstring unixgrp = "";
     
    201204                if ( !StrnCaseCmp(argv[i], "rid", strlen("rid")) ) {
    202205                        rid = get_int_param(argv[i]);
    203                         if ( rid < DOMAIN_GROUP_RID_ADMINS ) {
     206                        if ( rid < DOMAIN_RID_ADMINS ) {
    204207                                d_fprintf(stderr,
    205208                                          _("RID must be greater than %d\n"),
    206                                           (uint32)DOMAIN_GROUP_RID_ADMINS-1);
     209                                          (uint32)DOMAIN_RID_ADMINS-1);
    207210                                return -1;
    208211                        }
     
    300303        /* append the rid to our own domain/machine SID if we don't have a full SID */
    301304        if ( !string_sid[0] ) {
    302                 sid_copy(&sid, get_global_sam_sid());
    303                 sid_append_rid(&sid, rid);
     305                sid_compose(&sid, get_global_sam_sid(), rid);
    304306                sid_to_fstring(string_sid, &sid);
    305307        }
     
    337339static int net_groupmap_modify(struct net_context *c, int argc, const char **argv)
    338340{
    339         DOM_SID sid;
     341        struct dom_sid sid;
    340342        GROUP_MAP map;
    341343        fstring ntcomment = "";
     
    485487static int net_groupmap_delete(struct net_context *c, int argc, const char **argv)
    486488{
    487         DOM_SID sid;
     489        struct dom_sid sid;
    488490        fstring ntgroup = "";
    489491        fstring sid_string = "";
     
    582584
    583585        if (!have_map) {
    584                 DOM_SID sid;
     586                struct dom_sid sid;
    585587                have_map = ( (strncmp(ntgroup, "S-", 2) == 0) &&
    586588                             string_to_sid(&sid, ntgroup) &&
     
    613615                }
    614616
    615                 sid_copy(&map.sid, get_global_sam_sid());
    616                 sid_append_rid(&map.sid, c->opt_rid);
     617                sid_compose(&map.sid, get_global_sam_sid(), c->opt_rid);
    617618
    618619                map.sid_name_use = SID_NAME_DOM_GRP;
     
    708709static int net_groupmap_addmem(struct net_context *c, int argc, const char **argv)
    709710{
    710         DOM_SID alias, member;
     711        struct dom_sid alias, member;
    711712
    712713        if ( (argc != 2) ||
     
    731732static int net_groupmap_delmem(struct net_context *c, int argc, const char **argv)
    732733{
    733         DOM_SID alias, member;
     734        struct dom_sid alias, member;
    734735
    735736        if ( (argc != 2) ||
     
    754755static int net_groupmap_listmem(struct net_context *c, int argc, const char **argv)
    755756{
    756         DOM_SID alias;
    757         DOM_SID *members;
     757        struct dom_sid alias;
     758        struct dom_sid *members;
    758759        size_t i, num;
    759760
     
    787788
    788789static bool print_alias_memberships(TALLOC_CTX *mem_ctx,
    789                                     const DOM_SID *domain_sid,
    790                                     const DOM_SID *member)
     790                                    const struct dom_sid *domain_sid,
     791                                    const struct dom_sid *member)
    791792{
    792793        uint32 *alias_rids;
     
    805806
    806807        for (i = 0; i < num_alias_rids; i++) {
    807                 DOM_SID alias;
    808                 sid_copy(&alias, domain_sid);
    809                 sid_append_rid(&alias, alias_rids[i]);
     808                struct dom_sid alias;
     809                sid_compose(&alias, domain_sid, alias_rids[i]);
    810810                printf("%s\n", sid_string_tos(&alias));
    811811        }
     
    817817{
    818818        TALLOC_CTX *mem_ctx;
    819         DOM_SID *domain_sid, *builtin_sid, member;
     819        struct dom_sid *domain_sid, member;
    820820
    821821        if ( (argc != 1) ||
     
    835835
    836836        domain_sid = get_global_sam_sid();
    837         builtin_sid = string_sid_talloc(mem_ctx, "S-1-5-32");
    838         if ((domain_sid == NULL) || (builtin_sid == NULL)) {
     837        if (domain_sid == NULL) {
    839838                d_fprintf(stderr, _("Could not get domain sid\n"));
    840839                return -1;
     
    842841
    843842        if (!print_alias_memberships(mem_ctx, domain_sid, &member) ||
    844             !print_alias_memberships(mem_ctx, builtin_sid, &member))
     843            !print_alias_memberships(mem_ctx, &global_sid_Builtin, &member))
    845844                return -1;
    846845
  • vendor/current/source3/utils/net_idmap.c

    r414 r740  
    1818*/
    1919
    20 #define FOO(x) (x)
    2120#include "includes.h"
     21#include "system/filesys.h"
    2222#include "utils/net.h"
     23#include "secrets.h"
     24#include "idmap.h"
     25#include "dbwrap.h"
     26#include "../libcli/security/security.h"
     27#include "net_idmap_check.h"
     28#include "util_tdb.h"
    2329
    2430#define ALLOC_CHECK(mem) do { \
     
    3238 Helper function for net_idmap_dump. Dump one entry.
    3339 **********************************************************/
    34 static int net_idmap_dump_one_entry(TDB_CONTEXT *tdb,
    35                                     TDB_DATA key,
    36                                     TDB_DATA data,
     40static int net_idmap_dump_one_entry(struct db_record *rec,
    3741                                    void *unused)
    3842{
    39         if (strcmp((char *)key.dptr, "USER HWM") == 0) {
    40                 printf(_("USER HWM %d\n"), IVAL(data.dptr,0));
     43        if (strcmp((char *)rec->key.dptr, "USER HWM") == 0) {
     44                printf(_("USER HWM %d\n"), IVAL(rec->value.dptr,0));
    4145                return 0;
    4246        }
    4347
    44         if (strcmp((char *)key.dptr, "GROUP HWM") == 0) {
    45                 printf(_("GROUP HWM %d\n"), IVAL(data.dptr,0));
     48        if (strcmp((char *)rec->key.dptr, "GROUP HWM") == 0) {
     49                printf(_("GROUP HWM %d\n"), IVAL(rec->value.dptr,0));
    4650                return 0;
    4751        }
    4852
    49         if (strncmp((char *)key.dptr, "S-", 2) != 0)
     53        if (strncmp((char *)rec->key.dptr, "S-", 2) != 0)
    5054                return 0;
    5155
    52         printf("%s %s\n", data.dptr, key.dptr);
     56        printf("%s %s\n", rec->value.dptr, rec->key.dptr);
    5357        return 0;
     58}
     59
     60static const char* net_idmap_dbfile(struct net_context *c)
     61{
     62        const char* dbfile = NULL;
     63
     64        if (c->opt_db != NULL) {
     65                dbfile = talloc_strdup(talloc_tos(), c->opt_db);
     66                if (dbfile == NULL) {
     67                        d_fprintf(stderr, _("Out of memory!\n"));
     68                }
     69        } else if (strequal(lp_idmap_backend(), "tdb")) {
     70                dbfile = state_path("winbindd_idmap.tdb");
     71                if (dbfile == NULL) {
     72                        d_fprintf(stderr, _("Out of memory!\n"));
     73                }
     74        } else if (strequal(lp_idmap_backend(), "tdb2")) {
     75                dbfile = lp_parm_talloc_string(-1, "tdb", "idmap2.tdb", NULL);
     76                if (dbfile == NULL) {
     77                        dbfile = talloc_asprintf(talloc_tos(), "%s/idmap2.tdb",
     78                                                 lp_private_dir());
     79                }
     80                if (dbfile == NULL) {
     81                        d_fprintf(stderr, _("Out of memory!\n"));
     82                }
     83        } else {
     84                char* backend = talloc_strdup(talloc_tos(), lp_idmap_backend());
     85                char* args = strchr(backend, ':');
     86                if (args != NULL) {
     87                        *args = '\0';
     88                }
     89
     90                d_printf(_("Sorry, 'idmap backend = %s' is currently not supported\n"),
     91                         backend);
     92
     93                talloc_free(backend);
     94        }
     95
     96        return dbfile;
    5497}
    5598
     
    59102static int net_idmap_dump(struct net_context *c, int argc, const char **argv)
    60103{
    61         TDB_CONTEXT *idmap_tdb;
    62 
    63         if ( argc != 1  || c->display_usage) {
     104        struct db_context *db;
     105        TALLOC_CTX *mem_ctx;
     106        const char* dbfile;
     107        int ret = -1;
     108
     109        if ( argc > 1  || c->display_usage) {
    64110                d_printf("%s\n%s",
    65111                         _("Usage:"),
    66                          _("net idmap dump <inputfile>\n"
     112                         _("net idmap dump [[--db=]<inputfile>]\n"
    67113                           "  Dump current ID mapping.\n"
    68114                           "    inputfile\tTDB file to read mappings from.\n"));
     
    70116        }
    71117
    72         idmap_tdb = tdb_open_log(argv[0], 0, TDB_DEFAULT, O_RDONLY, 0);
    73 
    74         if (idmap_tdb == NULL) {
    75                 d_fprintf(stderr, _("Could not open idmap: %s\n"), argv[0]);
    76                 return -1;
    77         }
    78 
    79         tdb_traverse(idmap_tdb, net_idmap_dump_one_entry, NULL);
    80 
    81         tdb_close(idmap_tdb);
    82 
    83         return 0;
     118        mem_ctx = talloc_stackframe();
     119
     120        dbfile = (argc > 0) ? argv[0] : net_idmap_dbfile(c);
     121        if (dbfile == NULL) {
     122                goto done;
     123        }
     124        d_fprintf(stderr, _("dumping id mapping from %s\n"), dbfile);
     125
     126        db = db_open(mem_ctx, dbfile, 0, TDB_DEFAULT, O_RDONLY, 0);
     127        if (db == NULL) {
     128                d_fprintf(stderr, _("Could not open idmap db (%s): %s\n"),
     129                          dbfile, strerror(errno));
     130                goto done;
     131        }
     132
     133        db->traverse_read(db, net_idmap_dump_one_entry, NULL);
     134        ret = 0;
     135
     136done:
     137        talloc_free(mem_ctx);
     138        return ret;
    84139}
    85140
     
    88143 **********************************************************/
    89144
     145static int net_idmap_store_id_mapping(struct db_context *db,
     146                                      enum id_type type,
     147                                      unsigned long idval,
     148                                      const char *sid_string)
     149{
     150        NTSTATUS status;
     151        char *idstr = NULL;
     152
     153        switch(type) {
     154        case ID_TYPE_UID:
     155                idstr = talloc_asprintf(talloc_tos(), "UID %lu", idval);
     156                break;
     157        case ID_TYPE_GID:
     158                idstr = talloc_asprintf(talloc_tos(), "GID %lu", idval);
     159                break;
     160        default:
     161                d_fprintf(stderr, "Invalid id mapping type: %d\n", type);
     162                return -1;
     163        }
     164
     165        status = dbwrap_store_bystring(db, idstr,
     166                                       string_term_tdb_data(sid_string),
     167                                       TDB_REPLACE);
     168        if (!NT_STATUS_IS_OK(status)) {
     169                d_fprintf(stderr, "Error storing ID -> SID: "
     170                         "%s\n", nt_errstr(status));
     171                talloc_free(idstr);
     172                return -1;
     173        }
     174        status = dbwrap_store_bystring(db, sid_string,
     175                                       string_term_tdb_data(idstr),
     176                                       TDB_REPLACE);
     177        if (!NT_STATUS_IS_OK(status)) {
     178                d_fprintf(stderr, "Error storing SID -> ID: "
     179                         "%s\n", nt_errstr(status));
     180                talloc_free(idstr);
     181                return -1;
     182        }
     183
     184        return 0;
     185}
     186
    90187static int net_idmap_restore(struct net_context *c, int argc, const char **argv)
    91188{
    92         TALLOC_CTX *ctx;
    93         FILE *input;
     189        TALLOC_CTX *mem_ctx;
     190        FILE *input = NULL;
     191        struct db_context *db;
     192        const char *dbfile = NULL;
     193        int ret = 0;
    94194
    95195        if (c->display_usage) {
    96196                d_printf("%s\n%s",
    97197                         _("Usage:"),
    98                          _("net idmap restore [inputfile]\n"
     198                         _("net idmap restore [--db=<TDB>] [<inputfile>]\n"
    99199                           "  Restore ID mappings from file\n"
    100                            "    inputfile\tFile to load ID mappings from. If "
    101                            "not given, load data from stdin.\n"));
     200                           "    TDB\tFile to store ID mappings to."
     201                           "    inputfile\tFile to load ID mappings from. If not "
     202                           "given, load data from stdin.\n"));
    102203                return 0;
    103204        }
    104205
    105         if (! winbind_ping()) {
    106                 d_fprintf(stderr,
    107                           _("To use net idmap Winbindd must be running.\n"));
    108                 return -1;
    109         }
    110 
    111         ctx = talloc_new(NULL);
    112         ALLOC_CHECK(ctx);
     206        mem_ctx = talloc_stackframe();
     207
     208        dbfile = net_idmap_dbfile(c);
     209
     210        if (dbfile == NULL) {
     211                ret = -1;
     212                goto done;
     213        }
     214
     215        d_fprintf(stderr, _("restoring id mapping to %s\n"), dbfile);
    113216
    114217        if (argc == 1) {
    115218                input = fopen(argv[0], "r");
     219                if (input == NULL) {
     220                        d_fprintf(stderr, _("Could not open input file (%s): %s\n"),
     221                                  argv[0], strerror(errno));
     222                        ret = -1;
     223                        goto done;
     224                }
    116225        } else {
    117226                input = stdin;
     227        }
     228
     229        db = db_open(mem_ctx, dbfile, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0644);
     230        if (db == NULL) {
     231                d_fprintf(stderr, _("Could not open idmap db (%s): %s\n"),
     232                          dbfile, strerror(errno));
     233                ret = -1;
     234                goto done;
     235        }
     236
     237        if (db->transaction_start(db) != 0) {
     238                d_fprintf(stderr, _("Failed to start transaction.\n"));
     239                ret = -1;
     240                goto done;
    118241        }
    119242
     
    121244                char line[128], sid_string[128];
    122245                int len;
    123                 struct wbcDomainSid sid;
    124                 enum id_type type = ID_TYPE_NOT_SPECIFIED;
    125246                unsigned long idval;
    126                 wbcErr wbc_status;
    127247
    128248                if (fgets(line, 127, input) == NULL)
     
    134254                        line[len-1] = '\0';
    135255
    136                 if (sscanf(line, "GID %lu %128s", &idval, sid_string) == 2) {
    137                         type = ID_TYPE_GID;
    138                 } else if (sscanf(line, "UID %lu %128s", &idval, sid_string) == 2) {
    139                         type = ID_TYPE_UID;
     256                if (sscanf(line, "GID %lu %128s", &idval, sid_string) == 2)
     257                {
     258                        ret = net_idmap_store_id_mapping(db, ID_TYPE_GID,
     259                                                         idval, sid_string);
     260                        if (ret != 0) {
     261                                break;
     262                        }
     263                } else if (sscanf(line, "UID %lu %128s", &idval, sid_string) == 2)
     264                {
     265                        ret = net_idmap_store_id_mapping(db, ID_TYPE_UID,
     266                                                         idval, sid_string);
     267                        if (ret != 0) {
     268                                break;
     269                        }
    140270                } else if (sscanf(line, "USER HWM %lu", &idval) == 1) {
    141                         /* set uid hwm */
    142                         wbc_status = wbcSetUidHwm(idval);
    143                         if (!WBC_ERROR_IS_OK(wbc_status)) {
     271                        ret = dbwrap_store_int32(db, "USER HWM", idval);
     272                        if (ret != 0) {
     273                                d_fprintf(stderr, _("Could not store USER HWM.\n"));
     274                                break;
     275                        }
     276                } else if (sscanf(line, "GROUP HWM %lu", &idval) == 1) {
     277                        ret = dbwrap_store_int32(db, "GROUP HWM", idval);
     278                        if (ret != 0) {
    144279                                d_fprintf(stderr,
    145                                           _("Could not set USER HWM: %s\n"),
    146                                           wbcErrorString(wbc_status));
     280                                          _("Could not store GROUP HWM.\n"));
     281                                break;
    147282                        }
    148                         continue;
    149                 } else if (sscanf(line, "GROUP HWM %lu", &idval) == 1) {
    150                         /* set gid hwm */
    151                         wbc_status = wbcSetGidHwm(idval);
    152                         if (!WBC_ERROR_IS_OK(wbc_status)) {
    153                                 d_fprintf(stderr,
    154                                           _("Could not set GROUP HWM: %s\n"),
    155                                           wbcErrorString(wbc_status));
    156                         }
    157                         continue;
    158283                } else {
    159284                        d_fprintf(stderr, _("ignoring invalid line [%s]\n"),
     
    161286                        continue;
    162287                }
    163 
    164                 wbc_status = wbcStringToSid(sid_string, &sid);
    165                 if (!WBC_ERROR_IS_OK(wbc_status)) {
    166                         d_fprintf(stderr, _("ignoring invalid sid [%s]: %s\n"),
    167                                   sid_string, wbcErrorString(wbc_status));
    168                         continue;
    169                 }
    170 
    171                 if (type == ID_TYPE_UID) {
    172                         wbc_status = wbcSetUidMapping(idval, &sid);
    173                 } else {
    174                         wbc_status = wbcSetGidMapping(idval, &sid);
    175                 }
    176                 if (!WBC_ERROR_IS_OK(wbc_status)) {
    177                         d_fprintf(stderr,
    178                                   _("Could not set mapping of %s %lu to sid %s: %s\n"),
    179                                  (type == ID_TYPE_GID) ? "GID" : "UID",
    180                                  idval, sid_string,
    181                                  wbcErrorString(wbc_status));
    182                         continue;
    183                 }
    184         }
    185 
    186         if (input != stdin) {
     288        }
     289
     290        if (ret == 0) {
     291                if(db->transaction_commit(db) != 0) {
     292                        d_fprintf(stderr, _("Failed to commit transaction.\n"));
     293                        ret = -1;
     294                }
     295        } else {
     296                if (db->transaction_cancel(db) != 0) {
     297                        d_fprintf(stderr, _("Failed to cancel transaction.\n"));
     298                }
     299        }
     300
     301done:
     302        if ((input != NULL) && (input != stdin)) {
    187303                fclose(input);
    188304        }
    189305
    190         talloc_free(ctx);
    191         return 0;
     306        talloc_free(mem_ctx);
     307        return ret;
     308}
     309
     310static
     311NTSTATUS dbwrap_delete_mapping(struct db_context *db, TDB_DATA key1, bool force)
     312{
     313        TALLOC_CTX* mem_ctx = talloc_tos();
     314        struct db_record *rec1=NULL, *rec2=NULL;
     315        TDB_DATA key2;
     316        bool is_valid_mapping;
     317        NTSTATUS status = NT_STATUS_OK;
     318
     319        rec1 = db->fetch_locked(db, mem_ctx, key1);
     320        if (rec1 == NULL) {
     321                DEBUG(1, ("failed to fetch: %.*s\n", (int)key1.dsize, key1.dptr));
     322                status = NT_STATUS_NO_MEMORY;
     323                goto done;
     324        }
     325        key2 = rec1->value;
     326        if (key2.dptr == NULL) {
     327                DEBUG(1, ("could not find %.*s\n", (int)key1.dsize, key1.dptr));
     328                status = NT_STATUS_NOT_FOUND;
     329                goto done;
     330        }
     331
     332        DEBUG(2, ("mapping: %.*s -> %.*s\n",
     333                  (int)key1.dsize, key1.dptr, (int)key2.dsize, key2.dptr));
     334
     335        rec2 = db->fetch_locked(db, mem_ctx, key2);
     336        if (rec2 == NULL) {
     337                DEBUG(1, ("failed to fetch: %.*s\n", (int)key2.dsize, key2.dptr));
     338                status = NT_STATUS_NO_MEMORY;
     339                goto done;
     340        }
     341
     342        is_valid_mapping = tdb_data_equal(key1, rec2->value);
     343
     344        if (!is_valid_mapping) {
     345                DEBUG(1, ("invalid mapping: %.*s -> %.*s -> %.*s\n",
     346                          (int)key1.dsize, key1.dptr, (int)key2.dsize, key2.dptr,
     347                          (int)rec2->value.dsize, rec2->value.dptr ));
     348                if ( !force ) {
     349                        status = NT_STATUS_FILE_INVALID;
     350                        goto done;
     351                }
     352        }
     353
     354        status = rec1->delete_rec(rec1);
     355        if (!NT_STATUS_IS_OK(status)) {
     356                DEBUG(1, ("failed to delete: %.*s\n", (int)key1.dsize, key1.dptr));
     357                goto done;
     358        }
     359
     360        if (is_valid_mapping) {
     361                status = rec2->delete_rec(rec2);
     362                if (!NT_STATUS_IS_OK(status)) {
     363                        DEBUG(1, ("failed to delete: %.*s\n", (int)key2.dsize, key2.dptr));
     364                }
     365        }
     366done:
     367        TALLOC_FREE(rec1);
     368        TALLOC_FREE(rec2);
     369        return status;
     370}
     371
     372static
     373NTSTATUS delete_mapping_action(struct db_context *db, void* data)
     374{
     375        return dbwrap_delete_mapping(db, *(TDB_DATA*)data, false);
     376}
     377static
     378NTSTATUS delete_mapping_action_force(struct db_context *db, void* data)
     379{
     380        return dbwrap_delete_mapping(db, *(TDB_DATA*)data, true);
    192381}
    193382
     
    195384 Delete a SID mapping from a winbindd_idmap.tdb
    196385 **********************************************************/
     386static bool delete_args_ok(int argc, const char **argv)
     387{
     388        if (argc != 1)
     389                return false;
     390        if (strncmp(argv[0], "S-", 2) == 0)
     391                return true;
     392        if (strncmp(argv[0], "GID ", 4) == 0)
     393                return true;
     394        if (strncmp(argv[0], "UID ", 4) == 0)
     395                return true;
     396        return false;
     397}
     398
    197399static int net_idmap_delete(struct net_context *c, int argc, const char **argv)
     400{
     401        int ret = -1;
     402        struct db_context *db;
     403        TALLOC_CTX *mem_ctx;
     404        TDB_DATA key;
     405        NTSTATUS status;
     406        const char* dbfile;
     407
     408        if ( !delete_args_ok(argc,argv) || c->display_usage) {
     409                d_printf("%s\n%s",
     410                         _("Usage:"),
     411                         _("net idmap delete [-f] [--db=<TDB>] <ID>\n"
     412                           "  Delete mapping of ID from TDB.\n"
     413                           "    -f\tforce\n"
     414                           "    TDB\tidmap database\n"
     415                           "    ID\tSID|GID|UID\n"));
     416                return c->display_usage ? 0 : -1;
     417        }
     418
     419        mem_ctx = talloc_stackframe();
     420
     421        dbfile = net_idmap_dbfile(c);
     422        if (dbfile == NULL) {
     423                goto done;
     424        }
     425        d_fprintf(stderr, _("deleting id mapping from %s\n"), dbfile);
     426
     427        db = db_open(mem_ctx, dbfile, 0, TDB_DEFAULT, O_RDWR, 0);
     428        if (db == NULL) {
     429                d_fprintf(stderr, _("Could not open idmap db (%s): %s\n"),
     430                          dbfile, strerror(errno));
     431                goto done;
     432        }
     433
     434        key = string_term_tdb_data(argv[0]);
     435
     436        status = dbwrap_trans_do(db, (c->opt_force
     437                                      ? delete_mapping_action_force
     438                                      : delete_mapping_action),  &key);
     439
     440        if (!NT_STATUS_IS_OK(status)) {
     441                d_fprintf(stderr, _("could not delete mapping: %s\n"),
     442                          nt_errstr(status));
     443                goto done;
     444        }
     445        ret = 0;
     446done:
     447        talloc_free(mem_ctx);
     448        return ret;
     449}
     450
     451static int net_idmap_set(struct net_context *c, int argc, const char **argv)
    198452{
    199453        d_printf("%s\n", _("Not implemented yet"));
    200454        return -1;
    201455}
    202 
    203 static int net_idmap_set(struct net_context *c, int argc, const char **argv)
    204 {
    205         d_printf("%s\n", _("Not implemented yet"));
    206         return -1;
    207 }
    208 bool idmap_store_secret(const char *backend, bool alloc,
    209                         const char *domain, const char *identity,
    210                         const char *secret)
     456static bool idmap_store_secret(const char *backend,
     457                               const char *domain,
     458                               const char *identity,
     459                               const char *secret)
    211460{
    212461        char *tmp;
     
    214463        bool ret;
    215464
    216         if (alloc) {
    217                 r = asprintf(&tmp, "IDMAP_ALLOC_%s", backend);
    218         } else {
    219                 r = asprintf(&tmp, "IDMAP_%s_%s", backend, domain);
    220         }
     465        r = asprintf(&tmp, "IDMAP_%s_%s", backend, domain);
    221466
    222467        if (r < 0) return false;
     
    242487        if (argc != 2 || c->display_usage) {
    243488                d_printf("%s\n%s",
    244                          _("Usage:"),
    245                          _("net idmap secret {<DOMAIN>|alloc} <secret>\n"
    246                            "  Set the secret for the specified domain "
    247                            "(or alloc module)\n"
     489                         _("Usage:\n"),
     490                         _("net idmap secret <DOMAIN> <secret>\n"
     491                           "  Set the secret for the specified domain\n"
    248492                           "    DOMAIN\tDomain to set secret for.\n"
    249                            "    alloc\tSet secret for the alloc module\n"
    250493                           "    secret\tNew secret to set.\n"));
    251494                return c->display_usage?0:-1;
     
    257500        ALLOC_CHECK(ctx);
    258501
    259         if (strcmp(argv[0], "alloc") == 0) {
    260                 domain = NULL;
    261                 backend = lp_idmap_alloc_backend();
    262         } else {
    263                 domain = talloc_strdup(ctx, argv[0]);
    264                 ALLOC_CHECK(domain);
    265 
    266                 opt = talloc_asprintf(ctx, "idmap config %s", domain);
    267                 ALLOC_CHECK(opt);
    268 
    269                 backend = talloc_strdup(ctx, lp_parm_const_string(-1, opt, "backend", "tdb"));
    270                 ALLOC_CHECK(backend);
    271         }
     502        domain = talloc_strdup(ctx, argv[0]);
     503        ALLOC_CHECK(domain);
     504
     505        opt = talloc_asprintf(ctx, "idmap config %s", domain);
     506        ALLOC_CHECK(opt);
     507
     508        backend = talloc_strdup(ctx, lp_parm_const_string(-1, opt, "backend", "tdb"));
     509        ALLOC_CHECK(backend);
    272510
    273511        if ( ( ! backend) || ( ! strequal(backend, "ldap"))) {
     
    278516        }
    279517
    280         if (domain) {
    281 
    282                 dn = lp_parm_const_string(-1, opt, "ldap_user_dn", NULL);
    283                 if ( ! dn) {
    284                         d_fprintf(stderr,
    285                                   _("Missing ldap_user_dn option for domain "
    286                                     "%s\n"), domain);
    287                         talloc_free(ctx);
    288                         return -1;
    289                 }
    290 
    291                 ret = idmap_store_secret("ldap", false, domain, dn, secret);
    292         } else {
    293                 dn = lp_parm_const_string(-1, "idmap alloc config", "ldap_user_dn", NULL);
    294                 if ( ! dn) {
    295                         d_fprintf(stderr,
    296                                   _("Missing ldap_user_dn option for alloc "
    297                                     "backend\n"));
    298                         talloc_free(ctx);
    299                         return -1;
    300                 }
    301 
    302                 ret = idmap_store_secret("ldap", true, NULL, dn, secret);
    303         }
     518        dn = lp_parm_const_string(-1, opt, "ldap_user_dn", NULL);
     519        if ( ! dn) {
     520                d_fprintf(stderr,
     521                          _("Missing ldap_user_dn option for domain %s\n"),
     522                          domain);
     523                talloc_free(ctx);
     524                return -1;
     525        }
     526
     527        ret = idmap_store_secret("ldap", domain, dn, secret);
    304528
    305529        if ( ! ret) {
     
    313537}
    314538
    315 int net_help_idmap(struct net_context *c, int argc, const char **argv)
    316 {
    317         d_printf(_("net idmap dump <inputfile>\n"
    318                    "    Dump current id mapping\n"));
    319 
    320         d_printf(_("net idmap restore\n"
    321                    "    Restore entries from stdin\n"));
    322 
    323         /* Deliberately *not* document net idmap delete */
    324 
    325         d_printf(_("net idmap secret <DOMAIN>|alloc <secret>\n"
    326                    "    Set the secret for the specified DOMAIN (or the alloc "
    327                    "module)\n"));
    328 
    329         return -1;
     539static int net_idmap_check(struct net_context *c, int argc, const char **argv)
     540{
     541        const char* dbfile;
     542        struct check_options opts;
     543
     544        if ( argc > 1 || c->display_usage) {
     545                d_printf("%s\n%s",
     546                         _("Usage:"),
     547                         _("net idmap check  [-v] [-r] [-a] [-T] [-f] [-l] [[--db=]<TDB>]\n"
     548                           "  Check an idmap database.\n"
     549                           "    --verbose,-v\tverbose\n"
     550                           "    --repair,-r\trepair\n"
     551                           "    --auto,-a\tnoninteractive mode\n"
     552                           "    --test,-T\tdry run\n"
     553                           "    --fore,-f\tforce\n"
     554                           "    --lock,-l\tlock db while doing the check\n"
     555                           "    TDB\tidmap database\n"));
     556                return c->display_usage ? 0 : -1;
     557        }
     558
     559        dbfile = (argc > 0) ? argv[0] : net_idmap_dbfile(c);
     560        if (dbfile == NULL) {
     561                return -1;
     562        }
     563        d_fprintf(stderr, _("check database: %s\n"), dbfile);
     564
     565        opts = (struct check_options) {
     566                .lock = c->opt_lock || c->opt_long_list_entries,
     567                .test = c->opt_testmode,
     568                .automatic = c->opt_auto,
     569                .verbose = c->opt_verbose,
     570                .force = c->opt_force,
     571                .repair = c->opt_repair || c->opt_reboot,
     572        };
     573
     574        return net_idmap_check_db(dbfile, &opts);
    330575}
    331576
     
    334579        TALLOC_CTX *mem_ctx;
    335580        int result = -1;
    336         DOM_SID src_sid, dst_sid;
     581        struct dom_sid src_sid, dst_sid;
    337582        char *src, *dst;
    338583        struct db_context *db;
     
    428673                        net_idmap_delete,
    429674                        NET_TRANSPORT_LOCAL,
    430                         N_("Not implemented yet"),
    431                         N_("net idmap delete\n"
    432                            "  Not implemented yet")
     675                        N_("Delete ID mapping"),
     676                        N_("net idmap delete <ID>\n"
     677                           "  Delete ID mapping")
    433678                },
    434679                {
     
    437682                        NET_TRANSPORT_LOCAL,
    438683                        N_("Set secret for specified domain"),
    439                         N_("net idmap secret {<DOMAIN>|alloc} <secret>\n"
    440                            "  Set secret for specified domain or alloc module")
     684                        N_("net idmap secret <DOMAIN> <secret>\n"
     685                           "  Set secret for specified domain")
    441686                },
    442687                {
     
    448693                           "  Set acl map")
    449694                },
     695                {
     696                        "check",
     697                        net_idmap_check,
     698                        NET_TRANSPORT_LOCAL,
     699                        N_("Check id mappings"),
     700                        N_("net idmap check\n"
     701                           "  Check id mappings")
     702                },
    450703                {NULL, NULL, 0, NULL, NULL}
    451704        };
  • vendor/current/source3/utils/net_lookup.c

    r414 r740  
    1919#include "includes.h"
    2020#include "utils/net.h"
     21#include "libads/sitename_cache.h"
     22#include "libads/dns.h"
     23#include "../librpc/gen_ndr/ndr_netlogon.h"
     24#include "smb_krb5.h"
     25#include "../libcli/security/security.h"
     26#include "passdb/lookup_sid.h"
    2127
    2228int net_lookup_usage(struct net_context *c, int argc, const char **argv)
     
    320326{
    321327        const char *dom, *name;
    322         DOM_SID sid;
     328        struct dom_sid sid;
    323329        enum lsa_SidType type;
    324330
     
    344350{
    345351        const char *dom, *name;
    346         DOM_SID sid;
     352        struct dom_sid sid;
    347353        enum lsa_SidType type;
    348354
     
    406412        }
    407413
    408         status = dsgetdcname(mem_ctx, NULL, domain_name, NULL, site_name,
     414        if (!c->msg_ctx) {
     415                d_fprintf(stderr, _("Could not initialise message context. "
     416                        "Try running as root\n"));
     417                return -1;
     418        }
     419
     420        status = dsgetdcname(mem_ctx, c->msg_ctx, domain_name, NULL, site_name,
    409421                             flags, &info);
    410422        if (!NT_STATUS_IS_OK(status)) {
  • vendor/current/source3/utils/net_proto.h

    r427 r740  
    2424#define _NET_PROTO_H_
    2525
    26 
    27 /* The following definitions come from auth/token_util.c  */
    28 
    29 bool nt_token_check_sid ( const DOM_SID *sid, const NT_USER_TOKEN *token );
    30 bool nt_token_check_domain_rid( NT_USER_TOKEN *token, uint32 rid );
    31 NT_USER_TOKEN *get_root_nt_token( void );
    32 NTSTATUS add_aliases(const DOM_SID *domain_sid,
    33                      struct nt_user_token *token);
    34 struct nt_user_token *create_local_nt_token(TALLOC_CTX *mem_ctx,
    35                                             const DOM_SID *user_sid,
    36                                             bool is_guest,
    37                                             int num_groupsids,
    38                                             const DOM_SID *groupsids);
    39 void debug_nt_user_token(int dbg_class, int dbg_lev, NT_USER_TOKEN *token);
    40 void debug_unix_user_token(int dbg_class, int dbg_lev, uid_t uid, gid_t gid,
    41                            int n_groups, gid_t *groups);
     26#include "libads/ads_status.h"
    4227
    4328/* The following definitions come from utils/net.c  */
     
    4631
    4732/* The following definitions come from utils/net_ads.c  */
    48 
    49 ADS_STATUS ads_startup(struct net_context *c, bool only_own_domain, ADS_STRUCT **ads);
    50 ADS_STATUS ads_startup_nobind(struct net_context *c, bool only_own_domain, ADS_STRUCT **ads);
     33struct ads_struct;
     34ADS_STATUS ads_startup(struct net_context *c, bool only_own_domain, struct ads_struct **ads);
     35ADS_STATUS ads_startup_nobind(struct net_context *c, bool only_own_domain, struct ads_struct **ads);
    5136int net_ads_check_our_domain(struct net_context *c);
    5237int net_ads_check(struct net_context *c);
     
    10388/* The following definitions come from utils/net_idmap.c  */
    10489
    105 bool idmap_store_secret(const char *backend, bool alloc,
    106                         const char *domain, const char *identity,
    107                         const char *secret);
    108 int net_help_idmap(struct net_context *c, int argc, const char **argv);
    10990int net_idmap(struct net_context *c, int argc, const char **argv);
    11091
     
    155136
    156137NTSTATUS net_get_remote_domain_sid(struct cli_state *cli, TALLOC_CTX *mem_ctx,
    157                                    DOM_SID **domain_sid,
     138                                   struct dom_sid **domain_sid,
    158139                                   const char **domain_name);
    159140int run_rpc_command(struct net_context *c,
     
    167148int net_rpc_join(struct net_context *c, int argc, const char **argv);
    168149NTSTATUS rpc_info_internals(struct net_context *c,
    169                         const DOM_SID *domain_sid,
     150                        const struct dom_sid *domain_sid,
    170151                        const char *domain_name,
    171152                        struct cli_state *cli,
     
    194175int net_rpc_file(struct net_context *c, int argc, const char **argv);
    195176NTSTATUS rpc_init_shutdown_internals(struct net_context *c,
    196                                      const DOM_SID *domain_sid,
     177                                     const struct dom_sid *domain_sid,
    197178                                     const char *domain_name,
    198179                                     struct cli_state *cli,
     
    202183                                     const char **argv);
    203184NTSTATUS rpc_reg_shutdown_internals(struct net_context *c,
    204                                     const DOM_SID *domain_sid,
     185                                    const struct dom_sid *domain_sid,
    205186                                    const char *domain_name,
    206187                                    struct cli_state *cli,
     
    243224                       bool copy_timestamps, bool is_file);
    244225NTSTATUS rpc_printer_list_internals(struct net_context *c,
    245                                         const DOM_SID *domain_sid,
     226                                        const struct dom_sid *domain_sid,
    246227                                        const char *domain_name,
    247228                                        struct cli_state *cli,
     
    251232                                        const char **argv);
    252233NTSTATUS rpc_printer_driver_list_internals(struct net_context *c,
    253                                                 const DOM_SID *domain_sid,
     234                                                const struct dom_sid *domain_sid,
    254235                                                const char *domain_name,
    255236                                                struct cli_state *cli,
     
    259240                                                const char **argv);
    260241NTSTATUS rpc_printer_publish_publish_internals(struct net_context *c,
    261                                                 const DOM_SID *domain_sid,
     242                                                const struct dom_sid *domain_sid,
    262243                                                const char *domain_name,
    263244                                                struct cli_state *cli,
     
    267248                                                const char **argv);
    268249NTSTATUS rpc_printer_publish_unpublish_internals(struct net_context *c,
    269                                                 const DOM_SID *domain_sid,
     250                                                const struct dom_sid *domain_sid,
    270251                                                const char *domain_name,
    271252                                                struct cli_state *cli,
     
    275256                                                const char **argv);
    276257NTSTATUS rpc_printer_publish_update_internals(struct net_context *c,
    277                                                 const DOM_SID *domain_sid,
     258                                                const struct dom_sid *domain_sid,
    278259                                                const char *domain_name,
    279260                                                struct cli_state *cli,
     
    283264                                                const char **argv);
    284265NTSTATUS rpc_printer_publish_list_internals(struct net_context *c,
    285                                                 const DOM_SID *domain_sid,
     266                                                const struct dom_sid *domain_sid,
    286267                                                const char *domain_name,
    287268                                                struct cli_state *cli,
     
    291272                                                const char **argv);
    292273NTSTATUS rpc_printer_migrate_security_internals(struct net_context *c,
    293                                                 const DOM_SID *domain_sid,
     274                                                const struct dom_sid *domain_sid,
    294275                                                const char *domain_name,
    295276                                                struct cli_state *cli,
     
    299280                                                const char **argv);
    300281NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c,
    301                                                 const DOM_SID *domain_sid,
     282                                                const struct dom_sid *domain_sid,
    302283                                                const char *domain_name,
    303284                                                struct cli_state *cli,
     
    307288                                                const char **argv);
    308289NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c,
    309                                                 const DOM_SID *domain_sid,
     290                                                const struct dom_sid *domain_sid,
    310291                                                const char *domain_name,
    311292                                                struct cli_state *cli,
     
    315296                                                const char **argv);
    316297NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c,
    317                                                 const DOM_SID *domain_sid,
     298                                                const struct dom_sid *domain_sid,
    318299                                                const char *domain_name,
    319300                                                struct cli_state *cli,
     
    323304                                                const char **argv);
    324305NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c,
    325                                                 const DOM_SID *domain_sid,
     306                                                const struct dom_sid *domain_sid,
    326307                                                const char *domain_name,
    327308                                                struct cli_state *cli,
     
    344325
    345326NTSTATUS rpc_samdump_internals(struct net_context *c,
    346                                 const DOM_SID *domain_sid,
     327                                const struct dom_sid *domain_sid,
    347328                                const char *domain_name,
    348329                                struct cli_state *cli,
     
    352333                                const char **argv);
    353334int rpc_vampire_usage(struct net_context *c, int argc, const char **argv);
    354 NTSTATUS rpc_vampire_internals(struct net_context *c,
    355                                 const DOM_SID *domain_sid,
    356                                 const char *domain_name,
    357                                 struct cli_state *cli,
    358                                 struct rpc_pipe_client *pipe_hnd,
    359                                 TALLOC_CTX *mem_ctx,
    360                                 int argc,
    361                                 const char **argv);
    362335int rpc_vampire_passdb(struct net_context *c, int argc, const char **argv);
    363336int rpc_vampire_ldif(struct net_context *c, int argc, const char **argv);
    364 NTSTATUS rpc_vampire_ldif_internals(struct net_context *c,
    365                                     const DOM_SID *domain_sid,
    366                                     const char *domain_name,
    367                                     struct cli_state *cli,
    368                                     struct rpc_pipe_client *pipe_hnd,
    369                                     TALLOC_CTX *mem_ctx,
    370                                     int argc,
    371                                     const char **argv);
    372 NTSTATUS rpc_vampire_keytab_internals(struct net_context *c,
    373                                       const DOM_SID *domain_sid,
    374                                       const char *domain_name,
    375                                       struct cli_state *cli,
    376                                       struct rpc_pipe_client *pipe_hnd,
    377                                       TALLOC_CTX *mem_ctx,
    378                                       int argc,
    379                                       const char **argv);
    380337int rpc_vampire_keytab(struct net_context *c, int argc, const char **argv);
    381338
     
    428385int net_eventlog(struct net_context *c, int argc, const char **argv);
    429386
     387/* The following definitions come from utils/net_printing.c  */
     388
     389int net_printing(struct net_context *c, int argc, const char **argv);
     390
     391/* The following definitions come from utils/net_serverid.c  */
     392
     393int net_serverid(struct net_context *c, int argc, const char **argv);
     394
    430395/* The following definitions come from utils/net_util.c  */
    431396
     
    433398                             TALLOC_CTX *mem_ctx, struct cli_state *cli,
    434399                             const char *name, const char **ret_domain,
    435                              const char **ret_name, DOM_SID *ret_sid,
     400                             const char **ret_name, struct dom_sid *ret_sid,
    436401                             enum lsa_SidType *ret_type);
    437402NTSTATUS connect_to_service(struct net_context *c,
     
    487452NTSTATUS net_lookup_name_from_sid(struct net_context *c,
    488453                                TALLOC_CTX *ctx,
    489                                 DOM_SID *psid,
     454                                struct dom_sid *psid,
    490455                                const char **ppdomain,
    491456                                const char **ppname);
    492457NTSTATUS net_lookup_sid_from_name(struct net_context *c, TALLOC_CTX *ctx,
    493                                   const char *full_name, DOM_SID *pret_sid);
     458                                  const char *full_name, struct dom_sid *pret_sid);
    494459
    495460/* The following definitions come from utils/passwd_util.c  */
     
    501466int net_g_lock(struct net_context *c, int argc, const char **argv);
    502467
     468/* The following definitions come from utils/net_rpc_trust.c  */
     469int net_rpc_trust(struct net_context *c, int argc, const char **argv);
     470
    503471#endif /*  _NET_PROTO_H_  */
  • vendor/current/source3/utils/net_rap.c

    r414 r740  
    2424
    2525#include "includes.h"
     26#include "../librpc/gen_ndr/rap.h"
     27#include "../librpc/gen_ndr/svcctl.h"
    2628#include "utils/net.h"
     29#include "libsmb/libsmb.h"
     30#include "libsmb/clirap.h"
    2731
    2832/* The following messages were for error checking that is not properly
     
    227231        int ret;
    228232
    229         RAP_SHARE_INFO_2 sinfo;
     233        struct rap_share_info_2 sinfo;
    230234        char *p;
    231235        char *sharename;
     
    246250        }
    247251        *p = 0;
    248         strlcpy(sinfo.share_name, sharename, sizeof(sinfo.share_name));
     252        strlcpy((char *)sinfo.share_name, sharename, sizeof(sinfo.share_name));
    249253        sinfo.reserved1 = '\0';
    250254        sinfo.share_type = 0;
    251         sinfo.comment = smb_xstrdup(c->opt_comment);
     255        sinfo.comment = c->opt_comment ? smb_xstrdup(c->opt_comment) : "";
    252256        sinfo.perms = 0;
    253257        sinfo.maximum_users = c->opt_maxusers;
     
    813817        struct cli_state *cli;
    814818        int ret;
    815         RAP_USER_INFO_1 userinfo;
     819        struct rap_user_info_1 userinfo;
    816820
    817821        if (argc == 0 || c->display_usage) {
     
    822826                return -1;
    823827
    824         safe_strcpy(userinfo.user_name, argv[0], sizeof(userinfo.user_name)-1);
    825         if (c->opt_flags == -1)
     828        safe_strcpy((char *)userinfo.user_name, argv[0], sizeof(userinfo.user_name)-1);
     829        if (c->opt_flags == 0)
    826830                c->opt_flags = 0x21;
    827831
     
    957961        struct cli_state *cli;
    958962        int ret;
    959         RAP_GROUP_INFO_1 grinfo;
     963        struct rap_group_info_1 grinfo;
    960964
    961965        if (argc == 0 || c->display_usage) {
     
    967971
    968972        /* BB check for length 21 or smaller explicitly ? BB */
    969         safe_strcpy(grinfo.group_name, argv[0], sizeof(grinfo.group_name)-1);
     973        safe_strcpy((char *)grinfo.group_name, argv[0], sizeof(grinfo.group_name)-1);
    970974        grinfo.reserved1 = '\0';
    971975        grinfo.comment = smb_xstrdup(c->opt_comment ? c->opt_comment : "");
  • vendor/current/source3/utils/net_registry.c

    r414 r740  
    2121
    2222#include "includes.h"
     23#include "registry.h"
     24#include "registry/reg_api.h"
     25#include "registry/reg_util_token.h"
     26#include "registry/reg_init_basic.h"
    2327#include "utils/net.h"
    2428#include "utils/net_registry_util.h"
    25 
     29#include "include/g_lock.h"
     30#include "registry/reg_backend_db.h"
     31#include "registry/reg_import.h"
     32#include "registry/reg_format.h"
     33#include <assert.h>
     34#include "../libcli/security/display_sec.h"
     35#include "../libcli/security/sddl.h"
     36#include "../libcli/registry/util_reg.h"
     37#include "passdb/machine_sid.h"
    2638
    2739/*
     
    4052{
    4153        WERROR werr;
    42         NT_USER_TOKEN *token = NULL;
     54        struct security_token *token = NULL;
    4355        char *hivename = NULL;
    4456        char *tmp_subkeyname = NULL;
     
    111123}
    112124
    113 /*
    114  *
    115  * the main "net registry" function implementations
    116  *
    117  */
    118 
    119 static int net_registry_enumerate(struct net_context *c, int argc,
    120                                   const char **argv)
    121 {
    122         WERROR werr;
    123         struct registry_key *key = NULL;
    124         TALLOC_CTX *ctx = talloc_stackframe();
    125         char *subkey_name;
     125static WERROR registry_enumkey(struct registry_key* parent, const char* keyname, bool recursive)
     126{
     127        WERROR werr;
     128        TALLOC_CTX *ctx = talloc_stackframe();
     129        char*  subkey_name;
    126130        NTTIME modtime;
    127131        uint32_t count;
    128         char *valname = NULL;
     132        char* valname = NULL;
    129133        struct registry_value *valvalue = NULL;
    130         int ret = -1;
    131 
    132         if (argc != 1 || c->display_usage) {
    133                 d_printf("%s\n%s",
    134                          _("Usage:"),
    135                          _("net registry enumerate <path>\n"));
    136                 d_printf("%s\n%s",
    137                          _("Example:"),
    138                          _("net registry enumerate 'HKLM\\Software\\Samba'\n"));
    139                 goto done;
    140         }
    141 
    142         werr = open_key(ctx, argv[0], REG_KEY_READ, &key);
    143         if (!W_ERROR_IS_OK(werr)) {
    144                 d_fprintf(stderr, _("open_key failed: %s\n"), win_errstr(werr));
    145                 goto done;
    146         }
    147 
    148         for (count = 0;
    149              werr = reg_enumkey(ctx, key, count, &subkey_name, &modtime),
    150              W_ERROR_IS_OK(werr);
    151              count++)
    152         {
    153                 print_registry_key(subkey_name, &modtime);
    154         }
    155         if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
    156                 goto done;
     134        struct registry_key* key = NULL;
     135
     136        werr = reg_openkey(ctx, parent, keyname, REG_KEY_READ, &key);
     137        if (!W_ERROR_IS_OK(werr)) {
     138                goto done;
     139        }
     140
     141        if (recursive) {
     142                printf("[%s]\n\n", key->key->name);
     143        } else {
     144                for (count = 0;
     145                     werr = reg_enumkey(ctx, key, count, &subkey_name, &modtime),
     146                     W_ERROR_IS_OK(werr);
     147                     count++)
     148                {
     149                        print_registry_key(subkey_name, &modtime);
     150                }
     151                if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
     152                        goto done;
     153                }
    157154        }
    158155
     
    168165        }
    169166
    170         ret = 0;
    171 done:
    172         TALLOC_FREE(ctx);
    173         return ret;
    174 }
     167        if (!recursive) {
     168                werr = WERR_OK;
     169                goto done;
     170        }
     171
     172        for (count = 0;
     173             werr = reg_enumkey(ctx, key, count, &subkey_name, &modtime),
     174             W_ERROR_IS_OK(werr);
     175             count++)
     176        {
     177                werr = registry_enumkey(key, subkey_name, recursive);
     178                if (!W_ERROR_IS_OK(werr)) {
     179                        goto done;
     180                }
     181        }
     182        if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
     183                goto done;
     184        }
     185
     186        werr = WERR_OK;
     187
     188done:
     189        TALLOC_FREE(ctx);
     190        return werr;
     191}
     192
     193
     194
     195/*
     196 *
     197 * the main "net registry" function implementations
     198 *
     199 */
     200static int net_registry_enumerate(struct net_context *c, int argc,
     201                                  const char **argv)
     202{
     203        WERROR werr;
     204        struct registry_key *key = NULL;
     205        char* name = NULL;
     206        TALLOC_CTX *ctx = talloc_stackframe();
     207        int ret = -1;
     208
     209        if (argc != 1 || c->display_usage) {
     210                d_printf("%s\n%s",
     211                         _("Usage:"),
     212                         _("net registry enumerate <path>\n"));
     213                d_printf("%s\n%s",
     214                         _("Example:"),
     215                         _("net registry enumerate 'HKLM\\Software\\Samba'\n"));
     216                goto done;
     217        }
     218
     219        werr = open_hive(ctx, argv[0], REG_KEY_READ, &key, &name);
     220        if (!W_ERROR_IS_OK(werr)) {
     221                d_fprintf(stderr, _("open_key failed: %s\n"), win_errstr(werr));
     222                goto done;
     223        }
     224
     225        werr = registry_enumkey(key, name, c->opt_reboot);
     226        if (W_ERROR_IS_OK(werr)) {
     227                ret = 0;
     228        }
     229done:
     230        TALLOC_FREE(ctx);
     231        return ret;
     232}
     233
     234static int net_registry_enumerate_recursive(struct net_context *c, int argc,
     235                                            const char **argv)
     236{
     237        WERROR werr;
     238        struct registry_key *key = NULL;
     239        char* name = NULL;
     240        TALLOC_CTX *ctx = talloc_stackframe();
     241        int ret = -1;
     242
     243        if (argc != 1 || c->display_usage) {
     244                d_printf("%s\n%s",
     245                         _("Usage:"),
     246                         _("net registry enumerate <path>\n"));
     247                d_printf("%s\n%s",
     248                         _("Example:"),
     249                         _("net registry enumerate 'HKLM\\Software\\Samba'\n"));
     250                goto done;
     251        }
     252
     253        werr = open_hive(ctx, argv[0], REG_KEY_READ, &key, &name);
     254        if (!W_ERROR_IS_OK(werr)) {
     255                d_fprintf(stderr, _("open_key failed: %s\n"), win_errstr(werr));
     256                goto done;
     257        }
     258
     259        werr = registry_enumkey(key, name, true);
     260        if (W_ERROR_IS_OK(werr)) {
     261                ret = 0;
     262        }
     263done:
     264        TALLOC_FREE(ctx);
     265        return ret;
     266}
     267
    175268
    176269static int net_registry_createkey(struct net_context *c, int argc,
     
    233326}
    234327
    235 static int net_registry_deletekey(struct net_context *c, int argc,
    236                                   const char **argv)
     328static int net_registry_deletekey_internal(struct net_context *c, int argc,
     329                                           const char **argv,
     330                                           bool recursive)
    237331{
    238332        WERROR werr;
     
    264358        }
    265359
    266         werr = reg_deletekey(hivekey, subkeyname);
    267         if (!W_ERROR_IS_OK(werr)) {
     360        if (recursive) {
     361                werr = reg_deletekey_recursive(hivekey, subkeyname);
     362        } else {
     363                werr = reg_deletekey(hivekey, subkeyname);
     364        }
     365        if (!W_ERROR_IS_OK(werr) &&
     366            !(c->opt_force && W_ERROR_EQUAL(werr, WERR_BADFILE)))
     367        {
    268368                d_fprintf(stderr, "reg_deletekey %s: %s\n", _("failed"),
    269369                          win_errstr(werr));
     
    276376        TALLOC_FREE(ctx);
    277377        return ret;
     378}
     379
     380static int net_registry_deletekey(struct net_context *c, int argc,
     381                                  const char **argv)
     382{
     383        return net_registry_deletekey_internal(c, argc, argv, false);
     384}
     385
     386static int net_registry_deletekey_recursive(struct net_context *c, int argc,
     387                                            const char **argv)
     388{
     389        return net_registry_deletekey_internal(c, argc, argv, true);
    278390}
    279391
     
    290402                d_fprintf(stderr, "%s\n%s",
    291403                          _("Usage:"),
    292                           _("net rpc registry getvalue <key> <valuename>\n"));
     404                          _("net registry getvalue <key> <valuename>\n"));
    293405                goto done;
    294406        }
     
    326438{
    327439        return net_registry_getvalue_internal(c, argc, argv, true);
     440}
     441
     442static int net_registry_getvaluesraw(struct net_context *c, int argc,
     443                                     const char **argv)
     444{
     445        WERROR werr;
     446        int ret = -1;
     447        struct registry_key *key = NULL;
     448        TALLOC_CTX *ctx = talloc_stackframe();
     449        uint32_t idx;
     450
     451        if (argc != 1 || c->display_usage) {
     452                d_fprintf(stderr, "usage: net rpc registry getvaluesraw "
     453                          "<key>\n");
     454                goto done;
     455        }
     456
     457        werr = open_key(ctx, argv[0], REG_KEY_READ, &key);
     458        if (!W_ERROR_IS_OK(werr)) {
     459                d_fprintf(stderr, "open_key failed: %s\n", win_errstr(werr));
     460                goto done;
     461        }
     462
     463        idx = 0;
     464        while (true) {
     465                struct registry_value *val;
     466
     467                werr = reg_enumvalue(talloc_tos(), key, idx, NULL, &val);
     468
     469                if (W_ERROR_EQUAL(werr, WERR_NO_MORE_ITEMS)) {
     470                        ret = 0;
     471                        break;
     472                }
     473                if (!W_ERROR_IS_OK(werr)) {
     474                        break;
     475                }
     476                print_registry_value(val, true);
     477                TALLOC_FREE(val);
     478                idx += 1;
     479        }
     480done:
     481        TALLOC_FREE(ctx);
     482        return ret;
    328483}
    329484
     
    340495                d_fprintf(stderr, "%s\n%s",
    341496                          _("Usage:"),
    342                           _("net rpc registry setvalue <key> <valuename> "
     497                          _("net registry setvalue <key> <valuename> "
    343498                            "<type> [<val>]+\n"));
    344499                goto done;
     
    351506
    352507        if (strequal(argv[2], "dword")) {
     508                uint32_t v = strtoul(argv[3], NULL, 10);
    353509                value.type = REG_DWORD;
    354                 value.v.dword = strtoul(argv[3], NULL, 10);
     510                value.data = data_blob_talloc(ctx, NULL, 4);
     511                SIVAL(value.data.data, 0, v);
    355512        } else if (strequal(argv[2], "sz")) {
    356513                value.type = REG_SZ;
    357                 value.v.sz.len = strlen(argv[3])+1;
    358                 value.v.sz.str = CONST_DISCARD(char *, argv[3]);
     514                if (!push_reg_sz(ctx, &value.data, argv[3])) {
     515                        goto done;
     516                }
    359517        } else if (strequal(argv[2], "multi_sz")) {
     518                const char **array;
     519                int count = argc - 3;
     520                int i;
    360521                value.type = REG_MULTI_SZ;
    361                 value.v.multi_sz.num_strings = argc - 3;
    362                 value.v.multi_sz.strings = (char **)(argv + 3);
     522                array = talloc_zero_array(ctx, const char *, count + 1);
     523                if (array == NULL) {
     524                        goto done;
     525                }
     526                for (i=0; i < count; i++) {
     527                        array[i] = talloc_strdup(array, argv[count+i]);
     528                        if (array[i] == NULL) {
     529                                goto done;
     530                        }
     531                }
     532                if (!push_reg_multi_sz(ctx, &value.data, array)) {
     533                        goto done;
     534                }
    363535        } else {
    364536                d_fprintf(stderr, _("type \"%s\" not implemented\n"), argv[2]);
     
    383555done:
    384556        TALLOC_FREE(ctx);
     557        return ret;
     558}
     559
     560struct net_registry_increment_state {
     561        const char *keyname;
     562        const char *valuename;
     563        uint32_t increment;
     564        uint32_t newvalue;
     565        WERROR werr;
     566};
     567
     568static void net_registry_increment_fn(void *private_data)
     569{
     570        struct net_registry_increment_state *state =
     571                (struct net_registry_increment_state *)private_data;
     572        struct registry_value *value;
     573        struct registry_key *key = NULL;
     574        uint32_t v;
     575
     576        state->werr = open_key(talloc_tos(), state->keyname,
     577                               REG_KEY_READ|REG_KEY_WRITE, &key);
     578        if (!W_ERROR_IS_OK(state->werr)) {
     579                d_fprintf(stderr, _("open_key failed: %s\n"),
     580                          win_errstr(state->werr));
     581                goto done;
     582        }
     583
     584        state->werr = reg_queryvalue(key, key, state->valuename, &value);
     585        if (!W_ERROR_IS_OK(state->werr)) {
     586                d_fprintf(stderr, _("reg_queryvalue failed: %s\n"),
     587                          win_errstr(state->werr));
     588                goto done;
     589        }
     590
     591        if (value->type != REG_DWORD) {
     592                d_fprintf(stderr, _("value not a DWORD: %s\n"),
     593                          str_regtype(value->type));
     594                goto done;
     595        }
     596
     597        if (value->data.length < 4) {
     598                d_fprintf(stderr, _("value too short for regular DWORD\n"));
     599                goto done;
     600        }
     601
     602        v = IVAL(value->data.data, 0);
     603        v += state->increment;
     604        state->newvalue = v;
     605
     606        SIVAL(value->data.data, 0, v);
     607
     608        state->werr = reg_setvalue(key, state->valuename, value);
     609        if (!W_ERROR_IS_OK(state->werr)) {
     610                d_fprintf(stderr, _("reg_setvalue failed: %s\n"),
     611                          win_errstr(state->werr));
     612                goto done;
     613        }
     614
     615done:
     616        TALLOC_FREE(key);
     617        return;
     618}
     619
     620static int net_registry_increment(struct net_context *c, int argc,
     621                                  const char **argv)
     622{
     623        struct net_registry_increment_state state;
     624        NTSTATUS status;
     625        int ret = -1;
     626
     627        if (argc < 2 || c->display_usage) {
     628                d_fprintf(stderr, "%s\n%s",
     629                          _("Usage:"),
     630                          _("net registry increment <key> <valuename> "
     631                            "[<increment>]\n"));
     632                goto done;
     633        }
     634
     635        state.keyname = argv[0];
     636        state.valuename = argv[1];
     637
     638        state.increment = 1;
     639        if (argc == 3) {
     640                state.increment = strtoul(argv[2], NULL, 10);
     641        }
     642
     643        status = g_lock_do("registry_increment_lock", G_LOCK_WRITE,
     644                           timeval_set(600, 0), procid_self(),
     645                           net_registry_increment_fn, &state);
     646        if (!NT_STATUS_IS_OK(status)) {
     647                d_fprintf(stderr, _("g_lock_do failed: %s\n"),
     648                          nt_errstr(status));
     649                goto done;
     650        }
     651        if (!W_ERROR_IS_OK(state.werr)) {
     652                d_fprintf(stderr, _("increment failed: %s\n"),
     653                          win_errstr(state.werr));
     654                goto done;
     655        }
     656
     657        d_printf(_("%u\n"), (unsigned)state.newvalue);
     658
     659        ret = 0;
     660
     661done:
    385662        return ret;
    386663}
     
    397674                d_fprintf(stderr, "%s\n%s",
    398675                          _("Usage:"),
    399                           _("net rpc registry deletevalue <key> <valuename>\n"));
     676                          _("net registry deletevalue <key> <valuename>\n"));
    400677                goto done;
    401678        }
     
    409686        werr = reg_deletevalue(key, argv[1]);
    410687        if (!W_ERROR_IS_OK(werr)) {
    411                 d_fprintf(stderr, _("reg_deletekey failed: %s\n"),
     688                d_fprintf(stderr, _("reg_deletevalue failed: %s\n"),
    412689                          win_errstr(werr));
    413690                goto done;
     
    421698}
    422699
    423 static int net_registry_getsd(struct net_context *c, int argc,
    424                               const char **argv)
    425 {
    426         WERROR werr;
    427         int ret = -1;
     700static WERROR net_registry_getsd_internal(struct net_context *c,
     701                                          TALLOC_CTX *mem_ctx,
     702                                          const char *keyname,
     703                                          struct security_descriptor **sd)
     704{
     705        WERROR werr;
    428706        struct registry_key *key = NULL;
    429         struct security_descriptor *secdesc = NULL;
    430707        TALLOC_CTX *ctx = talloc_stackframe();
    431708        uint32_t access_mask = REG_KEY_READ |
     
    439716        access_mask = REG_KEY_READ;
    440717
     718        if (sd == NULL) {
     719                d_fprintf(stderr, _("internal error: invalid argument\n"));
     720                werr = WERR_INVALID_PARAM;
     721                goto done;
     722        }
     723
     724        if (strlen(keyname) == 0) {
     725                d_fprintf(stderr, _("error: zero length key name given\n"));
     726                werr = WERR_INVALID_PARAM;
     727                goto done;
     728        }
     729
     730        werr = open_key(ctx, keyname, access_mask, &key);
     731        if (!W_ERROR_IS_OK(werr)) {
     732                d_fprintf(stderr, "%s%s\n", _("open_key failed: "),
     733                          win_errstr(werr));
     734                goto done;
     735        }
     736
     737        werr = reg_getkeysecurity(mem_ctx, key, sd);
     738        if (!W_ERROR_IS_OK(werr)) {
     739                d_fprintf(stderr, "%s%s\n", _("reg_getkeysecurity failed: "),
     740                          win_errstr(werr));
     741                goto done;
     742        }
     743
     744        werr = WERR_OK;
     745
     746done:
     747        TALLOC_FREE(ctx);
     748        return werr;
     749}
     750
     751static int net_registry_getsd(struct net_context *c, int argc,
     752                              const char **argv)
     753{
     754        WERROR werr;
     755        int ret = -1;
     756        struct security_descriptor *secdesc = NULL;
     757        TALLOC_CTX *ctx = talloc_stackframe();
     758
    441759        if (argc != 1 || c->display_usage) {
    442760                d_printf("%s\n%s",
     
    448766                goto done;
    449767        }
    450         if (strlen(argv[0]) == 0) {
    451                 d_fprintf(stderr, "error: zero length key name given\n");
    452                 goto done;
    453         }
    454 
    455         werr = open_key(ctx, argv[0], access_mask, &key);
     768
     769        werr = net_registry_getsd_internal(c, ctx, argv[0], &secdesc);
     770        if (!W_ERROR_IS_OK(werr)) {
     771                goto done;
     772        }
     773
     774        display_sec_desc(secdesc);
     775
     776        ret = 0;
     777
     778done:
     779        TALLOC_FREE(ctx);
     780        return ret;
     781}
     782
     783static int net_registry_getsd_sddl(struct net_context *c,
     784                                   int argc, const char **argv)
     785{
     786        WERROR werr;
     787        int ret = -1;
     788        struct security_descriptor *secdesc = NULL;
     789        TALLOC_CTX *ctx = talloc_stackframe();
     790
     791        if (argc != 1 || c->display_usage) {
     792                d_printf("%s\n%s",
     793                         _("Usage:"),
     794                         _("net registry getsd_sddl <path>\n"));
     795                d_printf("%s\n%s",
     796                         _("Example:"),
     797                         _("net registry getsd_sddl 'HKLM\\Software\\Samba'\n"));
     798                goto done;
     799        }
     800
     801        werr = net_registry_getsd_internal(c, ctx, argv[0], &secdesc);
     802        if (!W_ERROR_IS_OK(werr)) {
     803                goto done;
     804        }
     805
     806        d_printf("%s\n", sddl_encode(ctx, secdesc, get_global_sam_sid()));
     807
     808        ret = 0;
     809
     810done:
     811        TALLOC_FREE(ctx);
     812        return ret;
     813}
     814
     815static WERROR net_registry_setsd_internal(struct net_context *c,
     816                                          TALLOC_CTX *mem_ctx,
     817                                          const char *keyname,
     818                                          struct security_descriptor *sd)
     819{
     820        WERROR werr;
     821        struct registry_key *key = NULL;
     822        TALLOC_CTX *ctx = talloc_stackframe();
     823        uint32_t access_mask = REG_KEY_WRITE |
     824                               SEC_FLAG_MAXIMUM_ALLOWED |
     825                               SEC_FLAG_SYSTEM_SECURITY;
     826
     827        /*
     828         * net_rpc_regsitry uses SEC_FLAG_SYSTEM_SECURITY, but access
     829         * is denied with these perms right now...
     830         */
     831        access_mask = REG_KEY_WRITE;
     832
     833        if (strlen(keyname) == 0) {
     834                d_fprintf(stderr, _("error: zero length key name given\n"));
     835                werr = WERR_INVALID_PARAM;
     836                goto done;
     837        }
     838
     839        werr = open_key(ctx, keyname, access_mask, &key);
     840        if (!W_ERROR_IS_OK(werr)) {
     841                d_fprintf(stderr, "%s%s\n", _("open_key failed: "),
     842                          win_errstr(werr));
     843                goto done;
     844        }
     845
     846        werr = reg_setkeysecurity(key, sd);
     847        if (!W_ERROR_IS_OK(werr)) {
     848                d_fprintf(stderr, "%s%s\n", _("reg_setkeysecurity failed: "),
     849                          win_errstr(werr));
     850                goto done;
     851        }
     852
     853        werr = WERR_OK;
     854
     855done:
     856        TALLOC_FREE(ctx);
     857        return werr;
     858}
     859
     860static int net_registry_setsd_sddl(struct net_context *c,
     861                                   int argc, const char **argv)
     862{
     863        WERROR werr;
     864        int ret = -1;
     865        struct security_descriptor *secdesc = NULL;
     866        TALLOC_CTX *ctx = talloc_stackframe();
     867
     868        if (argc != 2 || c->display_usage) {
     869                d_printf("%s\n%s",
     870                         _("Usage:"),
     871                         _("net registry setsd_sddl <path> <security_descriptor>\n"));
     872                d_printf("%s\n%s",
     873                         _("Example:"),
     874                         _("net registry setsd_sddl 'HKLM\\Software\\Samba'\n"));
     875                goto done;
     876        }
     877
     878        secdesc = sddl_decode(ctx, argv[1], get_global_sam_sid());
     879        if (secdesc == NULL) {
     880                goto done;
     881        }
     882
     883        werr = net_registry_setsd_internal(c, ctx, argv[0], secdesc);
     884        if (!W_ERROR_IS_OK(werr)) {
     885                goto done;
     886        }
     887
     888        ret = 0;
     889
     890done:
     891        TALLOC_FREE(ctx);
     892        return ret;
     893}
     894
     895/******************************************************************************/
     896/**
     897 * @defgroup net_registry net registry
     898 */
     899
     900/**
     901 * @defgroup net_registry_import Import
     902 * @ingroup net_registry
     903 * @{
     904 */
     905
     906struct import_ctx {
     907        TALLOC_CTX *mem_ctx;
     908};
     909
     910
     911static WERROR import_create_key(struct import_ctx* ctx,
     912                                struct registry_key* parent,
     913                                const char* name, void** pkey, bool* existing)
     914{
     915        WERROR werr;
     916        void* mem_ctx = talloc_new(ctx->mem_ctx);
     917
     918        struct registry_key* key = NULL;
     919        enum winreg_CreateAction action;
     920
     921        if (parent == NULL) {
     922                char* subkeyname = NULL;
     923                werr = open_hive(mem_ctx, name, REG_KEY_WRITE,
     924                         &parent, &subkeyname);
     925                if (!W_ERROR_IS_OK(werr)) {
     926                        d_fprintf(stderr, _("open_hive failed: %s\n"),
     927                                  win_errstr(werr));
     928                        goto done;
     929                }
     930                name = subkeyname;
     931        }
     932
     933        action = REG_ACTION_NONE;
     934        werr = reg_createkey(mem_ctx, parent, name, REG_KEY_WRITE,
     935                             &key, &action);
     936        if (!W_ERROR_IS_OK(werr)) {
     937                d_fprintf(stderr, _("reg_createkey failed: %s\n"),
     938                          win_errstr(werr));
     939                goto done;
     940        }
     941
     942        if (action == REG_ACTION_NONE) {
     943                d_fprintf(stderr, _("createkey did nothing -- huh?\n"));
     944                werr = WERR_CREATE_FAILED;
     945                goto done;
     946        }
     947
     948        if (existing != NULL) {
     949                *existing = (action == REG_OPENED_EXISTING_KEY);
     950        }
     951
     952        if (pkey!=NULL) {
     953                *pkey = talloc_steal(ctx->mem_ctx, key);
     954        }
     955
     956done:
     957        talloc_free(mem_ctx);
     958        return werr;
     959}
     960
     961static WERROR import_close_key(struct import_ctx* ctx,
     962                               struct registry_key* key)
     963{
     964        return WERR_OK;
     965}
     966
     967static WERROR import_delete_key(struct import_ctx* ctx,
     968                                struct registry_key* parent, const char* name)
     969{
     970        WERROR werr;
     971        void* mem_ctx = talloc_new(talloc_tos());
     972
     973        if (parent == NULL) {
     974                char* subkeyname = NULL;
     975                werr = open_hive(mem_ctx, name, REG_KEY_WRITE,
     976                         &parent, &subkeyname);
     977                if (!W_ERROR_IS_OK(werr)) {
     978                        d_fprintf(stderr, _("open_hive failed: %s\n"),
     979                                  win_errstr(werr));
     980                        goto done;
     981                }
     982                name = subkeyname;
     983        }
     984
     985        werr = reg_deletekey_recursive(parent, name);
     986        if (!W_ERROR_IS_OK(werr)) {
     987                d_fprintf(stderr, "reg_deletekey_recursive %s: %s\n", _("failed"),
     988                          win_errstr(werr));
     989                goto done;
     990        }
     991
     992done:
     993        talloc_free(mem_ctx);
     994        return werr;
     995}
     996
     997static WERROR import_create_val (struct import_ctx* ctx,
     998                                 struct registry_key* parent, const char* name,
     999                                 const struct registry_value* value)
     1000{
     1001        WERROR werr;
     1002
     1003        if (parent == NULL) {
     1004                return WERR_INVALID_PARAM;
     1005        }
     1006
     1007        werr = reg_setvalue(parent, name, value);
     1008        if (!W_ERROR_IS_OK(werr)) {
     1009                d_fprintf(stderr, _("reg_setvalue failed: %s\n"),
     1010                          win_errstr(werr));
     1011        }
     1012        return werr;
     1013}
     1014
     1015static WERROR import_delete_val (struct import_ctx* ctx, struct registry_key* parent, const char* name) {
     1016        WERROR werr;
     1017
     1018        if (parent == NULL) {
     1019                return WERR_INVALID_PARAM;
     1020        }
     1021
     1022        werr = reg_deletevalue(parent, name);
     1023        if (!W_ERROR_IS_OK(werr)) {
     1024                d_fprintf(stderr, _("reg_deletevalue failed: %s\n"),
     1025                          win_errstr(werr));
     1026        }
     1027
     1028        return werr;
     1029}
     1030
     1031
     1032static int net_registry_import(struct net_context *c, int argc,
     1033                               const char **argv)
     1034{
     1035        struct import_ctx import_ctx;
     1036        struct reg_import_callback import_callback = {
     1037                .openkey     = NULL,
     1038                .closekey    = (reg_import_callback_closekey_t)&import_close_key,
     1039                .createkey   = (reg_import_callback_createkey_t)&import_create_key,
     1040                .deletekey   = (reg_import_callback_deletekey_t)&import_delete_key,
     1041                .deleteval   = (reg_import_callback_deleteval_t)&import_delete_val,
     1042                .setval      = {
     1043                        .registry_value = (reg_import_callback_setval_registry_value_t)
     1044                                          &import_create_val,
     1045                },
     1046                .setval_type = REGISTRY_VALUE,
     1047                .data        = &import_ctx
     1048        };
     1049
     1050        int ret;
     1051
     1052        if (argc < 1 || argc > 2 || c->display_usage) {
     1053                d_printf("%s\n%s",
     1054                         _("Usage:"),
     1055                         _("net registry import <reg> [options]\n"));
     1056                d_printf("%s\n%s",
     1057                         _("Example:"),
     1058                         _("net registry import file.reg enc=CP1252\n"));
     1059                return -1;
     1060        }
     1061
     1062        ZERO_STRUCT(import_ctx);
     1063        import_ctx.mem_ctx = talloc_stackframe();
     1064
     1065        regdb_open();
     1066        regdb_transaction_start();
     1067
     1068        ret = reg_parse_file(argv[0],
     1069                             reg_import_adapter(import_ctx.mem_ctx,
     1070                                                import_callback),
     1071                             (argc > 1) ? argv[1] : NULL
     1072                );
     1073        if (ret < 0) {
     1074                d_printf("reg_parse_file failed: transaction canceled\n");
     1075                regdb_transaction_cancel();
     1076        } else{
     1077                regdb_transaction_commit();
     1078        }
     1079
     1080        regdb_close();
     1081        talloc_free(import_ctx.mem_ctx);
     1082
     1083        return ret;
     1084}
     1085/**@}*/
     1086
     1087/******************************************************************************/
     1088
     1089/**
     1090 * @defgroup net_registry_export Export
     1091 * @ingroup net_registry
     1092 * @{
     1093 */
     1094
     1095static int registry_export(TALLOC_CTX *ctx, /*const*/ struct registry_key* key,
     1096                           struct reg_format* f)
     1097{
     1098        int ret=-1;
     1099        WERROR werr;
     1100        uint32_t count;
     1101
     1102        struct registry_value *valvalue = NULL;
     1103        char *valname = NULL;
     1104
     1105        struct registry_key* subkey = NULL;
     1106        char *subkey_name = NULL;
     1107        NTTIME modtime = 0;
     1108
     1109        reg_format_registry_key(f, key, false);
     1110
     1111        /* print values */
     1112        for (count = 0;
     1113             werr = reg_enumvalue(ctx, key, count, &valname, &valvalue),
     1114                     W_ERROR_IS_OK(werr);
     1115             count++)
     1116        {
     1117                reg_format_registry_value(f, valname, valvalue);
     1118        }
     1119        if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
     1120                d_fprintf(stderr, _("reg_enumvalue failed: %s\n"),
     1121                          win_errstr(werr));
     1122                goto done;
     1123        }
     1124
     1125        /* recurse on subkeys */
     1126        for (count = 0;
     1127             werr = reg_enumkey(ctx, key, count, &subkey_name, &modtime),
     1128                     W_ERROR_IS_OK(werr);
     1129             count++)
     1130        {
     1131                werr = reg_openkey(ctx, key, subkey_name, REG_KEY_READ,
     1132                                   &subkey);
     1133                if (!W_ERROR_IS_OK(werr)) {
     1134                        d_fprintf(stderr, _("reg_openkey failed: %s\n"),
     1135                                  win_errstr(werr));
     1136                        goto done;
     1137                }
     1138
     1139                registry_export(ctx, subkey, f);
     1140        }
     1141        if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
     1142                d_fprintf(stderr, _("reg_enumkey failed: %s\n"),
     1143                          win_errstr(werr));
     1144                goto done;
     1145        }
     1146        ret = 0;
     1147done:
     1148        return ret;
     1149}
     1150
     1151static int net_registry_export(struct net_context *c, int argc,
     1152                               const char **argv)
     1153{
     1154        int ret=-1;
     1155        WERROR werr;
     1156        struct registry_key *key = NULL;
     1157        TALLOC_CTX *ctx = talloc_stackframe();
     1158        struct reg_format* f=NULL;
     1159
     1160        if (argc < 2 || argc > 3 || c->display_usage) {
     1161                d_printf("%s\n%s",
     1162                         _("Usage:"),
     1163                         _("net registry export <path> <file> [opt]\n"));
     1164                d_printf("%s\n%s",
     1165                         _("Example:"),
     1166                         _("net registry export 'HKLM\\Software\\Samba' "
     1167                           "samba.reg regedit5\n"));
     1168                goto done;
     1169        }
     1170
     1171        werr = open_key(ctx, argv[0], REG_KEY_READ, &key);
    4561172        if (!W_ERROR_IS_OK(werr)) {
    4571173                d_fprintf(stderr, _("open_key failed: %s\n"), win_errstr(werr));
     
    4591175        }
    4601176
    461         werr = reg_getkeysecurity(ctx, key, &secdesc);
    462         if (!W_ERROR_IS_OK(werr)) {
    463                 d_fprintf(stderr, _("reg_getkeysecurity failed: %s\n"),
    464                           win_errstr(werr));
    465                 goto done;
    466         }
    467 
    468         display_sec_desc(secdesc);
    469 
    470         ret = 0;
    471 
    472 done:
    473         TALLOC_FREE(ctx);
    474         return ret;
    475 }
     1177        f = reg_format_file(ctx, argv[1], (argc > 2) ? argv[2] : NULL);
     1178        if (f == NULL) {
     1179                d_fprintf(stderr, _("open file failed: %s\n"), strerror(errno));
     1180                goto done;
     1181        }
     1182
     1183        ret = registry_export(ctx, key, f);
     1184
     1185done:
     1186        TALLOC_FREE(ctx);
     1187        return ret;
     1188}
     1189/**@}*/
     1190
     1191/******************************************************************************/
     1192/**
     1193 * @defgroup net_registry_convert Convert
     1194 * @ingroup net_registry
     1195 * @{
     1196 */
     1197
     1198static int net_registry_convert(struct net_context *c, int argc,
     1199                               const char **argv)
     1200{
     1201        int ret;
     1202        void* mem_ctx;
     1203        const char* in_opt  = NULL;
     1204        const char* out_opt = NULL;
     1205
     1206        if (argc < 2 || argc > 4|| c->display_usage) {
     1207                d_printf("%s\n%s",
     1208                         _("Usage:"),
     1209                         _("net registry convert <in> <out> [in_opt] [out_opt]\n"
     1210                           "net registry convert <in> <out> [out_opt]\n"));
     1211                d_printf("%s\n%s",
     1212                         _("Example:"),
     1213                         _("net registry convert in.reg out.reg regedit4,enc=CP1252\n"));
     1214                return -1;
     1215        }
     1216
     1217        mem_ctx = talloc_stackframe();
     1218
     1219        switch (argc ) {
     1220        case 2:
     1221                break;
     1222        case 3:
     1223                out_opt = argv[2];
     1224                break;
     1225        case 4:
     1226                out_opt = argv[3];
     1227                in_opt  = argv[2];
     1228                break;
     1229        default:
     1230                assert(false);
     1231        }
     1232
     1233
     1234        ret = reg_parse_file(argv[0], (struct reg_parse_callback*)
     1235                             reg_format_file(mem_ctx, argv[1], out_opt),
     1236                             in_opt);
     1237
     1238        talloc_free(mem_ctx);
     1239
     1240        return ret;
     1241}
     1242/**@}*/
     1243
     1244/******************************************************************************/
    4761245
    4771246int net_registry(struct net_context *c, int argc, const char **argv)
     
    4891258                },
    4901259                {
     1260                        "enumerate_recursive",
     1261                        net_registry_enumerate_recursive,
     1262                        NET_TRANSPORT_LOCAL,
     1263                        N_("Enumerate registry keys and values"),
     1264                        N_("net registry enumerate_recursive\n"
     1265                           "    Enumerate registry keys and values")
     1266                },
     1267                {
    4911268                        "createkey",
    4921269                        net_registry_createkey,
     
    5051282                },
    5061283                {
     1284                        "deletekey_recursive",
     1285                        net_registry_deletekey_recursive,
     1286                        NET_TRANSPORT_LOCAL,
     1287                        N_("Delete a registry key with subkeys"),
     1288                        N_("net registry deletekey_recursive\n"
     1289                           "    Delete a registry key with subkeys")
     1290                },
     1291                {
    5071292                        "getvalue",
    5081293                        net_registry_getvalue,
     
    5211306                },
    5221307                {
     1308                        "getvaluesraw",
     1309                        net_registry_getvaluesraw,
     1310                        NET_TRANSPORT_LOCAL,
     1311                        "Print all values of a key in raw format",
     1312                        "net registry getvaluesraw <key>\n"
     1313                        "    Print a registry value (raw format)"
     1314                },
     1315                {
    5231316                        "setvalue",
    5241317                        net_registry_setvalue,
     
    5291322                },
    5301323                {
     1324                        "increment",
     1325                        net_registry_increment,
     1326                        NET_TRANSPORT_LOCAL,
     1327                        N_("Increment a DWORD registry value under a lock"),
     1328                        N_("net registry increment\n"
     1329                           "    Increment a DWORD registry value under a lock")
     1330                },
     1331                {
    5311332                        "deletevalue",
    5321333                        net_registry_deletevalue,
     
    5441345                           "    Get security descriptor")
    5451346                },
     1347                {
     1348                        "getsd_sddl",
     1349                        net_registry_getsd_sddl,
     1350                        NET_TRANSPORT_LOCAL,
     1351                        N_("Get security descriptor in sddl format"),
     1352                        N_("net registry getsd_sddl\n"
     1353                           "    Get security descriptor in sddl format")
     1354                },
     1355                {
     1356                        "setsd_sddl",
     1357                        net_registry_setsd_sddl,
     1358                        NET_TRANSPORT_LOCAL,
     1359                        N_("Set security descriptor from sddl format string"),
     1360                        N_("net registry setsd_sddl\n"
     1361                           "    Set security descriptor from sddl format string")
     1362                },
     1363                {
     1364                        "import",
     1365                        net_registry_import,
     1366                        NET_TRANSPORT_LOCAL,
     1367                        N_("Import .reg file"),
     1368                        N_("net registry import\n"
     1369                           "    Import .reg file")
     1370                },
     1371                {
     1372                        "export",
     1373                        net_registry_export,
     1374                        NET_TRANSPORT_LOCAL,
     1375                        N_("Export .reg file"),
     1376                        N_("net registry export\n"
     1377                           "    Export .reg file")
     1378                },
     1379                {
     1380                        "convert",
     1381                        net_registry_convert,
     1382                        NET_TRANSPORT_LOCAL,
     1383                        N_("Convert .reg file"),
     1384                        N_("net registry convert\n"
     1385                           "    Convert .reg file")
     1386                },
    5461387        { NULL, NULL, 0, NULL, NULL }
    5471388        };
  • vendor/current/source3/utils/net_registry_util.c

    r414 r740  
    2121
    2222#include "includes.h"
     23#include "registry.h"
    2324#include "utils/net_registry_util.h"
    2425#include "utils/net.h"
     26#include "../libcli/registry/util_reg.h"
    2527
    2628void print_registry_key(const char *keyname, NTTIME *modtime)
     
    3840        if (!raw) {
    3941                d_printf(_("Type       = %s\n"),
    40                          reg_type_lookup(valvalue->type));
     42                         str_regtype(valvalue->type));
    4143        }
    4244        switch(valvalue->type) {
    43         case REG_DWORD:
     45        case REG_DWORD: {
     46                uint32_t v = 0;
     47                if (valvalue->data.length >= 4) {
     48                        v = IVAL(valvalue->data.data, 0);
     49                }
    4450                if (!raw) {
    4551                        d_printf(_("Value      = "));
    4652                }
    47                 d_printf("%d\n", valvalue->v.dword);
     53                d_printf("%d\n", v);
    4854                break;
     55        }
    4956        case REG_SZ:
    50         case REG_EXPAND_SZ:
     57        case REG_EXPAND_SZ: {
     58                const char *s;
     59
     60                if (!pull_reg_sz(talloc_tos(), &valvalue->data, &s)) {
     61                        break;
     62                }
    5163                if (!raw) {
    5264                        d_printf(_("Value      = \""));
    5365                }
    54                 d_printf("%s", valvalue->v.sz.str);
     66                d_printf("%s", s);
    5567                if (!raw) {
    5668                        d_printf("\"");
     
    5870                d_printf("\n");
    5971                break;
     72        }
    6073        case REG_MULTI_SZ: {
    6174                uint32 j;
    62                 for (j = 0; j < valvalue->v.multi_sz.num_strings; j++) {
     75                const char **a;
     76
     77                if (!pull_reg_multi_sz(talloc_tos(), &valvalue->data, &a)) {
     78                        break;
     79                }
     80                for (j = 0; a[j] != NULL; j++) {
    6381                        if (!raw) {
    6482                                d_printf(_("Value[%3.3d] = \""), j);
    6583                        }
    66                         d_printf("%s", valvalue->v.multi_sz.strings[j]);
     84                        d_printf("%s", a[j]);
    6785                        if (!raw) {
    6886                                d_printf("\"");
     
    7694                        d_printf(_("Value      = "));
    7795                }
    78                 d_printf(_("%d bytes\n"), (int)valvalue->v.binary.length);
     96                d_printf(_("%d bytes\n"), (int)valvalue->data.length);
    7997                break;
    8098        default:
     
    98116 * Split path into hive name and subkeyname
    99117 * normalizations performed:
    100  *  - convert '/' to '\\'
     118 *  - if the path contains no '\\' characters,
     119 *    assume that the legacy format of using '/'
     120 *    as a separator is used and  convert '/' to '\\'
    101121 *  - strip trailing '\\' chars
    102122 */
     
    115135        }
    116136
    117         *hivename = talloc_string_sub(ctx, path, "/", "\\");
     137        if (strchr(path, '\\') == NULL) {
     138                *hivename = talloc_string_sub(ctx, path, "/", "\\");
     139        } else {
     140                *hivename = talloc_strdup(ctx, path);
     141        }
     142
    118143        if (*hivename == NULL) {
    119144                return WERR_NOMEM;
  • vendor/current/source3/utils/net_rpc.c

    r478 r740  
    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;
  • vendor/current/source3/utils/net_rpc_audit.c

    r414 r740  
    1919#include "includes.h"
    2020#include "utils/net.h"
    21 #include "../librpc/gen_ndr/cli_lsa.h"
     21#include "rpc_client/rpc_client.h"
     22#include "../librpc/gen_ndr/ndr_lsa_c.h"
     23#include "rpc_client/cli_lsarpc.h"
    2224
    2325/********************************************************************
     
    5658
    5759static NTSTATUS rpc_audit_get_internal(struct net_context *c,
    58                                        const DOM_SID *domain_sid,
     60                                       const struct dom_sid *domain_sid,
    5961                                       const char *domain_name,
    6062                                       struct cli_state *cli,
     
    6567{
    6668        struct policy_handle pol;
    67         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
     69        NTSTATUS status, result;
    6870        union lsa_PolicyInformation *info = NULL;
    6971        int i;
    7072        uint32_t audit_category;
     73        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    7174
    7275        if (argc < 1 || argc > 2) {
     
    8184        }
    8285
    83         result = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,
     86        status = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,
    8487                                        SEC_FLAG_MAXIMUM_ALLOWED,
    8588                                        &pol);
    8689
    87         if (!NT_STATUS_IS_OK(result)) {
    88                 goto done;
    89         }
    90 
    91         result = rpccli_lsa_QueryInfoPolicy(pipe_hnd, mem_ctx,
     90        if (!NT_STATUS_IS_OK(status)) {
     91                goto done;
     92        }
     93
     94        status = dcerpc_lsa_QueryInfoPolicy(b, mem_ctx,
    9295                                            &pol,
    9396                                            LSA_POLICY_INFO_AUDIT_EVENTS,
    94                                             &info);
    95 
     97                                            &info,
     98                                            &result);
     99        if (!NT_STATUS_IS_OK(status)) {
     100                goto done;
     101        }
    96102        if (!NT_STATUS_IS_OK(result)) {
     103                status = result;
    97104                goto done;
    98105        }
     
    112119
    113120 done:
    114         if (!NT_STATUS_IS_OK(result)) {
     121        if (!NT_STATUS_IS_OK(status)) {
    115122                d_printf(_("failed to get auditing policy: %s\n"),
    116                         nt_errstr(result));
    117         }
    118 
    119         return result;
     123                        nt_errstr(status));
     124        }
     125
     126        return status;
    120127}
    121128
     
    124131
    125132static NTSTATUS rpc_audit_set_internal(struct net_context *c,
    126                                        const DOM_SID *domain_sid,
     133                                       const struct dom_sid *domain_sid,
    127134                                       const char *domain_name,
    128135                                       struct cli_state *cli,
     
    133140{
    134141        struct policy_handle pol;
    135         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
     142        NTSTATUS status, result;
    136143        union lsa_PolicyInformation *info = NULL;
    137144        uint32_t audit_policy, audit_category;
     145        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    138146
    139147        if (argc < 2 || argc > 3) {
     
    163171        }
    164172
    165         result = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,
     173        status = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,
    166174                                        SEC_FLAG_MAXIMUM_ALLOWED,
    167175                                        &pol);
    168176
    169         if (!NT_STATUS_IS_OK(result)) {
    170                 goto done;
    171         }
    172 
    173         result = rpccli_lsa_QueryInfoPolicy(pipe_hnd, mem_ctx,
     177        if (!NT_STATUS_IS_OK(status)) {
     178                goto done;
     179        }
     180
     181        status = dcerpc_lsa_QueryInfoPolicy(b, mem_ctx,
    174182                                            &pol,
    175183                                            LSA_POLICY_INFO_AUDIT_EVENTS,
    176                                             &info);
    177 
     184                                            &info,
     185                                            &result);
     186        if (!NT_STATUS_IS_OK(status)) {
     187                goto done;
     188        }
    178189        if (!NT_STATUS_IS_OK(result)) {
     190                status = result;
    179191                goto done;
    180192        }
     
    182194        info->audit_events.settings[audit_category] = audit_policy;
    183195
    184         result = rpccli_lsa_SetInfoPolicy(pipe_hnd, mem_ctx,
     196        status = dcerpc_lsa_SetInfoPolicy(b, mem_ctx,
    185197                                          &pol,
    186198                                          LSA_POLICY_INFO_AUDIT_EVENTS,
    187                                           info);
    188 
     199                                          info,
     200                                          &result);
     201        if (!NT_STATUS_IS_OK(status)) {
     202                goto done;
     203        }
    189204        if (!NT_STATUS_IS_OK(result)) {
    190                 goto done;
    191         }
    192 
    193         result = rpccli_lsa_QueryInfoPolicy(pipe_hnd, mem_ctx,
     205                status = result;
     206                goto done;
     207        }
     208
     209        status = dcerpc_lsa_QueryInfoPolicy(b, mem_ctx,
    194210                                            &pol,
    195211                                            LSA_POLICY_INFO_AUDIT_EVENTS,
    196                                             &info);
     212                                            &info,
     213                                            &result);
     214        if (!NT_STATUS_IS_OK(status)) {
     215                goto done;
     216        }
     217
     218        status = result;
     219
    197220        {
    198221                const char *val = audit_policy_str(mem_ctx, info->audit_events.settings[audit_category]);
     
    202225
    203226 done:
    204         if (!NT_STATUS_IS_OK(result)) {
     227        if (!NT_STATUS_IS_OK(status)) {
    205228                d_printf(_("failed to set audit policy: %s\n"),
    206                          nt_errstr(result));
    207         }
    208 
    209         return result;
     229                         nt_errstr(status));
     230        }
     231
     232        return status;
    210233}
    211234
     
    220243{
    221244        struct policy_handle pol;
    222         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
     245        NTSTATUS status, result;
    223246        union lsa_PolicyInformation *info = NULL;
    224 
    225         result = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,
     247        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
     248
     249        status = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,
    226250                                        SEC_FLAG_MAXIMUM_ALLOWED,
    227251                                        &pol);
    228252
    229         if (!NT_STATUS_IS_OK(result)) {
    230                 goto done;
    231         }
    232 
    233         result = rpccli_lsa_QueryInfoPolicy(pipe_hnd, mem_ctx,
     253        if (!NT_STATUS_IS_OK(status)) {
     254                goto done;
     255        }
     256
     257        status = dcerpc_lsa_QueryInfoPolicy(b, mem_ctx,
    234258                                            &pol,
    235259                                            LSA_POLICY_INFO_AUDIT_EVENTS,
    236                                             &info);
     260                                            &info,
     261                                            &result);
     262        if (!NT_STATUS_IS_OK(status)) {
     263                goto done;
     264        }
    237265        if (!NT_STATUS_IS_OK(result)) {
     266                status = result;
    238267                goto done;
    239268        }
     
    241270        info->audit_events.auditing_mode = enable;
    242271
    243         result = rpccli_lsa_SetInfoPolicy(pipe_hnd, mem_ctx,
     272        status = dcerpc_lsa_SetInfoPolicy(b, mem_ctx,
    244273                                          &pol,
    245274                                          LSA_POLICY_INFO_AUDIT_EVENTS,
    246                                           info);
    247 
     275                                          info,
     276                                          &result);
     277        if (!NT_STATUS_IS_OK(status)) {
     278                goto done;
     279        }
    248280        if (!NT_STATUS_IS_OK(result)) {
     281                status = result;
    249282                goto done;
    250283        }
    251284
    252285 done:
    253         if (!NT_STATUS_IS_OK(result)) {
     286        if (!NT_STATUS_IS_OK(status)) {
    254287                d_printf(_("%s: %s\n"),
    255288                        enable ? _("failed to enable audit policy"):
    256289                                 _("failed to disable audit policy"),
    257                         nt_errstr(result));
    258         }
    259 
    260         return result;
     290                        nt_errstr(status));
     291        }
     292
     293        return status;
    261294}
    262295
     
    265298
    266299static NTSTATUS rpc_audit_disable_internal(struct net_context *c,
    267                                            const DOM_SID *domain_sid,
     300                                           const struct dom_sid *domain_sid,
    268301                                           const char *domain_name,
    269302                                           struct cli_state *cli,
     
    281314
    282315static NTSTATUS rpc_audit_enable_internal(struct net_context *c,
    283                                           const DOM_SID *domain_sid,
     316                                          const struct dom_sid *domain_sid,
    284317                                          const char *domain_name,
    285318                                          struct cli_state *cli,
     
    297330
    298331static NTSTATUS rpc_audit_list_internal(struct net_context *c,
    299                                         const DOM_SID *domain_sid,
     332                                        const struct dom_sid *domain_sid,
    300333                                        const char *domain_name,
    301334                                        struct cli_state *cli,
     
    306339{
    307340        struct policy_handle pol;
    308         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
     341        NTSTATUS status, result;
    309342        union lsa_PolicyInformation *info = NULL;
    310343        int i;
    311 
    312         result = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,
     344        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
     345
     346        status = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,
    313347                                        SEC_FLAG_MAXIMUM_ALLOWED,
    314348                                        &pol);
    315349
    316         if (!NT_STATUS_IS_OK(result)) {
    317                 goto done;
    318         }
    319 
    320         result = rpccli_lsa_QueryInfoPolicy(pipe_hnd, mem_ctx,
     350        if (!NT_STATUS_IS_OK(status)) {
     351                goto done;
     352        }
     353
     354        status = dcerpc_lsa_QueryInfoPolicy(b, mem_ctx,
    321355                                            &pol,
    322356                                            LSA_POLICY_INFO_AUDIT_EVENTS,
    323                                             &info);
     357                                            &info,
     358                                            &result);
     359        if (!NT_STATUS_IS_OK(status)) {
     360                goto done;
     361        }
    324362        if (!NT_STATUS_IS_OK(result)) {
     363                status = result;
    325364                goto done;
    326365        }
     
    351390
    352391 done:
    353         if (!NT_STATUS_IS_OK(result)) {
     392        if (!NT_STATUS_IS_OK(status)) {
    354393                d_printf(_("failed to list auditing policies: %s\n"),
    355                         nt_errstr(result));
    356         }
    357 
    358         return result;
     394                        nt_errstr(status));
     395        }
     396
     397        return status;
    359398}
    360399
  • vendor/current/source3/utils/net_rpc_join.c

    r414 r740  
    2121#include "includes.h"
    2222#include "utils/net.h"
     23#include "rpc_client/cli_pipe.h"
    2324#include "../libcli/auth/libcli_auth.h"
    24 #include "../librpc/gen_ndr/cli_lsa.h"
    25 #include "../librpc/gen_ndr/cli_samr.h"
     25#include "../librpc/gen_ndr/ndr_lsa_c.h"
     26#include "rpc_client/cli_lsarpc.h"
     27#include "../librpc/gen_ndr/ndr_samr_c.h"
     28#include "rpc_client/init_samr.h"
     29#include "../librpc/gen_ndr/ndr_netlogon.h"
     30#include "rpc_client/cli_netlogon.h"
     31#include "secrets.h"
     32#include "rpc_client/init_lsa.h"
     33#include "libsmb/libsmb.h"
    2634
    2735/* Macro for checking RPC error codes to make things more readable */
    2836
    2937#define CHECK_RPC_ERR(rpc, msg) \
    30         if (!NT_STATUS_IS_OK(result = rpc)) { \
    31                 DEBUG(0, (msg ": %s\n", nt_errstr(result))); \
     38        if (!NT_STATUS_IS_OK(status = rpc)) { \
     39                DEBUG(0, (msg ": %s\n", nt_errstr(status))); \
    3240                goto done; \
    3341        }
    3442
     43#define CHECK_DCERPC_ERR(rpc, msg) \
     44        if (!NT_STATUS_IS_OK(status = rpc)) { \
     45                DEBUG(0, (msg ": %s\n", nt_errstr(status))); \
     46                goto done; \
     47        } \
     48        if (!NT_STATUS_IS_OK(result)) { \
     49                status = result; \
     50                DEBUG(0, (msg ": %s\n", nt_errstr(result))); \
     51                goto done; \
     52        }
     53
     54
    3555#define CHECK_RPC_ERR_DEBUG(rpc, debug_args) \
    36         if (!NT_STATUS_IS_OK(result = rpc)) { \
     56        if (!NT_STATUS_IS_OK(status = rpc)) { \
    3757                DEBUG(0, debug_args); \
    3858                goto done; \
    3959        }
     60
     61#define CHECK_DCERPC_ERR_DEBUG(rpc, debug_args) \
     62        if (!NT_STATUS_IS_OK(status = rpc)) { \
     63                DEBUG(0, debug_args); \
     64                goto done; \
     65        } \
     66        if (!NT_STATUS_IS_OK(result)) { \
     67                status = result; \
     68                DEBUG(0, debug_args); \
     69                goto done; \
     70        }
     71
    4072
    4173/**
     
    143175        enum netr_SchannelType sec_channel_type;
    144176        struct rpc_pipe_client *pipe_hnd = NULL;
     177        struct dcerpc_binding_handle *b = NULL;
    145178
    146179        /* rpc variables */
    147180
    148181        struct policy_handle lsa_pol, sam_pol, domain_pol, user_pol;
    149         DOM_SID *domain_sid;
     182        struct dom_sid *domain_sid;
    150183        uint32 user_rid;
    151184
     
    159192        /* Misc */
    160193
    161         NTSTATUS result;
     194        NTSTATUS status, result;
    162195        int retval = 1;
    163196        const char *domain = NULL;
     
    169202        struct samr_Ids user_rids;
    170203        struct samr_Ids name_types;
     204
    171205
    172206        /* check what type of join */
     
    197231        /* Make authenticated connection to remote machine */
    198232
    199         result = net_make_ipc_connection(c, NET_FLAGS_PDC, &cli);
    200         if (!NT_STATUS_IS_OK(result)) {
     233        status = net_make_ipc_connection(c, NET_FLAGS_PDC, &cli);
     234        if (!NT_STATUS_IS_OK(status)) {
    201235                return 1;
    202236        }
     
    209243        /* Fetch domain sid */
    210244
    211         result = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc.syntax_id,
     245        status = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc.syntax_id,
    212246                                          &pipe_hnd);
    213         if (!NT_STATUS_IS_OK(result)) {
     247        if (!NT_STATUS_IS_OK(status)) {
    214248                DEBUG(0, ("Error connecting to LSA pipe. Error was %s\n",
    215                         nt_errstr(result) ));
    216                 goto done;
    217         }
    218 
     249                        nt_errstr(status) ));
     250                goto done;
     251        }
     252
     253        b = pipe_hnd->binding_handle;
    219254
    220255        CHECK_RPC_ERR(rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,
     
    223258                      "error opening lsa policy handle");
    224259
    225         CHECK_RPC_ERR(rpccli_lsa_QueryInfoPolicy(pipe_hnd, mem_ctx,
    226                                                  &lsa_pol,
    227                                                  LSA_POLICY_INFO_ACCOUNT_DOMAIN,
    228                                                  &info),
     260        CHECK_DCERPC_ERR(dcerpc_lsa_QueryInfoPolicy(b, mem_ctx,
     261                                                    &lsa_pol,
     262                                                    LSA_POLICY_INFO_ACCOUNT_DOMAIN,
     263                                                    &info,
     264                                                    &result),
    229265                      "error querying info policy");
    230266
     
    232268        domain_sid = info->account_domain.sid;
    233269
    234         rpccli_lsa_Close(pipe_hnd, mem_ctx, &lsa_pol);
     270        dcerpc_lsa_Close(b, mem_ctx, &lsa_pol, &result);
    235271        TALLOC_FREE(pipe_hnd); /* Done with this pipe */
    236272
     
    242278
    243279        /* Create domain user */
    244         result = cli_rpc_pipe_open_noauth(cli, &ndr_table_samr.syntax_id,
     280        status = cli_rpc_pipe_open_noauth(cli, &ndr_table_samr.syntax_id,
    245281                                          &pipe_hnd);
    246         if (!NT_STATUS_IS_OK(result)) {
     282        if (!NT_STATUS_IS_OK(status)) {
    247283                DEBUG(0, ("Error connecting to SAM pipe. Error was %s\n",
    248                         nt_errstr(result) ));
    249                 goto done;
    250         }
    251 
    252         CHECK_RPC_ERR(rpccli_samr_Connect2(pipe_hnd, mem_ctx,
    253                                            pipe_hnd->desthost,
    254                                            SAMR_ACCESS_ENUM_DOMAINS
    255                                            | SAMR_ACCESS_LOOKUP_DOMAIN,
    256                                            &sam_pol),
     284                        nt_errstr(status) ));
     285                goto done;
     286        }
     287
     288        b = pipe_hnd->binding_handle;
     289
     290        CHECK_DCERPC_ERR(dcerpc_samr_Connect2(b, mem_ctx,
     291                                              pipe_hnd->desthost,
     292                                              SAMR_ACCESS_ENUM_DOMAINS
     293                                              | SAMR_ACCESS_LOOKUP_DOMAIN,
     294                                              &sam_pol,
     295                                              &result),
    257296                      "could not connect to SAM database");
    258297
    259298
    260         CHECK_RPC_ERR(rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
    261                                              &sam_pol,
    262                                              SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1
    263                                              | SAMR_DOMAIN_ACCESS_CREATE_USER
    264                                              | SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
    265                                              domain_sid,
    266                                              &domain_pol),
     299        CHECK_DCERPC_ERR(dcerpc_samr_OpenDomain(b, mem_ctx,
     300                                                &sam_pol,
     301                                                SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1
     302                                                | SAMR_DOMAIN_ACCESS_CREATE_USER
     303                                                | SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
     304                                                domain_sid,
     305                                                &domain_pol,
     306                                                &result),
    267307                      "could not open domain");
    268308
    269309        /* Create domain user */
    270310        if ((acct_name = talloc_asprintf(mem_ctx, "%s$", global_myname())) == NULL) {
    271                 result = NT_STATUS_NO_MEMORY;
     311                status = NT_STATUS_NO_MEMORY;
    272312                goto done;
    273313        }
     
    284324        DEBUG(10, ("Creating account with flags: %d\n",acct_flags));
    285325
    286         result = rpccli_samr_CreateUser2(pipe_hnd, mem_ctx,
     326        status = dcerpc_samr_CreateUser2(b, mem_ctx,
    287327                                         &domain_pol,
    288328                                         &lsa_acct_name,
     
    291331                                         &user_pol,
    292332                                         &access_granted,
    293                                          &user_rid);
    294 
     333                                         &user_rid,
     334                                         &result);
     335        if (!NT_STATUS_IS_OK(status)) {
     336                goto done;
     337        }
    295338        if (!NT_STATUS_IS_OK(result) &&
    296339            !NT_STATUS_EQUAL(result, NT_STATUS_USER_EXISTS)) {
     340                status = result;
    297341                d_fprintf(stderr,_("Creation of workstation account failed\n"));
    298342
     
    311355
    312356        if (NT_STATUS_IS_OK(result)) {
    313                 rpccli_samr_Close(pipe_hnd, mem_ctx, &user_pol);
    314         }
    315 
    316         CHECK_RPC_ERR_DEBUG(rpccli_samr_LookupNames(pipe_hnd, mem_ctx,
    317                                                     &domain_pol,
    318                                                     1,
    319                                                     &lsa_acct_name,
    320                                                     &user_rids,
    321                                                     &name_types),
    322                             ("error looking up rid for user %s: %s\n",
    323                              acct_name, nt_errstr(result)));
     357                dcerpc_samr_Close(b, mem_ctx, &user_pol, &result);
     358        }
     359
     360        CHECK_DCERPC_ERR_DEBUG(dcerpc_samr_LookupNames(b, mem_ctx,
     361                                                       &domain_pol,
     362                                                       1,
     363                                                       &lsa_acct_name,
     364                                                       &user_rids,
     365                                                       &name_types,
     366                                                       &result),
     367                            ("error looking up rid for user %s: %s/%s\n",
     368                             acct_name, nt_errstr(status), nt_errstr(result)));
    324369
    325370        if (name_types.ids[0] != SID_NAME_USER) {
     
    332377        /* Open handle on user */
    333378
    334         CHECK_RPC_ERR_DEBUG(
    335                 rpccli_samr_OpenUser(pipe_hnd, mem_ctx,
     379        CHECK_DCERPC_ERR_DEBUG(
     380                dcerpc_samr_OpenUser(b, mem_ctx,
    336381                                     &domain_pol,
    337382                                     SEC_FLAG_MAXIMUM_ALLOWED,
    338383                                     user_rid,
    339                                      &user_pol),
    340                 ("could not re-open existing user %s: %s\n",
    341                  acct_name, nt_errstr(result)));
     384                                     &user_pol,
     385                                     &result),
     386                ("could not re-open existing user %s: %s/%s\n",
     387                 acct_name, nt_errstr(status), nt_errstr(result)));
    342388       
    343389        /* Create a random machine account password */
     
    355401        set_info.info24.password_expired = PASS_DONT_CHANGE_AT_NEXT_LOGON;
    356402
    357         CHECK_RPC_ERR(rpccli_samr_SetUserInfo2(pipe_hnd, mem_ctx,
    358                                                &user_pol,
    359                                                24,
    360                                                &set_info),
     403        CHECK_DCERPC_ERR(dcerpc_samr_SetUserInfo2(b, mem_ctx,
     404                                                  &user_pol,
     405                                                  24,
     406                                                  &set_info,
     407                                                  &result),
    361408                      "error setting trust account password");
    362409
     
    375422           as a normal user with "Add workstation to domain" privilege. */
    376423
    377         result = rpccli_samr_SetUserInfo(pipe_hnd, mem_ctx,
     424        status = dcerpc_samr_SetUserInfo(b, mem_ctx,
    378425                                         &user_pol,
    379426                                         16,
    380                                          &set_info);
    381 
    382         rpccli_samr_Close(pipe_hnd, mem_ctx, &user_pol);
     427                                         &set_info,
     428                                         &result);
     429
     430        dcerpc_samr_Close(b, mem_ctx, &user_pol, &result);
    383431        TALLOC_FREE(pipe_hnd); /* Done with this pipe */
    384432
    385433        /* Now check the whole process from top-to-bottom */
    386434
    387         result = cli_rpc_pipe_open_noauth(cli, &ndr_table_netlogon.syntax_id,
     435        status = cli_rpc_pipe_open_noauth(cli, &ndr_table_netlogon.syntax_id,
    388436                                          &pipe_hnd);
    389         if (!NT_STATUS_IS_OK(result)) {
     437        if (!NT_STATUS_IS_OK(status)) {
    390438                DEBUG(0,("Error connecting to NETLOGON pipe. Error was %s\n",
    391                         nt_errstr(result) ));
    392                 goto done;
    393         }
    394 
    395         result = rpccli_netlogon_setup_creds(pipe_hnd,
     439                        nt_errstr(status) ));
     440                goto done;
     441        }
     442
     443        status = rpccli_netlogon_setup_creds(pipe_hnd,
    396444                                        cli->desthost, /* server name */
    397445                                        domain,        /* domain */
     
    402450                                        &neg_flags);
    403451
    404         if (!NT_STATUS_IS_OK(result)) {
     452        if (!NT_STATUS_IS_OK(status)) {
    405453                DEBUG(0, ("Error in domain join verification (credential setup failed): %s\n\n",
    406                           nt_errstr(result)));
    407 
    408                 if ( NT_STATUS_EQUAL(result, NT_STATUS_ACCESS_DENIED) &&
     454                          nt_errstr(status)));
     455
     456                if ( NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) &&
    409457                     (sec_channel_type == SEC_CHAN_BDC) ) {
    410458                        d_fprintf(stderr, _("Please make sure that no computer "
     
    425473                struct rpc_pipe_client *netlogon_schannel_pipe;
    426474
    427                 result = cli_rpc_pipe_open_schannel_with_key(
     475                status = cli_rpc_pipe_open_schannel_with_key(
    428476                        cli, &ndr_table_netlogon.syntax_id, NCACN_NP,
    429477                        DCERPC_AUTH_LEVEL_PRIVACY, domain, &pipe_hnd->dc,
    430478                        &netlogon_schannel_pipe);
    431479
    432                 if (!NT_STATUS_IS_OK(result)) {
     480                if (!NT_STATUS_IS_OK(status)) {
    433481                        DEBUG(0, ("Error in domain join verification (schannel setup failed): %s\n\n",
    434                                   nt_errstr(result)));
    435 
    436                         if ( NT_STATUS_EQUAL(result, NT_STATUS_ACCESS_DENIED) &&
     482                                  nt_errstr(status)));
     483
     484                        if ( NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) &&
    437485                             (sec_channel_type == SEC_CHAN_BDC) ) {
    438486                                d_fprintf(stderr, _("Please make sure that no "
     
    464512
    465513        /* double-check, connection from scratch */
    466         result = net_rpc_join_ok(c, domain, cli->desthost, &cli->dest_ss);
    467         retval = NT_STATUS_IS_OK(result) ? 0 : -1;
     514        status = net_rpc_join_ok(c, domain, cli->desthost, &cli->dest_ss);
     515        retval = NT_STATUS_IS_OK(status) ? 0 : -1;
    468516
    469517done:
  • vendor/current/source3/utils/net_rpc_printer.c

    r597 r740  
    1818*/
    1919#include "includes.h"
     20#include "system/filesys.h"
    2021#include "utils/net.h"
    21 #include "../librpc/gen_ndr/cli_spoolss.h"
     22#include "rpc_client/rpc_client.h"
     23#include "../librpc/gen_ndr/ndr_spoolss_c.h"
     24#include "rpc_client/cli_spoolss.h"
     25#include "rpc_client/init_spoolss.h"
     26#include "nt_printing.h"
     27#include "registry/reg_objects.h"
     28#include "../libcli/security/security.h"
     29#include "../libcli/registry/util_reg.h"
     30#include "libsmb/libsmb.h"
    2231
    2332/* support itanium as well */
     
    6271        printf(_("\tHelpfile: [%s]\n\n"), r->help_file);
    6372
    64         for (i=0; r->dependent_files[i] != NULL; i++) {
     73        for (i=0; r->dependent_files && r->dependent_files[i] != NULL; i++) {
    6574                printf(_("\tDependentfiles: [%s]\n"), r->dependent_files[i]);
    6675        }
     
    7281}
    7382
    74 static void display_reg_value(const char *subkey, struct regval_blob value)
     83static void display_reg_value(const char *subkey, struct regval_blob *value)
    7584{
    7685        const char *text;
    7786        DATA_BLOB blob;
    7887
    79         switch(value.type) {
     88        switch(regval_type(value)) {
    8089        case REG_DWORD:
    8190                d_printf(_("\t[%s:%s]: REG_DWORD: 0x%08x\n"), subkey,
    82                         value.valuename, *((uint32_t *) value.data_p));
     91                        regval_name(value), *((uint32_t *) regval_data_p(value)));
    8392                break;
    8493
    8594        case REG_SZ:
    86                 blob = data_blob_const(value.data_p, value.size);
     95                blob = data_blob_const(regval_data_p(value), regval_size(value));
    8796                pull_reg_sz(talloc_tos(), &blob, &text);
    8897                if (!text) {
    8998                        break;
    9099                }
    91                 d_printf(_("\t[%s:%s]: REG_SZ: %s\n"), subkey, value.valuename,
     100                d_printf(_("\t[%s:%s]: REG_SZ: %s\n"), subkey, regval_name(value),
    92101                         text);
    93102                break;
     
    96105                d_printf(_("\t[%s:%s]: REG_BINARY: unknown length value not "
    97106                           "displayed\n"),
    98                          subkey, value.valuename);
     107                         subkey, regval_name(value));
    99108                break;
    100109
     
    102111                uint32_t i;
    103112                const char **values;
    104                 blob = data_blob_const(value.data_p, value.size);
     113                blob = data_blob_const(regval_data_p(value), regval_size(value));
    105114
    106115                if (!pull_reg_multi_sz(NULL, &blob, &values)) {
     
    109118                }
    110119
    111                 printf("%s: REG_MULTI_SZ: \n", value.valuename);
     120                printf("%s: REG_MULTI_SZ: \n", regval_name(value));
    112121                for (i=0; values[i] != NULL; i++) {
    113122                        d_printf("%s\n", values[i]);
     
    118127
    119128        default:
    120                 d_printf(_("\t%s: unknown type %d\n"), value.valuename,
    121                          value.type);
     129                d_printf(_("\t%s: unknown type %d\n"), regval_name(value),
     130                         regval_type(value));
    122131        }
    123132
     
    153162        uint16_t fnum_src = 0;
    154163        uint16_t fnum_dst = 0;
    155         SEC_DESC *sd = NULL;
     164        struct security_descriptor *sd = NULL;
    156165        uint16_t attr;
    157166        time_t f_atime, f_ctime, f_mtime;
     
    226235
    227236        if (copy_acls) {
     237                NTSTATUS status;
    228238
    229239                /* set acls */
    230                 if (!cli_set_secdesc(cli_share_dst, fnum_dst, sd)) {
    231                         DEBUG(0,("could not set secdesc on %s: %s\n",
    232                                 dst_name, cli_errstr(cli_share_dst)));
    233                         nt_status = cli_nt_error(cli_share_dst);
     240                status = cli_set_secdesc(cli_share_dst, fnum_dst, sd);
     241                if (!NT_STATUS_IS_OK(status)) {
     242                        DEBUG(0, ("could not set secdesc on %s: %s\n",
     243                                  dst_name, nt_errstr(status)));
     244                        nt_status = status;
    234245                        goto out;
    235246                }
     
    377388
    378389                /* copying file */
    379                 int n, ret;
     390                int n;
    380391                n = cli_read(cli_share_src, fnum_src, data, nread,
    381392                                read_size);
     
    384395                        break;
    385396
    386                 ret = cli_write(cli_share_dst, fnum_dst, 0, data,
    387                         nread, n);
    388 
    389                 if (n != ret) {
     397                nt_status = cli_writeall(cli_share_dst, fnum_dst, 0,
     398                                         (uint8_t *)data, nread, n, NULL);
     399
     400                if (!NT_STATUS_IS_OK(nt_status)) {
    390401                        d_fprintf(stderr, _("Error writing file: %s\n"),
    391                                 cli_errstr(cli_share_dst));
    392                         nt_status = cli_nt_error(cli_share_dst);
     402                                  nt_errstr(nt_status));
    393403                        goto out;
    394404                }
     
    487497                                    const char *file, const char *short_archi) {
    488498
    489         NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
    490499        const char *p;
    491500        char *src_name;
    492501        char *dst_name;
    493         char *version;
    494         char *filename;
     502        char *version = NULL;
     503        char *filename = NULL;
    495504        char *tok;
    496505
     
    509518        }
    510519
     520        if (version == NULL || filename == NULL) {
     521                return NT_STATUS_UNSUCCESSFUL;
     522        }
     523
    511524        /* build source file name */
    512         if (asprintf(&src_name, "\\%s\\%s\\%s", short_archi, version, filename) < 0 )
     525        src_name = talloc_asprintf(mem_ctx, "\\%s\\%s\\%s",
     526                                   short_archi, version, filename);
     527        if (src_name == NULL) {
    513528                return NT_STATUS_NO_MEMORY;
    514 
     529        }
    515530
    516531        /* create destination file name */
    517         if (asprintf(&dst_name, "\\%s\\%s", short_archi, filename) < 0 )
    518                 return NT_STATUS_NO_MEMORY;
     532        dst_name = talloc_asprintf(mem_ctx, "\\%s\\%s", short_archi, filename);
     533        if (dst_name == NULL) {
     534                return NT_STATUS_NO_MEMORY;
     535        }
    519536
    520537
    521538        /* finally copy the file */
    522         nt_status = net_copy_file(c, mem_ctx, cli_share_src, cli_share_dst,
    523                                   src_name, dst_name, false, false, false, true);
    524         if (!NT_STATUS_IS_OK(nt_status))
    525                 goto out;
    526 
    527         nt_status = NT_STATUS_OK;
    528 
    529 out:
    530         SAFE_FREE(src_name);
    531         SAFE_FREE(dst_name);
    532 
    533         return nt_status;
     539        return net_copy_file(c, mem_ctx, cli_share_src, cli_share_dst,
     540                             src_name, dst_name, false, false, false, true);
    534541}
    535542
     
    752759                                union spoolss_PrinterInfo *info)
    753760{
     761        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    754762        WERROR result;
    755763        NTSTATUS status;
     
    812820        }
    813821
    814         status = rpccli_spoolss_SetPrinter(pipe_hnd, mem_ctx,
     822        status = dcerpc_spoolss_SetPrinter(b, mem_ctx,
    815823                                           hnd,
    816824                                           &info_ctr,
     
    819827                                           0, /* command */
    820828                                           &result);
    821 
     829        if (!NT_STATUS_IS_OK(status)) {
     830                printf(_("cannot set printer-info: %s\n"), nt_errstr(status));
     831                return false;
     832        }
    822833        if (!W_ERROR_IS_OK(result)) {
    823834                printf(_("cannot set printer-info: %s\n"), win_errstr(result));
     
    837848                                       uint32_t offered)
    838849{
     850        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    839851        WERROR result;
    840852        NTSTATUS status;
    841853
    842854        /* setprinterdata call */
    843         status = rpccli_spoolss_SetPrinterData(pipe_hnd, mem_ctx,
     855        status = dcerpc_spoolss_SetPrinterData(b, mem_ctx,
    844856                                               hnd,
    845857                                               value_name,
     
    848860                                               offered,
    849861                                               &result);
    850 
     862        if (!NT_STATUS_IS_OK(status)) {
     863                printf (_("unable to set printerdata: %s\n"),
     864                        nt_errstr(status));
     865                return false;
     866        }
    851867        if (!W_ERROR_IS_OK(result)) {
    852868                printf (_("unable to set printerdata: %s\n"),
     
    911927                                        struct regval_blob *value)
    912928{
     929        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    913930        WERROR result;
    914931        NTSTATUS status;
    915932
    916933        /* setprinterdataex call */
    917         status = rpccli_spoolss_SetPrinterDataEx(pipe_hnd, mem_ctx,
     934        status = dcerpc_spoolss_SetPrinterDataEx(b, mem_ctx,
    918935                                                 hnd,
    919936                                                 keyname,
    920                                                  value->valuename,
    921                                                  value->type,
    922                                                  value->data_p,
    923                                                  value->size,
     937                                                 regval_name(value),
     938                                                 regval_type(value),
     939                                                 regval_data_p(value),
     940                                                 regval_size(value),
    924941                                                 &result);
    925 
     942        if (!NT_STATUS_IS_OK(status)) {
     943                printf(_("could not set printerdataex: %s\n"),
     944                       nt_errstr(status));
     945                return false;
     946        }
    926947        if (!W_ERROR_IS_OK(result)) {
    927948                printf(_("could not set printerdataex: %s\n"),
     
    974995                                                   info);
    975996        if (!W_ERROR_IS_OK(result)) {
    976                 printf(_("cannot enum drivers: %s\n"), win_errstr(result));
    977                 return false;
     997                if (W_ERROR_V(result) != W_ERROR_V(WERR_INVALID_ENVIRONMENT)) {
     998                        printf(_("cannot enum drivers for environment %s: %s\n"), env,
     999                                win_errstr(result));
     1000                        return false;
     1001                } else {
     1002                        printf(_("Server does not support environment [%s]\n"),
     1003                                env);
     1004                }
    9781005        }
    9791006
     
    10211048                             union spoolss_DriverInfo *info)
    10221049{
     1050        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    10231051        WERROR result;
    10241052        NTSTATUS status;
     
    10421070
    10431071        /* addprinterdriver call */
    1044         status = rpccli_spoolss_AddPrinterDriver(pipe_hnd, mem_ctx,
     1072        status = dcerpc_spoolss_AddPrinterDriver(b, mem_ctx,
    10451073                                                 pipe_hnd->srv_name_slash,
    10461074                                                 &info_ctr,
    10471075                                                 &result);
     1076        if (!NT_STATUS_IS_OK(status)) {
     1077                printf(_("cannot add driver: %s\n"), nt_errstr(status));
     1078                return false;
     1079        }
    10481080        /* be more verbose */
    10491081        if (W_ERROR_V(result) == W_ERROR_V(WERR_ACCESS_DENIED)) {
     
    10721104                        union spoolss_PrinterInfo **info_p)
    10731105{
     1106        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    10741107        struct policy_handle hnd;
     1108        WERROR werr;
    10751109
    10761110        /* no arguments given, enumerate all printers */
     
    10981132
    10991133        if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, *info_p)) {
    1100                 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
     1134                dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &werr);
    11011135                return false;
    11021136        }
    11031137
    1104         rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
     1138        dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &werr);
    11051139
    11061140        *num_printers = 1;
     
    11311165
    11321166NTSTATUS rpc_printer_list_internals(struct net_context *c,
    1133                                         const DOM_SID *domain_sid,
     1167                                        const struct dom_sid *domain_sid,
    11341168                                        const char *domain_name,
    11351169                                        struct cli_state *cli,
     
    11831217
    11841218NTSTATUS rpc_printer_driver_list_internals(struct net_context *c,
    1185                                                 const DOM_SID *domain_sid,
     1219                                                const struct dom_sid *domain_sid,
    11861220                                                const char *domain_name,
    11871221                                                struct cli_state *cli,
     
    12541288                                        uint32_t action)
    12551289{
     1290        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    12561291        NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
    12571292        uint32_t i, num_printers;
     
    13011336                default:
    13021337                        action_str = N_("unknown action");
    1303                         printf(_("unkown action: %d\n"), action);
     1338                        printf(_("unknown action: %d\n"), action);
    13041339                        break;
    13051340                }
     
    13131348                ZERO_STRUCT(secdesc_ctr);
    13141349
    1315                 nt_status = rpccli_spoolss_SetPrinter(pipe_hnd, mem_ctx,
     1350                nt_status = dcerpc_spoolss_SetPrinter(b, mem_ctx,
    13161351                                                      &hnd,
    13171352                                                      &info_ctr,
     
    13201355                                                      0, /* command */
    13211356                                                      &result);
    1322 
    1323                 if (!W_ERROR_IS_OK(result) && (W_ERROR_V(result) != W_ERROR_V(WERR_IO_PENDING))) {
     1357                if (!NT_STATUS_IS_OK(nt_status)) {
    13241358                        printf(_("cannot set printer-info: %s\n"),
    1325                                win_errstr(result));
     1359                               nt_errstr(nt_status));
     1360                        goto done;
     1361                }
     1362                if (!W_ERROR_IS_OK(result) && !W_ERROR_EQUAL(result, WERR_IO_PENDING)) {
     1363                        if ((action == DSPRINT_UPDATE) && W_ERROR_EQUAL(result, W_ERROR(0x80070002))) {
     1364                                printf(_("printer not published yet\n"));
     1365                        } else {
     1366                                printf(_("cannot set printer-info: %s\n"),
     1367                                       win_errstr(result));
     1368                        }
     1369                        nt_status = werror_to_ntstatus(result);
    13261370                        goto done;
    13271371                }
     
    13341378
    13351379done:
    1336         if (is_valid_policy_hnd(&hnd))
    1337                 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
     1380        if (is_valid_policy_hnd(&hnd)) {
     1381                dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &result);
     1382        }
    13381383
    13391384        return nt_status;
     
    13411386
    13421387NTSTATUS rpc_printer_publish_publish_internals(struct net_context *c,
    1343                                                 const DOM_SID *domain_sid,
     1388                                                const struct dom_sid *domain_sid,
    13441389                                                const char *domain_name,
    13451390                                                struct cli_state *cli,
     
    13531398
    13541399NTSTATUS rpc_printer_publish_unpublish_internals(struct net_context *c,
    1355                                                 const DOM_SID *domain_sid,
     1400                                                const struct dom_sid *domain_sid,
    13561401                                                const char *domain_name,
    13571402                                                struct cli_state *cli,
     
    13651410
    13661411NTSTATUS rpc_printer_publish_update_internals(struct net_context *c,
    1367                                                 const DOM_SID *domain_sid,
     1412                                                const struct dom_sid *domain_sid,
    13681413                                                const char *domain_name,
    13691414                                                struct cli_state *cli,
     
    13941439
    13951440NTSTATUS rpc_printer_publish_list_internals(struct net_context *c,
    1396                                                 const DOM_SID *domain_sid,
     1441                                                const struct dom_sid *domain_sid,
    13971442                                                const char *domain_name,
    13981443                                                struct cli_state *cli,
     
    14021447                                                const char **argv)
    14031448{
     1449        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    14041450        NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
    14051451        uint32_t i, num_printers;
     
    14101456        struct policy_handle hnd;
    14111457        int state;
     1458        WERROR werr;
    14121459
    14131460        if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &info_enum))
     
    14541501                                break;
    14551502                        default:
    1456                                 printf(_("unkown state: %d\n"), state);
     1503                                printf(_("unknown state: %d\n"), state);
    14571504                                break;
    14581505                }
     
    14621509
    14631510done:
    1464         if (is_valid_policy_hnd(&hnd))
    1465                 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
     1511        if (is_valid_policy_hnd(&hnd)) {
     1512                dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &werr);
     1513        }
    14661514
    14671515        return nt_status;
     
    14861534
    14871535NTSTATUS rpc_printer_migrate_security_internals(struct net_context *c,
    1488                                                 const DOM_SID *domain_sid,
     1536                                                const struct dom_sid *domain_sid,
    14891537                                                const char *domain_name,
    14901538                                                struct cli_state *cli,
     
    14941542                                                const char **argv)
    14951543{
     1544        struct dcerpc_binding_handle *b_src = pipe_hnd->binding_handle;
    14961545        /* TODO: what now, info2 or info3 ?
    14971546           convince jerry that we should add clientside setacls level 3 at least
     
    15031552        const char *printername, *sharename;
    15041553        struct rpc_pipe_client *pipe_hnd_dst = NULL;
     1554        struct dcerpc_binding_handle *b_dst = NULL;
    15051555        struct policy_handle hnd_src, hnd_dst;
    15061556        union spoolss_PrinterInfo *info_enum;
    15071557        struct cli_state *cli_dst = NULL;
    15081558        union spoolss_PrinterInfo info_src, info_dst;
     1559        WERROR werr;
    15091560
    15101561        DEBUG(3,("copying printer ACLs\n"));
     
    15131564        nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
    15141565                                     &ndr_table_spoolss.syntax_id);
    1515         if (!NT_STATUS_IS_OK(nt_status))
     1566        if (!NT_STATUS_IS_OK(nt_status)) {
    15161567                return nt_status;
    1517 
     1568        }
     1569        b_dst = pipe_hnd_dst->binding_handle;
    15181570
    15191571        /* enum source printers */
     
    15891641                /* close printer handles here */
    15901642                if (is_valid_policy_hnd(&hnd_src)) {
    1591                         rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
     1643                        dcerpc_spoolss_ClosePrinter(b_src, mem_ctx, &hnd_src, &werr);
    15921644                }
    15931645
    15941646                if (is_valid_policy_hnd(&hnd_dst)) {
    1595                         rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
     1647                        dcerpc_spoolss_ClosePrinter(b_dst, mem_ctx, &hnd_dst, &werr);
    15961648                }
    15971649
     
    16031655
    16041656        if (is_valid_policy_hnd(&hnd_src)) {
    1605                 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
     1657                dcerpc_spoolss_ClosePrinter(b_src, mem_ctx, &hnd_src, &werr);
    16061658        }
    16071659
    16081660        if (is_valid_policy_hnd(&hnd_dst)) {
    1609                 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
     1661                dcerpc_spoolss_ClosePrinter(b_dst, mem_ctx, &hnd_dst, &werr);
    16101662        }
    16111663
     
    16341686
    16351687NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c,
    1636                                                 const DOM_SID *domain_sid,
     1688                                                const struct dom_sid *domain_sid,
    16371689                                                const char *domain_name,
    16381690                                                struct cli_state *cli,
     
    16421694                                                const char **argv)
    16431695{
     1696        struct dcerpc_binding_handle *b_src = pipe_hnd->binding_handle;
    16441697        NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
    16451698        WERROR result;
     
    16491702        const char *printername, *sharename;
    16501703        struct rpc_pipe_client *pipe_hnd_dst = NULL;
     1704        struct dcerpc_binding_handle *b_dst = NULL;
    16511705        struct policy_handle hnd_src, hnd_dst;
    16521706        union spoolss_PrinterInfo *info_enum;
     
    16611715        nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
    16621716                                     &ndr_table_spoolss.syntax_id);
    1663         if (!NT_STATUS_IS_OK(nt_status))
     1717        if (!NT_STATUS_IS_OK(nt_status)) {
    16641718                return nt_status;
     1719        }
     1720        b_dst = pipe_hnd_dst->binding_handle;
    16651721
    16661722        /* enum src printers */
     
    17371793                        /* FIXME: there might be something wrong with samba's
    17381794                           builtin-forms */
    1739                         status = rpccli_spoolss_AddForm(pipe_hnd_dst, mem_ctx,
     1795                        status = dcerpc_spoolss_AddForm(b_dst, mem_ctx,
    17401796                                                        &hnd_dst,
    17411797                                                        1,
    17421798                                                        info,
    17431799                                                        &result);
     1800                        if (!NT_STATUS_IS_OK(status)) {
     1801                                d_printf(_("\tdcerpc_spoolss_AddForm form %d: [%s] - %s\n"),
     1802                                        f, forms[f].info1.form_name, nt_errstr(status));
     1803                                continue;
     1804                        }
    17441805                        if (!W_ERROR_IS_OK(result)) {
    17451806                                d_printf(_("\tAddForm form %d: [%s] refused.\n"),
     
    17551816                /* close printer handles here */
    17561817                if (is_valid_policy_hnd(&hnd_src)) {
    1757                         rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
     1818                        dcerpc_spoolss_ClosePrinter(b_src, mem_ctx, &hnd_src, &result);
    17581819                }
    17591820
    17601821                if (is_valid_policy_hnd(&hnd_dst)) {
    1761                         rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
     1822                        dcerpc_spoolss_ClosePrinter(b_dst, mem_ctx, &hnd_dst, &result);
    17621823                }
    17631824        }
     
    17671828done:
    17681829
    1769         if (is_valid_policy_hnd(&hnd_src))
    1770                 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
    1771 
    1772         if (is_valid_policy_hnd(&hnd_dst))
    1773                 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
     1830        if (is_valid_policy_hnd(&hnd_src)) {
     1831                dcerpc_spoolss_ClosePrinter(b_src, mem_ctx, &hnd_src, &result);
     1832        }
     1833
     1834        if (is_valid_policy_hnd(&hnd_dst)) {
     1835                dcerpc_spoolss_ClosePrinter(b_dst, mem_ctx, &hnd_dst, &result);
     1836        }
    17741837
    17751838        if (cli_dst) {
     
    17971860
    17981861NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c,
    1799                                                 const DOM_SID *domain_sid,
     1862                                                const struct dom_sid *domain_sid,
    18001863                                                const char *domain_name,
    18011864                                                struct cli_state *cli,
     
    18051868                                                const char **argv)
    18061869{
     1870        struct dcerpc_binding_handle *b_src = pipe_hnd->binding_handle;
    18071871        NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
    18081872        uint32_t i, p;
     
    18131877        bool got_dst_driver_share = false;
    18141878        struct rpc_pipe_client *pipe_hnd_dst = NULL;
     1879        struct dcerpc_binding_handle *b_dst = NULL;
    18151880        struct policy_handle hnd_src, hnd_dst;
    18161881        union spoolss_DriverInfo drv_info_src;
     
    18211886        struct cli_state *cli_share_dst = NULL;
    18221887        const char *drivername = NULL;
     1888        WERROR werr;
    18231889
    18241890        DEBUG(3,("copying printer-drivers\n"));
     
    18261892        nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
    18271893                                     &ndr_table_spoolss.syntax_id);
    1828         if (!NT_STATUS_IS_OK(nt_status))
     1894        if (!NT_STATUS_IS_OK(nt_status)) {
    18291895                return nt_status;
     1896        }
     1897        b_dst = pipe_hnd_dst->binding_handle;
    18301898
    18311899        /* open print$-share on the src server */
     
    19562024                /* close dst */
    19572025                if (is_valid_policy_hnd(&hnd_dst)) {
    1958                         rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
     2026                        dcerpc_spoolss_ClosePrinter(b_dst, mem_ctx, &hnd_dst, &werr);
    19592027                }
    19602028
    19612029                /* close src */
    19622030                if (is_valid_policy_hnd(&hnd_src)) {
    1963                         rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
     2031                        dcerpc_spoolss_ClosePrinter(b_src, mem_ctx, &hnd_src, &werr);
    19642032                }
    19652033        }
     
    19692037done:
    19702038
    1971         if (is_valid_policy_hnd(&hnd_src))
    1972                 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
    1973 
    1974         if (is_valid_policy_hnd(&hnd_dst))
    1975                 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
     2039        if (is_valid_policy_hnd(&hnd_dst)) {
     2040                dcerpc_spoolss_ClosePrinter(b_dst, mem_ctx, &hnd_dst, &werr);
     2041        }
     2042
     2043        /* close src */
     2044        if (is_valid_policy_hnd(&hnd_src)) {
     2045                dcerpc_spoolss_ClosePrinter(b_src, mem_ctx, &hnd_src, &werr);
     2046        }
    19762047
    19772048        if (cli_dst) {
     
    20082079
    20092080NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c,
    2010                                                 const DOM_SID *domain_sid,
     2081                                                const struct dom_sid *domain_sid,
    20112082                                                const char *domain_name,
    20122083                                                struct cli_state *cli,
     
    20162087                                                const char **argv)
    20172088{
     2089        struct dcerpc_binding_handle *b_src = pipe_hnd->binding_handle;
    20182090        WERROR result;
    20192091        NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
     
    20262098        const char *printername, *sharename;
    20272099        struct rpc_pipe_client *pipe_hnd_dst = NULL;
     2100        struct dcerpc_binding_handle *b_dst = NULL;
    20282101        struct spoolss_SetPrinterInfoCtr info_ctr;
    20292102
     
    20332106        nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
    20342107                                     &ndr_table_spoolss.syntax_id);
    2035         if (!NT_STATUS_IS_OK(nt_status))
     2108        if (!NT_STATUS_IS_OK(nt_status)) {
    20362109                return nt_status;
     2110        }
     2111        b_dst = pipe_hnd_dst->binding_handle;
    20372112
    20382113        /* enum printers */
     
    20822157                        /* close printer handle here - dst only, not got src yet. */
    20832158                        if (is_valid_policy_hnd(&hnd_dst)) {
    2084                                 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
     2159                                dcerpc_spoolss_ClosePrinter(b_dst, mem_ctx, &hnd_dst, &result);
    20852160                        }
    20862161                        continue;
     
    21252200                /* close printer handles here */
    21262201                if (is_valid_policy_hnd(&hnd_src)) {
    2127                         rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
     2202                        dcerpc_spoolss_ClosePrinter(b_src, mem_ctx, &hnd_src, &result);
    21282203                }
    21292204
    21302205                if (is_valid_policy_hnd(&hnd_dst)) {
    2131                         rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
     2206                        dcerpc_spoolss_ClosePrinter(b_dst, mem_ctx, &hnd_dst, &result);
    21322207                }
    21332208        }
     
    21362211
    21372212done:
    2138         if (is_valid_policy_hnd(&hnd_src))
    2139                 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
    2140 
    2141         if (is_valid_policy_hnd(&hnd_dst))
    2142                 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
     2213        if (is_valid_policy_hnd(&hnd_src)) {
     2214                dcerpc_spoolss_ClosePrinter(b_src, mem_ctx, &hnd_src, &result);
     2215        }
     2216
     2217        if (is_valid_policy_hnd(&hnd_dst)) {
     2218                dcerpc_spoolss_ClosePrinter(b_dst, mem_ctx, &hnd_dst, &result);
     2219        }
    21432220
    21442221        if (cli_dst) {
     
    21672244
    21682245NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c,
    2169                                                 const DOM_SID *domain_sid,
     2246                                                const struct dom_sid *domain_sid,
    21702247                                                const char *domain_name,
    21712248                                                struct cli_state *cli,
     
    21752252                                                const char **argv)
    21762253{
     2254        struct dcerpc_binding_handle *b_src = pipe_hnd->binding_handle;
    21772255
    21782256        /* FIXME: Here the nightmare begins */
     
    21802258        WERROR result;
    21812259        NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
    2182         uint32_t i = 0, p = 0, j = 0;
     2260        uint32_t i = 0, j = 0;
    21832261        uint32_t num_printers;
    21842262        uint32_t level = 2;
    21852263        const char *printername, *sharename;
    21862264        struct rpc_pipe_client *pipe_hnd_dst = NULL;
     2265        struct dcerpc_binding_handle *b_dst = NULL;
    21872266        struct policy_handle hnd_src, hnd_dst;
    21882267        union spoolss_PrinterInfo *info_enum;
     
    22022281        nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
    22032282                                     &ndr_table_spoolss.syntax_id);
    2204         if (!NT_STATUS_IS_OK(nt_status))
     2283        if (!NT_STATUS_IS_OK(nt_status)) {
    22052284                return nt_status;
     2285        }
     2286        b_dst = pipe_hnd_dst->binding_handle;
    22062287
    22072288        /* enum src printers */
     
    22282309        for (i = 0; i < num_printers; i++) {
    22292310
    2230                 uint32_t value_offered = 0, value_needed;
    2231                 uint32_t data_offered = 0, data_needed;
     2311                uint32_t value_needed;
     2312                uint32_t data_needed;
    22322313                enum winreg_Type type;
    2233                 uint8_t *buffer = NULL;
    2234                 const char *value_name = NULL;
     2314                struct spoolss_EnumPrinterData r;
    22352315
    22362316                /* do some initialization */
     
    23242404                */
    23252405
     2406                r.in.handle = &hnd_src;
     2407                r.in.enum_index = 0;
     2408                r.in.value_offered = 0;
     2409                r.in.data_offered = 0;
     2410                r.out.value_name = NULL;
     2411                r.out.value_needed = &value_needed;
     2412                r.out.type = &type;
     2413                r.out.data = NULL;
     2414                r.out.data_needed = &data_needed;
     2415
    23262416                /* enumerate data on src handle */
    2327                 nt_status = rpccli_spoolss_EnumPrinterData(pipe_hnd, mem_ctx,
    2328                                                            &hnd_src,
    2329                                                            p,
    2330                                                            value_name,
    2331                                                            value_offered,
    2332                                                            &value_needed,
    2333                                                            &type,
    2334                                                            buffer,
    2335                                                            data_offered,
    2336                                                            &data_needed,
    2337                                                            &result);
    2338 
    2339                 data_offered    = data_needed;
    2340                 value_offered   = value_needed;
    2341                 buffer          = talloc_zero_array(mem_ctx, uint8_t, data_needed);
    2342                 value_name      = talloc_zero_array(mem_ctx, char, value_needed);
     2417                nt_status = dcerpc_spoolss_EnumPrinterData_r(b_src, mem_ctx, &r);
     2418
     2419                r.in.data_offered       = *r.out.data_needed;
     2420                r.in.value_offered      = *r.out.value_needed;
     2421                r.out.data              = talloc_zero_array(mem_ctx, uint8_t, r.in.data_offered);
     2422                r.out.value_name        = talloc_zero_array(mem_ctx, char, r.in.value_offered);
    23432423
    23442424                /* loop for all printerdata of "PrinterDriverData" */
    2345                 while (NT_STATUS_IS_OK(nt_status) && W_ERROR_IS_OK(result)) {
    2346 
    2347                         nt_status = rpccli_spoolss_EnumPrinterData(pipe_hnd, mem_ctx,
    2348                                                                    &hnd_src,
    2349                                                                    p++,
    2350                                                                    value_name,
    2351                                                                    value_offered,
    2352                                                                    &value_needed,
    2353                                                                    &type,
    2354                                                                    buffer,
    2355                                                                    data_offered,
    2356                                                                    &data_needed,
    2357                                                                    &result);
     2425                while (NT_STATUS_IS_OK(nt_status) && W_ERROR_IS_OK(r.out.result)) {
     2426
     2427                        r.in.enum_index++;
     2428
     2429                        nt_status = dcerpc_spoolss_EnumPrinterData_r(b_src, mem_ctx, &r);
     2430
    23582431                        /* loop for all reg_keys */
    2359                         if (NT_STATUS_IS_OK(nt_status) && W_ERROR_IS_OK(result)) {
    2360 
    2361                                 struct regval_blob v;
     2432                        if (NT_STATUS_IS_OK(nt_status) && W_ERROR_IS_OK(r.out.result)) {
    23622433
    23632434                                /* display_value */
    23642435                                if (c->opt_verbose) {
    2365                                         fstrcpy(v.valuename, value_name);
    2366                                         v.type = type;
    2367                                         v.size = data_offered;
    2368                                         v.data_p = buffer;
     2436                                        struct regval_blob *v;
     2437
     2438                                        v = regval_compose(talloc_tos(),
     2439                                                           r.out.value_name,
     2440                                                           *r.out.type,
     2441                                                           r.out.data,
     2442                                                           r.in.data_offered);
     2443                                        if (v == NULL) {
     2444                                                nt_status = NT_STATUS_NO_MEMORY;
     2445                                                goto done;
     2446                                        }
     2447
    23692448                                        display_reg_value(SPOOL_PRINTERDATA_KEY, v);
     2449                                        talloc_free(v);
    23702450                                }
    23712451
    23722452                                /* set_value */
    23732453                                if (!net_spoolss_setprinterdata(pipe_hnd_dst, mem_ctx,
    2374                                                                 &hnd_dst, value_name,
    2375                                                                 type, buffer, data_offered))
     2454                                                                &hnd_dst, r.out.value_name,
     2455                                                                *r.out.type, r.out.data, r.in.data_offered))
    23762456                                        goto done;
    23772457
    23782458                                DEBUGADD(1,("\tSetPrinterData of [%s] succeeded\n",
    2379                                         v.valuename));
     2459                                            r.out.value_name));
    23802460                        }
    23812461                }
     
    24162496                        for (j=0; j < count; j++) {
    24172497
    2418                                 struct regval_blob value;
     2498                                struct regval_blob *value;
    24192499                                DATA_BLOB blob;
     2500
     2501                                ZERO_STRUCT(blob);
    24202502
    24212503                                /* although samba replies with sane data in most cases we
     
    24322514                                                /* although windows uses a multi-sz, we use a sz */
    24332515                                                push_reg_sz(mem_ctx, &blob, SAMBA_PRINTER_PORT_NAME);
    2434                                                 fstrcpy(value.valuename, SPOOL_REG_PORTNAME);
    24352516                                        }
    24362517
     
    24422523                                                }
    24432524                                                push_reg_sz(mem_ctx, &blob, unc_name);
    2444                                                 fstrcpy(value.valuename, SPOOL_REG_UNCNAME);
    24452525                                        }
    24462526
     
    24552535                                                        goto done;
    24562536                                                }
    2457                                                 push_reg_sz(mem_ctx, &blob, url);
     2537                                                push_reg_sz(mem_ctx, NULL, &blob, url);
    24582538                                                fstrcpy(value.valuename, SPOOL_REG_URL);
    24592539#endif
     
    24632543
    24642544                                                push_reg_sz(mem_ctx, &blob, longname);
    2465                                                 fstrcpy(value.valuename, SPOOL_REG_SERVERNAME);
    24662545                                        }
    24672546
     
    24692548
    24702549                                                push_reg_sz(mem_ctx, &blob, global_myname());
    2471                                                 fstrcpy(value.valuename, SPOOL_REG_SHORTSERVERNAME);
    24722550                                        }
    24732551
    2474                                         value.type = REG_SZ;
    2475                                         value.size = blob.length;
    2476                                         if (value.size) {
    2477                                                 value.data_p = blob.data;
    2478                                         } else {
    2479                                                 value.data_p = NULL;
     2552                                        value = regval_compose(talloc_tos(),
     2553                                                               info[j].value_name,
     2554                                                               REG_SZ,
     2555                                                               blob.length == 0 ? NULL : blob.data,
     2556                                                               blob.length);
     2557                                        if (value == NULL) {
     2558                                                nt_status = NT_STATUS_NO_MEMORY;
     2559                                                goto done;
    24802560                                        }
    24812561
     
    24852565                                        /* here we have to set all subkeys on the dst server */
    24862566                                        if (!net_spoolss_setprinterdataex(pipe_hnd_dst, mem_ctx, &hnd_dst,
    2487                                                         subkey, &value))
     2567                                                        subkey, value))
     2568                                        {
     2569                                                talloc_free(value);
    24882570                                                goto done;
    2489 
     2571                                        }
     2572
     2573                                        talloc_free(value);
    24902574                                } else {
    24912575
    2492                                         struct regval_blob v;
    2493 
    2494                                         fstrcpy(v.valuename, info[j].value_name);
    2495                                         v.type = info[j].type;
    2496                                         v.data_p = info[j].data->data;
    2497                                         v.size = info[j].data->length;
     2576                                        struct regval_blob *v;
     2577
     2578                                        v = regval_compose(talloc_tos(),
     2579                                                           info[j].value_name,
     2580                                                           info[j].type,
     2581                                                           info[j].data->data,
     2582                                                           info[j].data->length);
     2583                                        if (v == NULL) {
     2584                                                nt_status = NT_STATUS_NO_MEMORY;
     2585                                                goto done;
     2586                                        }
    24982587
    24992588                                        if (c->opt_verbose) {
     
    25032592                                        /* here we have to set all subkeys on the dst server */
    25042593                                        if (!net_spoolss_setprinterdataex(pipe_hnd_dst, mem_ctx, &hnd_dst,
    2505                                                         subkey, &v)) {
     2594                                                        subkey, v)) {
    25062595                                                goto done;
    25072596                                        }
    25082597
     2598                                        talloc_free(v);
    25092599                                }
    25102600
     
    25192609                /* close printer handles here */
    25202610                if (is_valid_policy_hnd(&hnd_src)) {
    2521                         rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
     2611                        dcerpc_spoolss_ClosePrinter(b_src, mem_ctx, &hnd_src, &result);
    25222612                }
    25232613
    25242614                if (is_valid_policy_hnd(&hnd_dst)) {
    2525                         rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
    2526                 }
    2527 
     2615                        dcerpc_spoolss_ClosePrinter(b_dst, mem_ctx, &hnd_dst, &result);
     2616                }
    25282617        }
    25292618
     
    25352624        SAFE_FREE(unc_name);
    25362625
    2537         if (is_valid_policy_hnd(&hnd_src))
    2538                 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
    2539 
    2540         if (is_valid_policy_hnd(&hnd_dst))
    2541                 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
     2626        if (is_valid_policy_hnd(&hnd_src)) {
     2627                dcerpc_spoolss_ClosePrinter(b_src, mem_ctx, &hnd_src, &result);
     2628        }
     2629
     2630        if (is_valid_policy_hnd(&hnd_dst)) {
     2631                dcerpc_spoolss_ClosePrinter(b_dst, mem_ctx, &hnd_dst, &result);
     2632        }
    25422633
    25432634        if (cli_dst) {
  • vendor/current/source3/utils/net_rpc_registry.c

    r587 r740  
    1919 
    2020#include "includes.h"
     21#include "system/filesys.h"
     22#include "rpc_client/rpc_client.h"
     23#include "registry.h"
    2124#include "utils/net.h"
    2225#include "utils/net_registry_util.h"
    23 #include "regfio.h"
    24 #include "reg_objects.h"
    25 #include "../librpc/gen_ndr/cli_winreg.h"
     26#include "registry/regfio.h"
     27#include "../librpc/gen_ndr/ndr_winreg_c.h"
     28#include "../librpc/gen_ndr/ndr_security.h"
     29#include "registry/reg_format.h"
     30#include "registry/reg_import.h"
     31#include <assert.h>
     32#include "../libcli/security/display_sec.h"
     33#include "../libcli/registry/util_reg.h"
     34#include "client.h"
     35
    2636
    2737/*******************************************************************
     
    2939*******************************************************************/
    3040
    31 static NTSTATUS rpccli_winreg_Connect(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
     41static NTSTATUS dcerpc_winreg_Connect(struct dcerpc_binding_handle *b, TALLOC_CTX *mem_ctx,
    3242                                      uint32_t reg_type, uint32_t access_mask,
    33                                       struct policy_handle *reg_hnd)
     43                                      struct policy_handle *reg_hnd, WERROR *werr)
    3444{
    3545        ZERO_STRUCTP(reg_hnd);
     
    3848        {
    3949        case HKEY_CLASSES_ROOT:
    40                 return rpccli_winreg_OpenHKCR( cli, mem_ctx, NULL,
    41                         access_mask, reg_hnd, NULL);
     50                return dcerpc_winreg_OpenHKCR(b, mem_ctx, NULL,
     51                        access_mask, reg_hnd, werr);
    4252
    4353        case HKEY_LOCAL_MACHINE:
    44                 return rpccli_winreg_OpenHKLM( cli, mem_ctx, NULL,
    45                         access_mask, reg_hnd, NULL);
     54                return dcerpc_winreg_OpenHKLM(b, mem_ctx, NULL,
     55                        access_mask, reg_hnd, werr);
    4656
    4757        case HKEY_USERS:
    48                 return rpccli_winreg_OpenHKU( cli, mem_ctx, NULL,
    49                         access_mask, reg_hnd, NULL);
     58                return dcerpc_winreg_OpenHKU(b, mem_ctx, NULL,
     59                        access_mask, reg_hnd, werr);
    5060
    5161        case HKEY_CURRENT_USER:
    52                 return rpccli_winreg_OpenHKCU( cli, mem_ctx, NULL,
    53                         access_mask, reg_hnd, NULL);
     62                return dcerpc_winreg_OpenHKCU(b, mem_ctx, NULL,
     63                        access_mask, reg_hnd, werr);
    5464
    5565        case HKEY_PERFORMANCE_DATA:
    56                 return rpccli_winreg_OpenHKPD( cli, mem_ctx, NULL,
    57                         access_mask, reg_hnd, NULL);
     66                return dcerpc_winreg_OpenHKPD(b, mem_ctx, NULL,
     67                        access_mask, reg_hnd, werr);
    5868
    5969        default:
     
    125135        uint32 hive;
    126136        NTSTATUS status;
     137        WERROR werr;
    127138        struct winreg_String key;
     139        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    128140
    129141        ZERO_STRUCT(key);
     
    133145        }
    134146
    135         status = rpccli_winreg_Connect(pipe_hnd, mem_ctx, hive, access_mask,
    136                                        hive_hnd);
     147        status = dcerpc_winreg_Connect(b, mem_ctx, hive, access_mask,
     148                                       hive_hnd, &werr);
    137149        if (!(NT_STATUS_IS_OK(status))) {
    138150                return status;
    139151        }
    140 
    141         status = rpccli_winreg_OpenKey(pipe_hnd, mem_ctx, hive_hnd, key, 0,
    142                                        access_mask, key_hnd, NULL);
     152        if (!W_ERROR_IS_OK(werr)) {
     153                return werror_to_ntstatus(werr);
     154        }
     155
     156        status = dcerpc_winreg_OpenKey(b, mem_ctx, hive_hnd, key, 0,
     157                                       access_mask, key_hnd, &werr);
    143158        if (!(NT_STATUS_IS_OK(status))) {
    144                 rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, hive_hnd, NULL);
     159                dcerpc_winreg_CloseKey(b, mem_ctx, hive_hnd, &werr);
    145160                return status;
     161        }
     162        if (!(W_ERROR_IS_OK(werr))) {
     163                WERROR _werr;
     164                dcerpc_winreg_CloseKey(b, mem_ctx, hive_hnd, &_werr);
     165                return werror_to_ntstatus(werr);
    146166        }
    147167
     
    157177        TALLOC_CTX *mem_ctx;
    158178        NTSTATUS status;
     179        WERROR werr;
    159180        uint32 num_subkeys, max_subkeylen, max_classlen;
    160181        uint32 num_values, max_valnamelen, max_valbufsize;
     
    165186        char **names, **classes;
    166187        NTTIME **modtimes;
     188        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    167189
    168190        if (!(mem_ctx = talloc_new(ctx))) {
     
    171193
    172194        ZERO_STRUCT(classname);
    173         status = rpccli_winreg_QueryInfoKey(
    174                 pipe_hnd, mem_ctx, key_hnd, &classname, &num_subkeys,
     195        status = dcerpc_winreg_QueryInfoKey(
     196                b, mem_ctx, key_hnd, &classname, &num_subkeys,
    175197                &max_subkeylen, &max_classlen, &num_values, &max_valnamelen,
    176                 &max_valbufsize, &secdescsize, &last_changed_time, NULL );
    177 
    178         if (!NT_STATUS_IS_OK(status)) {
     198                &max_valbufsize, &secdescsize, &last_changed_time, &werr);
     199
     200        if (!NT_STATUS_IS_OK(status)) {
     201                goto error;
     202        }
     203        if (!W_ERROR_IS_OK(werr)) {
     204                status = werror_to_ntstatus(werr);
    179205                goto error;
    180206        }
     
    199225                struct winreg_StringBuf name_buf;
    200226                NTTIME modtime;
    201                 WERROR werr;
    202227
    203228                c = '\0';
     
    211236                ZERO_STRUCT(modtime);
    212237
    213                 status = rpccli_winreg_EnumKey(pipe_hnd, mem_ctx, key_hnd,
     238                status = dcerpc_winreg_EnumKey(b, mem_ctx, key_hnd,
    214239                                               i, &name_buf, &class_buf,
    215240                                               &modtime, &werr);
    216 
     241                if (!NT_STATUS_IS_OK(status)) {
     242                        goto error;
     243                }
    217244                if (W_ERROR_EQUAL(werr,
    218245                                  WERR_NO_MORE_ITEMS) ) {
     
    220247                        break;
    221248                }
    222                 if (!NT_STATUS_IS_OK(status)) {
     249                if (!W_ERROR_IS_OK(werr)) {
     250                        status = werror_to_ntstatus(werr);
    223251                        goto error;
    224252                }
     
    271299        TALLOC_CTX *mem_ctx;
    272300        NTSTATUS status;
     301        WERROR werr;
    273302        uint32 num_subkeys, max_subkeylen, max_classlen;
    274303        uint32 num_values, max_valnamelen, max_valbufsize;
     
    279308        struct registry_value **values;
    280309        char **names;
     310        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    281311
    282312        if (!(mem_ctx = talloc_new(ctx))) {
     
    285315
    286316        ZERO_STRUCT(classname);
    287         status = rpccli_winreg_QueryInfoKey(
    288                 pipe_hnd, mem_ctx, key_hnd, &classname, &num_subkeys,
     317        status = dcerpc_winreg_QueryInfoKey(
     318                b, mem_ctx, key_hnd, &classname, &num_subkeys,
    289319                &max_subkeylen, &max_classlen, &num_values, &max_valnamelen,
    290                 &max_valbufsize, &secdescsize, &last_changed_time, NULL );
    291 
    292         if (!NT_STATUS_IS_OK(status)) {
     320                &max_valbufsize, &secdescsize, &last_changed_time, &werr);
     321
     322        if (!NT_STATUS_IS_OK(status)) {
     323                goto error;
     324        }
     325        if (!W_ERROR_IS_OK(werr)) {
     326                status = werror_to_ntstatus(werr);
    293327                goto error;
    294328        }
     
    325359                value_length = 0;
    326360
    327                 status = rpccli_winreg_EnumValue(pipe_hnd, mem_ctx, key_hnd,
     361                status = dcerpc_winreg_EnumValue(b, mem_ctx, key_hnd,
    328362                                                 i, &name_buf, &type,
    329363                                                 data, &data_size,
    330364                                                 &value_length, &err);
     365                if (!(NT_STATUS_IS_OK(status))) {
     366                        goto error;
     367                }
    331368
    332369                if ( W_ERROR_EQUAL(err,
     
    336373                }
    337374
    338                 if (!(NT_STATUS_IS_OK(status))) {
     375                if (!W_ERROR_IS_OK(err)) {
     376                        status = werror_to_ntstatus(err);
    339377                        goto error;
    340378                }
     
    350388                }
    351389
    352                 err = registry_pull_value(values, &values[i], type, data,
    353                                           data_size, value_length);
     390                values[i] = talloc_zero(values, struct registry_value);
     391                if (values[i] == NULL) {
     392                        status = NT_STATUS_NO_MEMORY;
     393                        goto error;
     394                }
     395
     396                values[i]->type = type;
     397                values[i]->data = data_blob_talloc(values[i], data, data_size);
     398        }
     399
     400        *pnum_values = num_values;
     401
     402        if (pvalnames) {
     403                *pvalnames = talloc_move(ctx, &names);
     404        }
     405        if (pvalues) {
     406                *pvalues = talloc_move(ctx, &values);
     407        }
     408
     409        status = NT_STATUS_OK;
     410
     411 error:
     412        TALLOC_FREE(mem_ctx);
     413        return status;
     414}
     415
     416static NTSTATUS registry_enumvalues2(TALLOC_CTX *ctx,
     417                                     struct rpc_pipe_client *pipe_hnd,
     418                                     struct policy_handle *key_hnd,
     419                                     uint32 *pnum_values, char ***pvalnames,
     420                                     struct regval_blob ***pvalues)
     421{
     422        TALLOC_CTX *mem_ctx;
     423        NTSTATUS status;
     424        WERROR werr;
     425        uint32 num_subkeys, max_subkeylen, max_classlen;
     426        uint32 num_values, max_valnamelen, max_valbufsize;
     427        uint32 i;
     428        NTTIME last_changed_time;
     429        uint32 secdescsize;
     430        struct winreg_String classname;
     431        struct regval_blob **values;
     432        char **names;
     433        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
     434
     435        if (!(mem_ctx = talloc_new(ctx))) {
     436                return NT_STATUS_NO_MEMORY;
     437        }
     438
     439        ZERO_STRUCT(classname);
     440        status = dcerpc_winreg_QueryInfoKey(
     441                b, mem_ctx, key_hnd, &classname, &num_subkeys,
     442                &max_subkeylen, &max_classlen, &num_values, &max_valnamelen,
     443                &max_valbufsize, &secdescsize, &last_changed_time, &werr);
     444
     445        if (!NT_STATUS_IS_OK(status)) {
     446                goto error;
     447        }
     448        if (!W_ERROR_IS_OK(werr)) {
     449                status = werror_to_ntstatus(werr);
     450                goto error;
     451        }
     452
     453        if (num_values == 0) {
     454                *pnum_values = 0;
     455                TALLOC_FREE(mem_ctx);
     456                return NT_STATUS_OK;
     457        }
     458
     459        if ((!(names = TALLOC_ARRAY(mem_ctx, char *, num_values))) ||
     460            (!(values = TALLOC_ARRAY(mem_ctx, struct regval_blob *,
     461                                     num_values)))) {
     462                status = NT_STATUS_NO_MEMORY;
     463                goto error;
     464        }
     465
     466        for (i=0; i<num_values; i++) {
     467                enum winreg_Type type = REG_NONE;
     468                uint8 *data = NULL;
     469                uint32 data_size;
     470                uint32 value_length;
     471
     472                char n;
     473                struct winreg_ValNameBuf name_buf;
     474                WERROR err;
     475
     476                n = '\0';
     477                name_buf.name = &n;
     478                name_buf.size = max_valnamelen + 2;
     479
     480                data_size = max_valbufsize;
     481                data = (uint8 *)TALLOC(mem_ctx, data_size);
     482                value_length = 0;
     483
     484                status = dcerpc_winreg_EnumValue(b, mem_ctx, key_hnd,
     485                                                 i, &name_buf, &type,
     486                                                 data, &data_size,
     487                                                 &value_length, &err);
     488                if (!(NT_STATUS_IS_OK(status))) {
     489                        goto error;
     490                }
     491
     492                if ( W_ERROR_EQUAL(err, WERR_NO_MORE_ITEMS) ) {
     493                        status = NT_STATUS_OK;
     494                        break;
     495                }
     496
    354497                if (!W_ERROR_IS_OK(err)) {
    355498                        status = werror_to_ntstatus(err);
    356499                        goto error;
    357500                }
     501
     502                if (name_buf.name == NULL) {
     503                        status = NT_STATUS_INVALID_PARAMETER;
     504                        goto error;
     505                }
     506
     507                if (!(names[i] = talloc_strdup(names, name_buf.name))) {
     508                        status = NT_STATUS_NO_MEMORY;
     509                        goto error;
     510                }
     511
     512                assert(value_length<=data_size); //???
     513
     514                values[i] = regval_compose(values,
     515                                           name_buf.name,
     516                                           type,
     517                                           data, value_length);
     518                if (!values[i]) {
     519                        status = NT_STATUS_NO_MEMORY;
     520                        goto error;
     521                }
    358522        }
    359523
     
    375539
    376540static NTSTATUS registry_getsd(TALLOC_CTX *mem_ctx,
    377                                struct rpc_pipe_client *pipe_hnd,
     541                               struct dcerpc_binding_handle *b,
    378542                               struct policy_handle *key_hnd,
    379543                               uint32_t sec_info,
    380                                struct KeySecurityData *sd)
    381 {
    382         return rpccli_winreg_GetKeySecurity(pipe_hnd, mem_ctx, key_hnd,
    383                                             sec_info, sd, NULL);
     544                               struct KeySecurityData *sd,
     545                               WERROR *werr)
     546{
     547        return dcerpc_winreg_GetKeySecurity(b, mem_ctx, key_hnd,
     548                                            sec_info, sd, werr);
    384549}
    385550
     
    392557{
    393558        struct winreg_String name_string;
    394         DATA_BLOB blob;
    395559        NTSTATUS result;
    396         WERROR err;
    397 
    398         err = registry_push_value(mem_ctx, value, &blob);
    399         if (!W_ERROR_IS_OK(err)) {
    400                 return werror_to_ntstatus(err);
    401         }
     560        WERROR werr;
     561        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    402562
    403563        ZERO_STRUCT(name_string);
    404564
    405565        name_string.name = name;
    406         result = rpccli_winreg_SetValue(pipe_hnd, blob.data, key_hnd,
     566        result = dcerpc_winreg_SetValue(b, mem_ctx, key_hnd,
    407567                                        name_string, value->type,
    408                                         blob.data, blob.length, NULL);
    409         TALLOC_FREE(blob.data);
    410         return result;
     568                                        value->data.data, value->data.length, &werr);
     569        if (!NT_STATUS_IS_OK(result)) {
     570                return result;
     571        }
     572
     573        return werror_to_ntstatus(werr);
    411574}
    412575
    413576static NTSTATUS rpc_registry_setvalue_internal(struct net_context *c,
    414                                                const DOM_SID *domain_sid,
     577                                               const struct dom_sid *domain_sid,
    415578                                               const char *domain_name,
    416579                                               struct cli_state *cli,
     
    422585        struct policy_handle hive_hnd, key_hnd;
    423586        NTSTATUS status;
     587        WERROR werr;
    424588        struct registry_value value;
     589        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    425590
    426591        status = registry_openkey(mem_ctx, pipe_hnd, argv[0],
     
    439604
    440605        if (strequal(argv[2], "dword")) {
     606                uint32_t v = strtoul(argv[3], NULL, 10);
    441607                value.type = REG_DWORD;
    442                 value.v.dword = strtoul(argv[3], NULL, 10);
     608                value.data = data_blob_talloc(mem_ctx, NULL, 4);
     609                SIVAL(value.data.data, 0, v);
    443610        }
    444611        else if (strequal(argv[2], "sz")) {
    445612                value.type = REG_SZ;
    446                 value.v.sz.len = strlen(argv[3])+1;
    447                 value.v.sz.str = CONST_DISCARD(char *, argv[3]);
     613                if (!push_reg_sz(mem_ctx, &value.data, argv[3])) {
     614                        status = NT_STATUS_NO_MEMORY;
     615                        goto error;
     616                }
    448617        }
    449618        else {
     
    462631
    463632 error:
    464         rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &key_hnd, NULL);
    465         rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &hive_hnd, NULL);
     633        dcerpc_winreg_CloseKey(b, mem_ctx, &key_hnd, &werr);
     634        dcerpc_winreg_CloseKey(b, mem_ctx, &hive_hnd, &werr);
    466635
    467636        return NT_STATUS_OK;
     
    484653
    485654static NTSTATUS rpc_registry_deletevalue_internal(struct net_context *c,
    486                                                   const DOM_SID *domain_sid,
     655                                                  const struct dom_sid *domain_sid,
    487656                                                  const char *domain_name,
    488657                                                  struct cli_state *cli,
     
    494663        struct policy_handle hive_hnd, key_hnd;
    495664        NTSTATUS status;
     665        WERROR werr;
    496666        struct winreg_String valuename;
     667        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    497668
    498669        ZERO_STRUCT(valuename);
     
    509680        valuename.name = argv[1];
    510681
    511         status = rpccli_winreg_DeleteValue(pipe_hnd, mem_ctx, &key_hnd,
    512                                            valuename, NULL);
    513 
     682        status = dcerpc_winreg_DeleteValue(b, mem_ctx, &key_hnd,
     683                                           valuename, &werr);
    514684        if (!NT_STATUS_IS_OK(status)) {
    515685                d_fprintf(stderr, _("registry_deletevalue failed: %s\n"),
    516686                          nt_errstr(status));
    517687        }
    518 
    519         rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &key_hnd, NULL);
    520         rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &hive_hnd, NULL);
     688        if (!W_ERROR_IS_OK(werr)) {
     689                status = werror_to_ntstatus(werr);
     690                d_fprintf(stderr, _("registry_deletevalue failed: %s\n"),
     691                          win_errstr(werr));
     692        }
     693
     694        dcerpc_winreg_CloseKey(b, mem_ctx, &key_hnd, &werr);
     695        dcerpc_winreg_CloseKey(b, mem_ctx, &hive_hnd, &werr);
    521696
    522697        return status;
     
    538713
    539714static NTSTATUS rpc_registry_getvalue_internal(struct net_context *c,
    540                                                const DOM_SID *domain_sid,
     715                                               const struct dom_sid *domain_sid,
    541716                                               const char *domain_name,
    542717                                               struct cli_state *cli,
     
    553728        struct registry_value *value = NULL;
    554729        enum winreg_Type type = REG_NONE;
    555         uint8_t *data = NULL;
    556730        uint32_t data_size = 0;
    557731        uint32_t value_length = 0;
    558732        TALLOC_CTX *tmp_ctx = talloc_stackframe();
     733        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    559734
    560735        ZERO_STRUCT(valuename);
     
    570745
    571746        valuename.name = argv[1];
     747
     748        value = talloc_zero(tmp_ctx, struct registry_value);
     749        if (value == NULL) {
     750                return NT_STATUS_NO_MEMORY;
     751        }
    572752
    573753        /*
     
    576756         * data buffer and call again.
    577757         */
    578         status = rpccli_winreg_QueryValue(pipe_hnd, tmp_ctx, &key_hnd,
     758        status = dcerpc_winreg_QueryValue(b, tmp_ctx, &key_hnd,
    579759                                          &valuename,
    580760                                          &type,
    581                                           data,
     761                                          NULL,
    582762                                          &data_size,
    583763                                          &value_length,
    584                                           NULL);
     764                                          &werr);
    585765
    586766        if (!NT_STATUS_IS_OK(status)) {
     
    589769                goto done;
    590770        }
    591 
    592         data = (uint8 *)TALLOC(tmp_ctx, data_size);
    593         value_length = 0;
    594 
    595         status = rpccli_winreg_QueryValue(pipe_hnd, tmp_ctx, &key_hnd,
     771        if (!W_ERROR_IS_OK(werr)) {
     772                status = werror_to_ntstatus(werr);
     773                d_fprintf(stderr, _("registry_queryvalue failed: %s\n"),
     774                          nt_errstr(status));
     775                goto done;
     776        }
     777
     778        value->data = data_blob_talloc(tmp_ctx, NULL, data_size);
     779
     780        status = dcerpc_winreg_QueryValue(b, tmp_ctx, &key_hnd,
    596781                                          &valuename,
    597782                                          &type,
    598                                           data,
     783                                          value->data.data,
    599784                                          &data_size,
    600785                                          &value_length,
    601                                           NULL);
     786                                          &werr);
    602787
    603788        if (!NT_STATUS_IS_OK(status)) {
     
    606791                goto done;
    607792        }
    608 
    609         werr = registry_pull_value(tmp_ctx, &value, type, data,
    610                                    data_size, value_length);
    611793        if (!W_ERROR_IS_OK(werr)) {
    612794                status = werror_to_ntstatus(werr);
     795                d_fprintf(stderr, _("registry_queryvalue failed: %s\n"),
     796                          win_errstr(werr));
    613797                goto done;
    614798        }
    615799
     800
     801        value->type = type;
     802
    616803        print_registry_value(value, raw);
    617804
    618805done:
    619         rpccli_winreg_CloseKey(pipe_hnd, tmp_ctx, &key_hnd, NULL);
    620         rpccli_winreg_CloseKey(pipe_hnd, tmp_ctx, &hive_hnd, NULL);
     806        dcerpc_winreg_CloseKey(b, tmp_ctx, &key_hnd, &werr);
     807        dcerpc_winreg_CloseKey(b, tmp_ctx, &hive_hnd, &werr);
    621808
    622809        TALLOC_FREE(tmp_ctx);
     
    626813
    627814static NTSTATUS rpc_registry_getvalue_full(struct net_context *c,
    628                                            const DOM_SID *domain_sid,
     815                                           const struct dom_sid *domain_sid,
    629816                                           const char *domain_name,
    630817                                           struct cli_state *cli,
     
    654841
    655842static NTSTATUS rpc_registry_getvalue_raw(struct net_context *c,
    656                                           const DOM_SID *domain_sid,
     843                                          const struct dom_sid *domain_sid,
    657844                                          const char *domain_name,
    658845                                          struct cli_state *cli,
     
    682869
    683870static NTSTATUS rpc_registry_createkey_internal(struct net_context *c,
    684                                                 const DOM_SID *domain_sid,
     871                                                const struct dom_sid *domain_sid,
    685872                                                const char *domain_name,
    686873                                                struct cli_state *cli,
     
    695882        enum winreg_CreateAction action;
    696883        NTSTATUS status;
     884        WERROR werr;
     885        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    697886
    698887        ZERO_STRUCT(key);
     
    703892        }
    704893
    705         status = rpccli_winreg_Connect(pipe_hnd, mem_ctx, hive,
     894        status = dcerpc_winreg_Connect(b, mem_ctx, hive,
    706895                                       SEC_FLAG_MAXIMUM_ALLOWED,
    707                                        &hive_hnd);
     896                                       &hive_hnd, &werr);
    708897        if (!(NT_STATUS_IS_OK(status))) {
    709898                return status;
    710899        }
     900        if (!W_ERROR_IS_OK(werr)) {
     901                return werror_to_ntstatus(werr);
     902        }
    711903
    712904        action = REG_ACTION_NONE;
    713905        keyclass.name = "";
    714906
    715         status = rpccli_winreg_CreateKey(pipe_hnd, mem_ctx, &hive_hnd, key,
     907        status = dcerpc_winreg_CreateKey(b, mem_ctx, &hive_hnd, key,
    716908                                         keyclass, 0, REG_KEY_READ, NULL,
    717                                          &key_hnd, &action, NULL);
     909                                         &key_hnd, &action, &werr);
    718910        if (!NT_STATUS_IS_OK(status)) {
    719911                d_fprintf(stderr, _("createkey returned %s\n"),
    720912                          nt_errstr(status));
    721                 rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &hive_hnd, NULL);
     913                dcerpc_winreg_CloseKey(b, mem_ctx, &hive_hnd, &werr);
    722914                return status;
     915        }
     916        if (!W_ERROR_IS_OK(werr)) {
     917                WERROR _werr;
     918                d_fprintf(stderr, _("createkey returned %s\n"),
     919                          win_errstr(werr));
     920                dcerpc_winreg_CloseKey(b, mem_ctx, &hive_hnd, &_werr);
     921                return werror_to_ntstatus(werr);
    723922        }
    724923
     
    735934        }
    736935
    737         rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &key_hnd, NULL);
    738         rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &hive_hnd, NULL);
     936        dcerpc_winreg_CloseKey(b, mem_ctx, &key_hnd, &werr);
     937        dcerpc_winreg_CloseKey(b, mem_ctx, &hive_hnd, &werr);
    739938
    740939        return status;
     
    756955
    757956static NTSTATUS rpc_registry_deletekey_internal(struct net_context *c,
    758                                                 const DOM_SID *domain_sid,
     957                                                const struct dom_sid *domain_sid,
    759958                                                const char *domain_name,
    760959                                                struct cli_state *cli,
     
    768967        struct winreg_String key;
    769968        NTSTATUS status;
     969        WERROR werr;
     970        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    770971
    771972        ZERO_STRUCT(key);
     
    775976        }
    776977
    777         status = rpccli_winreg_Connect(pipe_hnd, mem_ctx, hive,
     978        status = dcerpc_winreg_Connect(b, mem_ctx, hive,
    778979                                       SEC_FLAG_MAXIMUM_ALLOWED,
    779                                        &hive_hnd);
     980                                       &hive_hnd, &werr);
    780981        if (!(NT_STATUS_IS_OK(status))) {
    781982                return status;
    782983        }
    783 
    784         status = rpccli_winreg_DeleteKey(pipe_hnd, mem_ctx, &hive_hnd, key, NULL);
    785         rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &hive_hnd, NULL);
     984        if (!W_ERROR_IS_OK(werr)) {
     985                return werror_to_ntstatus(werr);
     986        }
     987
     988        status = dcerpc_winreg_DeleteKey(b, mem_ctx, &hive_hnd, key, &werr);
     989        if (is_valid_policy_hnd(&hive_hnd)) {
     990                WERROR _werr;
     991                dcerpc_winreg_CloseKey(b, mem_ctx, &hive_hnd, &_werr);
     992        }
    786993
    787994        if (!NT_STATUS_IS_OK(status)) {
    788995                d_fprintf(stderr, _("deletekey returned %s\n"),
    789996                          nt_errstr(status));
     997                return status;
     998        }
     999
     1000        if (!W_ERROR_IS_OK(werr)) {
     1001                d_fprintf(stderr, _("deletekey returned %s\n"),
     1002                          win_errstr(werr));
     1003                return werror_to_ntstatus(werr);
    7901004        }
    7911005
     
    8101024
    8111025static NTSTATUS rpc_registry_enumerate_internal(struct net_context *c,
    812                                                 const DOM_SID *domain_sid,
     1026                                                const struct dom_sid *domain_sid,
    8131027                                                const char *domain_name,
    8141028                                                struct cli_state *cli,
     
    8201034        struct policy_handle pol_hive, pol_key;
    8211035        NTSTATUS status;
     1036        WERROR werr;
    8221037        uint32 num_subkeys = 0;
    8231038        uint32 num_values = 0;
     
    8261041        uint32 i;
    8271042        struct registry_value **values = NULL;
     1043        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    8281044
    8291045        if (argc != 1 || c->display_usage) {
     
    8681084        }
    8691085
    870         rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &pol_key, NULL);
    871         rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &pol_hive, NULL);
     1086        dcerpc_winreg_CloseKey(b, mem_ctx, &pol_key, &werr);
     1087        dcerpc_winreg_CloseKey(b, mem_ctx, &pol_hive, &werr);
    8721088
    8731089        return status;
     
    8881104
    8891105static NTSTATUS rpc_registry_save_internal(struct net_context *c,
    890                                         const DOM_SID *domain_sid,
     1106                                        const struct dom_sid *domain_sid,
    8911107                                        const char *domain_name,
    8921108                                        struct cli_state *cli,
     
    9001116        NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
    9011117        struct winreg_String filename;
     1118        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    9021119
    9031120        if (argc != 2 || c->display_usage) {
     
    9171134
    9181135        filename.name = argv[1];
    919         status = rpccli_winreg_SaveKey( pipe_hnd, mem_ctx, &pol_key, &filename, NULL, NULL);
    920         if ( !W_ERROR_IS_OK(result) ) {
     1136        status = dcerpc_winreg_SaveKey(b, mem_ctx, &pol_key, &filename, NULL, &result);
     1137        if (!NT_STATUS_IS_OK(status)) {
    9211138                d_fprintf(stderr, _("Unable to save [%s] to %s:%s\n"), argv[0],
    9221139                          cli->desthost, argv[1]);
    9231140        }
     1141        if (!W_ERROR_IS_OK(result)) {
     1142                status = werror_to_ntstatus(result);
     1143                d_fprintf(stderr, _("Unable to save [%s] to %s:%s\n"), argv[0],
     1144                          cli->desthost, argv[1]);
     1145        }
    9241146
    9251147        /* cleanup */
    9261148
    927         rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &pol_key, NULL);
    928         rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &pol_hive, NULL);
     1149        dcerpc_winreg_CloseKey(b, mem_ctx, &pol_key, &result);
     1150        dcerpc_winreg_CloseKey(b, mem_ctx, &pol_hive, &result);
    9291151
    9301152        return status;
     
    9561178        for ( i=0; i<nk->num_values; i++ ) {
    9571179                d_printf( "\"%s\" = ", nk->values[i].valuename ? nk->values[i].valuename : "(default)" );
    958                 d_printf( "(%s) ", reg_type_lookup( nk->values[i].type ) );
     1180                d_printf( "(%s) ", str_regtype( nk->values[i].type ) );
    9591181
    9601182                data_size = nk->values[i].data_size & ~VK_DATA_IN_OFFSET;
     
    10381260        }
    10391261
    1040         if ( !(values = TALLOC_ZERO_P( subkeys, struct regval_ctr )) ) {
     1262        werr = regval_ctr_init(subkeys, &values);
     1263        if (!W_ERROR_IS_OK(werr)) {
    10411264                DEBUG(0,("write_registry_tree: talloc() failed!\n"));
    10421265                TALLOC_FREE(subkeys);
     
    10481271        for ( i=0; i<nk->num_values; i++ ) {
    10491272                regval_ctr_addvalue( values, nk->values[i].valuename, nk->values[i].type,
    1050                         (const char *)nk->values[i].data, (nk->values[i].data_size & ~VK_DATA_IN_OFFSET) );
     1273                        nk->values[i].data, (nk->values[i].data_size & ~VK_DATA_IN_OFFSET) );
    10511274        }
    10521275
     
    11911414
    11921415static NTSTATUS rpc_registry_getsd_internal(struct net_context *c,
    1193                                             const DOM_SID *domain_sid,
     1416                                            const struct dom_sid *domain_sid,
    11941417                                            const char *domain_name,
    11951418                                            struct cli_state *cli,
     
    12011424        struct policy_handle pol_hive, pol_key;
    12021425        NTSTATUS status;
     1426        WERROR werr;
    12031427        enum ndr_err_code ndr_err;
    12041428        struct KeySecurityData *sd = NULL;
     
    12061430        DATA_BLOB blob;
    12071431        struct security_descriptor sec_desc;
    1208         uint32_t access_mask = REG_KEY_READ |
    1209                                SEC_FLAG_MAXIMUM_ALLOWED |
     1432        uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED |
    12101433                               SEC_FLAG_SYSTEM_SECURITY;
     1434        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    12111435
    12121436        if (argc <1 || argc > 2 || c->display_usage) {
     
    12421466        }
    12431467
    1244         status = registry_getsd(mem_ctx, pipe_hnd, &pol_key, sec_info, sd);
     1468        status = registry_getsd(mem_ctx, b, &pol_key, sec_info, sd, &werr);
    12451469        if (!NT_STATUS_IS_OK(status)) {
    12461470                d_fprintf(stderr, _("getting sd failed: %s\n"),
    12471471                          nt_errstr(status));
     1472                goto out;
     1473        }
     1474        if (!W_ERROR_IS_OK(werr)) {
     1475                status = werror_to_ntstatus(werr);
     1476                d_fprintf(stderr, _("getting sd failed: %s\n"),
     1477                          win_errstr(werr));
    12481478                goto out;
    12491479        }
     
    12521482        blob.length = sd->size;
    12531483
    1254         ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, NULL, &sec_desc,
     1484        ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, &sec_desc,
    12551485                                       (ndr_pull_flags_fn_t)ndr_pull_security_descriptor);
    12561486        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     
    12631493
    12641494 out:
    1265         rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &pol_key, NULL);
    1266         rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &pol_hive, NULL);
     1495        dcerpc_winreg_CloseKey(b, mem_ctx, &pol_key, &werr);
     1496        dcerpc_winreg_CloseKey(b, mem_ctx, &pol_hive, &werr);
    12671497
    12681498        return status;
     
    12771507
    12781508/********************************************************************
    1279 ********************************************************************/
     1509 ********************************************************************/
     1510/**
     1511 * @defgroup net_rpc_registry net rpc registry
     1512 */
     1513
     1514/**
     1515 * @defgroup net_rpc_registry_export Export
     1516 * @ingroup net_rpc_registry
     1517 * @{
     1518 */
     1519
     1520static NTSTATUS registry_export(struct rpc_pipe_client* pipe_hnd,
     1521                                TALLOC_CTX* ctx,
     1522                                struct policy_handle* key_hnd,
     1523                                struct reg_format* f,
     1524                                const char* parentfullname,
     1525                                const char* name)
     1526{
     1527        NTSTATUS status;
     1528        uint32 num_subkeys = 0;
     1529        uint32 num_values = 0;
     1530        char **names = NULL, **classes = NULL;
     1531        NTTIME **modtimes = NULL;
     1532        struct regval_blob **values = NULL;
     1533        uint32 i;
     1534        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
     1535
     1536        TALLOC_CTX* mem_ctx = talloc_new(ctx);
     1537
     1538
     1539        const char* fullname = name
     1540                ? talloc_asprintf(mem_ctx, "%s\\%s", parentfullname, name)
     1541                : parentfullname;
     1542        reg_format_key(f, &fullname, 1, false);
     1543
     1544        status = registry_enumvalues2(mem_ctx, pipe_hnd, key_hnd, &num_values,
     1545                                      &names, &values);
     1546        if (!NT_STATUS_IS_OK(status)) {
     1547                d_fprintf(stderr, _("enumerating values failed: %s\n"),
     1548                          nt_errstr(status));
     1549                goto done;
     1550        }
     1551
     1552        for (i=0; i<num_values; i++) {
     1553                reg_format_regval_blob(f, names[i], values[i]);
     1554        }
     1555
     1556
     1557        status = registry_enumkeys(mem_ctx, pipe_hnd, key_hnd, &num_subkeys,
     1558                                   &names, &classes, &modtimes);
     1559        if (!NT_STATUS_IS_OK(status)) {
     1560                d_fprintf(stderr, _("enumerating keys failed: %s\n"),
     1561                          nt_errstr(status));
     1562                goto done;
     1563        }
     1564
     1565        for (i=0; i<num_subkeys; i++) {
     1566                struct policy_handle subkey_hnd;
     1567                struct winreg_String key;
     1568                WERROR werr;
     1569                ZERO_STRUCT(key);
     1570                /* key.name = talloc_strdup(mem_ctx, names[i]); ??? */
     1571                key.name = names[i];
     1572
     1573                status = dcerpc_winreg_OpenKey(b, mem_ctx, key_hnd, key,
     1574                                               0, REG_KEY_READ,
     1575                                               &subkey_hnd, &werr);
     1576                if (!NT_STATUS_IS_OK(status)) {
     1577                        d_fprintf(stderr,
     1578                                  _("dcerpc_winreg_OpenKey failed: %s %s\n"),
     1579                                  names[i], nt_errstr(status));
     1580                        continue;
     1581                }
     1582                if (!W_ERROR_IS_OK(werr)) {
     1583                        status = werror_to_ntstatus(werr);
     1584                        d_fprintf(stderr,
     1585                                  _("dcerpc_winreg_OpenKey failed: %s %s\n"),
     1586                                  names[i], win_errstr(werr));
     1587                        continue;
     1588                }
     1589
     1590                status = registry_export(pipe_hnd, mem_ctx, &subkey_hnd,
     1591                                         f, fullname, names[i]);
     1592                if (!(NT_STATUS_IS_OK(status))) {
     1593                        d_fprintf(stderr,
     1594                                  _("export key failed: %s %s\n"),
     1595                                  names[i], nt_errstr(status));
     1596                }
     1597                dcerpc_winreg_CloseKey(b, mem_ctx,
     1598                                       &subkey_hnd, &werr);
     1599        }
     1600done:
     1601        talloc_free(mem_ctx);
     1602        return status;
     1603}
     1604
     1605static NTSTATUS rpc_registry_export_internal(struct net_context *c,
     1606                                             const struct dom_sid *domain_sid,
     1607                                             const char *domain_name,
     1608                                             struct cli_state *cli,
     1609                                             struct rpc_pipe_client *pipe_hnd,
     1610                                             TALLOC_CTX *mem_ctx,
     1611                                             int argc,
     1612                                             const char **argv )
     1613{
     1614        struct policy_handle pol_hive, pol_key;
     1615        NTSTATUS status;
     1616        WERROR werr;
     1617        struct reg_format* f;
     1618        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
     1619
     1620        if (argc < 2 || argc > 3 || c->display_usage) {
     1621                d_printf("%s\n%s",
     1622                         _("Usage:"),
     1623                         _("net rpc registry export <path> <file> [opt]\n"));
     1624                d_printf("%s  net rpc registry export "
     1625                         "'HKLM\\Software\\Samba' samba.reg\n", _("Example:"));
     1626                return NT_STATUS_INVALID_PARAMETER;
     1627        }
     1628
     1629        status = registry_openkey(mem_ctx, pipe_hnd, argv[0], REG_KEY_READ,
     1630                                  &pol_hive, &pol_key);
     1631        if (!NT_STATUS_IS_OK(status)) {
     1632                d_fprintf(stderr, _("registry_openkey failed: %s\n"),
     1633                          nt_errstr(status));
     1634                return status;
     1635        }
     1636
     1637        f = reg_format_file(mem_ctx, argv[1], (argc > 2) ? argv[2] : NULL);
     1638        if (f == NULL) {
     1639                d_fprintf(stderr, _("open file failed: %s\n"), strerror(errno));
     1640                return map_nt_error_from_unix(errno);
     1641        }
     1642
     1643        status = registry_export(pipe_hnd, mem_ctx, &pol_key,
     1644                                 f, argv[0], NULL );
     1645        if (!NT_STATUS_IS_OK(status))
     1646                return status;
     1647
     1648        dcerpc_winreg_CloseKey(b, mem_ctx, &pol_key, &werr);
     1649        dcerpc_winreg_CloseKey(b, mem_ctx, &pol_hive, &werr);
     1650
     1651        return status;
     1652}
     1653/********************************************************************
     1654 ********************************************************************/
     1655
     1656static int rpc_registry_export(struct net_context *c, int argc,
     1657                               const char **argv )
     1658{
     1659        return run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0,
     1660                               rpc_registry_export_internal, argc, argv );
     1661}
     1662
     1663/**@}*/
     1664
     1665/********************************************************************
     1666 ********************************************************************/
     1667
     1668/**
     1669 * @defgroup net_rpc_registry_import Import
     1670 * @ingroup net_rpc_registry
     1671 * @{
     1672 */
     1673
     1674struct import_ctx {
     1675        struct rpc_pipe_client *pipe_hnd;
     1676        TALLOC_CTX *mem_ctx;
     1677};
     1678
     1679static WERROR import_create_key(struct import_ctx* ctx,
     1680                                struct policy_handle* parent, const char* name,
     1681                                void** pkey, bool* existing)
     1682{
     1683        WERROR werr;
     1684        NTSTATUS status;
     1685        void* mem_ctx = talloc_new(ctx->mem_ctx);
     1686
     1687        struct policy_handle* key = NULL;
     1688        struct policy_handle  hive;
     1689        struct winreg_String  keyclass, keyname;
     1690        enum winreg_CreateAction action = REG_ACTION_NONE;
     1691        struct dcerpc_binding_handle *b = ctx->pipe_hnd->binding_handle;
     1692
     1693        ZERO_STRUCT(keyname);
     1694        keyname.name = name;
     1695
     1696        if (parent == NULL) {
     1697                uint32 hive_idx = 0;
     1698                if (!reg_hive_key(mem_ctx, name, &hive_idx, &keyname.name)) {
     1699                        werr = WERR_FOOBAR;
     1700                        goto done;
     1701                }
     1702
     1703                status = dcerpc_winreg_Connect(b, mem_ctx,
     1704                                               hive_idx, SEC_FLAG_MAXIMUM_ALLOWED,
     1705                                               &hive, &werr);
     1706                if (!NT_STATUS_IS_OK(status)) {
     1707                        werr = ntstatus_to_werror(status);
     1708                        d_fprintf(stderr, _("dcerpc_winreg_Connect returned %s\n"),
     1709                                  nt_errstr(status));
     1710                        goto done;
     1711                }
     1712                if (!W_ERROR_IS_OK(werr)) {
     1713                        d_fprintf(stderr, _("dcerpc_winreg_Connect returned %s\n"),
     1714                                  win_errstr(werr));
     1715                        goto done;
     1716                }
     1717
     1718                parent = &hive;
     1719        }
     1720
     1721        key = talloc_zero(mem_ctx, struct policy_handle);
     1722        if (key == NULL) {
     1723                werr = WERR_NOMEM;
     1724                goto done;
     1725        }
     1726
     1727        ZERO_STRUCT(keyclass);
     1728        keyclass.name = "";
     1729
     1730        status = dcerpc_winreg_CreateKey(b, mem_ctx,
     1731                                         parent, keyname,
     1732                                         keyclass, 0, REG_KEY_READ, NULL,
     1733                                         key, &action, &werr);
     1734        if (!NT_STATUS_IS_OK(status)) {
     1735                werr = ntstatus_to_werror(status);
     1736                d_fprintf(stderr, _("dcerpc_winreg_CreateKey returned %s\n"),
     1737                          nt_errstr(status));
     1738                goto done;
     1739        }
     1740        if (!W_ERROR_IS_OK(werr)) {
     1741                d_fprintf(stderr, _("dcerpc_winreg_CreateKey returned %s\n"),
     1742                          win_errstr(werr));
     1743                goto done;
     1744        }
     1745
     1746        switch (action) {
     1747        case REG_CREATED_NEW_KEY:
     1748                d_printf(_("createkey created %s\n"), name);
     1749                if (existing != NULL)
     1750                        *existing = false;
     1751                break;
     1752
     1753        case REG_OPENED_EXISTING_KEY:
     1754                d_printf(_("createkey opened existing %s\n"), name);
     1755                if (existing != NULL)
     1756                        *existing = true;
     1757                break;
     1758
     1759        case REG_ACTION_NONE:
     1760                d_printf(_("createkey did nothing -- huh?\n"));
     1761                werr = WERR_CREATE_FAILED;
     1762                break;
     1763        default:
     1764                assert(false);
     1765        }
     1766
     1767done:
     1768        if ( parent == &hive ) {
     1769                WERROR _result;
     1770                dcerpc_winreg_CloseKey(b, mem_ctx,
     1771                                       parent, &_result);
     1772        }
     1773
     1774        if (pkey!=NULL) {
     1775                *pkey = talloc_steal(ctx->mem_ctx, key);
     1776        }
     1777
     1778        talloc_free(mem_ctx);
     1779        return werr;
     1780}
     1781
     1782static WERROR import_delete_key(struct import_ctx* ctx,
     1783                                struct policy_handle* parent, const char* name)
     1784{
     1785        WERROR werr;
     1786        NTSTATUS status;
     1787        void* mem_ctx = talloc_new(ctx->mem_ctx);
     1788        struct winreg_String  keyname = { 0, };
     1789        struct policy_handle  hive;
     1790        struct dcerpc_binding_handle *b = ctx->pipe_hnd->binding_handle;
     1791
     1792        keyname.name = name;
     1793
     1794        if (parent == NULL) {
     1795                uint32 hive_idx;
     1796                if (!reg_hive_key(mem_ctx, name, &hive_idx, &keyname.name)) {
     1797                        werr = WERR_FOOBAR;
     1798                        goto done;
     1799                }
     1800
     1801                status = dcerpc_winreg_Connect(b, mem_ctx, hive_idx,
     1802                                               SEC_FLAG_MAXIMUM_ALLOWED, &hive,
     1803                                               &werr);
     1804                if (!NT_STATUS_IS_OK(status)) {
     1805                        werr = ntstatus_to_werror(status);
     1806                        d_fprintf(stderr, _("dcerpc_winreg_Connect returned %s\n"),
     1807                                  nt_errstr(status));
     1808                        goto done;
     1809                }
     1810                if (!W_ERROR_IS_OK(werr)) {
     1811                        d_fprintf(stderr, _("dcerpc_winreg_Connect returned %s\n"),
     1812                                  win_errstr(werr));
     1813                        goto done;
     1814                }
     1815
     1816                parent = &hive;
     1817        }
     1818
     1819        status = dcerpc_winreg_DeleteKey(b, mem_ctx, parent,
     1820                                         keyname, &werr);
     1821        if (!NT_STATUS_IS_OK(status)) {
     1822                werr = ntstatus_to_werror(status);
     1823                d_fprintf(stderr, _("dcerpc_winreg_DeleteKey returned %s\n"),
     1824                          nt_errstr(status));
     1825                goto done;
     1826        }
     1827        if (!W_ERROR_IS_OK(werr)) {
     1828                d_fprintf(stderr, _("dcerpc_winreg_DeleteKey returned %s\n"),
     1829                          win_errstr(werr));
     1830                goto done;
     1831        }
     1832
     1833done:
     1834        if ( parent == &hive ) {
     1835                WERROR _result;
     1836                dcerpc_winreg_CloseKey(b, mem_ctx, parent, &_result);
     1837        }
     1838
     1839        talloc_free(mem_ctx);
     1840        return werr;
     1841}
     1842
     1843static WERROR import_close_key(struct import_ctx* ctx,
     1844                               struct policy_handle* key)
     1845{
     1846        WERROR werr;
     1847        NTSTATUS status;
     1848        void* mem_ctx = talloc_new(ctx->mem_ctx);
     1849        struct dcerpc_binding_handle *b = ctx->pipe_hnd->binding_handle;
     1850
     1851        status = dcerpc_winreg_CloseKey(b, mem_ctx, key, &werr);
     1852        if (!NT_STATUS_IS_OK(status)) {
     1853                werr = ntstatus_to_werror(status);
     1854                d_fprintf(stderr, _("dcerpc_winreg_CloseKey returned %s\n"),
     1855                          nt_errstr(status));
     1856                goto done;
     1857        }
     1858        if (!W_ERROR_IS_OK(werr)) {
     1859                d_fprintf(stderr, _("dcerpc_winreg_CloseKey returned %s\n"),
     1860                          win_errstr(werr));
     1861                goto done;
     1862        }
     1863
     1864        werr = (talloc_free(key) == 0) ? WERR_OK : WERR_GENERAL_FAILURE;
     1865done:
     1866        talloc_free(mem_ctx);
     1867        return werr;
     1868}
     1869
     1870static WERROR import_create_val(struct import_ctx* ctx,
     1871                                struct policy_handle* parent, const char* name,
     1872                                uint32_t type, const uint8_t* val, uint32_t len)
     1873{
     1874        WERROR werr;
     1875        NTSTATUS status;
     1876        void* mem_ctx = talloc_new(ctx->mem_ctx);
     1877        struct winreg_String valuename;
     1878        struct dcerpc_binding_handle *b = ctx->pipe_hnd->binding_handle;
     1879
     1880        if (parent == NULL) {
     1881                return WERR_INVALID_PARAM;
     1882        }
     1883
     1884        ZERO_STRUCT(valuename);
     1885        valuename.name = name;
     1886
     1887        status = dcerpc_winreg_SetValue(b, mem_ctx, parent,
     1888                                        valuename, type,
     1889                                        (uint8_t *)discard_const(val), len, &werr);
     1890        if (!NT_STATUS_IS_OK(status)) {
     1891                werr = ntstatus_to_werror(status);
     1892                d_fprintf(stderr, _("registry_setvalue failed: %s\n"),
     1893                          nt_errstr(status));
     1894                goto done;
     1895        }
     1896        if (!W_ERROR_IS_OK(werr)) {
     1897                d_fprintf(stderr, _("registry_setvalue failed: %s\n"),
     1898                          win_errstr(werr));
     1899                goto done;
     1900        }
     1901
     1902done:
     1903        talloc_free(mem_ctx);
     1904        return werr;
     1905}
     1906
     1907static WERROR import_delete_val(struct import_ctx* ctx,
     1908                                struct policy_handle* parent, const char* name)
     1909{
     1910        WERROR werr;
     1911        NTSTATUS status;
     1912        void* mem_ctx = talloc_new(ctx->mem_ctx);
     1913        struct winreg_String valuename;
     1914        struct dcerpc_binding_handle *b = ctx->pipe_hnd->binding_handle;
     1915
     1916        if (parent == NULL) {
     1917                return WERR_INVALID_PARAM;
     1918        }
     1919
     1920        ZERO_STRUCT(valuename);
     1921        valuename.name = name;
     1922
     1923        status = dcerpc_winreg_DeleteValue(b, mem_ctx,
     1924                                           parent, valuename, &werr);
     1925
     1926        if (!NT_STATUS_IS_OK(status)) {
     1927                werr = ntstatus_to_werror(status);
     1928                d_fprintf(stderr, _("registry_deletevalue failed: %s\n"),
     1929                          nt_errstr(status));
     1930                goto done;
     1931        }
     1932        if (!NT_STATUS_IS_OK(status)) {
     1933                d_fprintf(stderr, _("registry_deletevalue failed: %s\n"),
     1934                          win_errstr(werr));
     1935                goto done;
     1936        }
     1937
     1938done:
     1939        talloc_free(mem_ctx);
     1940        return werr;
     1941}
     1942
     1943
     1944
     1945static NTSTATUS rpc_registry_import_internal(struct net_context *c,
     1946                                             const struct dom_sid *domain_sid,
     1947                                             const char *domain_name,
     1948                                             struct cli_state *cli,
     1949                                             struct rpc_pipe_client *pipe_hnd,
     1950                                             TALLOC_CTX *mem_ctx,
     1951                                             int argc,
     1952                                             const char **argv )
     1953{
     1954        struct import_ctx import_ctx;
     1955
     1956        struct reg_import_callback import_callback = {
     1957                .openkey     = NULL,
     1958                .closekey    = (reg_import_callback_closekey_t)&import_close_key,
     1959                .createkey   = (reg_import_callback_createkey_t)&import_create_key,
     1960                .deletekey   = (reg_import_callback_deletekey_t)&import_delete_key,
     1961                .deleteval   = (reg_import_callback_deleteval_t)&import_delete_val,
     1962                .setval      = {
     1963                        .blob = (reg_import_callback_setval_blob_t)&import_create_val,
     1964                },
     1965                .setval_type = BLOB,
     1966                .data = &import_ctx
     1967        };
     1968
     1969        int ret;
     1970        if (argc < 1 || argc > 2 || c->display_usage) {
     1971                d_printf("%s\n%s",
     1972                         _("Usage:"),
     1973                         _("net rpc registry import <file> [options]\n"));
     1974                d_printf("%s  net rpc registry export "
     1975                         "samba.reg enc=CP1252,flags=0\n", _("Example:"));
     1976                return NT_STATUS_INVALID_PARAMETER;
     1977        }
     1978        ZERO_STRUCT(import_ctx);
     1979        import_ctx.pipe_hnd = pipe_hnd;
     1980        import_ctx.mem_ctx  = mem_ctx;
     1981        ret = reg_parse_file(argv[0],
     1982                             reg_import_adapter(import_ctx.mem_ctx,
     1983                                                import_callback
     1984                                     ),
     1985                             (argc > 1) ? argv[1] : NULL
     1986                );
     1987
     1988        return ret==0 ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
     1989}
     1990
     1991/********************************************************************
     1992 ********************************************************************/
     1993
     1994static int rpc_registry_import(struct net_context *c, int argc,
     1995                               const char **argv )
     1996{
     1997        return run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0,
     1998                               rpc_registry_import_internal, argc, argv );
     1999}
     2000
     2001/**@}*/
     2002/********************************************************************
     2003 ********************************************************************/
    12802004
    12812005int net_rpc_registry(struct net_context *c, int argc, const char **argv)
     
    13702094                           "    Get security descriptior")
    13712095                },
     2096                {
     2097                        "import",
     2098                        rpc_registry_import,
     2099                        NET_TRANSPORT_RPC,
     2100                        N_("Import .reg file"),
     2101                        N_("net rpc registry import\n"
     2102                           "    Import .reg file")
     2103                },
     2104                {
     2105                        "export",
     2106                        rpc_registry_export,
     2107                        NET_TRANSPORT_RPC,
     2108                        N_("Export .reg file"),
     2109                        N_("net rpc registry export\n"
     2110                           "    Export .reg file")
     2111                },
    13722112                {NULL, NULL, 0, NULL, NULL}
    13732113        };
    1374 
    13752114        return net_run_function(c, argc, argv, "net rpc registry", func);
    13762115}
  • vendor/current/source3/utils/net_rpc_rights.c

    r414 r740  
    2020#include "includes.h"
    2121#include "utils/net.h"
    22 #include "../librpc/gen_ndr/cli_lsa.h"
     22#include "rpc_client/rpc_client.h"
     23#include "../librpc/gen_ndr/ndr_lsa_c.h"
     24#include "rpc_client/cli_lsarpc.h"
     25#include "rpc_client/init_lsa.h"
     26#include "../libcli/security/security.h"
    2327
    2428/********************************************************************
     
    2731static NTSTATUS sid_to_name(struct rpc_pipe_client *pipe_hnd,
    2832                                TALLOC_CTX *mem_ctx,
    29                                 DOM_SID *sid,
     33                                struct dom_sid *sid,
    3034                                fstring name)
    3135{
    3236        struct policy_handle pol;
    3337        enum lsa_SidType *sid_types = NULL;
    34         NTSTATUS result;
     38        NTSTATUS status, result;
    3539        char **domains = NULL, **names = NULL;
    36 
    37         result = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,
     40        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
     41
     42        status = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,
    3843                SEC_FLAG_MAXIMUM_ALLOWED, &pol);
    3944
    40         if ( !NT_STATUS_IS_OK(result) )
    41                 return result;
    42 
    43         result = rpccli_lsa_lookup_sids(pipe_hnd, mem_ctx, &pol, 1, sid, &domains, &names, &sid_types);
    44 
    45         if ( NT_STATUS_IS_OK(result) ) {
     45        if ( !NT_STATUS_IS_OK(status) )
     46                return status;
     47
     48        status = rpccli_lsa_lookup_sids(pipe_hnd, mem_ctx, &pol, 1, sid, &domains, &names, &sid_types);
     49
     50        if ( NT_STATUS_IS_OK(status) ) {
    4651                if ( *domains[0] )
    4752                        fstr_sprintf( name, "%s\\%s", domains[0], names[0] );
     
    5055        }
    5156
    52         rpccli_lsa_Close(pipe_hnd, mem_ctx, &pol);
    53         return result;
     57        dcerpc_lsa_Close(b, mem_ctx, &pol, &result);
     58        return status;
    5459}
    5560
     
    5964static NTSTATUS name_to_sid(struct rpc_pipe_client *pipe_hnd,
    6065                            TALLOC_CTX *mem_ctx,
    61                             DOM_SID *sid, const char *name)
     66                            struct dom_sid *sid, const char *name)
    6267{
    6368        struct policy_handle pol;
    6469        enum lsa_SidType *sid_types;
    65         NTSTATUS result;
    66         DOM_SID *sids;
     70        NTSTATUS status, result;
     71        struct dom_sid *sids;
     72        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    6773
    6874        /* maybe its a raw SID */
     
    7177        }
    7278
    73         result = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,
     79        status = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,
    7480                SEC_FLAG_MAXIMUM_ALLOWED, &pol);
    7581
    76         if ( !NT_STATUS_IS_OK(result) )
    77                 return result;
    78 
    79         result = rpccli_lsa_lookup_names(pipe_hnd, mem_ctx, &pol, 1, &name,
     82        if ( !NT_STATUS_IS_OK(status) )
     83                return status;
     84
     85        status = rpccli_lsa_lookup_names(pipe_hnd, mem_ctx, &pol, 1, &name,
    8086                                         NULL, 1, &sids, &sid_types);
    8187
    82         if ( NT_STATUS_IS_OK(result) )
     88        if ( NT_STATUS_IS_OK(status) )
    8389                sid_copy( sid, &sids[0] );
    8490
    85         rpccli_lsa_Close(pipe_hnd, mem_ctx, &pol);
    86         return result;
     91        dcerpc_lsa_Close(b, mem_ctx, &pol, &result);
     92        return status;
    8793}
    8894
     
    94100                                struct policy_handle *pol )
    95101{
    96         NTSTATUS result;
     102        NTSTATUS status, result;
    97103        uint32 enum_context = 0;
    98104        uint32 pref_max_length=0x1000;
     
    103109        struct lsa_StringLarge *description = NULL;
    104110        struct lsa_PrivArray priv_array;
    105 
    106         result = rpccli_lsa_EnumPrivs(pipe_hnd, ctx,
     111        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
     112
     113        status = dcerpc_lsa_EnumPrivs(b, ctx,
    107114                                      pol,
    108115                                      &enum_context,
    109116                                      &priv_array,
    110                                       pref_max_length);
    111 
    112         if ( !NT_STATUS_IS_OK(result) )
     117                                      pref_max_length,
     118                                      &result);
     119
     120        if ( !NT_STATUS_IS_OK(status) )
     121                return status;
     122        if (!NT_STATUS_IS_OK(result)) {
    113123                return result;
     124        }
    114125
    115126        /* Print results */
     
    126137                init_lsa_String(&lsa_name, priv_array.privs[i].name.string);
    127138
    128                 result = rpccli_lsa_LookupPrivDisplayName(pipe_hnd, ctx,
     139                status = dcerpc_lsa_LookupPrivDisplayName(b, ctx,
    129140                                                          pol,
    130141                                                          &lsa_name,
     
    132143                                                          lang_id_sys,
    133144                                                          &description,
    134                                                           &lang_id_desc);
    135 
     145                                                          &lang_id_desc,
     146                                                          &result);
     147                if (!NT_STATUS_IS_OK(status)) {
     148                        d_printf("??????\n");
     149                        continue;
     150                }
    136151                if (!NT_STATUS_IS_OK(result)) {
    137152                        d_printf("??????\n");
     
    151166                                        TALLOC_CTX *ctx,
    152167                                        struct policy_handle *pol,
    153                                         DOM_SID *sid,
     168                                        struct dom_sid *sid,
    154169                                        const char *right)
    155170{
    156         NTSTATUS result;
     171        NTSTATUS status, result;
    157172        struct lsa_RightSet rights;
    158173        int i;
    159 
    160         result = rpccli_lsa_EnumAccountRights(pipe_hnd, ctx,
     174        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
     175
     176        status = dcerpc_lsa_EnumAccountRights(b, ctx,
    161177                                              pol,
    162178                                              sid,
    163                                               &rights);
    164 
     179                                              &rights,
     180                                              &result);
     181        if (!NT_STATUS_IS_OK(status)) {
     182                return status;
     183        }
    165184        if (!NT_STATUS_IS_OK(result)) {
    166185                return result;
     
    186205                                        TALLOC_CTX *ctx,
    187206                                        struct policy_handle *pol,
    188                                         DOM_SID *sid )
    189 {
    190         NTSTATUS result;
     207                                        struct dom_sid *sid )
     208{
     209        NTSTATUS status, result;
    191210        struct lsa_RightSet rights;
    192211        int i;
    193 
    194         result = rpccli_lsa_EnumAccountRights(pipe_hnd, ctx,
     212        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
     213
     214        status = dcerpc_lsa_EnumAccountRights(b, ctx,
    195215                                              pol,
    196216                                              sid,
    197                                               &rights);
    198 
     217                                              &rights,
     218                                              &result);
     219        if (!NT_STATUS_IS_OK(status))
     220                return status;
    199221        if (!NT_STATUS_IS_OK(result))
    200222                return result;
     
    219241                                                const char *privilege)
    220242{
    221         NTSTATUS result;
     243        NTSTATUS status, result;
    222244        uint32 enum_context=0;
    223245        uint32 pref_max_length=0x1000;
     
    225247        int i;
    226248        fstring name;
    227 
    228         result = rpccli_lsa_EnumAccounts(pipe_hnd, ctx,
     249        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
     250
     251        status = dcerpc_lsa_EnumAccounts(b, ctx,
    229252                                         pol,
    230253                                         &enum_context,
    231254                                         &sid_array,
    232                                          pref_max_length);
    233 
     255                                         pref_max_length,
     256                                         &result);
     257        if (!NT_STATUS_IS_OK(status))
     258                return status;
    234259        if (!NT_STATUS_IS_OK(result))
    235260                return result;
     
    239264        for ( i=0; i<sid_array.num_sids; i++ ) {
    240265
    241                 result = check_privilege_for_user(pipe_hnd, ctx, pol,
     266                status = check_privilege_for_user(pipe_hnd, ctx, pol,
    242267                                                  sid_array.sids[i].sid,
    243268                                                  privilege);
    244269
    245                 if ( ! NT_STATUS_IS_OK(result)) {
    246                         if ( ! NT_STATUS_EQUAL(result, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
    247                                 return result;
     270                if ( ! NT_STATUS_IS_OK(status)) {
     271                        if ( ! NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
     272                                return status;
    248273                        }
    249274                        continue;
     
    252277                /* try to convert the SID to a name.  Fall back to
    253278                   printing the raw SID if necessary */
    254                 result = sid_to_name( pipe_hnd, ctx, sid_array.sids[i].sid, name );
    255                 if ( !NT_STATUS_IS_OK (result) )
     279                status = sid_to_name( pipe_hnd, ctx, sid_array.sids[i].sid, name );
     280                if ( !NT_STATUS_IS_OK (status) )
    256281                        sid_to_fstring(name, sid_array.sids[i].sid);
    257282
     
    269294                                                struct policy_handle *pol)
    270295{
    271         NTSTATUS result;
     296        NTSTATUS status, result;
    272297        uint32 enum_context=0;
    273298        uint32 pref_max_length=0x1000;
     
    275300        int i;
    276301        fstring name;
    277 
    278         result = rpccli_lsa_EnumAccounts(pipe_hnd, ctx,
     302        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
     303
     304        status = dcerpc_lsa_EnumAccounts(b, ctx,
    279305                                         pol,
    280306                                         &enum_context,
    281307                                         &sid_array,
    282                                          pref_max_length);
    283 
     308                                         pref_max_length,
     309                                         &result);
     310        if (!NT_STATUS_IS_OK(status))
     311                return status;
    284312        if (!NT_STATUS_IS_OK(result))
    285313                return result;
     
    290318                   printing the raw SID if necessary */
    291319
    292                 result = sid_to_name(pipe_hnd, ctx, sid_array.sids[i].sid, name);
    293                 if ( !NT_STATUS_IS_OK (result) )
     320                status = sid_to_name(pipe_hnd, ctx, sid_array.sids[i].sid, name);
     321                if ( !NT_STATUS_IS_OK (status) )
    294322                        sid_to_fstring(name, sid_array.sids[i].sid);
    295323
    296324                d_printf("%s\n", name);
    297325
    298                 result = enum_privileges_for_user(pipe_hnd, ctx, pol,
     326                status = enum_privileges_for_user(pipe_hnd, ctx, pol,
    299327                                                  sid_array.sids[i].sid);
    300                 if ( !NT_STATUS_IS_OK(result) )
    301                         return result;
     328                if ( !NT_STATUS_IS_OK(status) )
     329                        return status;
    302330
    303331                d_printf("\n");
     
    311339
    312340static NTSTATUS rpc_rights_list_internal(struct net_context *c,
    313                                         const DOM_SID *domain_sid,
     341                                        const struct dom_sid *domain_sid,
    314342                                        const char *domain_name,
    315343                                        struct cli_state *cli,
     
    320348{
    321349        struct policy_handle pol;
    322         NTSTATUS result;
    323         DOM_SID sid;
     350        NTSTATUS status, result;
     351        struct dom_sid sid;
    324352        fstring privname;
    325353        struct lsa_String lsa_name;
     
    328356        uint16 lang_id_sys = 0;
    329357        uint16 lang_id_desc;
    330 
    331         result = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,
     358        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
     359
     360        status = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,
    332361                SEC_FLAG_MAXIMUM_ALLOWED, &pol);
    333362
    334         if ( !NT_STATUS_IS_OK(result) )
    335                 return result;
     363        if ( !NT_STATUS_IS_OK(status) )
     364                return status;
    336365
    337366        /* backwards compatibility; just list available privileges if no arguement */
    338367
    339368        if (argc == 0) {
    340                 result = enum_privileges(pipe_hnd, mem_ctx, &pol );
     369                status = enum_privileges(pipe_hnd, mem_ctx, &pol );
    341370                goto done;
    342371        }
     
    346375
    347376                if (argv[1] == NULL) {
    348                         result = enum_privileges(pipe_hnd, mem_ctx, &pol );
     377                        status = enum_privileges(pipe_hnd, mem_ctx, &pol );
    349378                        goto done;
    350379                }
     
    356385
    357386                        /* verify that this is a valid privilege for error reporting */
    358                         result = rpccli_lsa_LookupPrivDisplayName(pipe_hnd, mem_ctx,
     387                        status = dcerpc_lsa_LookupPrivDisplayName(b, mem_ctx,
    359388                                                                  &pol,
    360389                                                                  &lsa_name,
     
    362391                                                                  lang_id_sys,
    363392                                                                  &description,
    364                                                                   &lang_id_desc);
    365 
     393                                                                  &lang_id_desc,
     394                                                                  &result);
     395                        if (!NT_STATUS_IS_OK(status)) {
     396                                continue;
     397                        }
     398                        status = result;
    366399                        if ( !NT_STATUS_IS_OK(result) ) {
    367                                 if ( NT_STATUS_EQUAL( result, NT_STATUS_NO_SUCH_PRIVILEGE ) )
     400                                if ( NT_STATUS_EQUAL(result, NT_STATUS_NO_SUCH_PRIVILEGE))
    368401                                        d_fprintf(stderr, _("No such privilege "
    369402                                                  "exists: %s.\n"), privname);
     
    376409                        }
    377410
    378                         result = enum_accounts_for_privilege(pipe_hnd, mem_ctx, &pol, privname);
    379                         if (!NT_STATUS_IS_OK(result)) {
     411                        status = enum_accounts_for_privilege(pipe_hnd, mem_ctx, &pol, privname);
     412                        if (!NT_STATUS_IS_OK(status)) {
    380413                                d_fprintf(stderr, _("Error enumerating "
    381414                                          "accounts for privilege %s [%s].\n"),
    382                                           privname, nt_errstr(result));
     415                                          privname, nt_errstr(status));
    383416                                continue;
    384417                        }
     
    393426
    394427                if (argv[1] == NULL) {
    395                         result = enum_privileges_for_accounts(pipe_hnd, mem_ctx, &pol);
     428                        status = enum_privileges_for_accounts(pipe_hnd, mem_ctx, &pol);
    396429                        goto done;
    397430                }
    398431
    399432                while (argv[i] != NULL) {
    400                         result = name_to_sid(pipe_hnd, mem_ctx, &sid, argv[i]);
    401                         if (!NT_STATUS_IS_OK(result)) {
     433                        status = name_to_sid(pipe_hnd, mem_ctx, &sid, argv[i]);
     434                        if (!NT_STATUS_IS_OK(status)) {
    402435                                goto done;
    403436                        }
    404                         result = enum_privileges_for_user(pipe_hnd, mem_ctx, &pol, &sid);
    405                         if (!NT_STATUS_IS_OK(result)) {
     437                        status = enum_privileges_for_user(pipe_hnd, mem_ctx, &pol, &sid);
     438                        if (!NT_STATUS_IS_OK(status)) {
    406439                                goto done;
    407440                        }
     
    416449                d_printf("%s net rpc rights list [[accounts|privileges] "
    417450                         "[name|SID]]\n", _("Usage:"));
    418                 result = NT_STATUS_OK;
    419                 goto done;
    420         }
    421 
    422         result = name_to_sid(pipe_hnd, mem_ctx, &sid, argv[0]);
    423         if (!NT_STATUS_IS_OK(result)) {
    424                 goto done;
    425         }
    426         result = enum_privileges_for_user(pipe_hnd, mem_ctx, &pol, &sid );
     451                status = NT_STATUS_OK;
     452                goto done;
     453        }
     454
     455        status = name_to_sid(pipe_hnd, mem_ctx, &sid, argv[0]);
     456        if (!NT_STATUS_IS_OK(status)) {
     457                goto done;
     458        }
     459        status = enum_privileges_for_user(pipe_hnd, mem_ctx, &pol, &sid );
    427460
    428461done:
    429         rpccli_lsa_Close(pipe_hnd, mem_ctx, &pol);
    430 
    431         return result;
     462        dcerpc_lsa_Close(b, mem_ctx, &pol, &result);
     463
     464        return status;
    432465}
    433466
     
    436469
    437470static NTSTATUS rpc_rights_grant_internal(struct net_context *c,
    438                                         const DOM_SID *domain_sid,
     471                                        const struct dom_sid *domain_sid,
    439472                                        const char *domain_name,
    440473                                        struct cli_state *cli,
     
    445478{
    446479        struct policy_handle dom_pol;
    447         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
     480        NTSTATUS status, result;
    448481        struct lsa_RightSet rights;
    449482        int i;
    450 
    451         DOM_SID sid;
     483        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
     484
     485        struct dom_sid sid;
    452486
    453487        if (argc < 2 ) {
     
    458492        }
    459493
    460         result = name_to_sid(pipe_hnd, mem_ctx, &sid, argv[0]);
    461         if (NT_STATUS_EQUAL(result, NT_STATUS_NONE_MAPPED))
    462                 result = NT_STATUS_NO_SUCH_USER;
    463 
    464         if (!NT_STATUS_IS_OK(result))
    465                 goto done;
    466 
    467         result = rpccli_lsa_open_policy2(pipe_hnd, mem_ctx, true,
     494        status = name_to_sid(pipe_hnd, mem_ctx, &sid, argv[0]);
     495        if (NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED))
     496                status = NT_STATUS_NO_SUCH_USER;
     497
     498        if (!NT_STATUS_IS_OK(status))
     499                goto done;
     500
     501        status = rpccli_lsa_open_policy2(pipe_hnd, mem_ctx, true,
    468502                                     SEC_FLAG_MAXIMUM_ALLOWED,
    469503                                     &dom_pol);
    470504
    471         if (!NT_STATUS_IS_OK(result))
    472                 return result;
     505        if (!NT_STATUS_IS_OK(status))
     506                return status;
    473507
    474508        rights.count = argc-1;
     
    483517        }
    484518
    485         result = rpccli_lsa_AddAccountRights(pipe_hnd, mem_ctx,
     519        status = dcerpc_lsa_AddAccountRights(b, mem_ctx,
    486520                                             &dom_pol,
    487521                                             &sid,
    488                                              &rights);
    489 
    490         if (!NT_STATUS_IS_OK(result))
    491                 goto done;
     522                                             &rights,
     523                                             &result);
     524        if (!NT_STATUS_IS_OK(status))
     525                goto done;
     526        if (!NT_STATUS_IS_OK(result)) {
     527                status = result;
     528                goto done;
     529        }
    492530
    493531        d_printf(_("Successfully granted rights.\n"));
    494532
    495533 done:
    496         if ( !NT_STATUS_IS_OK(result) ) {
     534        if ( !NT_STATUS_IS_OK(status) ) {
    497535                d_fprintf(stderr, _("Failed to grant privileges for %s (%s)\n"),
    498                         argv[0], nt_errstr(result));
    499         }
    500 
    501         rpccli_lsa_Close(pipe_hnd, mem_ctx, &dom_pol);
    502 
    503         return result;
     536                        argv[0], nt_errstr(status));
     537        }
     538
     539        dcerpc_lsa_Close(b, mem_ctx, &dom_pol, &result);
     540
     541        return status;
    504542}
    505543
     
    508546
    509547static NTSTATUS rpc_rights_revoke_internal(struct net_context *c,
    510                                         const DOM_SID *domain_sid,
     548                                        const struct dom_sid *domain_sid,
    511549                                        const char *domain_name,
    512550                                        struct cli_state *cli,
     
    517555{
    518556        struct policy_handle dom_pol;
    519         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
     557        NTSTATUS status, result;
    520558        struct lsa_RightSet rights;
    521         DOM_SID sid;
     559        struct dom_sid sid;
    522560        int i;
     561        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    523562
    524563        if (argc < 2 ) {
     
    529568        }
    530569
    531         result = name_to_sid(pipe_hnd, mem_ctx, &sid, argv[0]);
    532         if (!NT_STATUS_IS_OK(result))
    533                 return result;
    534 
    535         result = rpccli_lsa_open_policy2(pipe_hnd, mem_ctx, true,
     570        status = name_to_sid(pipe_hnd, mem_ctx, &sid, argv[0]);
     571        if (!NT_STATUS_IS_OK(status))
     572                return status;
     573
     574        status = rpccli_lsa_open_policy2(pipe_hnd, mem_ctx, true,
    536575                                     SEC_FLAG_MAXIMUM_ALLOWED,
    537576                                     &dom_pol);
    538577
    539         if (!NT_STATUS_IS_OK(result))
    540                 return result;
     578        if (!NT_STATUS_IS_OK(status))
     579                return status;
    541580
    542581        rights.count = argc-1;
     
    551590        }
    552591
    553         result = rpccli_lsa_RemoveAccountRights(pipe_hnd, mem_ctx,
     592        status = dcerpc_lsa_RemoveAccountRights(b, mem_ctx,
    554593                                                &dom_pol,
    555594                                                &sid,
    556595                                                false,
    557                                                 &rights);
    558 
    559         if (!NT_STATUS_IS_OK(result))
    560                 goto done;
     596                                                &rights,
     597                                                &result);
     598        if (!NT_STATUS_IS_OK(status))
     599                goto done;
     600        if (!NT_STATUS_IS_OK(result)) {
     601                status = result;
     602                goto done;
     603        }
    561604
    562605        d_printf(_("Successfully revoked rights.\n"));
    563606
    564607done:
    565         if ( !NT_STATUS_IS_OK(result) ) {
     608        if ( !NT_STATUS_IS_OK(status) ) {
    566609                d_fprintf(stderr,_("Failed to revoke privileges for %s (%s)\n"),
    567                         argv[0], nt_errstr(result));
    568         }
    569 
    570         rpccli_lsa_Close(pipe_hnd, mem_ctx, &dom_pol);
    571 
    572         return result;
     610                        argv[0], nt_errstr(status));
     611        }
     612
     613        dcerpc_lsa_Close(b, mem_ctx, &dom_pol, &result);
     614
     615        return status;
    573616}
    574617
  • vendor/current/source3/utils/net_rpc_samsync.c

    r594 r740  
    2626#include "includes.h"
    2727#include "utils/net.h"
     28#include "../librpc/gen_ndr/ndr_netlogon.h"
     29#include "../librpc/gen_ndr/ndr_drsuapi.h"
     30#include "libnet/libnet_samsync.h"
     31#include "libnet/libnet_dssync.h"
     32#include "../libcli/security/security.h"
     33#include "passdb/machine_sid.h"
    2834
    2935static void parse_samsync_partial_replication_objects(TALLOC_CTX *mem_ctx,
     
    104110/* dump sam database via samsync rpc calls */
    105111NTSTATUS rpc_samdump_internals(struct net_context *c,
    106                                 const DOM_SID *domain_sid,
     112                                const struct dom_sid *domain_sid,
    107113                                const char *domain_name,
    108114                                struct cli_state *cli,
     
    170176}
    171177
    172 
    173 /* dump sam database via samsync rpc calls */
    174 NTSTATUS rpc_vampire_internals(struct net_context *c,
    175                                 const DOM_SID *domain_sid,
    176                                 const char *domain_name,
    177                                 struct cli_state *cli,
    178                                 struct rpc_pipe_client *pipe_hnd,
    179                                 TALLOC_CTX *mem_ctx,
    180                                 int argc,
    181                                 const char **argv)
    182 {
    183         NTSTATUS result;
    184         struct samsync_context *ctx = NULL;
    185 
    186         if (!sid_equal(domain_sid, get_global_sam_sid())) {
     178static NTSTATUS rpc_vampire_ds_internals(struct net_context *c,
     179                                         const struct dom_sid *domain_sid,
     180                                         const char *domain_name,
     181                                         struct cli_state *cli,
     182                                         struct rpc_pipe_client *pipe_hnd,
     183                                         TALLOC_CTX *mem_ctx,
     184                                         int argc,
     185                                         const char **argv)
     186{
     187        NTSTATUS status;
     188        struct dssync_context *ctx = NULL;
     189
     190        if (!dom_sid_equal(domain_sid, get_global_sam_sid())) {
    187191                d_printf(_("Cannot import users from %s at this time, "
    188192                           "as the current domain:\n\t%s: %s\nconflicts "
     
    199203        }
    200204
     205        status = libnet_dssync_init_context(mem_ctx,
     206                                            &ctx);
     207        if (!NT_STATUS_IS_OK(status)) {
     208                return status;
     209        }
     210
     211        ctx->cli                = pipe_hnd;
     212        ctx->domain_name        = domain_name;
     213        ctx->ops                = &libnet_dssync_passdb_ops;
     214
     215        status = libnet_dssync(mem_ctx, ctx);
     216        if (!NT_STATUS_IS_OK(status) && ctx->error_message) {
     217                d_fprintf(stderr, "%s\n", ctx->error_message);
     218                goto out;
     219        }
     220
     221        if (ctx->result_message) {
     222                d_fprintf(stdout, "%s\n", ctx->result_message);
     223        }
     224
     225 out:
     226        TALLOC_FREE(ctx);
     227
     228        return status;
     229}
     230
     231/* dump sam database via samsync rpc calls */
     232static NTSTATUS rpc_vampire_internals(struct net_context *c,
     233                                      const struct dom_sid *domain_sid,
     234                                      const char *domain_name,
     235                                      struct cli_state *cli,
     236                                      struct rpc_pipe_client *pipe_hnd,
     237                                      TALLOC_CTX *mem_ctx,
     238                                      int argc,
     239                                      const char **argv)
     240{
     241        NTSTATUS result;
     242        struct samsync_context *ctx = NULL;
     243
     244        if (!dom_sid_equal(domain_sid, get_global_sam_sid())) {
     245                d_printf(_("Cannot import users from %s at this time, "
     246                           "as the current domain:\n\t%s: %s\nconflicts "
     247                           "with the remote domain\n\t%s: %s\n"
     248                           "Perhaps you need to set: \n\n\tsecurity=user\n\t"
     249                           "workgroup=%s\n\n in your smb.conf?\n"),
     250                         domain_name,
     251                         get_global_sam_name(),
     252                         sid_string_dbg(get_global_sam_sid()),
     253                         domain_name,
     254                         sid_string_dbg(domain_sid),
     255                         domain_name);
     256                return NT_STATUS_UNSUCCESSFUL;
     257        }
     258
    201259        result = libnet_samsync_init_context(mem_ctx,
    202260                                             domain_sid,
     
    232290
    233291        /* fetch builtin */
    234         ctx->domain_sid = sid_dup_talloc(mem_ctx, &global_sid_Builtin);
     292        ctx->domain_sid = dom_sid_dup(mem_ctx, &global_sid_Builtin);
    235293        ctx->domain_sid_str = sid_string_talloc(mem_ctx, ctx->domain_sid);
    236294        result = libnet_samsync(SAM_DATABASE_BUILTIN, ctx);
     
    252310int rpc_vampire_passdb(struct net_context *c, int argc, const char **argv)
    253311{
     312        int ret = 0;
     313        NTSTATUS status;
     314        struct cli_state *cli = NULL;
     315        struct net_dc_info dc_info;
     316
    254317        if (c->display_usage) {
    255318                d_printf(  "%s\n"
     
    261324        }
    262325
    263         return run_rpc_command(c, NULL, &ndr_table_netlogon.syntax_id, 0,
    264                                rpc_vampire_internals, argc, argv);
    265 }
    266 
    267 NTSTATUS rpc_vampire_ldif_internals(struct net_context *c,
    268                                     const DOM_SID *domain_sid,
    269                                     const char *domain_name,
    270                                     struct cli_state *cli,
    271                                     struct rpc_pipe_client *pipe_hnd,
    272                                     TALLOC_CTX *mem_ctx,
    273                                     int argc,
    274                                     const char **argv)
     326        status = net_make_ipc_connection(c, 0, &cli);
     327        if (!NT_STATUS_IS_OK(status)) {
     328                return -1;
     329        }
     330
     331        status = net_scan_dc(c, cli, &dc_info);
     332        if (!NT_STATUS_IS_OK(status)) {
     333                return -1;
     334        }
     335
     336        if (!dc_info.is_ad) {
     337                printf(_("DC is not running Active Directory\n"));
     338                ret = run_rpc_command(c, cli, &ndr_table_netlogon.syntax_id,
     339                                      0,
     340                                      rpc_vampire_internals, argc, argv);
     341                return ret;
     342        }
     343
     344        if (!c->opt_force) {
     345                d_printf(  "%s\n"
     346                           "net rpc vampire passdb\n"
     347                           "    %s\n",
     348                         _("Usage:"),
     349                         _("Should not be used against Active Directory, maybe use --force"));
     350                return -1;
     351        }
     352
     353        ret = run_rpc_command(c, cli, &ndr_table_drsuapi.syntax_id,
     354                              NET_FLAGS_SEAL | NET_FLAGS_TCP,
     355                              rpc_vampire_ds_internals, argc, argv);
     356        if (ret != 0 && dc_info.is_mixed_mode) {
     357                printf(_("Fallback to NT4 vampire on Mixed-Mode AD "
     358                         "Domain\n"));
     359                ret = run_rpc_command(c, cli, &ndr_table_netlogon.syntax_id,
     360                                      0,
     361                                      rpc_vampire_internals, argc, argv);
     362        }
     363
     364        return ret;
     365}
     366
     367static NTSTATUS rpc_vampire_ldif_internals(struct net_context *c,
     368                                           const struct dom_sid *domain_sid,
     369                                           const char *domain_name,
     370                                           struct cli_state *cli,
     371                                           struct rpc_pipe_client *pipe_hnd,
     372                                           TALLOC_CTX *mem_ctx,
     373                                           int argc,
     374                                           const char **argv)
    275375{
    276376        NTSTATUS status;
     
    315415
    316416        /* fetch builtin */
    317         ctx->domain_sid = sid_dup_talloc(mem_ctx, &global_sid_Builtin);
     417        ctx->domain_sid = dom_sid_dup(mem_ctx, &global_sid_Builtin);
    318418        ctx->domain_sid_str = sid_string_talloc(mem_ctx, ctx->domain_sid);
    319419        status = libnet_samsync(SAM_DATABASE_BUILTIN, ctx);
     
    350450
    351451
    352 NTSTATUS rpc_vampire_keytab_internals(struct net_context *c,
    353                                       const DOM_SID *domain_sid,
    354                                       const char *domain_name,
    355                                       struct cli_state *cli,
    356                                       struct rpc_pipe_client *pipe_hnd,
    357                                       TALLOC_CTX *mem_ctx,
    358                                       int argc,
    359                                       const char **argv)
     452static NTSTATUS rpc_vampire_keytab_internals(struct net_context *c,
     453                                             const struct dom_sid *domain_sid,
     454                                             const char *domain_name,
     455                                             struct cli_state *cli,
     456                                             struct rpc_pipe_client *pipe_hnd,
     457                                             TALLOC_CTX *mem_ctx,
     458                                             int argc,
     459                                             const char **argv)
    360460{
    361461        NTSTATUS status;
     
    411511
    412512static NTSTATUS rpc_vampire_keytab_ds_internals(struct net_context *c,
    413                                                 const DOM_SID *domain_sid,
     513                                                const struct dom_sid *domain_sid,
    414514                                                const char *domain_name,
    415515                                                struct cli_state *cli,
  • vendor/current/source3/utils/net_rpc_service.c

    r414 r740  
    1919#include "includes.h"
    2020#include "utils/net.h"
    21 #include "../librpc/gen_ndr/cli_svcctl.h"
     21#include "rpc_client/rpc_client.h"
     22#include "../librpc/gen_ndr/ndr_svcctl.h"
     23#include "../librpc/gen_ndr/ndr_svcctl_c.h"
    2224
    2325struct svc_state_msg {
     
    6062********************************************************************/
    6163
     64static WERROR open_service(struct dcerpc_binding_handle *b,
     65                           TALLOC_CTX *mem_ctx,
     66                           struct policy_handle *hSCM,
     67                           const char *service,
     68                           uint32_t access_mask,
     69                           struct policy_handle *hService)
     70{
     71        NTSTATUS status;
     72        WERROR result;
     73
     74        status = dcerpc_svcctl_OpenServiceW(b, mem_ctx,
     75                                            hSCM,
     76                                            service,
     77                                            access_mask,
     78                                            hService,
     79                                            &result);
     80        if (!NT_STATUS_IS_OK(status)) {
     81                result = ntstatus_to_werror(status);
     82                d_fprintf(stderr, _("Failed to open service.  [%s]\n"),
     83                          nt_errstr(status));
     84                return result;
     85        }
     86        if (!W_ERROR_IS_OK(result) ) {
     87                d_fprintf(stderr, _("Failed to open service.  [%s]\n"),
     88                          win_errstr(result));
     89                return result;
     90        }
     91
     92        return WERR_OK;
     93}
     94
     95/********************************************************************
     96********************************************************************/
     97
     98static WERROR open_scm(struct dcerpc_binding_handle *b,
     99                       TALLOC_CTX *mem_ctx,
     100                       const char *server_name,
     101                       uint32_t access_mask,
     102                       struct policy_handle *hSCM)
     103{
     104        NTSTATUS status;
     105        WERROR result;
     106
     107        status = dcerpc_svcctl_OpenSCManagerW(b, mem_ctx,
     108                                              server_name,
     109                                              NULL,
     110                                              access_mask,
     111                                              hSCM,
     112                                              &result);
     113        if (!NT_STATUS_IS_OK(status)) {
     114                result = ntstatus_to_werror(status);
     115                d_fprintf(stderr,
     116                          _("Failed to open Service Control Manager. [%s]\n"),
     117                          nt_errstr(status));
     118                return result;
     119        }
     120        if (!W_ERROR_IS_OK(result)) {
     121                d_fprintf(stderr,
     122                          _("Failed to open Service Control Manager. [%s]\n"),
     123                          win_errstr(result));
     124                return result;
     125        }
     126
     127        return WERR_OK;
     128}
     129
     130/********************************************************************
     131********************************************************************/
     132
    62133static WERROR query_service_state(struct rpc_pipe_client *pipe_hnd,
    63134                                TALLOC_CTX *mem_ctx,
     
    70141        WERROR result = WERR_GENERAL_FAILURE;
    71142        NTSTATUS status;
     143        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    72144
    73145        /* now cycle until the status is actually 'watch_state' */
    74146
    75         status = rpccli_svcctl_OpenServiceW(pipe_hnd, mem_ctx,
    76                                             hSCM,
    77                                             service,
    78                                             SC_RIGHT_SVC_QUERY_STATUS,
    79                                             &hService,
    80                                             &result);
    81         if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) {
    82                 d_fprintf(stderr, _("Failed to open service.  [%s]\n"),
    83                           win_errstr(result));
     147        result = open_service(b, mem_ctx, hSCM, service,
     148                              SC_RIGHT_SVC_QUERY_STATUS,
     149                              &hService);
     150        if (!W_ERROR_IS_OK(result) ) {
    84151                return result;
    85152        }
    86153
    87         status = rpccli_svcctl_QueryServiceStatus(pipe_hnd, mem_ctx,
     154        status = dcerpc_svcctl_QueryServiceStatus(b, mem_ctx,
    88155                                                  &hService,
    89156                                                  &service_status,
    90157                                                  &result);
    91 
    92         if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) {
    93                 *state = service_status.state;
    94         }
    95 
    96         rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService, NULL);
     158        if (!NT_STATUS_IS_OK(status)) {
     159                result = ntstatus_to_werror(status);
     160                goto done;
     161        }
     162        if (!W_ERROR_IS_OK(result)) {
     163                goto done;
     164        }
     165
     166        *state = service_status.state;
     167
     168 done:
     169        if (is_valid_policy_hnd(&hService)) {
     170                WERROR _result;
     171                dcerpc_svcctl_CloseServiceHandle(b, mem_ctx, &hService, &_result);
     172        }
    97173
    98174        return result;
     
    149225        struct SERVICE_STATUS service_status;
    150226        uint32 state = 0;
     227        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    151228
    152229        /* Open the Service */
    153230
    154         status = rpccli_svcctl_OpenServiceW(pipe_hnd, mem_ctx,
    155                                             hSCM,
    156                                             service,
    157                                             (SC_RIGHT_SVC_STOP|SC_RIGHT_SVC_PAUSE_CONTINUE),
    158                                             &hService,
    159                                             &result);
    160 
    161         if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) {
    162                 d_fprintf(stderr, _("Failed to open service.  [%s]\n"),
    163                           win_errstr(result));
    164                 goto done;
     231        result = open_service(b, mem_ctx, hSCM, service,
     232                              (SC_RIGHT_SVC_STOP|SC_RIGHT_SVC_PAUSE_CONTINUE),
     233                              &hService);
     234        if (!W_ERROR_IS_OK(result) ) {
     235                return result;
    165236        }
    166237
    167238        /* get the status */
    168239
    169         status = rpccli_svcctl_ControlService(pipe_hnd, mem_ctx,
     240        status = dcerpc_svcctl_ControlService(b, mem_ctx,
    170241                                              &hService,
    171242                                              control,
     
    173244                                              &result);
    174245
    175         if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) {
     246        if (!NT_STATUS_IS_OK(status)) {
     247                result = ntstatus_to_werror(status);
     248                d_fprintf(stderr, _("Control service request failed.  [%s]\n"),
     249                          nt_errstr(status));
     250                goto done;
     251        }
     252        if (!W_ERROR_IS_OK(result) ) {
    176253                d_fprintf(stderr, _("Control service request failed.  [%s]\n"),
    177254                          win_errstr(result));
     
    186263
    187264done:
    188         rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService, NULL);
     265        if (is_valid_policy_hnd(&hService)) {
     266                WERROR _result;
     267                dcerpc_svcctl_CloseServiceHandle(b, mem_ctx, &hService, &_result);
     268        }
    189269
    190270        return result;
     
    195275
    196276static NTSTATUS rpc_service_list_internal(struct net_context *c,
    197                                         const DOM_SID *domain_sid,
     277                                        const struct dom_sid *domain_sid,
    198278                                        const char *domain_name,
    199279                                        struct cli_state *cli,
     
    208288        NTSTATUS status;
    209289        int i;
     290        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    210291
    211292        uint8_t *buffer = NULL;
     
    220301        }
    221302
    222         status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx,
    223                                               pipe_hnd->srv_name_slash,
    224                                               NULL,
    225                                               SC_RIGHT_MGR_ENUMERATE_SERVICE,
    226                                               &hSCM,
    227                                               &result);
    228         if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
    229                 d_fprintf(stderr,
    230                           _("Failed to open Service Control Manager. [%s]\n"),
    231                           win_errstr(result));
     303        result = open_scm(b, mem_ctx, pipe_hnd->srv_name_slash,
     304                          SC_RIGHT_MGR_ENUMERATE_SERVICE,
     305                          &hSCM);
     306        if (!W_ERROR_IS_OK(result)) {
    232307                return werror_to_ntstatus(result);
    233308        }
    234309
    235310        do {
    236                 status = rpccli_svcctl_EnumServicesStatusW(pipe_hnd, mem_ctx,
     311                status = dcerpc_svcctl_EnumServicesStatusW(b, mem_ctx,
    237312                                                           &hSCM,
    238313                                                           SERVICE_TYPE_WIN32,
     
    245320                                                           &result);
    246321
    247                 if (NT_STATUS_IS_ERR(status)) {
     322                if (!NT_STATUS_IS_OK(status)) {
     323                        d_fprintf(stderr,
     324                                _("Failed to enumerate services.  [%s]\n"),
     325                                nt_errstr(status));
     326                        break;
     327                }
     328
     329                if (W_ERROR_EQUAL(result, WERR_MORE_DATA) && bytes_needed > 0) {
     330                        buffer = talloc_array(mem_ctx, uint8_t, bytes_needed);
     331                        buf_size = bytes_needed;
     332                        continue;
     333                }
     334
     335                if (!W_ERROR_IS_OK(result)) {
     336                        status = werror_to_ntstatus(result);
    248337                        d_fprintf(stderr,
    249338                                _("Failed to enumerate services.  [%s]\n"),
     
    252341                }
    253342
    254                 if (W_ERROR_EQUAL(result, WERR_MORE_DATA) && bytes_needed > 0) {
    255                         buffer = talloc_array(mem_ctx, uint8_t, bytes_needed);
    256                         buf_size = bytes_needed;
    257                         continue;
    258                 }
    259 
    260343                if ( num_services == 0 ) {
    261344                        d_printf(_("No services returned\n"));
     
    277360                        }
    278361
    279                         ndr = ndr_pull_init_blob(&blob, mem_ctx, NULL);
     362                        ndr = ndr_pull_init_blob(&blob, mem_ctx);
    280363                        if (ndr == NULL) {
    281364                                status = NT_STATUS_NO_MEMORY;
     
    299382        } while (W_ERROR_EQUAL(result, WERR_MORE_DATA));
    300383
    301         rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM, NULL);
     384        if (is_valid_policy_hnd(&hSCM)) {
     385                WERROR _result;
     386                dcerpc_svcctl_CloseServiceHandle(b, mem_ctx, &hSCM, &_result);
     387        }
    302388
    303389        return status;
     
    308394
    309395static NTSTATUS rpc_service_status_internal(struct net_context *c,
    310                                                 const DOM_SID *domain_sid,
     396                                                const struct dom_sid *domain_sid,
    311397                                                const char *domain_name,
    312398                                                struct cli_state *cli,
     
    323409        uint32_t buf_size = sizeof(config);
    324410        uint32_t ret_size = 0;
     411        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    325412
    326413        if (argc != 1 ) {
     
    330417
    331418        /* Open the Service Control Manager */
    332         status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx,
    333                                               pipe_hnd->srv_name_slash,
    334                                               NULL,
    335                                               SC_RIGHT_MGR_ENUMERATE_SERVICE,
    336                                               &hSCM,
    337                                               &result);
    338         if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
    339                 d_fprintf(stderr,
    340                           _("Failed to open Service Control Manager. [%s]\n"),
    341                           win_errstr(result));
     419        result = open_scm(b, mem_ctx, pipe_hnd->srv_name_slash,
     420                          SC_RIGHT_MGR_ENUMERATE_SERVICE,
     421                          &hSCM);
     422        if (!W_ERROR_IS_OK(result)) {
    342423                return werror_to_ntstatus(result);
    343424        }
     
    345426        /* Open the Service */
    346427
    347         status = rpccli_svcctl_OpenServiceW(pipe_hnd, mem_ctx,
    348                                             &hSCM,
    349                                             argv[0],
    350                                             (SC_RIGHT_SVC_QUERY_STATUS|SC_RIGHT_SVC_QUERY_CONFIG),
    351                                             &hService,
    352                                             &result);
    353 
    354         if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) {
    355                 d_fprintf(stderr, _("Failed to open service.  [%s]\n"),
    356                           win_errstr(result));
     428        result = open_service(b, mem_ctx, &hSCM, argv[0],
     429                              (SC_RIGHT_SVC_QUERY_STATUS|SC_RIGHT_SVC_QUERY_CONFIG),
     430                              &hService);
     431        if (!W_ERROR_IS_OK(result) ) {
    357432                goto done;
    358433        }
     
    360435        /* get the status */
    361436
    362         status = rpccli_svcctl_QueryServiceStatus(pipe_hnd, mem_ctx,
     437        status = dcerpc_svcctl_QueryServiceStatus(b, mem_ctx,
    363438                                                  &hService,
    364439                                                  &service_status,
    365440                                                  &result);
    366 
    367         if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) {
     441        if (!NT_STATUS_IS_OK(status)) {
     442                result = ntstatus_to_werror(status);
     443                d_fprintf(stderr, _("Query status request failed.  [%s]\n"),
     444                          nt_errstr(status));
     445                goto done;
     446        }
     447
     448        if (!W_ERROR_IS_OK(result) ) {
    368449                d_fprintf(stderr, _("Query status request failed.  [%s]\n"),
    369450                          win_errstr(result));
     
    376457        /* get the config */
    377458
    378         status = rpccli_svcctl_QueryServiceConfigW(pipe_hnd, mem_ctx,
     459        status = dcerpc_svcctl_QueryServiceConfigW(b, mem_ctx,
    379460                                                   &hService,
    380461                                                   &config,
     
    382463                                                   &ret_size,
    383464                                                   &result);
     465        if (!NT_STATUS_IS_OK(status)) {
     466                result = ntstatus_to_werror(status);
     467                d_fprintf(stderr, _("Query config request failed.  [%s]\n"),
     468                          nt_errstr(status));
     469                goto done;
     470        }
     471
    384472        if (W_ERROR_EQUAL(result, WERR_INSUFFICIENT_BUFFER)) {
    385473                buf_size = ret_size;
    386                 status = rpccli_svcctl_QueryServiceConfigW(pipe_hnd, mem_ctx,
     474                status = dcerpc_svcctl_QueryServiceConfigW(b, mem_ctx,
    387475                                                           &hService,
    388476                                                           &config,
     
    390478                                                           &ret_size,
    391479                                                           &result);
    392         }
    393 
    394         if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) {
     480                if (!NT_STATUS_IS_OK(status)) {
     481                        result = ntstatus_to_werror(status);
     482                        d_fprintf(stderr, _("Query config request failed.  [%s]\n"),
     483                                  nt_errstr(status));
     484                        goto done;
     485                }
     486        }
     487
     488        if (!W_ERROR_IS_OK(result) ) {
    395489                d_fprintf(stderr, _("Query config request failed.  [%s]\n"),
    396490                          win_errstr(result));
     
    433527
    434528done:
    435         rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService, NULL);
    436         rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM, NULL);
     529        if (is_valid_policy_hnd(&hService)) {
     530                WERROR _result;
     531                dcerpc_svcctl_CloseServiceHandle(b, mem_ctx, &hService, &_result);
     532        }
     533        if (is_valid_policy_hnd(&hSCM)) {
     534                WERROR _result;
     535                dcerpc_svcctl_CloseServiceHandle(b, mem_ctx, &hSCM, &_result);
     536        }
    437537
    438538        return werror_to_ntstatus(result);
     
    443543
    444544static NTSTATUS rpc_service_stop_internal(struct net_context *c,
    445                                         const DOM_SID *domain_sid,
     545                                        const struct dom_sid *domain_sid,
    446546                                        const char *domain_name,
    447547                                        struct cli_state *cli,
     
    453553        struct policy_handle hSCM;
    454554        WERROR result = WERR_GENERAL_FAILURE;
    455         NTSTATUS status;
    456         fstring servicename;
     555        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    457556
    458557        if (argc != 1 ) {
     
    461560        }
    462561
    463         fstrcpy( servicename, argv[0] );
    464 
    465562        /* Open the Service Control Manager */
    466         status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx,
    467                                               pipe_hnd->srv_name_slash,
    468                                               NULL,
    469                                               SC_RIGHT_MGR_ENUMERATE_SERVICE,
    470                                               &hSCM,
    471                                               &result);
    472         if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
    473                 d_fprintf(stderr,
    474                           _("Failed to open Service Control Manager.  [%s]\n"),
    475                           win_errstr(result));
     563        result = open_scm(b, mem_ctx, pipe_hnd->srv_name_slash,
     564                          SC_RIGHT_MGR_ENUMERATE_SERVICE,
     565                          &hSCM);
     566        if (!W_ERROR_IS_OK(result)) {
    476567                return werror_to_ntstatus(result);
    477568        }
    478569
    479         result = control_service(pipe_hnd, mem_ctx, &hSCM, servicename,
     570        result = control_service(pipe_hnd, mem_ctx, &hSCM, argv[0],
    480571                SVCCTL_CONTROL_STOP, SVCCTL_STOPPED );
    481572
    482         rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM, NULL);
     573        if (is_valid_policy_hnd(&hSCM)) {
     574                WERROR _result;
     575                dcerpc_svcctl_CloseServiceHandle(b, mem_ctx, &hSCM, &_result);
     576        }
    483577
    484578        return werror_to_ntstatus(result);
     
    489583
    490584static NTSTATUS rpc_service_pause_internal(struct net_context *c,
    491                                         const DOM_SID *domain_sid,
     585                                        const struct dom_sid *domain_sid,
    492586                                        const char *domain_name,
    493587                                        struct cli_state *cli,
     
    499593        struct policy_handle hSCM;
    500594        WERROR result = WERR_GENERAL_FAILURE;
    501         NTSTATUS status;
    502         fstring servicename;
     595        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    503596
    504597        if (argc != 1 ) {
     
    507600        }
    508601
    509         fstrcpy( servicename, argv[0] );
    510 
    511602        /* Open the Service Control Manager */
    512         status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx,
    513                                               pipe_hnd->srv_name_slash,
    514                                               NULL,
    515                                               SC_RIGHT_MGR_ENUMERATE_SERVICE,
    516                                               &hSCM,
    517                                               &result);
    518         if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
    519                 d_fprintf(stderr,
    520                           _("Failed to open Service Control Manager.  [%s]\n"),
    521                           win_errstr(result));
     603        result = open_scm(b, mem_ctx, pipe_hnd->srv_name_slash,
     604                          SC_RIGHT_MGR_ENUMERATE_SERVICE,
     605                          &hSCM);
     606        if (!W_ERROR_IS_OK(result)) {
    522607                return werror_to_ntstatus(result);
    523608        }
    524609
    525         result = control_service(pipe_hnd, mem_ctx, &hSCM, servicename,
     610        result = control_service(pipe_hnd, mem_ctx, &hSCM, argv[0],
    526611                SVCCTL_CONTROL_PAUSE, SVCCTL_PAUSED );
    527612
    528         rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM, NULL);
     613        if (is_valid_policy_hnd(&hSCM)) {
     614                WERROR _result;
     615                dcerpc_svcctl_CloseServiceHandle(b, mem_ctx, &hSCM, &_result);
     616        }
    529617
    530618        return werror_to_ntstatus(result);
     
    535623
    536624static NTSTATUS rpc_service_resume_internal(struct net_context *c,
    537                                         const DOM_SID *domain_sid,
     625                                        const struct dom_sid *domain_sid,
    538626                                        const char *domain_name,
    539627                                        struct cli_state *cli,
     
    545633        struct policy_handle hSCM;
    546634        WERROR result = WERR_GENERAL_FAILURE;
    547         NTSTATUS status;
    548         fstring servicename;
     635        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    549636
    550637        if (argc != 1 ) {
     
    553640        }
    554641
    555         fstrcpy( servicename, argv[0] );
    556 
    557642        /* Open the Service Control Manager */
    558         status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx,
    559                                               pipe_hnd->srv_name_slash,
    560                                               NULL,
    561                                               SC_RIGHT_MGR_ENUMERATE_SERVICE,
    562                                               &hSCM,
    563                                               &result);
    564         if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
    565                 d_fprintf(stderr,
    566                           _("Failed to open Service Control Manager.  [%s]\n"),
    567                           win_errstr(result));
     643        result = open_scm(b, mem_ctx, pipe_hnd->srv_name_slash,
     644                          SC_RIGHT_MGR_ENUMERATE_SERVICE,
     645                          &hSCM);
     646        if (!W_ERROR_IS_OK(result)) {
    568647                return werror_to_ntstatus(result);
    569648        }
    570649
    571         result = control_service(pipe_hnd, mem_ctx, &hSCM, servicename,
     650        result = control_service(pipe_hnd, mem_ctx, &hSCM, argv[0],
    572651                SVCCTL_CONTROL_CONTINUE, SVCCTL_RUNNING );
    573652
    574         rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM, NULL);
     653        if (is_valid_policy_hnd(&hSCM)) {
     654                WERROR _result;
     655                dcerpc_svcctl_CloseServiceHandle(b, mem_ctx, &hSCM, &_result);
     656        }
    575657
    576658        return werror_to_ntstatus(result);
     
    581663
    582664static NTSTATUS rpc_service_start_internal(struct net_context *c,
    583                                         const DOM_SID *domain_sid,
     665                                        const struct dom_sid *domain_sid,
    584666                                        const char *domain_name,
    585667                                        struct cli_state *cli,
     
    593675        NTSTATUS status;
    594676        uint32 state = 0;
     677        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    595678
    596679        if (argc != 1 ) {
     
    600683
    601684        /* Open the Service Control Manager */
    602         status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx,
    603                                               pipe_hnd->srv_name_slash,
    604                                               NULL,
    605                                               SC_RIGHT_MGR_ENUMERATE_SERVICE,
    606                                               &hSCM,
    607                                               &result);
    608         if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
    609                 d_fprintf(stderr,
    610                           _("Failed to open Service Control Manager.  [%s]\n"),
    611                           win_errstr(result));
     685        result = open_scm(b, mem_ctx, pipe_hnd->srv_name_slash,
     686                          SC_RIGHT_MGR_ENUMERATE_SERVICE,
     687                          &hSCM);
     688        if (!W_ERROR_IS_OK(result)) {
    612689                return werror_to_ntstatus(result);
    613690        }
    614691
     692
    615693        /* Open the Service */
    616694
    617         status = rpccli_svcctl_OpenServiceW(pipe_hnd, mem_ctx,
    618                                             &hSCM,
    619                                             argv[0],
    620                                             SC_RIGHT_SVC_START,
    621                                             &hService,
    622                                             &result);
    623 
    624         if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) {
    625                 d_fprintf(stderr, _("Failed to open service.  [%s]\n"),
    626                           win_errstr(result));
     695        result = open_service(b, mem_ctx, &hSCM, argv[0],
     696                              SC_RIGHT_SVC_START,
     697                              &hService);
     698        if (!W_ERROR_IS_OK(result) ) {
    627699                goto done;
    628700        }
     
    630702        /* get the status */
    631703
    632         status = rpccli_svcctl_StartServiceW(pipe_hnd, mem_ctx,
     704        status = dcerpc_svcctl_StartServiceW(b, mem_ctx,
    633705                                             &hService,
    634706                                             0,
     
    636708                                             &result);
    637709
    638         if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) {
     710        if (!NT_STATUS_IS_OK(status)) {
     711                result = ntstatus_to_werror(status);
     712                d_fprintf(stderr, _("Query status request failed.  [%s]\n"),
     713                          nt_errstr(status));
     714                goto done;
     715        }
     716        if (!W_ERROR_IS_OK(result) ) {
    639717                d_fprintf(stderr, _("Query status request failed.  [%s]\n"),
    640718                          win_errstr(result));
     
    652730
    653731done:
    654         rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService, NULL);
    655         rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM, NULL);
     732        if (is_valid_policy_hnd(&hService)) {
     733                WERROR _result;
     734                dcerpc_svcctl_CloseServiceHandle(b, mem_ctx, &hService, &_result);
     735        }
     736        if (is_valid_policy_hnd(&hSCM)) {
     737                WERROR _result;
     738                dcerpc_svcctl_CloseServiceHandle(b, mem_ctx, &hSCM, &_result);
     739        }
    656740
    657741        return werror_to_ntstatus(result);
     
    662746
    663747static NTSTATUS rpc_service_delete_internal(struct net_context *c,
    664                                             const DOM_SID *domain_sid,
     748                                            const struct dom_sid *domain_sid,
    665749                                            const char *domain_name,
    666750                                            struct cli_state *cli,
     
    673757        WERROR result = WERR_GENERAL_FAILURE;
    674758        NTSTATUS status;
     759        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    675760
    676761        if (argc != 1 ) {
     
    679764        }
    680765
     766        ZERO_STRUCT(hSCM);
     767        ZERO_STRUCT(hService);
     768
    681769        /* Open the Service Control Manager */
    682         status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx,
    683                                               pipe_hnd->srv_name_slash,
    684                                               NULL,
    685                                               SC_RIGHT_MGR_ENUMERATE_SERVICE,
    686                                               &hSCM,
    687                                               &result);
    688         if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
    689                 d_fprintf(stderr,
    690                         _("Failed to open Service Control Manager.  [%s]\n"),
    691                         win_errstr(result));
     770        result = open_scm(b, mem_ctx, pipe_hnd->srv_name_slash,
     771                          SC_RIGHT_MGR_ENUMERATE_SERVICE,
     772                          &hSCM);
     773        if (!W_ERROR_IS_OK(result)) {
    692774                return werror_to_ntstatus(result);
    693775        }
     
    695777        /* Open the Service */
    696778
    697         status = rpccli_svcctl_OpenServiceW(pipe_hnd, mem_ctx,
    698                                             &hSCM,
    699                                             argv[0],
    700                                             SERVICE_ALL_ACCESS,
    701                                             &hService,
    702                                             &result);
    703 
    704         if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) {
    705                 d_fprintf(stderr, _("Failed to open service.  [%s]\n"),
    706                         win_errstr(result));
     779        result = open_service(b, mem_ctx, &hSCM, argv[0],
     780                              SERVICE_ALL_ACCESS,
     781                              &hService);
     782        if (!W_ERROR_IS_OK(result) ) {
    707783                goto done;
    708784        }
     
    710786        /* Delete the Service */
    711787
    712         status = rpccli_svcctl_DeleteService(pipe_hnd, mem_ctx,
     788        status = dcerpc_svcctl_DeleteService(b, mem_ctx,
    713789                                             &hService,
    714790                                             &result);
    715791
    716         if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) {
     792        if (!NT_STATUS_IS_OK(status)) {
     793                result = ntstatus_to_werror(status);
     794                d_fprintf(stderr, _("Delete service request failed.  [%s]\n"),
     795                        nt_errstr(status));
     796                goto done;
     797        }
     798        if (!W_ERROR_IS_OK(result)) {
    717799                d_fprintf(stderr, _("Delete service request failed.  [%s]\n"),
    718800                        win_errstr(result));
     
    724806 done:
    725807        if (is_valid_policy_hnd(&hService)) {
    726                 rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService, NULL);
     808                WERROR _result;
     809                dcerpc_svcctl_CloseServiceHandle(b, mem_ctx, &hService, &_result);
    727810        }
    728811        if (is_valid_policy_hnd(&hSCM)) {
    729                 rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM, NULL);
     812                WERROR _result;
     813                dcerpc_svcctl_CloseServiceHandle(b, mem_ctx, &hSCM, &_result);
    730814        }
    731815
     
    737821
    738822static NTSTATUS rpc_service_create_internal(struct net_context *c,
    739                                             const DOM_SID *domain_sid,
     823                                            const struct dom_sid *domain_sid,
    740824                                            const char *domain_name,
    741825                                            struct cli_state *cli,
     
    751835        const char *DisplayName;
    752836        const char *binary_path;
     837        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    753838
    754839        if (argc != 3) {
     
    758843        }
    759844
     845        ZERO_STRUCT(hSCM);
     846        ZERO_STRUCT(hService);
     847
    760848        /* Open the Service Control Manager */
    761         status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx,
    762                                               pipe_hnd->srv_name_slash,
    763                                               NULL,
    764                                               SC_RIGHT_MGR_CREATE_SERVICE,
    765                                               &hSCM,
    766                                               &result);
    767         if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
    768                 d_fprintf(stderr,
    769                         _("Failed to open Service Control Manager.  [%s]\n"),
    770                         win_errstr(result));
     849        result = open_scm(b, mem_ctx, pipe_hnd->srv_name_slash,
     850                          SC_RIGHT_MGR_CREATE_SERVICE,
     851                          &hSCM);
     852        if (!W_ERROR_IS_OK(result)) {
    771853                return werror_to_ntstatus(result);
    772854        }
     
    778860        binary_path = argv[2];
    779861
    780         status = rpccli_svcctl_CreateServiceW(pipe_hnd, mem_ctx,
     862        status = dcerpc_svcctl_CreateServiceW(b, mem_ctx,
    781863                                              &hSCM,
    782864                                              ServiceName,
     
    796878                                              &hService,
    797879                                              &result);
    798 
    799         if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) {
     880        if (!NT_STATUS_IS_OK(status)) {
     881                result = ntstatus_to_werror(status);
    800882                d_fprintf(stderr, _("Create service request failed.  [%s]\n"),
    801                         win_errstr(result));
     883                          nt_errstr(status));
     884                goto done;
     885        }
     886        if (!W_ERROR_IS_OK(result)) {
     887                d_fprintf(stderr, _("Create service request failed.  [%s]\n"),
     888                          win_errstr(result));
    802889                goto done;
    803890        }
     
    807894 done:
    808895        if (is_valid_policy_hnd(&hService)) {
    809                 rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService, NULL);
     896                WERROR _result;
     897                dcerpc_svcctl_CloseServiceHandle(b, mem_ctx, &hService, &_result);
    810898        }
    811899        if (is_valid_policy_hnd(&hSCM)) {
    812                 rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM, NULL);
     900                WERROR _result;
     901                dcerpc_svcctl_CloseServiceHandle(b, mem_ctx, &hSCM, &_result);
    813902        }
    814903
  • vendor/current/source3/utils/net_rpc_sh_acct.c

    r414 r740  
    1919#include "includes.h"
    2020#include "utils/net.h"
    21 #include "../librpc/gen_ndr/cli_samr.h"
     21#include "rpc_client/rpc_client.h"
     22#include "../librpc/gen_ndr/ndr_samr_c.h"
     23#include "../libcli/security/security.h"
    2224
    2325/*
     
    4143{
    4244        struct policy_handle connect_pol, domain_pol;
    43         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
     45        NTSTATUS status, result;
    4446        union samr_DomainInfo *info1 = NULL;
    4547        union samr_DomainInfo *info3 = NULL;
    4648        union samr_DomainInfo *info12 = NULL;
    4749        int store;
     50        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
    4851
    4952        ZERO_STRUCT(connect_pol);
     
    5255        /* Get sam policy handle */
    5356
    54         result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
     57        status = dcerpc_samr_Connect2(b, mem_ctx,
    5558                                      pipe_hnd->desthost,
    5659                                      MAXIMUM_ALLOWED_ACCESS,
    57                                       &connect_pol);
     60                                      &connect_pol,
     61                                      &result);
     62        if (!NT_STATUS_IS_OK(status)) {
     63                goto done;
     64        }
    5865        if (!NT_STATUS_IS_OK(result)) {
     66                status = result;
    5967                goto done;
    6068        }
     
    6270        /* Get domain policy handle */
    6371
    64         result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
     72        status = dcerpc_samr_OpenDomain(b, mem_ctx,
    6573                                        &connect_pol,
    6674                                        MAXIMUM_ALLOWED_ACCESS,
    6775                                        ctx->domain_sid,
    68                                         &domain_pol);
     76                                        &domain_pol,
     77                                        &result);
     78        if (!NT_STATUS_IS_OK(status)) {
     79                goto done;
     80        }
    6981        if (!NT_STATUS_IS_OK(result)) {
    70                 goto done;
    71         }
    72 
    73         result = rpccli_samr_QueryDomainInfo(pipe_hnd, mem_ctx,
     82                status = result;
     83                goto done;
     84        }
     85
     86        status = dcerpc_samr_QueryDomainInfo(b, mem_ctx,
    7487                                             &domain_pol,
    7588                                             1,
    76                                              &info1);
    77 
     89                                             &info1,
     90                                             &result);
     91        if (!NT_STATUS_IS_OK(status)) {
     92                goto done;
     93        }
    7894        if (!NT_STATUS_IS_OK(result)) {
     95                status = result;
    7996                d_fprintf(stderr, _("query_domain_info level 1 failed: %s\n"),
    8097                          nt_errstr(result));
     
    8299        }
    83100
    84         result = rpccli_samr_QueryDomainInfo(pipe_hnd, mem_ctx,
     101        status = dcerpc_samr_QueryDomainInfo(b, mem_ctx,
    85102                                             &domain_pol,
    86103                                             3,
    87                                              &info3);
    88 
     104                                             &info3,
     105                                             &result);
     106        if (!NT_STATUS_IS_OK(status)) {
     107                goto done;
     108        }
    89109        if (!NT_STATUS_IS_OK(result)) {
     110                status = result;
    90111                d_fprintf(stderr, _("query_domain_info level 3 failed: %s\n"),
    91112                          nt_errstr(result));
     
    93114        }
    94115
    95         result = rpccli_samr_QueryDomainInfo(pipe_hnd, mem_ctx,
     116        status = dcerpc_samr_QueryDomainInfo(b, mem_ctx,
    96117                                             &domain_pol,
    97118                                             12,
    98                                              &info12);
    99 
     119                                             &info12,
     120                                             &result);
     121        if (!NT_STATUS_IS_OK(status)) {
     122                goto done;
     123        }
    100124        if (!NT_STATUS_IS_OK(result)) {
     125                status = result;
    101126                d_fprintf(stderr, _("query_domain_info level 12 failed: %s\n"),
    102127                          nt_errstr(result));
     
    114139        switch (store) {
    115140        case 1:
    116                 result = rpccli_samr_SetDomainInfo(pipe_hnd, mem_ctx,
     141                status = dcerpc_samr_SetDomainInfo(b, mem_ctx,
    117142                                                   &domain_pol,
    118143                                                   1,
    119                                                    info1);
     144                                                   info1,
     145                                                   &result);
    120146                break;
    121147        case 3:
    122                 result = rpccli_samr_SetDomainInfo(pipe_hnd, mem_ctx,
     148                status = dcerpc_samr_SetDomainInfo(b, mem_ctx,
    123149                                                   &domain_pol,
    124150                                                   3,
    125                                                    info3);
     151                                                   info3,
     152                                                   &result);
    126153                break;
    127154        case 12:
    128                 result = rpccli_samr_SetDomainInfo(pipe_hnd, mem_ctx,
     155                status = dcerpc_samr_SetDomainInfo(b, mem_ctx,
    129156                                                   &domain_pol,
    130157                                                   12,
    131                                                    info12);
     158                                                   info12,
     159                                                   &result);
    132160                break;
    133161        default:
    134162                d_fprintf(stderr, _("Got unexpected info level %d\n"), store);
    135                 result = NT_STATUS_INTERNAL_ERROR;
    136                 goto done;
    137         }
     163                status = NT_STATUS_INTERNAL_ERROR;
     164                goto done;
     165        }
     166
     167        if (!NT_STATUS_IS_OK(status)) {
     168                goto done;
     169        }
     170
     171        status = result;
    138172
    139173 done:
    140174        if (is_valid_policy_hnd(&domain_pol)) {
    141                 rpccli_samr_Close(pipe_hnd, mem_ctx, &domain_pol);
     175                dcerpc_samr_Close(b, mem_ctx, &domain_pol, &result);
    142176        }
    143177        if (is_valid_policy_hnd(&connect_pol)) {
    144                 rpccli_samr_Close(pipe_hnd, mem_ctx, &connect_pol);
    145         }
    146 
    147         return result;
     178                dcerpc_samr_Close(b, mem_ctx, &connect_pol, &result);
     179        }
     180
     181        return status;
    148182}
    149183
  • vendor/current/source3/utils/net_rpc_shell.c

    r414 r740  
    2020
    2121#include "includes.h"
     22#include "popt_common.h"
    2223#include "utils/net.h"
     24#include "rpc_client/cli_pipe.h"
     25#include "../librpc/gen_ndr/ndr_samr.h"
     26#include "lib/netapi/netapi.h"
     27#include "lib/netapi/netapi_net.h"
     28#include "../libcli/smbreadline/smbreadline.h"
     29#include "libsmb/libsmb.h"
    2330
    2431static NTSTATUS rpc_sh_info(struct net_context *c,
     
    219226        }
    220227
    221         if (libnetapi_init(&c->netapi_ctx) != 0) {
     228        if (libnetapi_net_init(&c->netapi_ctx) != 0) {
    222229                return -1;
    223230        }
  • vendor/current/source3/utils/net_sam.c

    r594 r740  
    2020
    2121#include "includes.h"
     22#include "system/passwd.h"
    2223#include "utils/net.h"
     24#include "../librpc/gen_ndr/samr.h"
     25#include "smbldap.h"
     26#include "../libcli/security/security.h"
     27#include "lib/winbind_util.h"
     28#include "passdb.h"
     29#include "lib/privileges.h"
    2330
    2431/*
     
    3239{
    3340        struct samu *sam_acct = NULL;
    34         DOM_SID sid;
     41        struct dom_sid sid;
    3542        enum lsa_SidType type;
    3643        const char *dom, *name;
     
    135142{
    136143        struct samu *sam_acct = NULL;
    137         DOM_SID sid;
     144        struct dom_sid sid;
    138145        enum lsa_SidType type;
    139146        const char *dom, *name;
     
    228235{
    229236        struct samu *sam_acct = NULL;
    230         DOM_SID sid;
     237        struct dom_sid sid;
    231238        enum lsa_SidType type;
    232239        const char *dom, *name;
     
    294301{
    295302        GROUP_MAP map;
    296         DOM_SID sid;
     303        struct dom_sid sid;
    297304        enum lsa_SidType type;
    298305        const char *dom, *name;
     
    631638}
    632639
    633 extern PRIVS privs[];
    634 
    635640static int net_sam_rights_list(struct net_context *c, int argc,
    636641                               const char **argv)
    637642{
    638         SE_PRIV mask;
     643        enum sec_privilege privilege;
    639644
    640645        if (argc > 1 || c->display_usage) {
     
    647652        if (argc == 0) {
    648653                int i;
    649                 int num = count_all_privileges();
     654                int num = num_privileges_in_short_list();
    650655
    651656                for (i=0; i<num; i++) {
    652                         d_printf("%s\n", privs[i].name);
     657                        d_printf("%s\n", sec_privilege_name_from_index(i));
    653658                }
    654659                return 0;
    655660        }
    656661
    657         if (se_priv_from_name(argv[0], &mask)) {
    658                 DOM_SID *sids;
     662        privilege = sec_privilege_id(argv[0]);
     663
     664        if (privilege != SEC_PRIV_INVALID) {
     665                struct dom_sid *sids;
    659666                int i, num_sids;
    660667                NTSTATUS status;
    661668
    662                 status = privilege_enum_sids(&mask, talloc_tos(),
     669                status = privilege_enum_sids(privilege, talloc_tos(),
    663670                                             &sids, &num_sids);
    664671                if (!NT_STATUS_IS_OK(status)) {
     
    689696                                const char **argv)
    690697{
    691         DOM_SID sid;
     698        struct dom_sid sid;
    692699        enum lsa_SidType type;
    693700        const char *dom, *name;
    694         SE_PRIV mask;
    695701        int i;
    696702
     
    709715
    710716        for (i=1; i < argc; i++) {
    711                 if (!se_priv_from_name(argv[i], &mask)) {
     717                enum sec_privilege privilege = sec_privilege_id(argv[i]);
     718                if (privilege == SEC_PRIV_INVALID) {
    712719                        d_fprintf(stderr, _("%s unknown\n"), argv[i]);
    713720                        return -1;
    714721                }
    715722
    716                 if (!grant_privilege(&sid, &mask)) {
     723                if (!grant_privilege_by_name(&sid, argv[i])) {
    717724                        d_fprintf(stderr, _("Could not grant privilege\n"));
    718725                        return -1;
     
    728735                                const char **argv)
    729736{
    730         DOM_SID sid;
     737        struct dom_sid sid;
    731738        enum lsa_SidType type;
    732739        const char *dom, *name;
    733         SE_PRIV mask;
    734740        int i;
    735741
     
    748754
    749755        for (i=1; i < argc; i++) {
    750 
    751                 if (!se_priv_from_name(argv[i], &mask)) {
     756                enum sec_privilege privilege = sec_privilege_id(argv[i]);
     757                if (privilege == SEC_PRIV_INVALID) {
    752758                        d_fprintf(stderr, _("%s unknown\n"), argv[i]);
    753759                        return -1;
    754760                }
    755761
    756                 if (!revoke_privilege(&sid, &mask)) {
     762                if (!revoke_privilege_by_name(&sid, argv[i])) {
    757763                        d_fprintf(stderr, _("Could not revoke privilege\n"));
    758764                        return -1;
     
    895901static NTSTATUS unmap_unix_group(const struct group *grp, GROUP_MAP *pmap)
    896902{
    897         NTSTATUS status;
    898903        GROUP_MAP map;
    899904        const char *grpname;
    900         DOM_SID dom_sid;
     905        struct dom_sid dom_sid;
    901906
    902907        map.gid = grp->gr_gid;
     
    915920        }
    916921
    917         status = pdb_delete_group_mapping_entry(dom_sid);
    918 
    919         return status;
     922        return pdb_delete_group_mapping_entry(dom_sid);
    920923}
    921924
     
    990993                                     const char **argv)
    991994{
    992         DOM_SID sid;
     995        struct dom_sid sid;
    993996        uint32_t rid;
    994997        enum lsa_SidType type;
     
    10711074static int net_sam_deletelocalgroup(struct net_context *c, int argc, const char **argv)
    10721075{
    1073         DOM_SID sid;
     1076        struct dom_sid sid;
    10741077        enum lsa_SidType type;
    10751078        const char *dom, *name;
     
    11181121        enum lsa_SidType type;
    11191122        fstring groupname;
    1120         DOM_SID sid;
     1123        struct dom_sid sid;
    11211124
    11221125        if (argc != 1 || c->display_usage) {
     
    11701173{
    11711174        const char *groupdomain, *groupname, *memberdomain, *membername;
    1172         DOM_SID group, member;
     1175        struct dom_sid group, member;
    11731176        enum lsa_SidType grouptype, membertype;
    11741177        NTSTATUS status;
     
    12591262        const char *memberdomain = NULL;
    12601263        const char *membername = NULL;
    1261         DOM_SID group, member;
     1264        struct dom_sid group, member;
    12621265        enum lsa_SidType grouptype;
    12631266        NTSTATUS status;
     
    13311334{
    13321335        const char *groupdomain, *groupname;
    1333         DOM_SID group;
    1334         DOM_SID *members = NULL;
     1336        struct dom_sid group;
     1337        struct dom_sid *members = NULL;
    13351338        size_t i, num_members = 0;
    13361339        enum lsa_SidType grouptype;
     
    15431546static int net_sam_show(struct net_context *c, int argc, const char **argv)
    15441547{
    1545         DOM_SID sid;
     1548        struct dom_sid sid;
    15461549        enum lsa_SidType type;
    15471550        const char *dom, *name;
     
    15811584        struct smbldap_state *ls;
    15821585        GROUP_MAP gmap;
    1583         DOM_SID gsid;
     1586        struct dom_sid gsid;
    15841587        gid_t domusers_gid = -1;
    15851588        gid_t domadmins_gid = -1;
    15861589        struct samu *samuser;
    15871590        struct passwd *pwd;
     1591        bool is_ipa = false;
    15881592
    15891593        if (c->display_usage) {
     
    16161620        trim_char(ldap_bk, ' ', ' ');
    16171621
    1618         if (strcmp(ldap_bk, "ldapsam") != 0) {
     1622        if (strcmp(ldap_bk, "IPA_ldapsam") == 0 ) {
     1623                is_ipa = true;
     1624        }
     1625
     1626        if (strcmp(ldap_bk, "ldapsam") != 0 && !is_ipa ) {
    16191627                d_fprintf(stderr,
    16201628                          _("Provisioning works only with ldapsam backend\n"));
     
    16301638        }
    16311639
    1632         if (!winbind_ping()) {
     1640        if (!is_ipa && !winbind_ping()) {
    16331641                d_fprintf(stderr, _("winbind seems not to run. Provisioning "
    16341642                            "LDAP only works when winbind runs.\n"));
     
    16431651        d_printf(_("Checking for Domain Users group.\n"));
    16441652
    1645         sid_compose(&gsid, get_global_sam_sid(), DOMAIN_GROUP_RID_USERS);
     1653        sid_compose(&gsid, get_global_sam_sid(), DOMAIN_RID_USERS);
    16461654
    16471655        if (!pdb_getgrsid(&gmap, gsid)) {
     
    16571665
    16581666                /* lets allocate a new groupid for this group */
    1659                 if (!winbind_allocate_gid(&domusers_gid)) {
    1660                         d_fprintf(stderr, _("Unable to allocate a new gid to "
    1661                                             "create Domain Users group!\n"));
    1662                         goto domu_done;
     1667                if (is_ipa) {
     1668                        domusers_gid = 999;
     1669                } else {
     1670                        if (!winbind_allocate_gid(&domusers_gid)) {
     1671                                d_fprintf(stderr, _("Unable to allocate a new gid to "
     1672                                                    "create Domain Users group!\n"));
     1673                                goto domu_done;
     1674                        }
    16631675                }
    16641676
     
    16761688                smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXGROUP);
    16771689                smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_GROUPMAP);
     1690                if (is_ipa) {
     1691                        smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "groupofnames");
     1692                        smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "nestedgroup");
     1693                        smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "ipausergroup");
     1694                }
    16781695                smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", uname);
    16791696                smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", wname);
     
    16911708                                            "to ldap directory\n"));
    16921709                }
     1710
     1711                if (is_ipa) {
     1712                        if (!pdb_getgrsid(&gmap, gsid)) {
     1713                                d_fprintf(stderr, _("Failed to read just "
     1714                                                    "created domain group.\n"));
     1715                                goto failed;
     1716                        } else {
     1717                                domusers_gid = gmap.gid;
     1718                        }
     1719                }
    16931720        } else {
    16941721                domusers_gid = gmap.gid;
     
    17001727        d_printf(_("Checking for Domain Admins group.\n"));
    17011728
    1702         sid_compose(&gsid, get_global_sam_sid(), DOMAIN_GROUP_RID_ADMINS);
     1729        sid_compose(&gsid, get_global_sam_sid(), DOMAIN_RID_ADMINS);
    17031730
    17041731        if (!pdb_getgrsid(&gmap, gsid)) {
     
    17141741
    17151742                /* lets allocate a new groupid for this group */
    1716                 if (!winbind_allocate_gid(&domadmins_gid)) {
    1717                         d_fprintf(stderr, _("Unable to allocate a new gid to "
    1718                                             "create Domain Admins group!\n"));
    1719                         goto doma_done;
     1743                if (is_ipa) {
     1744                        domadmins_gid = 999;
     1745                } else {
     1746                        if (!winbind_allocate_gid(&domadmins_gid)) {
     1747                                d_fprintf(stderr, _("Unable to allocate a new gid to "
     1748                                                    "create Domain Admins group!\n"));
     1749                                goto doma_done;
     1750                        }
    17201751                }
    17211752
     
    17331764                smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXGROUP);
    17341765                smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_GROUPMAP);
     1766                if (is_ipa) {
     1767                        smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "groupofnames");
     1768                        smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "nestedgroup");
     1769                        smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "ipausergroup");
     1770                }
    17351771                smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", uname);
    17361772                smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", wname);
     
    17481784                                            "to ldap directory\n"));
    17491785                }
     1786
     1787                if (is_ipa) {
     1788                        if (!pdb_getgrsid(&gmap, gsid)) {
     1789                                d_fprintf(stderr, _("Failed to read just "
     1790                                                    "created domain group.\n"));
     1791                                goto failed;
     1792                        } else {
     1793                                domadmins_gid = gmap.gid;
     1794                        }
     1795                }
    17501796        } else {
    17511797                domadmins_gid = gmap.gid;
     
    17651811        if (!pdb_getsampwnam(samuser, "Administrator")) {
    17661812                LDAPMod **mods = NULL;
    1767                 DOM_SID sid;
     1813                struct dom_sid sid;
    17681814                char *dn;
    17691815                char *name;
     
    17721818                char *shell;
    17731819                char *dir;
     1820                char *princ;
    17741821                uid_t uid;
    17751822                int rc;
     
    17831830                        goto done;
    17841831                }
    1785                 if (!winbind_allocate_uid(&uid)) {
    1786                         d_fprintf(stderr,
    1787                                   _("Unable to allocate a new uid to create "
    1788                                     "the Administrator user!\n"));
    1789                         goto done;
    1790                 }
     1832
     1833                if (is_ipa) {
     1834                        uid = 999;
     1835                } else {
     1836                        if (!winbind_allocate_uid(&uid)) {
     1837                                d_fprintf(stderr,
     1838                                          _("Unable to allocate a new uid to create "
     1839                                            "the Administrator user!\n"));
     1840                                goto done;
     1841                        }
     1842                }
     1843
    17911844                name = talloc_strdup(tc, "Administrator");
    17921845                dn = talloc_asprintf(tc, "uid=Administrator,%s", lp_ldap_user_suffix());
     
    18071860                }
    18081861
    1809                 sid_compose(&sid, get_global_sam_sid(), DOMAIN_USER_RID_ADMIN);
     1862                sid_compose(&sid, get_global_sam_sid(), DOMAIN_RID_ADMINISTRATOR);
     1863
     1864                if (!winbind_allocate_uid(&uid)) {
     1865                        d_fprintf(stderr,
     1866                                  _("Unable to allocate a new uid to create "
     1867                                    "the Administrator user!\n"));
     1868                        goto done;
     1869                }
    18101870
    18111871                smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_ACCOUNT);
    18121872                smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXACCOUNT);
    18131873                smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_SAMBASAMACCOUNT);
     1874                if (is_ipa) {
     1875                        smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "person");
     1876                        smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "organizationalperson");
     1877                        smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "inetorgperson");
     1878                        smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "inetuser");
     1879                        smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "krbprincipalaux");
     1880                        smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "krbticketpolicyaux");
     1881                        smbldap_set_mod(&mods, LDAP_MOD_ADD, "sn", name);
     1882                        princ = talloc_asprintf(tc, "%s@%s", name, lp_realm());
     1883                        if (!princ) {
     1884                                d_fprintf(stderr, _("Out of Memory!\n"));
     1885                                goto failed;
     1886                        }
     1887                        smbldap_set_mod(&mods, LDAP_MOD_ADD, "krbPrincipalName", princ);
     1888                }
    18141889                smbldap_set_mod(&mods, LDAP_MOD_ADD, "uid", name);
    18151890                smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", name);
     
    18331908                                            "to ldap directory\n"));
    18341909                }
     1910
     1911                if (is_ipa) {
     1912                        if (!pdb_getsampwnam(samuser, "Administrator")) {
     1913                                d_fprintf(stderr, _("Failed to read just "
     1914                                                    "created user.\n"));
     1915                                goto failed;
     1916                        }
     1917                }
    18351918        } else {
    18361919                d_printf(_("found!\n"));
     
    18471930        if (!pdb_getsampwnam(samuser, lp_guestaccount())) {
    18481931                LDAPMod **mods = NULL;
    1849                 DOM_SID sid;
     1932                struct dom_sid sid;
    18501933                char *dn;
    18511934                char *uidstr;
     
    18541937
    18551938                d_printf(_("Adding the Guest user.\n"));
     1939
     1940                sid_compose(&sid, get_global_sam_sid(), DOMAIN_RID_GUEST);
    18561941
    18571942                pwd = Get_Pwnam_alloc(tc, lp_guestaccount());
     
    18691954                        }
    18701955                        pwd->pw_name = talloc_strdup(pwd, lp_guestaccount());
    1871                         if (!winbind_allocate_uid(&(pwd->pw_uid))) {
    1872                                 d_fprintf(stderr,
    1873                                           _("Unable to allocate a new uid to "
    1874                                             "create the Guest user!\n"));
    1875                                 goto done;
     1956
     1957                        if (is_ipa) {
     1958                                pwd->pw_uid = 999;
     1959                        } else {
     1960                                if (!winbind_allocate_uid(&(pwd->pw_uid))) {
     1961                                        d_fprintf(stderr,
     1962                                                  _("Unable to allocate a new uid to "
     1963                                                    "create the Guest user!\n"));
     1964                                        goto done;
     1965                                }
    18761966                        }
    18771967                        pwd->pw_gid = domusers_gid;
     
    18841974                }
    18851975
    1886                 sid_compose(&sid, get_global_sam_sid(), DOMAIN_USER_RID_GUEST);
    1887 
    18881976                dn = talloc_asprintf(tc, "uid=%s,%s", pwd->pw_name, lp_ldap_user_suffix ());
    18891977                uidstr = talloc_asprintf(tc, "%u", (unsigned int)pwd->pw_uid);
     
    18971985                smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXACCOUNT);
    18981986                smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_SAMBASAMACCOUNT);
     1987                if (is_ipa) {
     1988                        smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "person");
     1989                        smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "organizationalperson");
     1990                        smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "inetorgperson");
     1991                        smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "inetuser");
     1992                        smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "krbprincipalaux");
     1993                        smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "krbticketpolicyaux");
     1994                        smbldap_set_mod(&mods, LDAP_MOD_ADD, "sn", pwd->pw_name);
     1995                }
    18991996                smbldap_set_mod(&mods, LDAP_MOD_ADD, "uid", pwd->pw_name);
    19001997                smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", pwd->pw_name);
     
    19222019                                            "ldap directory\n"));
    19232020                }
     2021
     2022                if (is_ipa) {
     2023                        if (!pdb_getsampwnam(samuser, lp_guestaccount())) {
     2024                                d_fprintf(stderr, _("Failed to read just "
     2025                                                    "created user.\n"));
     2026                                goto failed;
     2027                        }
     2028                }
    19242029        } else {
    19252030                d_printf(_("found!\n"));
     
    19282033        d_printf(_("Checking Guest's group.\n"));
    19292034
    1930         pwd = Get_Pwnam_alloc(talloc_autofree_context(), lp_guestaccount());
     2035        pwd = Get_Pwnam_alloc(tc, lp_guestaccount());
    19312036        if (!pwd) {
    19322037                d_fprintf(stderr,
     
    19632068                }
    19642069
    1965                 sid_compose(&gsid, get_global_sam_sid(), DOMAIN_GROUP_RID_GUESTS);
     2070                sid_compose(&gsid, get_global_sam_sid(), DOMAIN_RID_GUESTS);
    19662071
    19672072                smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXGROUP);
    19682073                smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_GROUPMAP);
     2074                if (is_ipa) {
     2075                        smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "groupofnames");
     2076                        smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "nestedgroup");
     2077                        smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "ipausergroup");
     2078                }
    19692079                smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", uname);
    19702080                smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", wname);
  • vendor/current/source3/utils/net_share.c

    r427 r740  
    6363int net_share(struct net_context *c, int argc, const char **argv)
    6464{
    65 
    6665        if (argc > 0 && StrCaseCmp(argv[0], "HELP") == 0) {
    67                 net_share_usage(c, argc, argv);
    68                 return 0;
     66                        net_share_usage(c, argc, argv);
     67                        return 0;
    6968        }
    7069
  • vendor/current/source3/utils/net_status.c

    r414 r740  
    1919#include "includes.h"
    2020#include "utils/net.h"
     21#include "session.h"
     22#include "messages.h"
    2123
    2224int net_status_usage(struct net_context *c, int argc, const char **argv)
     
    2931}
    3032
    31 static int show_session(struct db_record *rec, void *private_data)
     33static int show_session(const char *key, struct sessionid *session,
     34                        void *private_data)
    3235{
    3336        bool *parseable = (bool *)private_data;
    34         struct sessionid sessionid;
    35 
    36         if (rec->value.dsize != sizeof(sessionid))
    37                 return 0;
    38 
    39         memcpy(&sessionid, rec->value.dptr, sizeof(sessionid));
    40 
    41         if (!process_exists(sessionid.pid)) {
     37
     38        if (!process_exists(session->pid)) {
    4239                return 0;
    4340        }
     
    4542        if (*parseable) {
    4643                d_printf("%s\\%s\\%s\\%s\\%s\n",
    47                          procid_str_static(&sessionid.pid), uidtoname(sessionid.uid),
    48                          gidtoname(sessionid.gid),
    49                          sessionid.remote_machine, sessionid.hostname);
     44                         procid_str_static(&session->pid),
     45                         uidtoname(session->uid),
     46                         gidtoname(session->gid),
     47                         session->remote_machine, session->hostname);
    5048        } else {
    5149                d_printf("%7s   %-12s  %-12s  %-12s (%s)\n",
    52                          procid_str_static(&sessionid.pid), uidtoname(sessionid.uid),
    53                          gidtoname(sessionid.gid),
    54                          sessionid.remote_machine, sessionid.hostname);
     50                         procid_str_static(&session->pid),
     51                         uidtoname(session->uid),
     52                         gidtoname(session->gid),
     53                         session->remote_machine, session->hostname);
    5554        }
    5655
     
    6059static int net_status_sessions(struct net_context *c, int argc, const char **argv)
    6160{
    62         struct db_context *db;
    6361        bool parseable;
    6462
     
    8987        }
    9088
    91         db = db_open(NULL, lock_path("sessionid.tdb"), 0,
    92                      TDB_CLEAR_IF_FIRST, O_RDONLY, 0644);
    93         if (db == NULL) {
    94                 d_fprintf(stderr, _("%s not initialised\n"),
    95                           lock_path("sessionid.tdb"));
    96                 return -1;
    97         }
    98 
    99         db->traverse_read(db, show_session, &parseable);
    100         TALLOC_FREE(db);
    101 
     89        sessionid_traverse_read(show_session, &parseable);
    10290        return 0;
    10391}
     
    128116};
    129117
    130 static int collect_pid(struct db_record *rec, void *private_data)
     118static int collect_pids(const char *key, struct sessionid *session,
     119                        void *private_data)
    131120{
    132121        struct sessionids *ids = (struct sessionids *)private_data;
    133         struct sessionid sessionid;
    134 
    135         if (rec->value.dsize != sizeof(sessionid))
    136                 return 0;
    137 
    138         memcpy(&sessionid, rec->value.dptr, sizeof(sessionid));
    139 
    140         if (!process_exists(sessionid.pid))
     122
     123        if (!process_exists(session->pid))
    141124                return 0;
    142125
     
    147130                return 0;
    148131        }
    149         ids->entries[ids->num_entries-1] = sessionid;
    150 
    151         return 0;
    152 }
    153 
    154 static int show_share_parseable(struct db_record *rec,
    155                                 const struct connections_key *key,
     132        ids->entries[ids->num_entries-1] = *session;
     133
     134        return 0;
     135}
     136
     137static int show_share_parseable(const struct connections_key *key,
    156138                                const struct connections_data *crec,
    157139                                void *state)
     
    190172{
    191173        struct sessionids ids;
    192         struct db_context *db;
    193174
    194175        ids.num_entries = 0;
    195176        ids.entries = NULL;
    196177
    197         db = db_open(NULL, lock_path("sessionid.tdb"), 0,
    198                      TDB_CLEAR_IF_FIRST, O_RDONLY, 0644);
    199         if (db == NULL) {
    200                 d_fprintf(stderr, _("%s not initialised\n"),
    201                           lock_path("sessionid.tdb"));
    202                 return -1;
    203         }
    204 
    205         db->traverse_read(db, collect_pid, &ids);
    206         TALLOC_FREE(db);
    207 
    208         connections_forall(show_share_parseable, &ids);
     178        sessionid_traverse_read(collect_pids, &ids);
     179
     180        connections_forall_read(show_share_parseable, &ids);
    209181
    210182        SAFE_FREE(ids.entries);
  • vendor/current/source3/utils/net_time.c

    r414 r740  
    1919#include "includes.h"
    2020#include "utils/net.h"
     21#include "libsmb/nmblib.h"
     22#include "libsmb/libsmb.h"
    2123
    2224/*
     
    104106}
    105107
    106 /* try to set the system clock using /bin/date */
     108/* try to set the system clock */
    107109static int net_time_set(struct net_context *c, int argc, const char **argv)
    108110{
    109         time_t t = nettime(c, NULL);
    110         char *cmd;
     111        struct timeval tv;
    111112        int result;
    112113
    113         if (t == 0) return -1;
    114 
    115         /* yes, I know this is cheesy. Use "net time system" if you want to
    116            roll your own. I'm putting this in as it works on a large number
    117            of systems and the user has a choice in whether its used or not */
    118         if (asprintf(&cmd, "/bin/date %s", systime(t)) == -1) {
    119                 return -1;
    120         }
    121         result = system(cmd);
     114        tv.tv_sec = nettime(c, NULL);
     115        tv.tv_usec=0;
     116
     117        if (tv.tv_sec == 0) return -1;
     118
     119        result = settimeofday(&tv,NULL);
     120
    122121        if (result)
    123                 d_fprintf(stderr, _("%s failed.  Error was (%s)\n"),
    124                         cmd, strerror(errno));
    125         free(cmd);
     122                d_fprintf(stderr, _("setting system clock failed.  Error was (%s)\n"),
     123                        strerror(errno));
    126124
    127125        return result;
  • vendor/current/source3/utils/net_usershare.c

    r414 r740  
    2020
    2121#include "includes.h"
     22#include "system/passwd.h"
     23#include "system/filesys.h"
    2224#include "utils/net.h"
     25#include "../libcli/security/security.h"
    2326
    2427struct {
     
    3841        {N_("Path is not a directory"), USERSHARE_PATH_NOT_DIRECTORY},
    3942        {N_("System error"), USERSHARE_POSIX_ERR},
     43        {N_("Malformed sharename definition"), USERSHARE_MALFORMED_SHARENAME_DEF},
     44        {N_("Bad sharename (doesn't match filename)"), USERSHARE_BAD_SHARENAME},
    4045        {NULL,(enum usershare_err)-1}
    4146};
     
    329334        int fd = -1;
    330335        int numlines = 0;
    331         SEC_DESC *psd = NULL;
     336        struct security_descriptor *psd = NULL;
    332337        char *basepath;
    333338        char *sharepath = NULL;
    334339        char *comment = NULL;
     340        char *cp_sharename = NULL;
    335341        char *acl_str;
    336342        int num_aces;
     
    393399                                &sharepath,
    394400                                &comment,
     401                                &cp_sharename,
    395402                                &psd,
    396403                                &guest_ok);
     
    474481        /* NOTE: This is smb.conf-like output. Do not translate. */
    475482        if (pi->op == US_INFO_OP) {
    476                 d_printf("[%s]\n", fl->pathname );
     483                d_printf("[%s]\n", cp_sharename );
    477484                d_printf("path=%s\n", sharepath );
    478485                d_printf("comment=%s\n", comment);
     
    480487                d_printf("guest_ok=%c\n\n", guest_ok ? 'y' : 'n');
    481488        } else if (pi->op == US_LIST_OP) {
    482                 d_printf("%s\n", fl->pathname);
     489                d_printf("%s\n", cp_sharename);
    483490        }
    484491
     
    618625        SMB_STRUCT_STAT lsbuf;
    619626        char *sharename;
     627        const char *cp_sharename;
    620628        char *full_path;
    621629        char *full_path_tmp;
     
    646654                        return net_usershare_add_usage(c, argc, argv);
    647655                case 2:
     656                        cp_sharename = argv[0];
    648657                        sharename = strlower_talloc(ctx, argv[0]);
    649658                        us_path = argv[1];
    650659                        break;
    651660                case 3:
     661                        cp_sharename = argv[0];
    652662                        sharename = strlower_talloc(ctx, argv[0]);
    653663                        us_path = argv[1];
     
    655665                        break;
    656666                case 4:
     667                        cp_sharename = argv[0];
    657668                        sharename = strlower_talloc(ctx, argv[0]);
    658669                        us_path = argv[1];
     
    661672                        break;
    662673                case 5:
     674                        cp_sharename = argv[0];
    663675                        sharename = strlower_talloc(ctx, argv[0]);
    664676                        us_path = argv[1];
     
    798810
    799811        for (i = 0; i < num_aces; i++) {
    800                 DOM_SID sid;
     812                struct dom_sid sid;
    801813                const char *pcolon = strchr_m(pacl, ':');
    802814                const char *name;
     
    898910                          full_path_tmp );
    899911                TALLOC_FREE(ctx);
     912                close(tmpfd);
    900913                return -1;
    901914        }
     
    907920                          full_path_tmp );
    908921                TALLOC_FREE(ctx);
     922                close(tmpfd);
    909923                return -1;
    910924        }
     
    916930                          full_path_tmp );
    917931                TALLOC_FREE(ctx);
     932                close(tmpfd);
    918933                return -1;
    919934        }
     
    925940                          full_path_tmp );
    926941                TALLOC_FREE(ctx);
     942                close(tmpfd);
    927943                return -1;
    928944        }
     
    930946        /* Create the in-memory image of the file. */
    931947        file_img = talloc_strdup(ctx, "#VERSION 2\npath=");
    932         file_img = talloc_asprintf_append(file_img, "%s\ncomment=%s\nusershare_acl=%s\nguest_ok=%c\n",
    933                         us_path, us_comment, us_acl, guest_ok ? 'y' : 'n');
     948        file_img = talloc_asprintf_append(file_img,
     949                        "%s\ncomment=%s\nusershare_acl=%s\n"
     950                        "guest_ok=%c\nsharename=%s\n",
     951                        us_path,
     952                        us_comment,
     953                        us_acl,
     954                        guest_ok ? 'y' : 'n',
     955                        cp_sharename);
    934956
    935957        to_write = strlen(file_img);
     
    942964                unlink(full_path_tmp);
    943965                TALLOC_FREE(ctx);
     966                close(tmpfd);
    944967                return -1;
    945968        }
  • vendor/current/source3/utils/net_util.c

    r414 r740  
    2222#include "includes.h"
    2323#include "utils/net.h"
    24 #include "../librpc/gen_ndr/cli_lsa.h"
    25 #include "../librpc/gen_ndr/cli_dssetup.h"
     24#include "rpc_client/cli_pipe.h"
     25#include "../librpc/gen_ndr/ndr_lsa_c.h"
     26#include "rpc_client/cli_lsarpc.h"
     27#include "../librpc/gen_ndr/ndr_dssetup_c.h"
     28#include "secrets.h"
     29#include "../libcli/security/security.h"
     30#include "libsmb/libsmb.h"
    2631
    2732NTSTATUS net_rpc_lookup_name(struct net_context *c,
    2833                             TALLOC_CTX *mem_ctx, struct cli_state *cli,
    2934                             const char *name, const char **ret_domain,
    30                              const char **ret_name, DOM_SID *ret_sid,
     35                             const char **ret_name, struct dom_sid *ret_sid,
    3136                             enum lsa_SidType *ret_type)
    3237{
    3338        struct rpc_pipe_client *lsa_pipe = NULL;
    3439        struct policy_handle pol;
    35         NTSTATUS result = NT_STATUS_OK;
     40        NTSTATUS status, result;
    3641        const char **dom_names;
    37         DOM_SID *sids;
     42        struct dom_sid *sids;
    3843        enum lsa_SidType *types;
     44        struct dcerpc_binding_handle *b;
    3945
    4046        ZERO_STRUCT(pol);
    4147
    42         result = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc.syntax_id,
     48        status = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc.syntax_id,
    4349                                          &lsa_pipe);
    44         if (!NT_STATUS_IS_OK(result)) {
     50        if (!NT_STATUS_IS_OK(status)) {
    4551                d_fprintf(stderr, _("Could not initialise lsa pipe\n"));
    46                 return result;
    47         }
    48 
    49         result = rpccli_lsa_open_policy(lsa_pipe, mem_ctx, false,
     52                return status;
     53        }
     54
     55        b = lsa_pipe->binding_handle;
     56
     57        status = rpccli_lsa_open_policy(lsa_pipe, mem_ctx, false,
    5058                                        SEC_FLAG_MAXIMUM_ALLOWED,
    5159                                        &pol);
    52         if (!NT_STATUS_IS_OK(result)) {
     60        if (!NT_STATUS_IS_OK(status)) {
    5361                d_fprintf(stderr, "open_policy %s: %s\n", _("failed"),
    54                           nt_errstr(result));
    55                 return result;
    56         }
    57 
    58         result = rpccli_lsa_lookup_names(lsa_pipe, mem_ctx, &pol, 1,
     62                          nt_errstr(status));
     63                return status;
     64        }
     65
     66        status = rpccli_lsa_lookup_names(lsa_pipe, mem_ctx, &pol, 1,
    5967                                         &name, &dom_names, 1, &sids, &types);
    6068
    61         if (!NT_STATUS_IS_OK(result)) {
     69        if (!NT_STATUS_IS_OK(status)) {
    6270                /* This can happen easily, don't log an error */
    6371                goto done;
     
    7987 done:
    8088        if (is_valid_policy_hnd(&pol)) {
    81                 rpccli_lsa_Close(lsa_pipe, mem_ctx, &pol);
     89                dcerpc_lsa_Close(b, mem_ctx, &pol, &result);
    8290        }
    8391        TALLOC_FREE(lsa_pipe);
    8492
    85         return result;
     93        return status;
    8694}
    8795
     
    118126                                        service_name, service_type,
    119127                                        c->opt_user_name, c->opt_workgroup,
    120                                         c->opt_password, flags, Undefined, NULL);
     128                                        c->opt_password, flags, Undefined);
    121129        if (!NT_STATUS_IS_OK(nt_status)) {
    122130                d_fprintf(stderr, _("Could not connect to server %s\n"),
     
    202210                                        "IPC$", "IPC",
    203211                                        "", "",
    204                                         "", 0, Undefined, NULL);
     212                                        "", 0, Undefined);
    205213
    206214        if (NT_STATUS_IS_OK(nt_status)) {
     
    262270                                        c->opt_password,
    263271                                        CLI_FULL_CONNECTION_USE_KERBEROS,
    264                                         Undefined, NULL);
     272                                        Undefined);
    265273
    266274        SAFE_FREE(user_and_realm);
     
    416424                }
    417425
    418                 if (is_zero_addr((struct sockaddr *)&pdc_ss)) {
     426                if (is_zero_addr(&pdc_ss)) {
    419427                        return false;
    420428                }
     
    473481                return false;
    474482        }
    475         if (is_zero_addr((struct sockaddr *)server_ss)) {
     483        if (is_zero_addr(server_ss)) {
    476484                return false;
    477485        }
     
    619627}
    620628
     629static NTSTATUS net_scan_dc_noad(struct net_context *c,
     630                                 struct cli_state *cli,
     631                                 struct net_dc_info *dc_info)
     632{
     633        TALLOC_CTX *mem_ctx = talloc_tos();
     634        struct rpc_pipe_client *pipe_hnd = NULL;
     635        struct dcerpc_binding_handle *b;
     636        NTSTATUS status, result;
     637        struct policy_handle pol;
     638        union lsa_PolicyInformation *info;
     639
     640        ZERO_STRUCTP(dc_info);
     641        ZERO_STRUCT(pol);
     642
     643        status = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc.syntax_id,
     644                                          &pipe_hnd);
     645        if (!NT_STATUS_IS_OK(status)) {
     646                return status;
     647        }
     648
     649        b = pipe_hnd->binding_handle;
     650
     651        status = dcerpc_lsa_open_policy(b, mem_ctx,
     652                                        false,
     653                                        SEC_FLAG_MAXIMUM_ALLOWED,
     654                                        &pol,
     655                                        &result);
     656        if (!NT_STATUS_IS_OK(status)) {
     657                goto done;
     658        }
     659        if (!NT_STATUS_IS_OK(result)) {
     660                status = result;
     661                goto done;
     662        }
     663
     664        status = dcerpc_lsa_QueryInfoPolicy(b, mem_ctx,
     665                                            &pol,
     666                                            LSA_POLICY_INFO_ACCOUNT_DOMAIN,
     667                                            &info,
     668                                            &result);
     669        if (!NT_STATUS_IS_OK(status)) {
     670                goto done;
     671        }
     672        if (!NT_STATUS_IS_OK(result)) {
     673                status = result;
     674                goto done;
     675        }
     676
     677        dc_info->netbios_domain_name = talloc_strdup(mem_ctx, info->account_domain.name.string);
     678        if (dc_info->netbios_domain_name == NULL) {
     679                status = NT_STATUS_NO_MEMORY;
     680                goto done;
     681        }
     682
     683 done:
     684        if (is_valid_policy_hnd(&pol)) {
     685                dcerpc_lsa_Close(b, mem_ctx, &pol, &result);
     686        }
     687
     688        TALLOC_FREE(pipe_hnd);
     689
     690        return status;
     691}
     692
    621693NTSTATUS net_scan_dc(struct net_context *c,
    622694                     struct cli_state *cli,
     
    625697        TALLOC_CTX *mem_ctx = talloc_tos();
    626698        struct rpc_pipe_client *dssetup_pipe = NULL;
     699        struct dcerpc_binding_handle *dssetup_handle = NULL;
    627700        union dssetup_DsRoleInfo info;
    628701        NTSTATUS status;
     702        WERROR werr;
    629703
    630704        ZERO_STRUCTP(dc_info);
     
    633707                                          &dssetup_pipe);
    634708        if (!NT_STATUS_IS_OK(status)) {
    635                 return status;
    636         }
    637 
    638         status = rpccli_dssetup_DsRoleGetPrimaryDomainInformation(dssetup_pipe, mem_ctx,
     709                DEBUG(10,("net_scan_dc: failed to open dssetup pipe with %s, "
     710                        "retrying with lsa pipe\n", nt_errstr(status)));
     711                return net_scan_dc_noad(c, cli, dc_info);
     712        }
     713        dssetup_handle = dssetup_pipe->binding_handle;
     714
     715        status = dcerpc_dssetup_DsRoleGetPrimaryDomainInformation(dssetup_handle, mem_ctx,
    639716                                                                  DS_ROLE_BASIC_INFORMATION,
    640717                                                                  &info,
    641                                                                   NULL);
     718                                                                  &werr);
    642719        TALLOC_FREE(dssetup_pipe);
    643720
     721        if (NT_STATUS_IS_OK(status)) {
     722                status = werror_to_ntstatus(werr);
     723        }
    644724        if (!NT_STATUS_IS_OK(status)) {
    645725                return status;
  • vendor/current/source3/utils/netlookup.c

    r414 r740  
    2222#include "includes.h"
    2323#include "utils/net.h"
     24#include "rpc_client/cli_pipe.h"
     25#include "../librpc/gen_ndr/ndr_lsa.h"
     26#include "rpc_client/cli_lsarpc.h"
     27#include "libsmb/libsmb.h"
    2428
    2529/********************************************************
     
    108112#endif
    109113                                        0,
    110                                         Undefined,
    111                                         NULL);
     114                                        Undefined);
    112115
    113116        if (!NT_STATUS_IS_OK(nt_status)) {
     
    156159NTSTATUS net_lookup_name_from_sid(struct net_context *c,
    157160                                TALLOC_CTX *ctx,
    158                                 DOM_SID *psid,
     161                                struct dom_sid *psid,
    159162                                const char **ppdomain,
    160163                                const char **ppname)
     
    198201
    199202NTSTATUS net_lookup_sid_from_name(struct net_context *c, TALLOC_CTX *ctx,
    200                                   const char *full_name, DOM_SID *pret_sid)
     203                                  const char *full_name, struct dom_sid *pret_sid)
    201204{
    202205        NTSTATUS nt_status;
    203206        struct con_struct *csp = NULL;
    204         DOM_SID *sids = NULL;
     207        struct dom_sid *sids = NULL;
    205208        enum lsa_SidType *types = NULL;
    206209
  • vendor/current/source3/utils/nmblookup.c

    r414 r740  
    2121
    2222#include "includes.h"
    23 
    24 extern bool AllowDebugChange;
     23#include "popt_common.h"
     24#include "libsmb/nmblib.h"
    2525
    2626static bool give_flags = false;
     
    108108****************************************************************************/
    109109
    110 static void do_node_status(int fd,
    111                 const char *name,
     110static void do_node_status(const char *name,
    112111                int type,
    113112                struct sockaddr_storage *pss)
     
    115114        struct nmb_name nname;
    116115        int count, i, j;
    117         NODE_STATUS_STRUCT *status;
     116        struct node_status *addrs;
    118117        struct node_status_extra extra;
    119118        fstring cleanname;
    120119        char addr[INET6_ADDRSTRLEN];
     120        NTSTATUS status;
    121121
    122122        print_sockaddr(addr, sizeof(addr), pss);
    123123        d_printf("Looking up status of %s\n",addr);
    124124        make_nmb_name(&nname, name, type);
    125         status = node_status_query(fd, &nname, pss, &count, &extra);
    126         if (status) {
     125        status = node_status_query(talloc_tos(), &nname, pss,
     126                                   &addrs, &count, &extra);
     127        if (NT_STATUS_IS_OK(status)) {
    127128                for (i=0;i<count;i++) {
    128                         pull_ascii_fstring(cleanname, status[i].name);
     129                        pull_ascii_fstring(cleanname, addrs[i].name);
    129130                        for (j=0;cleanname[j];j++) {
    130131                                if (!isprint((int)cleanname[j])) {
     
    133134                        }
    134135                        d_printf("\t%-15s <%02x> - %s\n",
    135                                cleanname,status[i].type,
    136                                node_status_flags(status[i].flags));
     136                               cleanname,addrs[i].type,
     137                               node_status_flags(addrs[i].flags));
    137138                }
    138139                d_printf("\n\tMAC Address = %02X-%02X-%02X-%02X-%02X-%02X\n",
     
    141142                                extra.mac_addr[4], extra.mac_addr[5]);
    142143                d_printf("\n");
    143                 SAFE_FREE(status);
     144                TALLOC_FREE(addrs);
    144145        } else {
    145146                d_printf("No reply from %s\n\n",addr);
     
    154155static bool query_one(const char *lookup, unsigned int lookup_type)
    155156{
    156         int j, count, flags = 0;
     157        int j, count;
     158        uint8_t flags;
    157159        struct sockaddr_storage *ip_list=NULL;
     160        NTSTATUS status = NT_STATUS_NOT_FOUND;
    158161
    159162        if (got_bcast) {
     
    161164                print_sockaddr(addr, sizeof(addr), &bcast_addr);
    162165                d_printf("querying %s on %s\n", lookup, addr);
    163                 ip_list = name_query(ServerFD,lookup,lookup_type,use_bcast,
    164                                      use_bcast?true:recursion_desired,
    165                                      &bcast_addr, &count, &flags, NULL);
     166                status = name_query(lookup,lookup_type,use_bcast,
     167                                    use_bcast?true:recursion_desired,
     168                                    &bcast_addr, talloc_tos(),
     169                                    &ip_list, &count, &flags);
    166170        } else {
    167171                const struct in_addr *bcast;
     
    180184                        d_printf("querying %s on %s\n",
    181185                               lookup, addr);
    182                         ip_list = name_query(ServerFD,lookup,lookup_type,
    183                                              use_bcast,
    184                                              use_bcast?True:recursion_desired,
    185                                              &bcast_ss,&count, &flags, NULL);
    186                 }
    187         }
    188 
    189         if (!ip_list) {
     186                        status = name_query(lookup,lookup_type,
     187                                            use_bcast,
     188                                            use_bcast?True:recursion_desired,
     189                                            &bcast_ss, talloc_tos(),
     190                                            &ip_list, &count, &flags);
     191                }
     192        }
     193
     194        if (!NT_STATUS_IS_OK(status)) {
    190195                return false;
    191196        }
     
    215220                 */
    216221                if (find_status) {
    217                         do_node_status(ServerFD, lookup,
    218                                         lookup_type, &ip_list[j]);
    219                 }
    220         }
    221 
    222         free(ip_list);
    223 
    224         return (ip_list != NULL);
     222                        do_node_status(lookup, lookup_type, &ip_list[j]);
     223                }
     224        }
     225
     226        TALLOC_FREE(ip_list);
     227
     228        return NT_STATUS_IS_OK(status);
    225229}
    226230
     
    259263        load_case_tables();
    260264
    261         setup_logging(argv[0],True);
     265        setup_logging(argv[0], DEBUG_STDOUT);
    262266
    263267        pc = poptGetContext("nmblookup", argc, (const char **)argv,
     
    336340                        in_addr_to_sockaddr_storage(&ss, ip);
    337341                        fstrcpy(lookup,"*");
    338                         do_node_status(ServerFD, lookup, lookup_type, &ss);
     342                        do_node_status(lookup, lookup_type, &ss);
    339343                        continue;
    340344                }
  • vendor/current/source3/utils/ntlm_auth.c

    r597 r740  
    2525
    2626#include "includes.h"
     27#include "popt_common.h"
    2728#include "utils/ntlm_auth.h"
    2829#include "../libcli/auth/libcli_auth.h"
    2930#include "../libcli/auth/spnego.h"
     31#include "../libcli/auth/ntlmssp.h"
    3032#include "smb_krb5.h"
    3133#include <iniparser.h>
     34#include "../lib/crypto/arcfour.h"
     35#include "libads/kerberos_proto.h"
     36#include "nsswitch/winbind_client.h"
     37#include "librpc/gen_ndr/krb5pac.h"
     38#include "../lib/util/asn1.h"
    3239
    3340#ifndef PAM_WINBIND_CONFIG_FILE
     
    225232        if (opt_challenge.length)
    226233                return opt_challenge;
    227        
     234
    228235        chal = data_blob(NULL, 8);
    229236
     
    244251                return False;
    245252        }
    246        
     253
    247254        fstrcpy(user, p+1);
    248255        fstrcpy(domain, domuser);
     
    302309        int ctrl = 0;
    303310        dictionary *d = NULL;
    304        
     311
    305312        if (!opt_pam_winbind_conf || !*opt_pam_winbind_conf) {
    306313                opt_pam_winbind_conf = PAM_WINBIND_CONFIG_FILE;
     
    308315
    309316        d = iniparser_load(CONST_DISCARD(char *, opt_pam_winbind_conf));
    310        
     317
    311318        if (!d) {
    312319                return 0;
    313320        }
    314        
     321
    315322        if (iniparser_getboolean(d, CONST_DISCARD(char *, "global:krb5_auth"), false)) {
    316323                ctrl |= WINBIND_KRB5_AUTH;
     
    318325
    319326        iniparser_freedict(d);
    320        
     327
    321328        return ctrl;
    322329}
     
    440447                request.data.auth_crap.nt_resp_len = nt_response->length;
    441448        }
    442        
     449
    443450        result = winbindd_request_response(WINBINDD_PAM_AUTH_CRAP, &request, &response);
    444451        SAFE_FREE(request.extra_data.data);
     
    453460                return nt_status;
    454461        }
    455        
     462
    456463        nt_status = (NT_STATUS(response.data.auth.nt_status));
    457464        if (!NT_STATUS_IS_OK(nt_status)) {
     
    535542                request.data.chng_pswd_auth_crap.old_lm_hash_enc_len = old_lm_hash_enc.length;
    536543        }
    537        
     544
    538545        result = winbindd_request_response(WINBINDD_PAM_CHNG_PSWD_AUTH_CRAP, &request, &response);
    539546
     
    548555                return nt_status;
    549556        }
    550        
     557
    551558        nt_status = (NT_STATUS(response.data.auth.nt_status));
    552559        if (!NT_STATUS_IS_OK(nt_status))
     
    559566
    560567        winbindd_free_response(&response);
    561        
     568
    562569    return nt_status;
    563570}
    564571
    565 static NTSTATUS winbind_pw_check(struct ntlmssp_state *ntlmssp_state, DATA_BLOB *user_session_key, DATA_BLOB *lm_session_key)
     572static NTSTATUS winbind_pw_check(struct ntlmssp_state *ntlmssp_state, TALLOC_CTX *mem_ctx,
     573                                 DATA_BLOB *user_session_key, DATA_BLOB *lm_session_key)
    566574{
    567575        static const char zeros[16] = { 0, };
     
    573581
    574582        nt_status = contact_winbind_auth_crap(ntlmssp_state->user, ntlmssp_state->domain,
    575                                               ntlmssp_state->workstation,
     583                                              ntlmssp_state->client.netbios_name,
    576584                                              &ntlmssp_state->chal,
    577585                                              &ntlmssp_state->lm_resp,
     
    583591        if (NT_STATUS_IS_OK(nt_status)) {
    584592                if (memcmp(lm_key, zeros, 8) != 0) {
    585                         *lm_session_key = data_blob_talloc(ntlmssp_state, NULL, 16);
     593                        *lm_session_key = data_blob_talloc(mem_ctx, NULL, 16);
    586594                        memcpy(lm_session_key->data, lm_key, 8);
    587595                        memset(lm_session_key->data+8, '\0', 8);
    588596                }
    589                
     597
    590598                if (memcmp(user_sess_key, zeros, 16) != 0) {
    591                         *user_session_key = data_blob_talloc(ntlmssp_state, user_sess_key, 16);
    592                 }
    593                 ntlmssp_state->auth_context = talloc_strdup(ntlmssp_state,
    594                                                             unix_name);
     599                        *user_session_key = data_blob_talloc(mem_ctx, user_sess_key, 16);
     600                }
     601                ntlmssp_state->callback_private = talloc_strdup(ntlmssp_state,
     602                                                                unix_name);
    595603        } else {
    596604                DEBUG(NT_STATUS_EQUAL(nt_status, NT_STATUS_ACCESS_DENIED) ? 0 : 3,
    597605                      ("Login for user [%s]\\[%s]@[%s] failed due to [%s]\n",
    598606                       ntlmssp_state->domain, ntlmssp_state->user,
    599                        ntlmssp_state->workstation,
     607                       ntlmssp_state->client.netbios_name,
    600608                       error_string ? error_string : "unknown error (NULL)"));
    601                 ntlmssp_state->auth_context = NULL;
     609                ntlmssp_state->callback_private = NULL;
    602610        }
    603611
     
    607615}
    608616
    609 static NTSTATUS local_pw_check(struct ntlmssp_state *ntlmssp_state, DATA_BLOB *user_session_key, DATA_BLOB *lm_session_key)
     617static NTSTATUS local_pw_check(struct ntlmssp_state *ntlmssp_state, TALLOC_CTX *mem_ctx,
     618                               DATA_BLOB *user_session_key, DATA_BLOB *lm_session_key)
    610619{
    611620        NTSTATUS nt_status;
     
    613622
    614623        nt_lm_owf_gen (opt_password, nt_pw.hash, lm_pw.hash);
    615        
    616         nt_status = ntlm_password_check(ntlmssp_state,
     624
     625        nt_status = ntlm_password_check(mem_ctx,
    617626                                        true, true, 0,
    618627                                        &ntlmssp_state->chal,
     
    623632                                        ntlmssp_state->domain,
    624633                                        &lm_pw, &nt_pw, user_session_key, lm_session_key);
    625        
     634
    626635        if (NT_STATUS_IS_OK(nt_status)) {
    627                 ntlmssp_state->auth_context = talloc_asprintf(ntlmssp_state,
     636                ntlmssp_state->callback_private = talloc_asprintf(ntlmssp_state,
    628637                                                              "%s%c%s", ntlmssp_state->domain,
    629638                                                              *lp_winbind_separator(),
     
    631640        } else {
    632641                DEBUG(3, ("Login for user [%s]\\[%s]@[%s] failed due to [%s]\n",
    633                           ntlmssp_state->domain, ntlmssp_state->user, ntlmssp_state->workstation,
     642                          ntlmssp_state->domain, ntlmssp_state->user,
     643                          ntlmssp_state->client.netbios_name,
    634644                          nt_errstr(nt_status)));
    635                 ntlmssp_state->auth_context = NULL;
     645                ntlmssp_state->callback_private = NULL;
    636646        }
    637647        return nt_status;
    638648}
    639649
    640 static NTSTATUS ntlm_auth_start_ntlmssp_client(NTLMSSP_STATE **client_ntlmssp_state)
     650static NTSTATUS ntlm_auth_start_ntlmssp_client(struct ntlmssp_state **client_ntlmssp_state)
    641651{
    642652        NTSTATUS status;
     
    647657        }
    648658
    649         status = ntlmssp_client_start(client_ntlmssp_state);
     659        status = ntlmssp_client_start(NULL,
     660                                      global_myname(),
     661                                      lp_workgroup(),
     662                                      lp_client_ntlmv2_auth(),
     663                                      client_ntlmssp_state);
    650664
    651665        if (!NT_STATUS_IS_OK(status)) {
    652666                DEBUG(1, ("Could not start NTLMSSP client: %s\n",
    653667                          nt_errstr(status)));
    654                 ntlmssp_end(client_ntlmssp_state);
     668                TALLOC_FREE(*client_ntlmssp_state);
    655669                return status;
    656670        }
     
    661675                DEBUG(1, ("Could not set username: %s\n",
    662676                          nt_errstr(status)));
    663                 ntlmssp_end(client_ntlmssp_state);
     677                TALLOC_FREE(*client_ntlmssp_state);
    664678                return status;
    665679        }
     
    670684                DEBUG(1, ("Could not set domain: %s\n",
    671685                          nt_errstr(status)));
    672                 ntlmssp_end(client_ntlmssp_state);
     686                TALLOC_FREE(*client_ntlmssp_state);
    673687                return status;
    674688        }
     
    676690        if (opt_password) {
    677691                status = ntlmssp_set_password(*client_ntlmssp_state, opt_password);
    678        
     692
    679693                if (!NT_STATUS_IS_OK(status)) {
    680694                        DEBUG(1, ("Could not set password: %s\n",
    681695                                  nt_errstr(status)));
    682                         ntlmssp_end(client_ntlmssp_state);
     696                        TALLOC_FREE(*client_ntlmssp_state);
    683697                        return status;
    684698                }
     
    688702}
    689703
    690 static NTSTATUS ntlm_auth_start_ntlmssp_server(NTLMSSP_STATE **ntlmssp_state)
    691 {
    692         NTSTATUS status = ntlmssp_server_start(ntlmssp_state);
    693        
     704static NTSTATUS ntlm_auth_start_ntlmssp_server(struct ntlmssp_state **ntlmssp_state)
     705{
     706        NTSTATUS status;
     707        const char *netbios_name;
     708        const char *netbios_domain;
     709        const char *dns_name;
     710        char *dns_domain;
     711        bool is_standalone = false;
     712
     713        if (opt_password) {
     714                netbios_name = global_myname();
     715                netbios_domain = lp_workgroup();
     716        } else {
     717                netbios_name = get_winbind_netbios_name();
     718                netbios_domain = get_winbind_domain();
     719        }
     720        /* This should be a 'netbios domain -> DNS domain' mapping */
     721        dns_domain = get_mydnsdomname(talloc_tos());
     722        if (dns_domain) {
     723                strlower_m(dns_domain);
     724        }
     725        dns_name = get_mydnsfullname();
     726
     727        status = ntlmssp_server_start(NULL,
     728                                      is_standalone,
     729                                      netbios_name,
     730                                      netbios_domain,
     731                                      dns_name,
     732                                      dns_domain,
     733                                      ntlmssp_state);
    694734        if (!NT_STATUS_IS_OK(status)) {
    695735                DEBUG(1, ("Could not start NTLMSSP server: %s\n",
     
    701741        if (opt_password) {
    702742                (*ntlmssp_state)->check_password = local_pw_check;
    703                 (*ntlmssp_state)->get_domain = lp_workgroup;
    704                 (*ntlmssp_state)->get_global_myname = global_myname;
    705743        } else {
    706744                (*ntlmssp_state)->check_password = winbind_pw_check;
    707                 (*ntlmssp_state)->get_domain = get_winbind_domain;
    708                 (*ntlmssp_state)->get_global_myname = get_winbind_netbios_name;
    709745        }
    710746        return NT_STATUS_OK;
     
    733769         * ntlm_ccache_auth, it will fail. So, we have to ask the trusted
    734770         * domain's child for ccache_ntlm_auth. that is to say, we have to
    735          * set WBFALG_PAM_CONTACT_TRUSTDOM in request.flags.
     771         * set WBFLAG_PAM_CONTACT_TRUSTDOM in request.flags.
    736772         */
    737773        ctrl = get_pam_winbind_config();
     
    829865
    830866        if (strncmp(buf, "YR", 2) == 0) {
    831                 if (state->ntlmssp_state)
    832                         ntlmssp_end(&state->ntlmssp_state);
     867                TALLOC_FREE(state->ntlmssp_state);
    833868                state->svr_state = SERVER_INITIAL;
    834869        } else if (strncmp(buf, "KK", 2) == 0) {
     
    896931                DEBUG(0, ("NTLMSSP BH: %s\n", nt_errstr(nt_status)));
    897932
    898                 ntlmssp_end(&state->ntlmssp_state);
     933                TALLOC_FREE(state->ntlmssp_state);
    899934        } else if (!NT_STATUS_IS_OK(nt_status)) {
    900935                *response = talloc_asprintf(mem_ctx, "NA %s",
     
    904939                *response = talloc_asprintf(
    905940                        mem_ctx, "AF %s",
    906                         (char *)state->ntlmssp_state->auth_context);
     941                        (char *)state->ntlmssp_state->callback_private);
    907942                DEBUG(10, ("NTLMSSP OK!\n"));
    908943
     
    10071042
    10081043        if (strncmp(buf, "YR", 2) == 0) {
    1009                 if (state->ntlmssp_state)
    1010                         ntlmssp_end(&state->ntlmssp_state);
     1044                TALLOC_FREE(state->ntlmssp_state);
    10111045                state->cli_state = CLIENT_INITIAL;
    10121046        } else if (strncmp(buf, "TT", 2) == 0) {
     
    10991133                DEBUG(10, ("NTLMSSP OK!\n"));
    11001134                state->cli_state = CLIENT_FINISHED;
    1101                 if (state->ntlmssp_state)
    1102                         ntlmssp_end(&state->ntlmssp_state);
     1135                TALLOC_FREE(state->ntlmssp_state);
    11031136        } else {
    11041137                x_fprintf(x_stdout, "BH %s\n", nt_errstr(nt_status));
    11051138                DEBUG(0, ("NTLMSSP BH: %s\n", nt_errstr(nt_status)));
    11061139                state->cli_state = CLIENT_ERROR;
    1107                 if (state->ntlmssp_state)
    1108                         ntlmssp_end(&state->ntlmssp_state);
     1140                TALLOC_FREE(state->ntlmssp_state);
    11091141        }
    11101142
     
    11171149        char *user, *pass;     
    11181150        user=buf;
    1119        
     1151
    11201152        pass=(char *)memchr(buf,' ',length);
    11211153        if (!pass) {
     
    11261158        *pass='\0';
    11271159        pass++;
    1128        
     1160
    11291161        if (state->helper_mode == SQUID_2_5_BASIC) {
    11301162                rfc1738_unescape(user);
    11311163                rfc1738_unescape(pass);
    11321164        }
    1133        
     1165
    11341166        if (check_plaintext_auth(user, pass, False)) {
    11351167                x_fprintf(x_stdout, "OK\n");
     
    11971229}
    11981230
    1199 static bool _spnego_parse_krb5_wrap(TALLOC_CTX *ctx, DATA_BLOB blob, DATA_BLOB *ticket, uint8 tok_id[2])
     1231bool spnego_parse_krb5_wrap(TALLOC_CTX *ctx, DATA_BLOB blob, DATA_BLOB *ticket, uint8 tok_id[2])
    12001232{
    12011233        bool ret;
     
    12621294
    12631295        if (strncmp(buf, "YR", 2) == 0) {
    1264                 if (state->ntlmssp_state)
    1265                         ntlmssp_end(&state->ntlmssp_state);
     1296                TALLOC_FREE(state->ntlmssp_state);
    12661297                TALLOC_FREE(state->spnego_mech);
    12671298                TALLOC_FREE(state->spnego_mech_oid);
     
    13961427                                                    "NTLMSSP challenge, but "
    13971428                                                    "already got one\n");
    1398                                 ntlmssp_end(&state->ntlmssp_state);
     1429                                TALLOC_FREE(state->ntlmssp_state);
    13991430                                return;
    14001431                        }
     
    14731504                }
    14741505                if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
    1475                         ntlmssp_end(&state->ntlmssp_state);
     1506                        TALLOC_FREE(state->ntlmssp_state);
    14761507                }
    14771508#ifdef HAVE_KRB5
     
    14801511                DATA_BLOB ap_rep;
    14811512                DATA_BLOB session_key;
    1482                 struct PAC_DATA *pac_data = NULL;
     1513                struct PAC_LOGON_INFO *logon_info = NULL;
    14831514                DATA_BLOB ticket;
    14841515                uint8_t tok_id[2];
    14851516
    1486                 if (!_spnego_parse_krb5_wrap(ctx, raw_in_token,
    1487                                              &ticket, tok_id)) {
     1517                if (!spnego_parse_krb5_wrap(ctx, raw_in_token,
     1518                                            &ticket, tok_id)) {
    14881519                        DEBUG(1, ("spnego_parse_krb5_wrap failed\n"));
    14891520                        x_fprintf(x_stdout, "BH spnego_parse_krb5_wrap failed\n");
     
    14931524                status = ads_verify_ticket(ctx, lp_realm(), 0,
    14941525                                           &ticket,
    1495                                            &principal, &pac_data, &ap_rep,
     1526                                           &principal, &logon_info, &ap_rep,
    14961527                                           &session_key, True);
    14971528
     
    15151546                        user = talloc_strdup(ctx, principal);
    15161547
    1517                         if (pac_data) {
    1518                                 struct PAC_LOGON_INFO *logon_info;
    1519                                 logon_info = get_logon_info_from_pac(
    1520                                         pac_data);
    1521                                 if (logon_info) {
    1522                                         netsamlogon_cache_store(
    1523                                                 user,
    1524                                                 &logon_info->info3);
    1525                                 }
     1548                        if (logon_info) {
     1549                                netsamlogon_cache_store(
     1550                                        user, &logon_info->info3);
    15261551                        }
    15271552
     
    15871612}
    15881613
    1589 static NTLMSSP_STATE *client_ntlmssp_state = NULL;
     1614static struct ntlmssp_state *client_ntlmssp_state = NULL;
    15901615
    15911616static bool manage_client_ntlmssp_init(struct spnego_data spnego)
     
    16381663                DEBUG(1, ("Expected OK or MORE_PROCESSING_REQUIRED, got: %s\n",
    16391664                          nt_errstr(status)));
    1640                 ntlmssp_end(&client_ntlmssp_state);
     1665                TALLOC_FREE(client_ntlmssp_state);
    16411666                return False;
    16421667        }
     
    16711696        if (spnego.negTokenTarg.negResult == SPNEGO_REJECT) {
    16721697                x_fprintf(x_stdout, "NA\n");
    1673                 ntlmssp_end(&client_ntlmssp_state);
     1698                TALLOC_FREE(client_ntlmssp_state);
    16741699                return;
    16751700        }
     
    16771702        if (spnego.negTokenTarg.negResult == SPNEGO_ACCEPT_COMPLETED) {
    16781703                x_fprintf(x_stdout, "AF\n");
    1679                 ntlmssp_end(&client_ntlmssp_state);
     1704                TALLOC_FREE(client_ntlmssp_state);
    16801705                return;
    16811706        }
     
    16841709                                       spnego.negTokenTarg.responseToken,
    16851710                                       &request);
    1686                
     1711
    16871712        if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
    16881713                DEBUG(1, ("Expected MORE_PROCESSING_REQUIRED from "
     
    16921717                                    "ntlmssp_client_update\n");
    16931718                data_blob_free(&request);
    1694                 ntlmssp_end(&client_ntlmssp_state);
     1719                TALLOC_FREE(client_ntlmssp_state);
    16951720                return;
    16961721        }
     
    17011726        spnego.negTokenTarg.responseToken = request;
    17021727        spnego.negTokenTarg.mechListMIC = null_blob;
    1703        
     1728
    17041729        spnego_write_data(ctx, &to_server, &spnego);
    17051730        data_blob_free(&request);
     
    17451770        principal[spnego.negTokenInit.mechListMIC.length] = '\0';
    17461771
    1747         retval = cli_krb5_get_ticket(principal, 0, &tkt, &session_key_krb5, 0, NULL, NULL, NULL);
    1748 
     1772        retval = cli_krb5_get_ticket(ctx, principal, 0,
     1773                                          &tkt, &session_key_krb5,
     1774                                          0, NULL, NULL, NULL);
    17491775        if (retval) {
    17501776                char *user = NULL;
     
    17691795                }
    17701796
    1771                 retval = cli_krb5_get_ticket(principal, 0, &tkt, &session_key_krb5, 0, NULL, NULL, NULL);
    1772 
     1797                retval = cli_krb5_get_ticket(ctx, principal, 0,
     1798                                                  &tkt, &session_key_krb5,
     1799                                                  0, NULL, NULL, NULL);
    17731800                if (retval) {
    17741801                        DEBUG(10, ("Kinit suceeded, but getting a ticket failed: %s\n", error_message(retval)));
     
    18551882
    18561883                opt_password = SMB_STRNDUP((const char *)request.data, request.length);
    1857                
     1884
    18581885                if (opt_password == NULL) {
    18591886                        DEBUG(1, ("Out of memory\n"));
     
    19411968                        }
    19421969
    1943                         ntlmssp_end(&client_ntlmssp_state);
     1970                        TALLOC_FREE(client_ntlmssp_state);
    19441971                        goto out;
    19451972                }
     
    19832010        static bool ntlm_server_1_user_session_key;
    19842011        static bool ntlm_server_1_lm_session_key;
    1985        
     2012
    19862013        if (strequal(buf, ".")) {
    19872014                if (!full_username && !username) {     
     
    20132040                                fstring fstr_user;
    20142041                                fstring fstr_domain;
    2015                                
     2042
    20162043                                if (!parse_ntlm_auth_domain_user(full_username, fstr_user, fstr_domain)) {
    20172044                                        /* username might be 'tainted', don't print into our new-line deleimianted stream */
     
    20302057                        if (ntlm_server_1_lm_session_key)
    20312058                                flags |= WBFLAG_PAM_LMKEY;
    2032                        
     2059
    20332060                        if (ntlm_server_1_user_session_key)
    20342061                                flags |= WBFLAG_PAM_USER_SESSION_KEY;
     
    20992126        if (!parameter) {
    21002127                parameter = strstr_m(request, ": ");
    2101                
     2128
    21022129                if (!parameter) {
    21032130                        DEBUG(0, ("Parameter not found!\n"));
     
    21052132                        return;
    21062133                }
    2107                
     2134
    21082135                parameter[0] ='\0';
    21092136                parameter++;
     
    21862213                        new_nt_pswd = data_blob(NULL, 516);
    21872214                        old_nt_hash_enc = data_blob(NULL, 16);
    2188                        
     2215
    21892216                        /* Calculate the MD4 hash (NT compatible) of the
    21902217                         * password */
     
    21942221                        /* E_deshash returns false for 'long'
    21952222                           passwords (> 14 DOS chars). 
    2196                            
     2223
    21972224                           Therefore, don't send a buffer
    21982225                           encrypted with the truncated hash
     
    22232250                        encode_pw_buffer(new_nt_pswd.data, newpswd,
    22242251                                         STR_UNICODE);
    2225        
     2252
    22262253                        arcfour_crypt(new_nt_pswd.data, old_nt_hash, 516);
    22272254                        E_old_pw_hash(new_nt_hash, old_nt_hash,
    22282255                                      old_nt_hash_enc.data);
    22292256                }
    2230                
     2257
    22312258                if (!full_username && !username) {     
    22322259                        x_fprintf(x_stdout, "Error: No username supplied!\n");
     
    22372264                } else {
    22382265                        char *error_string = NULL;
    2239                        
     2266
    22402267                        if (full_username && !username) {
    22412268                                fstring fstr_user;
    22422269                                fstring fstr_domain;
    2243                                
     2270
    22442271                                if (!parse_ntlm_auth_domain_user(full_username,
    22452272                                                                 fstr_user,
     
    22592286                                        domain = smb_xstrdup(fstr_domain);
    22602287                                }
    2261                                
     2288
    22622289                        }
    22632290
     
    22992326        if (!parameter) {
    23002327                parameter = strstr_m(request, ": ");
    2301                
     2328
    23022329                if (!parameter) {
    23032330                        DEBUG(0, ("Parameter not found!\n"));
     
    23052332                        return;
    23062333                }
    2307                
     2334
    23082335                parameter[0] ='\0';
    23092336                parameter++;
     
    25812608                { "request-nt-key", 0, POPT_ARG_NONE, &request_user_session_key, OPT_USER_SESSION_KEY, "Retrieve User (NT) session key"},
    25822609                { "use-cached-creds", 0, POPT_ARG_NONE, &use_cached_creds, OPT_USE_CACHED_CREDS, "Use cached credentials if no password is given"},
    2583                 { "diagnostics", 0, POPT_ARG_NONE, &diagnostics, OPT_DIAGNOSTICS, "Perform diagnostics on the authentictaion chain"},
     2610                { "diagnostics", 0, POPT_ARG_NONE, &diagnostics,
     2611                  OPT_DIAGNOSTICS,
     2612                  "Perform diagnostics on the authentication chain"},
    25842613                { "require-membership-of", 0, POPT_ARG_STRING, &require_membership_of, OPT_REQUIRE_MEMBERSHIP, "Require that a user be a member of this group (either name or SID) for authentication to succeed" },
    25852614                { "pam-winbind-conf", 0, POPT_ARG_STRING, &opt_pam_winbind_conf, OPT_PAM_WINBIND_CONF, "Require that request must set WBFLAG_PAM_CONTACT_TRUSTDOM when krb5 auth is required" },
     
    25922621        load_case_tables();
    25932622
    2594         dbf = x_stderr;
     2623        setup_logging("ntlm_auth", DEBUG_STDERR);
    25952624
    25962625        /* Parse options */
  • vendor/current/source3/utils/ntlm_auth_diagnostics.c

    r414 r740  
    2525#include "utils/ntlm_auth.h"
    2626#include "../libcli/auth/libcli_auth.h"
     27#include "nsswitch/winbind_client.h"
    2728
    2829#undef DBGC_CLASS
  • vendor/current/source3/utils/pdbedit.c

    r414 r740  
    2222
    2323#include "includes.h"
     24#include "popt_common.h"
     25#include "../librpc/gen_ndr/samr.h"
     26#include "../libcli/security/security.h"
     27#include "passdb.h"
    2428
    2529#define BIT_BACKEND     0x00000004
     
    5660#define MASK_USER_GOOD          0x60405FE0
    5761
    58 static int get_sid_from_cli_string(DOM_SID *sid, const char *str_sid)
     62static int get_sid_from_cli_string(struct dom_sid *sid, const char *str_sid)
    5963{
    6064        uint32_t rid;
     
    6973                        return -1;
    7074                }
    71                 sid_copy(sid, get_global_sam_sid());
    72                 sid_append_rid(sid, rid);
     75                sid_compose(sid, get_global_sam_sid(), rid);
    7376        }
    7477
     
    105108                struct samu *user;
    106109                struct samu *account;
    107                 DOM_SID user_sid;
     110                struct dom_sid user_sid;
    108111
    109112                DEBUG(4, ("Processing account %s\n", userentry.account_name));
     
    203206
    204207        for (i=1; decode_account_policy_name(i) != NULL; i++) {
    205                 uint32 policy_value;
     208                uint32_t policy_value;
    206209                if (!account_policy_get_default(i, &policy_value)) {
    207210                        fprintf(stderr, "Can't get default account policy\n");
     
    227230
    228231        for ( i=1; decode_account_policy_name(i) != NULL; i++ ) {
    229                 uint32 policy_value;
     232                uint32_t policy_value;
    230233                NTSTATUS status;
    231234
     
    263266        if (verbosity) {
    264267                char temp[44];
    265                 const uint8 *hours;
     268                const uint8_t *hours;
    266269
    267270                printf ("Unix username:        %s\n", pdb_get_username(sam_pwent));
     
    330333                       nt_passwd,
    331334                       pdb_encode_acct_ctrl(pdb_get_acct_ctrl(sam_pwent),NEW_PW_FORMAT_SPACE_PADDED_LEN),
    332                        (uint32)convert_time_t_to_uint32(pdb_get_pass_last_set_time(sam_pwent)));
     335                       (uint32)convert_time_t_to_uint32_t(pdb_get_pass_last_set_time(sam_pwent)));
    333336        } else {
    334337                uid = nametouid(pdb_get_username(sam_pwent));
     
    378381        struct samu *sam_pwent;
    379382        TALLOC_CTX *tosctx;
    380         DOM_SID user_sid;
     383        struct dom_sid user_sid;
    381384        bool bret;
    382385        int ret;
     
    436439        struct samu *sam_pwent;
    437440        TALLOC_CTX *tosctx;
    438         DOM_SID user_sid;
     441        struct dom_sid user_sid;
    439442        NTSTATUS status;
    440443        bool bret;
     
    506509        uint32_t not_settable;
    507510        uint32_t new_flags;
    508         DOM_SID u_sid;
     511        struct dom_sid u_sid;
    509512        bool ret;
    510513
     
    525528                memset(hours_array, 0xff, hours_len);
    526529
    527                 pdb_set_hours(sam_pwent, hours_array, PDB_CHANGED);
     530                pdb_set_hours(sam_pwent, hours_array, hours_len, PDB_CHANGED);
    528531        }
    529532
     
    594597                        }
    595598
    596                         value = convert_uint32_to_time_t(num);
     599                        value = convert_uint32_t_to_time_t(num);
    597600                }
    598601
     
    620623        uint32_t not_settable;
    621624        uint32_t new_flags;
    622         DOM_SID m_sid;
     625        struct dom_sid m_sid;
    623626        char *name;
    624627        int len;
     
    711714        TALLOC_CTX *tosctx;
    712715        NTSTATUS status;
    713         DOM_SID u_sid;
     716        struct dom_sid u_sid;
    714717        int flags;
    715718        int ret;
     
    808811        TALLOC_CTX *tosctx;
    809812        NTSTATUS status;
    810         DOM_SID m_sid;
     813        struct dom_sid m_sid;
    811814        char *compatpwd;
    812815        char *name;
     
    10571060        load_case_tables();
    10581061
    1059         setup_logging("pdbedit", True);
     1062        setup_logging("pdbedit", DEBUG_STDOUT);
    10601063
    10611064        pc = poptGetContext(NULL, argc, (const char **) argv, long_options,
     
    11341137        /* account policy operations */
    11351138        if ((checkparms & BIT_ACCPOLICY) && !(checkparms & ~(BIT_ACCPOLICY + BIT_ACCPOLVAL))) {
    1136                 uint32 value;
     1139                uint32_t value;
    11371140                enum pdb_policy_type field = account_policy_name_to_typenum(account_policy);
    11381141                if (field == 0) {
  • vendor/current/source3/utils/profiles.c

    r587 r740  
    1 /* 
    2    Samba Unix/Linux SMB client utility profiles.c 
    3    
    4    Copyright (C) Richard Sharpe, <rsharpe@richardsharpe.com>   2002 
    5    Copyright (C) Jelmer Vernooij (conversion to popt)          2003 
    6    Copyright (C) Gerald (Jerry) Carter                         2005 
     1/*
     2   Samba Unix/Linux SMB client utility profiles.c
     3
     4   Copyright (C) Richard Sharpe, <rsharpe@richardsharpe.com>   2002
     5   Copyright (C) Jelmer Vernooij (conversion to popt)          2003
     6   Copyright (C) Gerald (Jerry) Carter                         2005
    77
    88   This program is free software; you can redistribute it and/or modify
     
    1010   the Free Software Foundation; either version 3 of the License, or
    1111   (at your option) any later version.
    12    
     12
    1313   This program is distributed in the hope that it will be useful,
    1414   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1515   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1616   GNU General Public License for more details.
    17    
     17
    1818   You should have received a copy of the GNU General Public License
    19    along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     19   along with this program.  If not, see <http://www.gnu.org/licenses/>.
    2020*/
    21                                  
     21
    2222#include "includes.h"
    23 #include "regfio.h"
     23#include "system/filesys.h"
     24#include "popt_common.h"
     25#include "registry/reg_objects.h"
     26#include "registry/regfio.h"
     27#include "../libcli/security/security.h"
    2428
    2529/* GLOBAL VARIABLES */
    2630
    27 DOM_SID old_sid, new_sid;
     31struct dom_sid old_sid, new_sid;
    2832int change = 0, new_val = 0;
    2933int opt_verbose = False;
     
    5660********************************************************************/
    5761
    58 static bool swap_sid_in_acl( SEC_DESC *sd, DOM_SID *s1, DOM_SID *s2 )
     62static bool swap_sid_in_acl( struct security_descriptor *sd, struct dom_sid *s1, struct dom_sid *s2 )
    5963{
    60         SEC_ACL *theacl;
     64        struct security_acl *theacl;
    6165        int i;
    6266        bool update = False;
    6367
    6468        verbose_output("  Owner SID: %s\n", sid_string_tos(sd->owner_sid));
    65         if ( sid_equal( sd->owner_sid, s1 ) ) {
     69        if ( dom_sid_equal( sd->owner_sid, s1 ) ) {
    6670                sid_copy( sd->owner_sid, s2 );
    6771                update = True;
    68                 verbose_output("  New Owner SID: %s\n", 
     72                verbose_output("  New Owner SID: %s\n",
    6973                        sid_string_tos(sd->owner_sid));
    7074
     
    7276
    7377        verbose_output("  Group SID: %s\n", sid_string_tos(sd->group_sid));
    74         if ( sid_equal( sd->group_sid, s1 ) ) {
     78        if ( dom_sid_equal( sd->group_sid, s1 ) ) {
    7579                sid_copy( sd->group_sid, s2 );
    7680                update = True;
    77                 verbose_output("  New Group SID: %s\n", 
     81                verbose_output("  New Group SID: %s\n",
    7882                        sid_string_tos(sd->group_sid));
    7983        }
     
    8286        verbose_output("  DACL: %d entries:\n", theacl->num_aces);
    8387        for ( i=0; i<theacl->num_aces; i++ ) {
    84                 verbose_output("    Trustee SID: %s\n", 
     88                verbose_output("    Trustee SID: %s\n",
    8589                        sid_string_tos(&theacl->aces[i].trustee));
    86                 if ( sid_equal( &theacl->aces[i].trustee, s1 ) ) {
     90                if ( dom_sid_equal( &theacl->aces[i].trustee, s1 ) ) {
    8791                        sid_copy( &theacl->aces[i].trustee, s2 );
    8892                        update = True;
    89                         verbose_output("    New Trustee SID: %s\n", 
     93                        verbose_output("    New Trustee SID: %s\n",
    9094                                sid_string_tos(&theacl->aces[i].trustee));
    9195                }
     
    96100        verbose_output("  SACL: %d entries: \n", theacl->num_aces);
    97101        for ( i=0; i<theacl->num_aces; i++ ) {
    98                 verbose_output("    Trustee SID: %s\n", 
     102                verbose_output("    Trustee SID: %s\n",
    99103                        sid_string_tos(&theacl->aces[i].trustee));
    100                 if ( sid_equal( &theacl->aces[i].trustee, s1 ) ) {
     104                if ( dom_sid_equal( &theacl->aces[i].trustee, s1 ) ) {
    101105                        sid_copy( &theacl->aces[i].trustee, s2 );
    102106                        update = True;
    103                         verbose_output("    New Trustee SID: %s\n", 
     107                        verbose_output("    New Trustee SID: %s\n",
    104108                                sid_string_tos(&theacl->aces[i].trustee));
    105109                }
     
    117121{
    118122        REGF_NK_REC *key, *subkey;
    119         SEC_DESC *new_sd;
     123        struct security_descriptor *new_sd;
    120124        struct regval_ctr *values;
    121125        struct regsubkey_ctr *subkeys;
     
    140144        }
    141145
    142         if ( !(values = TALLOC_ZERO_P( subkeys, struct regval_ctr )) ) {
     146        werr = regval_ctr_init(subkeys, &values);
     147        if (!W_ERROR_IS_OK(werr)) {
    143148                TALLOC_FREE( subkeys );
    144149                DEBUG(0,("copy_registry_tree: talloc() failure!\n"));
     
    150155        for ( i=0; i<nk->num_values; i++ ) {
    151156                regval_ctr_addvalue( values, nk->values[i].valuename, nk->values[i].type,
    152                         (const char *)nk->values[i].data, (nk->values[i].data_size & ~VK_DATA_IN_OFFSET) );
     157                        nk->values[i].data, (nk->values[i].data_size & ~VK_DATA_IN_OFFSET) );
    153158        }
    154159
     
    212217        /* setup logging options */
    213218
    214         setup_logging( "profiles", True );
    215         dbf = x_stderr;
    216         x_setbuf( x_stderr, NULL );
     219        setup_logging( "profiles", DEBUG_STDERR);
    217220
    218221        pc = poptGetContext("profiles", argc, (const char **)argv, long_options,
  • vendor/current/source3/utils/sharesec.c

    r414 r740  
    2424
    2525#include "includes.h"
     26#include "popt_common.h"
     27#include "../libcli/security/security.h"
     28#include "passdb/machine_sid.h"
    2629
    2730static TALLOC_CTX *ctx;
     
    6568********************************************************************/
    6669
    67 static void print_ace(FILE *f, SEC_ACE *ace)
     70static void print_ace(FILE *f, struct security_ace *ace)
    6871{
    6972        const struct perm_value *v;
     
    125128********************************************************************/
    126129
    127 static void sec_desc_print(FILE *f, SEC_DESC *sd)
     130static void sec_desc_print(FILE *f, struct security_descriptor *sd)
    128131{
    129132        uint32 i;
     
    139142        /* Print aces */
    140143        for (i = 0; sd->dacl && i < sd->dacl->num_aces; i++) {
    141                 SEC_ACE *ace = &sd->dacl->aces[i];
     144                struct security_ace *ace = &sd->dacl->aces[i];
    142145                fprintf(f, "ACL:");
    143146                print_ace(f, ace);
     
    150153********************************************************************/
    151154
    152 static bool parse_ace(SEC_ACE *ace, const char *orig_str)
     155static bool parse_ace(struct security_ace *ace, const char *orig_str)
    153156{
    154157        char *p;
     
    158161        unsigned int aflags = 0;
    159162        unsigned int amask = 0;
    160         DOM_SID sid;
     163        struct dom_sid sid;
    161164        uint32_t mask;
    162165        const struct perm_value *v;
     
    295298********************************************************************/
    296299
    297 static SEC_DESC* parse_acl_string(TALLOC_CTX *mem_ctx, const char *szACL, size_t *sd_size )
    298 {
    299         SEC_DESC *sd = NULL;
    300         SEC_ACE *ace;
    301         SEC_ACL *theacl;
     300static struct security_descriptor* parse_acl_string(TALLOC_CTX *mem_ctx, const char *szACL, size_t *sd_size )
     301{
     302        struct security_descriptor *sd = NULL;
     303        struct security_ace *ace;
     304        struct security_acl *theacl;
    302305        int num_ace;
    303306        const char *pacl;
     
    310313        num_ace = count_chars( pacl, ',' ) + 1;
    311314
    312         if ( !(ace = TALLOC_ZERO_ARRAY( mem_ctx, SEC_ACE, num_ace )) )
     315        if ( !(ace = TALLOC_ZERO_ARRAY( mem_ctx, struct security_ace, num_ace )) )
    313316                return NULL;
    314317
     
    330333                return NULL;
    331334
    332         sd = make_sec_desc( mem_ctx, SEC_DESC_REVISION, SEC_DESC_SELF_RELATIVE,
     335        sd = make_sec_desc( mem_ctx, SD_REVISION, SEC_DESC_SELF_RELATIVE,
    333336                NULL, NULL, NULL, theacl, sd_size);
    334337
     
    336339}
    337340
    338 /* add an ACE to a list of ACEs in a SEC_ACL */
    339 static bool add_ace(TALLOC_CTX *mem_ctx, SEC_ACL **the_acl, SEC_ACE *ace)
    340 {
    341         SEC_ACL *new_ace;
    342         SEC_ACE *aces;
     341/* add an ACE to a list of ACEs in a struct security_acl */
     342static bool add_ace(TALLOC_CTX *mem_ctx, struct security_acl **the_acl, struct security_ace *ace)
     343{
     344        struct security_acl *new_ace;
     345        struct security_ace *aces;
    343346        if (! *the_acl) {
    344347                return (((*the_acl) = make_sec_acl(mem_ctx, 3, 1, ace)) != NULL);
    345348        }
    346349
    347         if (!(aces = SMB_CALLOC_ARRAY(SEC_ACE, 1+(*the_acl)->num_aces))) {
    348                 return False;
    349         }
    350         memcpy(aces, (*the_acl)->aces, (*the_acl)->num_aces * sizeof(SEC_ACE));
    351         memcpy(aces+(*the_acl)->num_aces, ace, sizeof(SEC_ACE));
     350        if (!(aces = SMB_CALLOC_ARRAY(struct security_ace, 1+(*the_acl)->num_aces))) {
     351                return False;
     352        }
     353        memcpy(aces, (*the_acl)->aces, (*the_acl)->num_aces * sizeof(struct
     354        security_ace));
     355        memcpy(aces+(*the_acl)->num_aces, ace, sizeof(struct security_ace));
    352356        new_ace = make_sec_acl(mem_ctx,(*the_acl)->revision,1+(*the_acl)->num_aces, aces);
    353357        SAFE_FREE(aces);
     
    361365   allowed ACEs. */
    362366
    363 static int ace_compare(SEC_ACE *ace1, SEC_ACE *ace2)
     367static int ace_compare(struct security_ace *ace1, struct security_ace *ace2)
    364368{
    365369        if (sec_ace_equal(ace1, ace2))
     
    369373                return ace2->type - ace1->type;
    370374
    371         if (sid_compare(&ace1->trustee, &ace2->trustee))
    372                 return sid_compare(&ace1->trustee, &ace2->trustee);
     375        if (dom_sid_compare(&ace1->trustee, &ace2->trustee))
     376                return dom_sid_compare(&ace1->trustee, &ace2->trustee);
    373377
    374378        if (ace1->flags != ace2->flags)
     
    381385                return ace1->size - ace2->size;
    382386
    383         return memcmp(ace1, ace2, sizeof(SEC_ACE));
    384 }
    385 
    386 static void sort_acl(SEC_ACL *the_acl)
     387        return memcmp(ace1, ace2, sizeof(struct security_ace));
     388}
     389
     390static void sort_acl(struct security_acl *the_acl)
    387391{
    388392        uint32 i;
    389393        if (!the_acl) return;
    390394
    391         qsort(the_acl->aces, the_acl->num_aces, sizeof(the_acl->aces[0]), QSORT_CAST ace_compare);
     395        TYPESAFE_QSORT(the_acl->aces, the_acl->num_aces, ace_compare);
    392396
    393397        for (i=1;i<the_acl->num_aces;) {
     
    407411static int change_share_sec(TALLOC_CTX *mem_ctx, const char *sharename, char *the_acl, enum acl_mode mode)
    408412{
    409         SEC_DESC *sd = NULL;
    410         SEC_DESC *old = NULL;
     413        struct security_descriptor *sd = NULL;
     414        struct security_descriptor *old = NULL;
    411415        size_t sd_size = 0;
    412416        uint32 i, j;
     
    458462
    459463                for (j=0;old->dacl && j<old->dacl->num_aces;j++) {
    460                     if (sid_equal(&sd->dacl->aces[i].trustee,
     464                    if (dom_sid_equal(&sd->dacl->aces[i].trustee,
    461465                        &old->dacl->aces[j].trustee)) {
    462466                        old->dacl->aces[j] = sd->dacl->aces[i];
     
    541545
    542546        /* set default debug level to 1 regardless of what smb.conf sets */
    543         setup_logging( "sharesec", True );
    544         DEBUGLEVEL_CLASS[DBGC_ALL] = 1;
    545         dbf = x_stderr;
    546         x_setbuf( x_stderr, NULL );
     547        setup_logging( "sharesec", DEBUG_STDERR);
     548
     549        load_case_tables();
     550
     551        lp_set_cmdline("log level", "1");
    547552
    548553        pc = poptGetContext("sharesec", argc, argv, long_options, 0);
     
    592597        setlinebuf(stdout);
    593598
    594         load_case_tables();
    595 
    596         lp_load( get_dyn_CONFIGFILE(), False, False, False, True );
     599        lp_load_with_registry_shares( get_dyn_CONFIGFILE(), False, False, False,
     600                                      True );
    597601
    598602        /* check for initializing secrets.tdb first */
    599603
    600604        if ( initialize_sid ) {
    601                 DOM_SID *sid = get_global_sam_sid();
     605                struct dom_sid *sid = get_global_sam_sid();
    602606
    603607                if ( !sid ) {
  • vendor/current/source3/utils/smbcacls.c

    r414 r740  
    1 /* 
     1/*
    22   Unix SMB/CIFS implementation.
    33   ACL get/set utility
    4    
     4
    55   Copyright (C) Andrew Tridgell 2000
    66   Copyright (C) Tim Potter      2000
    77   Copyright (C) Jeremy Allison  2000
    88   Copyright (C) Jelmer Vernooij 2003
    9    
     9
    1010   This program is free software; you can redistribute it and/or modify
    1111   it under the terms of the GNU General Public License as published by
    1212   the Free Software Foundation; either version 3 of the License, or
    1313   (at your option) any later version.
    14    
     14
    1515   This program is distributed in the hope that it will be useful,
    1616   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1717   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1818   GNU General Public License for more details.
    19    
     19
    2020   You should have received a copy of the GNU General Public License
    2121   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2323
    2424#include "includes.h"
    25 
    26 extern bool AllowDebugChange;
     25#include "popt_common.h"
     26#include "rpc_client/cli_pipe.h"
     27#include "../librpc/gen_ndr/ndr_lsa.h"
     28#include "rpc_client/cli_lsarpc.h"
     29#include "../libcli/security/security.h"
     30#include "libsmb/libsmb.h"
     31#include "libsmb/clirap.h"
     32#include "passdb/machine_sid.h"
    2733
    2834static int test_args;
     
    3440static int numeric;
    3541
     42static int sddl;
     43
    3644enum acl_mode {SMB_ACL_SET, SMB_ACL_DELETE, SMB_ACL_MODIFY, SMB_ACL_ADD };
    37 enum chown_mode {REQUEST_NONE, REQUEST_CHOWN, REQUEST_CHGRP};
     45enum chown_mode {REQUEST_NONE, REQUEST_CHOWN, REQUEST_CHGRP, REQUEST_INHERIT};
    3846enum exit_values {EXIT_OK, EXIT_FAILED, EXIT_PARSE_ERROR};
    3947
     
    6573
    6674static NTSTATUS cli_lsa_lookup_sid(struct cli_state *cli,
    67                                    const DOM_SID *sid,
     75                                   const struct dom_sid *sid,
    6876                                   TALLOC_CTX *mem_ctx,
    6977                                   enum lsa_SidType *type,
     
    118126                                    const char *name,
    119127                                    enum lsa_SidType *type,
    120                                     DOM_SID *sid)
     128                                    struct dom_sid *sid)
    121129{
    122130        uint16 orig_cnum = cli->cnum;
     
    125133        NTSTATUS status;
    126134        TALLOC_CTX *frame = talloc_stackframe();
    127         DOM_SID *sids;
     135        struct dom_sid *sids;
    128136        enum lsa_SidType *types;
    129137
     
    164172
    165173/* convert a SID to a string, either numeric or username/group */
    166 static void SidToString(struct cli_state *cli, fstring str, const DOM_SID *sid)
     174static void SidToString(struct cli_state *cli, fstring str, const struct dom_sid *sid)
    167175{
    168176        char *domain = NULL;
     
    193201
    194202/* convert a string to a SID, either numeric or username/group */
    195 static bool StringToSid(struct cli_state *cli, DOM_SID *sid, const char *str)
     203static bool StringToSid(struct cli_state *cli, struct dom_sid *sid, const char *str)
    196204{
    197205        enum lsa_SidType type;
    198206
    199         if (strncmp(str, "S-", 2) == 0) {
    200                 return string_to_sid(sid, str);
     207        if (string_to_sid(sid, str)) {
     208                return true;
    201209        }
    202210
     
    265273
    266274/* print an ACE on a FILE, using either numeric or ascii representation */
    267 static void print_ace(struct cli_state *cli, FILE *f, SEC_ACE *ace)
     275static void print_ace(struct cli_state *cli, FILE *f, struct security_ace *ace)
    268276{
    269277        const struct perm_value *v;
     
    353361                }
    354362
    355                 if (*p != '|' && *p != '\0') {
     363                switch (*p) {
     364                case '|':
     365                        p++;
     366                case '\0':
     367                        continue;
     368                default:
    356369                        return false;
    357370                }
     
    361374
    362375/* parse an ACE in the same format as print_ace() */
    363 static bool parse_ace(struct cli_state *cli, SEC_ACE *ace,
     376static bool parse_ace(struct cli_state *cli, struct security_ace *ace,
    364377                      const char *orig_str)
    365378{
     
    370383        unsigned int aflags = 0;
    371384        unsigned int amask = 0;
    372         DOM_SID sid;
     385        struct dom_sid sid;
    373386        uint32_t mask;
    374387        const struct perm_value *v;
     
    527540}
    528541
    529 /* add an ACE to a list of ACEs in a SEC_ACL */
    530 static bool add_ace(SEC_ACL **the_acl, SEC_ACE *ace)
    531 {
    532         SEC_ACL *new_ace;
    533         SEC_ACE *aces;
     542/* add an ACE to a list of ACEs in a struct security_acl */
     543static bool add_ace(struct security_acl **the_acl, struct security_ace *ace)
     544{
     545        struct security_acl *new_ace;
     546        struct security_ace *aces;
    534547        if (! *the_acl) {
    535548                return (((*the_acl) = make_sec_acl(talloc_tos(), 3, 1, ace))
     
    537550        }
    538551
    539         if (!(aces = SMB_CALLOC_ARRAY(SEC_ACE, 1+(*the_acl)->num_aces))) {
     552        if (!(aces = SMB_CALLOC_ARRAY(struct security_ace, 1+(*the_acl)->num_aces))) {
    540553                return False;
    541554        }
    542         memcpy(aces, (*the_acl)->aces, (*the_acl)->num_aces * sizeof(SEC_ACE));
    543         memcpy(aces+(*the_acl)->num_aces, ace, sizeof(SEC_ACE));
     555        memcpy(aces, (*the_acl)->aces, (*the_acl)->num_aces * sizeof(struct
     556        security_ace));
     557        memcpy(aces+(*the_acl)->num_aces, ace, sizeof(struct security_ace));
    544558        new_ace = make_sec_acl(talloc_tos(),(*the_acl)->revision,1+(*the_acl)->num_aces, aces);
    545559        SAFE_FREE(aces);
     
    549563
    550564/* parse a ascii version of a security descriptor */
    551 static SEC_DESC *sec_desc_parse(TALLOC_CTX *ctx, struct cli_state *cli, char *str)
     565static struct security_descriptor *sec_desc_parse(TALLOC_CTX *ctx, struct cli_state *cli, char *str)
    552566{
    553567        const char *p = str;
    554568        char *tok;
    555         SEC_DESC *ret = NULL;
     569        struct security_descriptor *ret = NULL;
    556570        size_t sd_size;
    557         DOM_SID *grp_sid=NULL, *owner_sid=NULL;
    558         SEC_ACL *dacl=NULL;
     571        struct dom_sid *grp_sid=NULL, *owner_sid=NULL;
     572        struct security_acl *dacl=NULL;
    559573        int revision=1;
    560574
     
    570584                                goto done;
    571585                        }
    572                         owner_sid = SMB_CALLOC_ARRAY(DOM_SID, 1);
     586                        owner_sid = SMB_CALLOC_ARRAY(struct dom_sid, 1);
    573587                        if (!owner_sid ||
    574588                            !StringToSid(cli, owner_sid, tok+6)) {
     
    584598                                goto done;
    585599                        }
    586                         grp_sid = SMB_CALLOC_ARRAY(DOM_SID, 1);
     600                        grp_sid = SMB_CALLOC_ARRAY(struct dom_sid, 1);
    587601                        if (!grp_sid ||
    588602                            !StringToSid(cli, grp_sid, tok+6)) {
     
    594608
    595609                if (strncmp(tok,"ACL:", 4) == 0) {
    596                         SEC_ACE ace;
     610                        struct security_ace ace;
    597611                        if (!parse_ace(cli, &ace, tok+4)) {
    598612                                goto done;
     
    621635
    622636/* print a ascii version of a security descriptor on a FILE handle */
    623 static void sec_desc_print(struct cli_state *cli, FILE *f, SEC_DESC *sd)
     637static void sec_desc_print(struct cli_state *cli, FILE *f, struct security_descriptor *sd)
    624638{
    625639        fstring sidstr;
     
    649663        /* Print aces */
    650664        for (i = 0; sd->dacl && i < sd->dacl->num_aces; i++) {
    651                 SEC_ACE *ace = &sd->dacl->aces[i];
     665                struct security_ace *ace = &sd->dacl->aces[i];
    652666                fprintf(f, "ACL:");
    653667                print_ace(cli, f, ace);
     
    657671}
    658672
    659 /*****************************************************
     673/*****************************************************
     674get fileinfo for filename
     675*******************************************************/
     676static uint16 get_fileinfo(struct cli_state *cli, const char *filename)
     677{
     678        uint16_t fnum = (uint16_t)-1;
     679        uint16 mode = 0;
     680        NTSTATUS status;
     681
     682        /* The desired access below is the only one I could find that works
     683           with NT4, W2KP and Samba */
     684
     685        status = cli_ntcreate(cli, filename, 0, CREATE_ACCESS_READ,
     686                              0, FILE_SHARE_READ|FILE_SHARE_WRITE,
     687                              FILE_OPEN, 0x0, 0x0, &fnum);
     688        if (!NT_STATUS_IS_OK(status)) {
     689                printf("Failed to open %s: %s\n", filename, nt_errstr(status));
     690                return 0;
     691        }
     692
     693        status = cli_qfileinfo_basic(cli, fnum, &mode, NULL, NULL, NULL,
     694                                     NULL, NULL, NULL);
     695        if (!NT_STATUS_IS_OK(status)) {
     696                printf("Failed to file info %s: %s\n", filename,
     697                       nt_errstr(status));
     698        }
     699
     700        cli_close(cli, fnum);
     701
     702        return mode;
     703}
     704
     705/*****************************************************
     706get sec desc for filename
     707*******************************************************/
     708static struct security_descriptor *get_secdesc(struct cli_state *cli, const char *filename)
     709{
     710        uint16_t fnum = (uint16_t)-1;
     711        struct security_descriptor *sd;
     712        NTSTATUS status;
     713
     714        /* The desired access below is the only one I could find that works
     715           with NT4, W2KP and Samba */
     716
     717        status = cli_ntcreate(cli, filename, 0, CREATE_ACCESS_READ,
     718                              0, FILE_SHARE_READ|FILE_SHARE_WRITE,
     719                              FILE_OPEN, 0x0, 0x0, &fnum);
     720        if (!NT_STATUS_IS_OK(status)) {
     721                printf("Failed to open %s: %s\n", filename, nt_errstr(status));
     722                return NULL;
     723        }
     724
     725        sd = cli_query_secdesc(cli, fnum, talloc_tos());
     726
     727        cli_close(cli, fnum);
     728
     729        if (!sd) {
     730                printf("Failed to get security descriptor\n");
     731                return NULL;
     732        }
     733        return sd;
     734}
     735
     736/*****************************************************
     737set sec desc for filename
     738*******************************************************/
     739static bool set_secdesc(struct cli_state *cli, const char *filename,
     740                        struct security_descriptor *sd)
     741{
     742        uint16_t fnum = (uint16_t)-1;
     743        bool result=true;
     744        NTSTATUS status;
     745
     746        /* The desired access below is the only one I could find that works
     747           with NT4, W2KP and Samba */
     748
     749        status = cli_ntcreate(cli, filename, 0,
     750                              WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS,
     751                              0, FILE_SHARE_READ|FILE_SHARE_WRITE,
     752                              FILE_OPEN, 0x0, 0x0, &fnum);
     753        if (!NT_STATUS_IS_OK(status)) {
     754                printf("Failed to open %s: %s\n", filename, nt_errstr(status));
     755                return false;
     756        }
     757
     758        status = cli_set_secdesc(cli, fnum, sd);
     759        if (!NT_STATUS_IS_OK(status)) {
     760                printf("ERROR: security description set failed: %s\n",
     761                       nt_errstr(status));
     762                result=false;
     763        }
     764
     765        cli_close(cli, fnum);
     766        return result;
     767}
     768
     769/*****************************************************
    660770dump the acls for a file
    661771*******************************************************/
    662 static int cacl_dump(struct cli_state *cli, char *filename)
     772static int cacl_dump(struct cli_state *cli, const char *filename)
    663773{
    664774        int result = EXIT_FAILED;
    665         uint16_t fnum = (uint16_t)-1;
    666         SEC_DESC *sd;
    667 
    668         if (test_args)
     775        struct security_descriptor *sd;
     776
     777        if (test_args)
    669778                return EXIT_OK;
    670779
    671         if (!NT_STATUS_IS_OK(cli_ntcreate(cli, filename, 0, CREATE_ACCESS_READ, 0,
    672                                 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum))) {
    673                 printf("Failed to open %s: %s\n", filename, cli_errstr(cli));
    674                 goto done;
    675         }
    676 
    677         sd = cli_query_secdesc(cli, fnum, talloc_tos());
    678 
    679         if (!sd) {
    680                 printf("ERROR: secdesc query failed: %s\n", cli_errstr(cli));
    681                 goto done;
    682         }
    683 
    684         sec_desc_print(cli, stdout, sd);
    685 
    686         result = EXIT_OK;
    687 
    688 done:
    689         if (fnum != (uint16_t)-1)
    690                 cli_close(cli, fnum);
     780        sd = get_secdesc(cli, filename);
     781
     782        if (sd) {
     783                if (sddl) {
     784                        printf("%s\n", sddl_encode(talloc_tos(), sd,
     785                                           get_global_sam_sid()));
     786                } else {
     787                        sec_desc_print(cli, stdout, sd);
     788                }
     789                result = EXIT_OK;
     790        }
    691791
    692792        return result;
     
    701801                        const char *filename, const char *new_username)
    702802{
    703         uint16_t fnum;
    704         DOM_SID sid;
    705         SEC_DESC *sd, *old;
     803        struct dom_sid sid;
     804        struct security_descriptor *sd, *old;
    706805        size_t sd_size;
    707 
    708         if (!NT_STATUS_IS_OK(cli_ntcreate(cli, filename, 0, CREATE_ACCESS_READ, 0,
    709                                 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum))) {
    710                 printf("Failed to open %s: %s\n", filename, cli_errstr(cli));
    711                 return EXIT_FAILED;
    712         }
    713806
    714807        if (!StringToSid(cli, &sid, new_username))
    715808                return EXIT_PARSE_ERROR;
    716809
    717         old = cli_query_secdesc(cli, fnum, talloc_tos());
    718 
    719         cli_close(cli, fnum);
     810        old = get_secdesc(cli, filename);
    720811
    721812        if (!old) {
    722                 printf("owner_set: Failed to query old descriptor\n");
    723813                return EXIT_FAILED;
    724814        }
     
    729819                           NULL, NULL, &sd_size);
    730820
    731         if (!NT_STATUS_IS_OK(cli_ntcreate(cli, filename, 0, WRITE_OWNER_ACCESS, 0,
    732                         FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum))) {
    733                 printf("Failed to open %s: %s\n", filename, cli_errstr(cli));
     821        if (!set_secdesc(cli, filename, sd)) {
    734822                return EXIT_FAILED;
    735823        }
    736 
    737         if (!cli_set_secdesc(cli, fnum, sd)) {
    738                 printf("ERROR: secdesc set failed: %s\n", cli_errstr(cli));
    739                 cli_close(cli, fnum);
    740                 return EXIT_FAILED;
    741         }
    742 
    743         cli_close(cli, fnum);
    744824
    745825        return EXIT_OK;
     
    755835   Inherited ACEs unchanged" */
    756836
    757 static int ace_compare(SEC_ACE *ace1, SEC_ACE *ace2)
     837static int ace_compare(struct security_ace *ace1, struct security_ace *ace2)
    758838{
    759839        if (sec_ace_equal(ace1, ace2))
     
    773853                return ace2->type - ace1->type;
    774854
    775         if (sid_compare(&ace1->trustee, &ace2->trustee))
    776                 return sid_compare(&ace1->trustee, &ace2->trustee);
     855        if (dom_sid_compare(&ace1->trustee, &ace2->trustee))
     856                return dom_sid_compare(&ace1->trustee, &ace2->trustee);
    777857
    778858        if (ace1->flags != ace2->flags)
     
    785865                return ace1->size - ace2->size;
    786866
    787         return memcmp(ace1, ace2, sizeof(SEC_ACE));
    788 }
    789 
    790 static void sort_acl(SEC_ACL *the_acl)
     867        return memcmp(ace1, ace2, sizeof(struct security_ace));
     868}
     869
     870static void sort_acl(struct security_acl *the_acl)
    791871{
    792872        uint32 i;
    793873        if (!the_acl) return;
    794874
    795         qsort(the_acl->aces, the_acl->num_aces, sizeof(the_acl->aces[0]), QSORT_CAST ace_compare);
     875        TYPESAFE_QSORT(the_acl->aces, the_acl->num_aces, ace_compare);
    796876
    797877        for (i=1;i<the_acl->num_aces;) {
     
    812892*******************************************************/
    813893
    814 static int cacl_set(struct cli_state *cli, char *filename,
     894static int cacl_set(struct cli_state *cli, const char *filename,
    815895                    char *the_acl, enum acl_mode mode)
    816896{
    817         uint16_t fnum;
    818         SEC_DESC *sd, *old;
     897        struct security_descriptor *sd, *old;
    819898        uint32 i, j;
    820899        size_t sd_size;
    821900        int result = EXIT_OK;
    822901
    823         sd = sec_desc_parse(talloc_tos(), cli, the_acl);
     902        if (sddl) {
     903                sd = sddl_decode(talloc_tos(), the_acl, get_global_sam_sid());
     904        } else {
     905                sd = sec_desc_parse(talloc_tos(), cli, the_acl);
     906        }
    824907
    825908        if (!sd) return EXIT_PARSE_ERROR;
    826909        if (test_args) return EXIT_OK;
    827910
    828         /* The desired access below is the only one I could find that works
    829            with NT4, W2KP and Samba */
    830 
    831         if (!NT_STATUS_IS_OK(cli_ntcreate(cli, filename, 0, CREATE_ACCESS_READ, 0,
    832                                 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum))) {
    833                 printf("cacl_set failed to open %s: %s\n", filename, cli_errstr(cli));
     911        old = get_secdesc(cli, filename);
     912
     913        if (!old) {
    834914                return EXIT_FAILED;
    835915        }
    836 
    837         old = cli_query_secdesc(cli, fnum, talloc_tos());
    838 
    839         if (!old) {
    840                 printf("calc_set: Failed to query old descriptor\n");
    841                 return EXIT_FAILED;
    842         }
    843 
    844         cli_close(cli, fnum);
    845916
    846917        /* the logic here is rather more complex than I would like */
     
    876947
    877948                        for (j=0;old->dacl && j<old->dacl->num_aces;j++) {
    878                                 if (sid_equal(&sd->dacl->aces[i].trustee,
     949                                if (dom_sid_equal(&sd->dacl->aces[i].trustee,
    879950                                              &old->dacl->aces[j].trustee)) {
    880951                                        old->dacl->aces[j] = sd->dacl->aces[i];
     
    9291000                           NULL, old->dacl, &sd_size);
    9301001
    931         if (!NT_STATUS_IS_OK(cli_ntcreate(cli, filename, 0, WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS, 0,
    932                         FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum))) {
    933                 printf("cacl_set failed to open %s: %s\n", filename, cli_errstr(cli));
     1002        if (!set_secdesc(cli, filename, sd)) {
     1003                result = EXIT_FAILED;
     1004        }
     1005
     1006        return result;
     1007}
     1008
     1009/*****************************************************
     1010set the inherit on a file
     1011*******************************************************/
     1012static int inherit(struct cli_state *cli, const char *filename,
     1013                   const char *type)
     1014{
     1015        struct security_descriptor *old,*sd;
     1016        uint32 oldattr;
     1017        size_t sd_size;
     1018        int result = EXIT_OK;
     1019
     1020        old = get_secdesc(cli, filename);
     1021
     1022        if (!old) {
    9341023                return EXIT_FAILED;
    9351024        }
    9361025
    937         if (!cli_set_secdesc(cli, fnum, sd)) {
    938                 printf("ERROR: secdesc set failed: %s\n", cli_errstr(cli));
     1026        oldattr = get_fileinfo(cli,filename);
     1027
     1028        if (strcmp(type,"allow")==0) {
     1029                if ((old->type & SEC_DESC_DACL_PROTECTED) ==
     1030                    SEC_DESC_DACL_PROTECTED) {
     1031                        int i;
     1032                        char *parentname,*temp;
     1033                        struct security_descriptor *parent;
     1034                        temp = talloc_strdup(talloc_tos(), filename);
     1035
     1036                        old->type=old->type & (~SEC_DESC_DACL_PROTECTED);
     1037
     1038                        /* look at parent and copy in all its inheritable ACL's. */
     1039                        string_replace(temp, '\\', '/');
     1040                        if (!parent_dirname(talloc_tos(),temp,&parentname,NULL)) {
     1041                                return EXIT_FAILED;
     1042                        }
     1043                        string_replace(parentname, '/', '\\');
     1044                        parent = get_secdesc(cli,parentname);
     1045                        if (parent == NULL) {
     1046                                return EXIT_FAILED;
     1047                        }
     1048                        for (i=0;i<parent->dacl->num_aces;i++) {
     1049                                struct security_ace *ace=&parent->dacl->aces[i];
     1050                                /* Add inherited flag to all aces */
     1051                                ace->flags=ace->flags|
     1052                                           SEC_ACE_FLAG_INHERITED_ACE;
     1053                                if ((oldattr & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY) {
     1054                                        if ((ace->flags & SEC_ACE_FLAG_CONTAINER_INHERIT) ==
     1055                                            SEC_ACE_FLAG_CONTAINER_INHERIT) {
     1056                                                add_ace(&old->dacl, ace);
     1057                                        }
     1058                                } else {
     1059                                        if ((ace->flags & SEC_ACE_FLAG_OBJECT_INHERIT) ==
     1060                                            SEC_ACE_FLAG_OBJECT_INHERIT) {
     1061                                                /* clear flags for files */
     1062                                                ace->flags=0;
     1063                                                add_ace(&old->dacl, ace);
     1064                                        }
     1065                                }
     1066                        }
     1067                } else {
     1068                        printf("Already set to inheritable permissions.\n");
     1069                        return EXIT_FAILED;
     1070                }
     1071        } else if (strcmp(type,"remove")==0) {
     1072                if ((old->type & SEC_DESC_DACL_PROTECTED) !=
     1073                    SEC_DESC_DACL_PROTECTED) {
     1074                        old->type=old->type | SEC_DESC_DACL_PROTECTED;
     1075
     1076                        /* remove all inherited ACL's. */
     1077                        if (old->dacl) {
     1078                                int i;
     1079                                struct security_acl *temp=old->dacl;
     1080                                old->dacl=make_sec_acl(talloc_tos(), 3, 0, NULL);
     1081                                for (i=temp->num_aces-1;i>=0;i--) {
     1082                                        struct security_ace *ace=&temp->aces[i];
     1083                                        /* Remove all ace with INHERITED flag set */
     1084                                        if ((ace->flags & SEC_ACE_FLAG_INHERITED_ACE) !=
     1085                                            SEC_ACE_FLAG_INHERITED_ACE) {
     1086                                                add_ace(&old->dacl,ace);
     1087                                        }
     1088                                }
     1089                        }
     1090                } else {
     1091                        printf("Already set to no inheritable permissions.\n");
     1092                        return EXIT_FAILED;
     1093                }
     1094        } else if (strcmp(type,"copy")==0) {
     1095                if ((old->type & SEC_DESC_DACL_PROTECTED) !=
     1096                    SEC_DESC_DACL_PROTECTED) {
     1097                        old->type=old->type | SEC_DESC_DACL_PROTECTED;
     1098
     1099                        /* convert all inherited ACL's to non inherated ACL's. */
     1100                        if (old->dacl) {
     1101                                int i;
     1102                                for (i=0;i<old->dacl->num_aces;i++) {
     1103                                        struct security_ace *ace=&old->dacl->aces[i];
     1104                                        /* Remove INHERITED FLAG from all aces */
     1105                                        ace->flags=ace->flags&(~SEC_ACE_FLAG_INHERITED_ACE);
     1106                                }
     1107                        }
     1108                } else {
     1109                        printf("Already set to no inheritable permissions.\n");
     1110                        return EXIT_FAILED;
     1111                }
     1112        }
     1113
     1114        /* Denied ACE entries must come before allowed ones */
     1115        sort_acl(old->dacl);
     1116
     1117        sd = make_sec_desc(talloc_tos(),old->revision, old->type,
     1118                           old->owner_sid, old->group_sid,
     1119                           NULL, old->dacl, &sd_size);
     1120
     1121        if (!set_secdesc(cli, filename, sd)) {
    9391122                result = EXIT_FAILED;
    9401123        }
    9411124
    942         /* Clean up */
    943 
    944         cli_close(cli, fnum);
    945 
    9461125        return result;
    9471126}
    948 
    9491127
    9501128/*****************************************************
     
    9801158                                get_cmdline_auth_info_password(auth_info),
    9811159                                flags,
    982                                 get_cmdline_auth_info_signing_state(auth_info),
    983                                 NULL);
     1160                                get_cmdline_auth_info_signing_state(auth_info));
    9841161        if (!NT_STATUS_IS_OK(nt_status)) {
    9851162                DEBUG(0,("cli_full_connection failed! (%s)\n", nt_errstr(nt_status)));
     
    10241201                { "chown", 'C', POPT_ARG_STRING, NULL, 'C', "Change ownership of a file", "USERNAME" },
    10251202                { "chgrp", 'G', POPT_ARG_STRING, NULL, 'G', "Change group ownership of a file", "GROUPNAME" },
     1203                { "inherit", 'I', POPT_ARG_STRING, NULL, 'I', "Inherit allow|remove|copy" },
    10261204                { "numeric", 0, POPT_ARG_NONE, &numeric, 1, "Don't resolve sids or masks to names" },
     1205                { "sddl", 0, POPT_ARG_NONE, &sddl, 1, "Output and input acls in sddl format" },
    10271206                { "test-args", 't', POPT_ARG_NONE, &test_args, 1, "Test arguments"},
    10281207                POPT_COMMON_SAMBA
     
    10401219        load_case_tables();
    10411220
    1042 
    10431221        /* set default debug level to 1 regardless of what smb.conf sets */
    1044         setup_logging( "smbcacls", True );
    1045         DEBUGLEVEL_CLASS[DBGC_ALL] = 1;
    1046         dbf = x_stderr;
    1047         x_setbuf( x_stderr, NULL );
    1048         AllowDebugChange = false;
     1222        setup_logging( "smbcacls", DEBUG_STDERR);
     1223        lp_set_cmdline("log level", "1");
    10491224
    10501225        setlinebuf(stdout);
     
    10941269                        owner_username = poptGetOptArg(pc);
    10951270                        change_mode = REQUEST_CHGRP;
     1271                        break;
     1272
     1273                case 'I':
     1274                        owner_username = poptGetOptArg(pc);
     1275                        change_mode = REQUEST_INHERIT;
    10961276                        break;
    10971277                }
     
    11551335        /* Perform requested action */
    11561336
    1157         if (change_mode != REQUEST_NONE) {
     1337        if (change_mode == REQUEST_INHERIT) {
     1338                result = inherit(cli, filename, owner_username);
     1339        } else if (change_mode != REQUEST_NONE) {
    11581340                result = owner_set(cli, change_mode, filename, owner_username);
    11591341        } else if (the_acl) {
  • vendor/current/source3/utils/smbcontrol.c

    r414 r740  
    99   Copyright (C) Simo Sorce 2002
    1010   Copyright (C) James Peach 2006
    11    
     11
    1212   This program is free software; you can redistribute it and/or modify
    1313   it under the terms of the GNU General Public License as published by
    1414   the Free Software Foundation; either version 3 of the License, or
    1515   (at your option) any later version.
    16    
     16
    1717   This program is distributed in the hope that it will be useful,
    1818   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1919   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2020   GNU General Public License for more details.
    21    
     21
    2222   You should have received a copy of the GNU General Public License
    2323   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2525
    2626#include "includes.h"
     27#include "system/filesys.h"
     28#include "popt_common.h"
     29#include "librpc/gen_ndr/spoolss.h"
     30#include "nt_printing.h"
     31#include "printing/notify.h"
     32#include "libsmb/nmblib.h"
     33#include "messages.h"
     34#include "util_tdb.h"
    2735
    2836#if HAVE_LIBUNWIND_H
     
    6270        DEBUG(10,("smbcontrol/send_message: broadcast message to "
    6371                  "%d processes\n", n_sent));
    64        
     72
    6573        return ret;
    6674}
     
    110118                                DATA_BLOB *data)
    111119{
    112         printf("PID %u: %.*s", (unsigned int)procid_to_pid(&pid),
    113                (int)data->length, (const char *)data->data);
     120        char *pidstr;
     121
     122        pidstr = procid_str(talloc_tos(), &pid);
     123        printf("PID %s: %.*s", pidstr, (int)data->length,
     124               (const char *)data->data);
     125        TALLOC_FREE(pidstr);
    114126        num_replies++;
    115127}
     
    123135                            DATA_BLOB *data)
    124136{
    125         printf("%.*s", (int)data->length, (const char *)data->data);
     137        printf("%*s", (int)data->length, (const char *)data->data);
    126138        num_replies++;
    127139}
     
    158170                            strlen(argv[1]) + 1);
    159171}
     172
     173
     174static bool do_idmap(struct messaging_context *msg_ctx,
     175                     const struct server_id pid,
     176                     const int argc, const char **argv)
     177{
     178        static const char* usage = "Usage: "
     179                "smbcontrol <dest> idmap <cmd> [arg]\n"
     180                "\tcmd:\tflush [gid|uid]\n"
     181                "\t\tdelete \"UID <uid>\"|\"GID <gid>\"|<sid>\n"
     182                "\t\tkill \"UID <uid>\"|\"GID <gid>\"|<sid>\n";
     183        const char* arg = NULL;
     184        int arglen = 0;
     185        int msg_type;
     186
     187        switch (argc) {
     188        case 2:
     189                break;
     190        case 3:
     191                arg = argv[2];
     192                arglen = strlen(arg) + 1;
     193                break;
     194        default:
     195                fprintf(stderr, "%s", usage);
     196                return false;
     197        }
     198
     199        if (strcmp(argv[1], "flush") == 0) {
     200                msg_type = MSG_IDMAP_FLUSH;
     201        }
     202        else if (strcmp(argv[1], "delete") == 0) {
     203                msg_type = MSG_IDMAP_DELETE;
     204        }
     205        else if (strcmp(argv[1], "kill") == 0) {
     206                msg_type = MSG_IDMAP_KILL;
     207        }
     208        else if (strcmp(argv[1], "help") == 0) {
     209                fprintf(stdout, "%s", usage);
     210                return true;
     211        }
     212        else {
     213                fprintf(stderr, "%s", usage);
     214                return false;
     215        }
     216
     217        return send_message(msg_ctx, pid, msg_type, arg, arglen);
     218}
     219
    160220
    161221#if defined(HAVE_LIBUNWIND_PTRACE) && defined(HAVE_LINUX_PTRACE)
     
    260320}
    261321
    262 static int stack_trace_connection(struct db_record *rec,
    263                                   const struct connections_key *key,
     322static int stack_trace_connection(const struct connections_key *key,
    264323                                  const struct connections_data *crec,
    265324                                  void *priv)
     
    292351                print_stack_trace(dest, &count);
    293352        } else {
    294                 connections_forall(stack_trace_connection, &count);
     353                connections_forall_read(stack_trace_connection, &count);
    295354        }
    296355
     
    477536                break;
    478537        }
    479        
     538
    480539        printf("Profiling %s on pid %u\n",s,(unsigned int)procid_to_pid(&pid));
    481540}
     
    573632                fprintf(stderr, "\tprinter <printername> <comment|port|"
    574633                        "driver> <value>\n");
    575                
     634
    576635                return False;
    577636        }
     
    586645                        return False;
    587646                }
    588                
    589                 notify_printer_status_byname(argv[2], PRINTER_STATUS_PAUSED);
     647
     648                notify_printer_status_byname(messaging_event_context(msg_ctx),
     649                                             msg_ctx, argv[2],
     650                                             PRINTER_STATUS_PAUSED);
    590651
    591652                goto send;
     
    598659                        return False;
    599660                }
    600                
    601                 notify_printer_status_byname(argv[2], PRINTER_STATUS_OK);
     661
     662                notify_printer_status_byname(messaging_event_context(msg_ctx),
     663                                             msg_ctx, argv[2],
     664                                             PRINTER_STATUS_OK);
    602665
    603666                goto send;
     
    615678
    616679                notify_job_status_byname(
    617                         argv[2], jobid, JOB_STATUS_PAUSED,
     680                        messaging_event_context(msg_ctx), msg_ctx,
     681                        argv[2], jobid, JOB_STATUS_PAUSED,
    618682                        SPOOLSS_NOTIFY_MSG_UNIX_JOBID);
    619683
     
    632696
    633697                notify_job_status_byname(
     698                        messaging_event_context(msg_ctx), msg_ctx,
    634699                        argv[2], jobid, JOB_STATUS_QUEUED,
    635700                        SPOOLSS_NOTIFY_MSG_UNIX_JOBID);
     
    649714
    650715                notify_job_status_byname(
     716                        messaging_event_context(msg_ctx), msg_ctx,
    651717                        argv[2], jobid, JOB_STATUS_DELETING,
    652718                        SPOOLSS_NOTIFY_MSG_UNIX_JOBID);
    653                
     719
    654720                notify_job_status_byname(
     721                        messaging_event_context(msg_ctx), msg_ctx,
    655722                        argv[2], jobid, JOB_STATUS_DELETING|
    656723                        JOB_STATUS_DELETED,
     
    661728        } else if (strcmp(cmd, "printer") == 0) {
    662729                uint32 attribute;
    663                
     730
    664731                if (argc != 5) {
    665732                        fprintf(stderr, "Usage: smbcontrol <dest> printnotify "
     
    681748                }
    682749
    683                 notify_printer_byname(argv[2], attribute,
     750                notify_printer_byname(messaging_event_context(msg_ctx),
     751                                      msg_ctx, argv[2], attribute,
    684752                                      CONST_DISCARD(char *, argv[4]));
    685753
     
    708776
    709777        return send_message(msg_ctx, pid, MSG_SMB_FORCE_TDIS, argv[1],
     778                            strlen(argv[1]) + 1);
     779}
     780
     781/* Tell winbindd an IP got dropped */
     782
     783static bool do_ip_dropped(struct messaging_context *msg_ctx,
     784                          const struct server_id pid,
     785                          const int argc, const char **argv)
     786{
     787        if (argc != 2) {
     788                fprintf(stderr, "Usage: smbcontrol <dest> ip-dropped "
     789                        "<ip-address>\n");
     790                return False;
     791        }
     792
     793        return send_message(msg_ctx, pid, MSG_WINBIND_IP_DROPPED, argv[1],
    710794                            strlen(argv[1]) + 1);
    711795}
     
    903987        tdb = tdb_open_log(cache_path("winbindd_cache.tdb"),
    904988                                WINBINDD_CACHE_TDB_DEFAULT_HASH_SIZE,
    905                                 TDB_DEFAULT /* TDB_CLEAR_IF_FIRST */, O_RDWR|O_CREAT, 0600);
     989                                TDB_DEFAULT|TDB_INCOMPATIBLE_HASH /* TDB_CLEAR_IF_FIRST */,
     990                                O_RDWR|O_CREAT, 0600);
    906991
    907992        if (!tdb) {
     
    9351020                /* Check that the entry "WINBINDD_OFFLINE" still exists. */
    9361021                d = tdb_fetch_bystring( tdb, "WINBINDD_OFFLINE" );
    937        
     1022
    9381023                if (!d.dptr || d.dsize != 4) {
    9391024                        SAFE_FREE(d.dptr);
     
    9551040        struct server_id myid;
    9561041
    957         myid = pid_to_procid(sys_getpid());
     1042        myid = messaging_server_id(msg_ctx);
    9581043
    9591044        if (argc != 1) {
     
    9871072        struct server_id myid;
    9881073
    989         myid = pid_to_procid(sys_getpid());
     1074        myid = messaging_server_id(msg_ctx);
    9901075
    9911076        if (argc != 1) {
     
    10071092        int buf_len = 0;
    10081093
    1009         myid = pid_to_procid(sys_getpid());
     1094        myid = messaging_server_id(msg_ctx);
    10101095
    10111096        if (argc < 1 || argc > 2) {
    1012                 fprintf(stderr, "Usage: smbcontrol <dest> dump_domain_list "
     1097                fprintf(stderr, "Usage: smbcontrol <dest> dump-domain-list "
    10131098                        "<domain>\n");
    10141099                return false;
     
    10701155                                      const int argc, const char **argv)
    10711156{
    1072         struct server_id myid = pid_to_procid(sys_getpid());
     1157        struct server_id myid;
     1158
     1159        myid = messaging_server_id(msg_ctx);
    10731160
    10741161        if (argc != 1) {
     
    11661253} msg_types[] = {
    11671254        { "debug", do_debug, "Set debuglevel"  },
     1255        { "idmap", do_idmap, "Manipulate idmap cache" },
    11681256        { "force-election", do_election,
    11691257          "Force a browse election" },
     
    11781266        { "printnotify", do_printnotify, "Send a print notify message" },
    11791267        { "close-share", do_closeshare, "Forcibly disconnect a share" },
     1268        { "ip-dropped", do_ip_dropped, "Tell winbind that an IP got dropped" },
    11801269        { "lockretry", do_lockretry, "Force a blocking lock retry" },
    11811270        { "brl-revalidate", do_brl_revalidate, "Revalidate all brl entries" },
     
    12261315/* Return the pid number for a string destination */
    12271316
    1228 static struct server_id parse_dest(const char *dest)
     1317static struct server_id parse_dest(struct messaging_context *msg,
     1318                                   const char *dest)
    12291319{
    12301320        struct server_id result = {-1};
     
    12401330
    12411331        if (strequal(dest, "self")) {
    1242                 return pid_to_procid(sys_getpid());
     1332                return messaging_server_id(msg);
    12431333        }
    12441334
     
    12781368        /* Check destination */
    12791369
    1280         pid = parse_dest(dest);
     1370        pid = parse_dest(msg_ctx, dest);
    12811371        if (!procid_valid(&pid)) {
    12821372                return False;
     
    13431433        load_case_tables();
    13441434
    1345         setup_logging(argv[0],True);
    1346        
     1435        setup_logging(argv[0], DEBUG_STDOUT);
     1436
    13471437        /* Parse command line arguments using popt */
    13481438
     
    13871477         * routines mostly return True==1 for success, but
    13881478         * shell needs 0. */
    1389        
     1479
    13901480        if (!(evt_ctx = tevent_context_init(NULL)) ||
    1391             !(msg_ctx = messaging_init(NULL, server_id_self(), evt_ctx))) {
     1481            !(msg_ctx = messaging_init(NULL, procid_self(), evt_ctx))) {
    13921482                fprintf(stderr, "could not init messaging context\n");
    13931483                TALLOC_FREE(frame);
    13941484                exit(1);
    13951485        }
    1396        
     1486
    13971487        ret = !do_command(msg_ctx, argc, argv);
    13981488        TALLOC_FREE(frame);
  • vendor/current/source3/utils/smbcquotas.c

    r414 r740  
    22   Unix SMB/CIFS implementation.
    33   QUOTA get/set utility
    4    
     4
    55   Copyright (C) Andrew Tridgell                2000
    66   Copyright (C) Tim Potter                     2000
    77   Copyright (C) Jeremy Allison                 2000
    88   Copyright (C) Stefan (metze) Metzmacher      2003
    9    
     9
    1010   This program is free software; you can redistribute it and/or modify
    1111   it under the terms of the GNU General Public License as published by
    1212   the Free Software Foundation; either version 3 of the License, or
    1313   (at your option) any later version.
    14    
     14
    1515   This program is distributed in the hope that it will be useful,
    1616   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1717   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1818   GNU General Public License for more details.
    19    
     19
    2020   You should have received a copy of the GNU General Public License
    2121   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2323
    2424#include "includes.h"
     25#include "popt_common.h"
     26#include "rpc_client/cli_pipe.h"
     27#include "../librpc/gen_ndr/ndr_lsa.h"
     28#include "rpc_client/cli_lsarpc.h"
     29#include "fake_file.h"
     30#include "../libcli/security/security.h"
     31#include "libsmb/libsmb.h"
    2532
    2633static char *server;
     
    7380                got_policy_hnd = True;
    7481        }
    75        
     82
    7683        return True;
    7784}
    7885
    7986/* convert a SID to a string, either numeric or username/group */
    80 static void SidToString(fstring str, DOM_SID *sid, bool _numeric)
     87static void SidToString(fstring str, struct dom_sid *sid, bool _numeric)
    8188{
    8289        char **domains = NULL;
     
    103110                 domains[0], lp_winbind_separator(),
    104111                 names[0]);
    105        
    106112}
    107113
    108114/* convert a string to a SID, either numeric or username/group */
    109 static bool StringToSid(DOM_SID *sid, const char *str)
     115static bool StringToSid(struct dom_sid *sid, const char *str)
    110116{
    111117        enum lsa_SidType *types = NULL;
    112         DOM_SID *sids = NULL;
     118        struct dom_sid *sids = NULL;
    113119        bool result = True;
    114120
    115         if (strncmp(str, "S-", 2) == 0) {
    116                 return string_to_sid(sid, str);
     121        if (string_to_sid(sid, str)) {
     122                return true;
    117123        }
    118124
     
    224230}
    225231
     232
     233static const char *quota_str_static(uint64_t val, bool special, bool _numeric)
     234{
     235        const char *result;
     236
     237        if (!_numeric&&special&&(val == SMB_NTQUOTAS_NO_LIMIT)) {
     238                return "NO LIMIT";
     239        }
     240        result = talloc_asprintf(talloc_tos(), "%"PRIu64, val);
     241        SMB_ASSERT(result != NULL);
     242        return result;
     243}
     244
     245static void dump_ntquota(SMB_NTQUOTA_STRUCT *qt, bool _verbose,
     246                         bool _numeric,
     247                         void (*_sidtostring)(fstring str,
     248                                              struct dom_sid *sid,
     249                                              bool _numeric))
     250{
     251        TALLOC_CTX *frame = talloc_stackframe();
     252
     253        if (!qt) {
     254                smb_panic("dump_ntquota() called with NULL pointer");
     255        }
     256
     257        switch (qt->qtype) {
     258        case SMB_USER_FS_QUOTA_TYPE:
     259        {
     260                d_printf("File System QUOTAS:\n");
     261                d_printf("Limits:\n");
     262                d_printf(" Default Soft Limit: %15s\n",
     263                         quota_str_static(qt->softlim,True,_numeric));
     264                d_printf(" Default Hard Limit: %15s\n",
     265                         quota_str_static(qt->hardlim,True,_numeric));
     266                d_printf("Quota Flags:\n");
     267                d_printf(" Quotas Enabled: %s\n",
     268                         ((qt->qflags&QUOTAS_ENABLED)
     269                          ||(qt->qflags&QUOTAS_DENY_DISK))?"On":"Off");
     270                d_printf(" Deny Disk:      %s\n",
     271                         (qt->qflags&QUOTAS_DENY_DISK)?"On":"Off");
     272                d_printf(" Log Soft Limit: %s\n",
     273                         (qt->qflags&QUOTAS_LOG_THRESHOLD)?"On":"Off");
     274                d_printf(" Log Hard Limit: %s\n",
     275                         (qt->qflags&QUOTAS_LOG_LIMIT)?"On":"Off");
     276        }
     277        break;
     278        case SMB_USER_QUOTA_TYPE:
     279        {
     280                fstring username_str = {0};
     281
     282                if (_sidtostring) {
     283                        _sidtostring(username_str,&qt->sid,_numeric);
     284                } else {
     285                        sid_to_fstring(username_str, &qt->sid);
     286                }
     287
     288                if (_verbose) {
     289                        d_printf("Quotas for User: %s\n",username_str);
     290                        d_printf("Used Space: %15s\n",
     291                                 quota_str_static(qt->usedspace,False,
     292                                                  _numeric));
     293                        d_printf("Soft Limit: %15s\n",
     294                                 quota_str_static(qt->softlim,True,
     295                                                  _numeric));
     296                        d_printf("Hard Limit: %15s\n",
     297                                 quota_str_static(qt->hardlim,True,_numeric));
     298                } else {
     299                        d_printf("%-30s: ",username_str);
     300                        d_printf("%15s/",quota_str_static(
     301                                         qt->usedspace,False,_numeric));
     302                        d_printf("%15s/",quota_str_static(
     303                                         qt->softlim,True,_numeric));
     304                        d_printf("%15s\n",quota_str_static(
     305                                         qt->hardlim,True,_numeric));
     306                }
     307        }
     308        break;
     309        default:
     310                d_printf("dump_ntquota() invalid qtype(%d)\n",qt->qtype);
     311        }
     312        TALLOC_FREE(frame);
     313        return;
     314}
     315
     316static void dump_ntquota_list(SMB_NTQUOTA_LIST **qtl, bool _verbose,
     317                              bool _numeric,
     318                              void (*_sidtostring)(fstring str,
     319                                                   struct dom_sid *sid,
     320                                                   bool _numeric))
     321{
     322        SMB_NTQUOTA_LIST *cur;
     323
     324        for (cur = *qtl;cur;cur = cur->next) {
     325                if (cur->quotas)
     326                        dump_ntquota(cur->quotas,_verbose,_numeric,
     327                                     _sidtostring);
     328        }
     329}
     330
    226331static int do_quota(struct cli_state *cli,
    227332                enum SMB_QUOTA_TYPE qtype,
     
    234339        SMB_NTQUOTA_LIST *qtl = NULL;
    235340        SMB_NTQUOTA_STRUCT qt;
     341        NTSTATUS status;
     342
    236343        ZERO_STRUCT(qt);
    237344
    238         if (!cli_get_fs_attr_info(cli, &fs_attrs)) {
     345        status = cli_get_fs_attr_info(cli, &fs_attrs);
     346        if (!NT_STATUS_IS_OK(status)) {
    239347                d_printf("Failed to get the filesystem attributes %s.\n",
    240                         cli_errstr(cli));
     348                         nt_errstr(status));
    241349                return -1;
    242350        }
     
    247355        }
    248356
    249         if (!NT_STATUS_IS_OK(cli_get_quota_handle(cli, &quota_fnum))) {
     357        status = cli_get_quota_handle(cli, &quota_fnum);
     358        if (!NT_STATUS_IS_OK(status)) {
    250359                d_printf("Quotas are not enabled on this share.\n");
    251360                d_printf("Failed to open %s  %s.\n",
    252                         FAKE_FILE_NAME_QUOTA_WIN32,cli_errstr(cli));
     361                         FAKE_FILE_NAME_QUOTA_WIN32,
     362                         nt_errstr(status));
    253363                return -1;
    254364        }
     
    263373                        switch(cmd) {
    264374                                case QUOTA_GET:
    265                                         if (!cli_get_user_quota(cli, quota_fnum, &qt)) {
     375                                        status = cli_get_user_quota(
     376                                                cli, quota_fnum, &qt);
     377                                        if (!NT_STATUS_IS_OK(status)) {
    266378                                                d_printf("%s cli_get_user_quota %s\n",
    267                                                          cli_errstr(cli),username_str);
     379                                                         nt_errstr(status),
     380                                                         username_str);
    268381                                                return -1;
    269382                                        }
     
    272385                                case QUOTA_SETLIM:
    273386                                        pqt->sid = qt.sid;
    274                                         if (!cli_set_user_quota(cli, quota_fnum, pqt)) {
     387                                        status = cli_set_user_quota(
     388                                                cli, quota_fnum, pqt);
     389                                        if (!NT_STATUS_IS_OK(status)) {
    275390                                                d_printf("%s cli_set_user_quota %s\n",
    276                                                          cli_errstr(cli),username_str);
    277                                                 return -1;
    278                                         }
    279                                         if (!cli_get_user_quota(cli, quota_fnum, &qt)) {
     391                                                         nt_errstr(status),
     392                                                         username_str);
     393                                                return -1;
     394                                        }
     395                                        status = cli_get_user_quota(
     396                                                cli, quota_fnum, &qt);
     397                                        if (!NT_STATUS_IS_OK(status)) {
    280398                                                d_printf("%s cli_get_user_quota %s\n",
    281                                                          cli_errstr(cli),username_str);
     399                                                         nt_errstr(status),
     400                                                         username_str);
    282401                                                return -1;
    283402                                        }
     
    285404                                        break;
    286405                                case QUOTA_LIST:
    287                                         if (!cli_list_user_quota(cli, quota_fnum, &qtl)) {
     406                                        status = cli_list_user_quota(
     407                                                cli, quota_fnum, &qtl);
     408                                        if (!NT_STATUS_IS_OK(status)) {
    288409                                                d_printf("%s cli_set_user_quota %s\n",
    289                                                          cli_errstr(cli),username_str);
     410                                                         nt_errstr(status),
     411                                                         username_str);
    290412                                                return -1;
    291413                                        }
     
    301423                        switch(cmd) {
    302424                                case QUOTA_GET:
    303                                         if (!cli_get_fs_quota_info(cli, quota_fnum, &qt)) {
     425                                        status = cli_get_fs_quota_info(
     426                                                cli, quota_fnum, &qt);
     427                                        if (!NT_STATUS_IS_OK(status)) {
    304428                                                d_printf("%s cli_get_fs_quota_info\n",
    305                                                          cli_errstr(cli));
     429                                                         nt_errstr(status));
    306430                                                return -1;
    307431                                        }
     
    309433                                        break;
    310434                                case QUOTA_SETLIM:
    311                                         if (!cli_get_fs_quota_info(cli, quota_fnum, &qt)) {
     435                                        status = cli_get_fs_quota_info(
     436                                                cli, quota_fnum, &qt);
     437                                        if (!NT_STATUS_IS_OK(status)) {
    312438                                                d_printf("%s cli_get_fs_quota_info\n",
    313                                                          cli_errstr(cli));
     439                                                         nt_errstr(status));
    314440                                                return -1;
    315441                                        }
    316442                                        qt.softlim = pqt->softlim;
    317443                                        qt.hardlim = pqt->hardlim;
    318                                         if (!cli_set_fs_quota_info(cli, quota_fnum, &qt)) {
     444                                        status = cli_set_fs_quota_info(
     445                                                cli, quota_fnum, &qt);
     446                                        if (!NT_STATUS_IS_OK(status)) {
    319447                                                d_printf("%s cli_set_fs_quota_info\n",
    320                                                          cli_errstr(cli));
    321                                                 return -1;
    322                                         }
    323                                         if (!cli_get_fs_quota_info(cli, quota_fnum, &qt)) {
     448                                                         nt_errstr(status));
     449                                                return -1;
     450                                        }
     451                                        status = cli_get_fs_quota_info(
     452                                                cli, quota_fnum, &qt);
     453                                        if (!NT_STATUS_IS_OK(status)) {
    324454                                                d_printf("%s cli_get_fs_quota_info\n",
    325                                                          cli_errstr(cli));
     455                                                         nt_errstr(status));
    326456                                                return -1;
    327457                                        }
     
    329459                                        break;
    330460                                case QUOTA_SETFLAGS:
    331                                         if (!cli_get_fs_quota_info(cli, quota_fnum, &qt)) {
     461                                        status = cli_get_fs_quota_info(
     462                                                cli, quota_fnum, &qt);
     463                                        if (!NT_STATUS_IS_OK(status)) {
    332464                                                d_printf("%s cli_get_fs_quota_info\n",
    333                                                          cli_errstr(cli));
     465                                                         nt_errstr(status));
    334466                                                return -1;
    335467                                        }
    336468                                        qt.qflags = pqt->qflags;
    337                                         if (!cli_set_fs_quota_info(cli, quota_fnum, &qt)) {
     469                                        status = cli_set_fs_quota_info(
     470                                                cli, quota_fnum, &qt);
     471                                        if (!NT_STATUS_IS_OK(status)) {
    338472                                                d_printf("%s cli_set_fs_quota_info\n",
    339                                                          cli_errstr(cli));
    340                                                 return -1;
    341                                         }
    342                                         if (!cli_get_fs_quota_info(cli, quota_fnum, &qt)) {
     473                                                         nt_errstr(status));
     474                                                return -1;
     475                                        }
     476                                        status = cli_get_fs_quota_info(
     477                                                cli, quota_fnum, &qt);
     478                                        if (!NT_STATUS_IS_OK(status)) {
    343479                                                d_printf("%s cli_get_fs_quota_info\n",
    344                                                          cli_errstr(cli));
     480                                                         nt_errstr(status));
    345481                                                return -1;
    346482                                        }
     
    395531                                            get_cmdline_auth_info_password(smbcquotas_auth_info),
    396532                                            flags,
    397                                             get_cmdline_auth_info_signing_state(smbcquotas_auth_info),
    398                                             NULL);
     533                                            get_cmdline_auth_info_signing_state(smbcquotas_auth_info));
    399534        if (!NT_STATUS_IS_OK(nt_status)) {
    400535                DEBUG(0,("cli_full_connection failed! (%s)\n", nt_errstr(nt_status)));
     
    460595
    461596        /* set default debug level to 1 regardless of what smb.conf sets */
    462         setup_logging( "smbcquotas", True );
    463         DEBUGLEVEL_CLASS[DBGC_ALL] = 1;
    464         dbf = x_stderr;
    465         x_setbuf( x_stderr, NULL );
     597        setup_logging( "smbcquotas", DEBUG_STDERR);
     598        lp_set_cmdline("log level", "1");
    466599
    467600        setlinebuf(stdout);
     
    608741                        break;
    609742                default:
    610                        
    611743                        result = EXIT_FAILED;
    612744                        break;
  • vendor/current/source3/utils/smbfilter.c

    r591 r740  
    33   SMB filter/socket plugin
    44   Copyright (C) Andrew Tridgell 1999
    5    
     5
    66   This program is free software; you can redistribute it and/or modify
    77   it under the terms of the GNU General Public License as published by
    88   the Free Software Foundation; either version 3 of the License, or
    99   (at your option) any later version.
    10    
     10
    1111   This program is distributed in the hope that it will be useful,
    1212   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1313   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1414   GNU General Public License for more details.
    15    
     15
    1616   You should have received a copy of the GNU General Public License
    1717   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    1919
    2020#include "includes.h"
     21#include "system/filesys.h"
     22#include "system/select.h"
     23#include "../lib/util/select.h"
     24#include "libsmb/nmblib.h"
    2125
    2226#define SECURITY_MASK 0
     
    4448        if (write(fd, ppacket, length) != length) {
    4549                fprintf(stderr,"Failed to write %s\n", fname);
     50                close(fd);
    4651                return;
    4752        }
     
    190195
    191196        while (c != -1 || s != -1) {
    192                 fd_set fds;
    193                 int num;
    194                
    195                 FD_ZERO(&fds);
    196                 if (s >= 0 && s < FD_SETSIZE) FD_SET(s, &fds);
    197                 if (c >= 0 && c < FD_SETSIZE) FD_SET(c, &fds);
    198 
    199                 num = sys_select_intr(MAX(s+1, c+1),&fds,NULL,NULL,NULL);
    200                 if (num <= 0) continue;
    201                
    202                 if (c != -1 && FD_ISSET(c, &fds)) {
     197                struct pollfd fds[2];
     198                int num_fds, ret;
     199
     200                memset(fds, 0, sizeof(struct pollfd) * 2);
     201                fds[0].fd = -1;
     202                fds[1].fd = -1;
     203                num_fds = 0;
     204
     205                if (s != -1) {
     206                        fds[num_fds].fd = s;
     207                        fds[num_fds].events = POLLIN|POLLHUP;
     208                        num_fds += 1;
     209                }
     210                if (c != -1) {
     211                        fds[num_fds].fd = c;
     212                        fds[num_fds].events = POLLIN|POLLHUP;
     213                        num_fds += 1;
     214                }
     215
     216                ret = sys_poll_intr(fds, num_fds, -1);
     217                if (ret <= 0) {
     218                        continue;
     219                }
     220
     221                /*
     222                 * find c in fds and see if it's readable
     223                 */
     224                if ((c != -1) &&
     225                    (((fds[0].fd == c)
     226                      && (fds[0].revents & (POLLIN|POLLHUP|POLLERR))) ||
     227                     ((fds[1].fd == c)
     228                      && (fds[1].revents & (POLLIN|POLLHUP|POLLERR))))) {
    203229                        size_t len;
    204230                        if (!NT_STATUS_IS_OK(receive_smb_raw(
     
    214240                        }                       
    215241                }
    216                 if (s != -1 && FD_ISSET(s, &fds)) {
     242
     243                /*
     244                 * find s in fds and see if it's readable
     245                 */
     246                if ((s != -1) &&
     247                    (((fds[0].fd == s)
     248                      && (fds[0].revents & (POLLIN|POLLHUP|POLLERR))) ||
     249                     ((fds[1].fd == s)
     250                      && (fds[1].revents & (POLLIN|POLLHUP|POLLERR))))) {
    217251                        size_t len;
    218252                        if (!NT_STATUS_IS_OK(receive_smb_raw(
     
    246280        zero_sockaddr(&my_ss);
    247281        s = open_socket_in(SOCK_STREAM, 445, 0, &my_ss, True);
    248        
     282
    249283        if (s == -1) {
    250284                d_printf("bind failed\n");
     
    262296
    263297        while (1) {
    264                 fd_set fds;
    265                 int num;
     298                int num, revents;
    266299                struct sockaddr_storage ss;
    267300                socklen_t in_addrlen = sizeof(ss);
    268                
    269                 FD_ZERO(&fds);
    270                 if (s < 0 || s >= FD_SETSIZE) {
    271                         break;
    272                 }
    273                 FD_SET(s, &fds);
    274 
    275                 num = sys_select_intr(s+1,&fds,NULL,NULL,NULL);
    276                 if (num > 0) {
     301
     302                num = poll_intr_one_fd(s, POLLIN|POLLHUP, -1, &revents);
     303                if ((num > 0) && (revents & (POLLIN|POLLHUP|POLLERR))) {
    277304                        c = accept(s, (struct sockaddr *)&ss, &in_addrlen);
    278305                        if (c != -1) {
     
    298325        load_case_tables();
    299326
    300         setup_logging(argv[0],True);
     327        setup_logging(argv[0], DEBUG_STDOUT);
    301328
    302329        configfile = get_dyn_CONFIGFILE();
  • vendor/current/source3/utils/smbget.c

    r597 r740  
    88   the Free Software Foundation; either version 3 of the License, or
    99   (at your option) any later version.
    10    
     10
    1111   This program is distributed in the hope that it will be useful,
    1212   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1313   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1414   GNU General Public License for more details.
    15    
     15
    1616   You should have received a copy of the GNU General Public License
    1717   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
    1818
    1919#include "includes.h"
     20#include "system/filesys.h"
     21#include "popt_common.h"
    2022#include "libsmbclient.h"
    2123
     
    5052static int blocksize = SMB_DEFAULT_BLOCKSIZE;
    5153
    52 static int smb_download_file(const char *base, const char *name, int recursive, int resume, char *outfile);
     54static int smb_download_file(const char *base, const char *name, int recursive,
     55                             int resume, int toplevel, char *outfile);
    5356
    5457static int get_num_cols(void)
     
    7578static void human_readable(off_t s, char *buffer, int l)
    7679{
    77         if(s > 1024 * 1024 * 1024) snprintf(buffer, l, "%.2fGB",
    78                                             1.0 * s / (1024 * 1024 * 1024));
    79         else if(s > 1024 * 1024) snprintf(buffer, l, "%.2fMB",
    80                                           1.0 * s / (1024 * 1024));
    81         else if(s > 1024) snprintf(buffer, l, "%.2fkB", 1.0 * s / 1024);
    82         else snprintf(buffer, l, OFF_T_FORMAT"b", (OFF_T_FORMAT_CAST)s);
     80        if (s > 1024 * 1024 * 1024) {
     81                snprintf(buffer, l, "%.2fGB", 1.0 * s / (1024 * 1024 * 1024));
     82        } else if (s > 1024 * 1024) {
     83                snprintf(buffer, l, "%.2fMB", 1.0 * s / (1024 * 1024));
     84        } else if (s > 1024) {
     85                snprintf(buffer, l, "%.2fkB", 1.0 * s / 1024);
     86        } else {
     87                snprintf(buffer, l, OFF_T_FORMAT"b", (OFF_T_FORMAT_CAST)s);
     88        }
    8389}
    8490
     
    138144        dirhandle = smbc_opendir(path);
    139145        if(dirhandle < 1) {
    140                 if(errno == ENOTDIR) return smb_download_file(base, name, 1, resume, NULL);
     146                if (errno == ENOTDIR) {
     147                        return smb_download_file(base, name, 1, resume,
     148                                                 0, NULL);
     149                }
    141150                fprintf(stderr, "Can't open directory %s: %s\n", path, strerror(errno));
    142151                return 1;
     
    145154        while(*relname == '/')relname++;
    146155        mkdir(relname, 0755);
    147        
     156
    148157        tmpname = SMB_STRDUP(name);
    149158
     
    168177
    169178                case SMBC_FILE:
    170                         ret = smb_download_file(base, newname, 1, resume, NULL);
     179                        ret = smb_download_file(base, newname, 1, resume, 0,
     180                                                NULL);
    171181                        break;
    172182
     
    182192                        if(!quiet)printf("Ignoring comms share %s\n", dirent->name);
    183193                        break;
    184                        
     194
    185195                case SMBC_IPC_SHARE:
    186196                        if(!quiet)printf("Ignoring ipc$ share %s\n", dirent->name);
     
    201211                        return 1;
    202212                }
    203                
     213
    204214                if(chmod(relname, remotestat.st_mode) < 0) {
    205215                        fprintf(stderr, "Unable to change mode of local dir %s to %o\n", relname,
     
    250260                return;
    251261        }
    252        
     262
    253263        if(columns) {
    254264                int required = strlen(name), available = columns - len - strlen("[] ");
     
    269279/* Return 1 on error, 0 on success. */
    270280
    271 static int smb_download_file(const char *base, const char *name, int recursive, int resume, char *outfile) {
     281static int smb_download_file(const char *base, const char *name, int recursive,
     282                             int resume, int toplevel, char *outfile)
     283{
    272284        int remotehandle, localhandle;
    273         time_t start_time = time(NULL);
     285        time_t start_time = time_mono(NULL);
    274286        const char *newpath;
    275287        char path[SMB_MAXPATHLEN];
     
    280292
    281293        snprintf(path, SMB_MAXPATHLEN-1, "%s%s%s", base, (*base && *name && name[0] != '/' && base[strlen(base)-1] != '/')?"/":"", name);
    282        
     294
    283295        remotehandle = smbc_open(path, O_RDONLY, 0755);
    284296
     
    325337        } else newpath = name;
    326338
    327         if(newpath[0] == '/')newpath++;
    328        
     339        if (!toplevel && (newpath[0] == '/')) {
     340                newpath++;
     341        }
     342
    329343        /* Open local file according to the mode */
    330344        if(update) {
     
    353367                        return 1;
    354368                }
    355        
     369
    356370                if (fstat(localhandle, &localstat) != 0) {
    357371                        fprintf(stderr, "Can't fstat %s: %s\n", newpath, strerror(errno));
     
    404418                                        (OFF_T_FORMAT_CAST)off1,
    405419                                        (OFF_T_FORMAT_CAST)off2);
     420                                smbc_close(remotehandle); close(localhandle);
    406421                                return 1;
    407422                        }
     
    435450
    436451        readbuf = (char *)SMB_MALLOC(blocksize);
     452        if (!readbuf) {
     453                return 1;
     454        }
    437455
    438456        /* Now, download all bytes from offset_download to the end */
     
    459477                if(dots)fputc('.', stderr);
    460478                else if(!quiet) {
    461                         print_progress(newpath, start_time, time(NULL), start_offset, curpos, remotestat.st_size);
     479                        print_progress(newpath, start_time, time_mono(NULL),
     480                                        start_offset, curpos, remotestat.st_size);
    462481                }
    463482        }
     
    499518        human_readable(total_bytes, bs, sizeof(bs));
    500519        if(!quiet)fprintf(stderr, "Downloaded %s in %lu seconds\n", bs,
    501                 (unsigned long)(time(NULL) - total_start_time));
     520                (unsigned long)(time_mono(NULL) - total_start_time));
    502521        exit(0);
    503522}
     
    655674                        "require");
    656675        }
    657        
     676
    658677        columns = get_num_cols();
    659678
    660         total_start_time = time(NULL);
     679        total_start_time = time_mono(NULL);
    661680
    662681        while ( (file = poptGetArg(pc)) ) {
    663682                if (!recursive)
    664                         ret = smb_download_file(file, "", recursive, resume, outputfile);
     683                        ret = smb_download_file(file, "", recursive, resume,
     684                                                1, outputfile);
    665685                else
    666686                        ret = smb_download_dir(file, "", resume);
  • vendor/current/source3/utils/smbpasswd.c

    r414 r740  
    1818
    1919#include "includes.h"
    20 
    21 extern bool AllowDebugChange;
     20#include "system/passwd.h"
     21#include "secrets.h"
     22#include "../librpc/gen_ndr/samr.h"
     23#include "../lib/util/util_pw.h"
     24#include "passdb.h"
    2225
    2326/*
     
    153156                        break;
    154157                case 'D':
    155                         DEBUGLEVEL = atoi(optarg);
     158                        lp_set_cmdline("log level", optarg);
    156159                        break;
    157160                case 'U': {
     
    341344        }
    342345
    343         if (!user_name[0] && (pwd = getpwuid_alloc(talloc_autofree_context(), geteuid()))) {
     346        if (!user_name[0] && (pwd = getpwuid_alloc(talloc_tos(), geteuid()))) {
    344347                fstrcpy(user_name, pwd->pw_name);
    345348                TALLOC_FREE(pwd);
     
    506509
    507510        if (!user_name[0]) {
    508                 pwd = getpwuid_alloc(talloc_autofree_context(), getuid());
     511                pwd = getpwuid_alloc(talloc_tos(), getuid());
    509512                if (pwd) {
    510513                        fstrcpy(user_name,pwd->pw_name);
     
    569572        int ret;
    570573
    571         AllowDebugChange = False;
    572 
    573574#if defined(HAVE_SET_AUTH_PARAMETERS)
    574575        set_auth_parameters(argc, argv);
     
    583584        local_flags = process_options(argc, argv, local_flags);
    584585
    585         setup_logging("smbpasswd", True);
     586        setup_logging("smbpasswd", DEBUG_STDERR);
    586587
    587588        /*
  • vendor/current/source3/utils/smbtree.c

    r414 r740  
    2121
    2222#include "includes.h"
    23 #include "../librpc/gen_ndr/cli_srvsvc.h"
     23#include "popt_common.h"
     24#include "rpc_client/cli_pipe.h"
     25#include "../librpc/gen_ndr/ndr_srvsvc_c.h"
     26#include "libsmb/libsmb.h"
     27#include "libsmb/clirap.h"
    2428
    2529static int use_bcast;
     
    158162        uint32_t resume_handle = 0;
    159163        uint32_t total_entries = 0;
     164        struct dcerpc_binding_handle *b;
    160165
    161166        mem_ctx = talloc_new(NULL);
     
    175180        }
    176181
     182        b = pipe_hnd->binding_handle;
     183
    177184        ZERO_STRUCT(info_ctr);
    178185        ZERO_STRUCT(ctr1);
     
    181188        info_ctr.ctr.ctr1 = &ctr1;
    182189
    183         status = rpccli_srvsvc_NetShareEnumAll(pipe_hnd, mem_ctx,
     190        status = dcerpc_srvsvc_NetShareEnumAll(b, mem_ctx,
    184191                                               pipe_hnd->desthost,
    185192                                               &info_ctr,
     
    291298        setlinebuf(stdout);
    292299
    293         dbf = x_stderr;
    294 
    295         setup_logging(argv[0],True);
     300        setup_logging(argv[0], DEBUG_STDERR);
    296301
    297302        auth_info = user_auth_info_init(frame);
  • vendor/current/source3/utils/status.c

    r414 r740  
    3232
    3333#include "includes.h"
     34#include "system/filesys.h"
     35#include "popt_common.h"
     36#include "dbwrap.h"
     37#include "../libcli/security/security.h"
     38#include "session.h"
     39#include "locking/proto.h"
     40#include "messages.h"
    3441
    3542#define SMB_MAXPIDS             2048
     
    233240}
    234241
    235 static int traverse_fn1(struct db_record *rec,
    236                         const struct connections_key *key,
     242static int traverse_fn1(const struct connections_key *key,
    237243                        const struct connections_data *crec,
    238244                        void *state)
     
    253259}
    254260
    255 static int traverse_sessionid(struct db_record *db, void *state)
    256 {
    257         struct sessionid sessionid;
     261static int traverse_sessionid(const char *key, struct sessionid *session,
     262                              void *private_data)
     263{
    258264        fstring uid_str, gid_str;
    259265
    260         if (db->value.dsize != sizeof(sessionid))
     266        if (!process_exists(session->pid)
     267            || !Ucrit_checkUid(session->uid)) {
    261268                return 0;
    262 
    263         memcpy(&sessionid, db->value.dptr, sizeof(sessionid));
    264 
    265         if (!process_exists(sessionid.pid) || !Ucrit_checkUid(sessionid.uid)) {
    266                 return 0;
    267         }
    268 
    269         Ucrit_addPid( sessionid.pid );
    270 
    271         fstr_sprintf(uid_str, "%u", (unsigned int)sessionid.uid);
    272         fstr_sprintf(gid_str, "%u", (unsigned int)sessionid.gid);
     269        }
     270
     271        Ucrit_addPid(session->pid);
     272
     273        fstr_sprintf(uid_str, "%u", (unsigned int)session->uid);
     274        fstr_sprintf(gid_str, "%u", (unsigned int)session->gid);
    273275
    274276        d_printf("%-7s   %-12s  %-12s  %-12s (%s)\n",
    275                  procid_str_static(&sessionid.pid),
    276                  numeric_only ? uid_str : uidtoname(sessionid.uid),
    277                  numeric_only ? gid_str : gidtoname(sessionid.gid),
    278                  sessionid.remote_machine, sessionid.hostname);
     277                 procid_str_static(&session->pid),
     278                 numeric_only ? uid_str : uidtoname(session->uid),
     279                 numeric_only ? gid_str : gidtoname(session->gid),
     280                 session->remote_machine, session->hostname);
    279281
    280282        return 0;
     
    312314        load_case_tables();
    313315
    314         setup_logging(argv[0],True);
    315 
    316         dbf = x_stderr;
     316        setup_logging(argv[0], DEBUG_STDERR);
    317317
    318318        if (getuid() != geteuid()) {
     
    413413
    414414        if ( show_processes ) {
    415                 struct db_context *db;
    416                 db = db_open(NULL, lock_path("sessionid.tdb"), 0,
    417                              TDB_CLEAR_IF_FIRST, O_RDONLY, 0644);
    418                 if (!db) {
    419                         d_printf("sessionid.tdb not initialised\n");
    420                 } else {
    421                         d_printf("\nSamba version %s\n",samba_version_string());
    422                         d_printf("PID     Username      Group         Machine                        \n");
    423                         d_printf("-------------------------------------------------------------------\n");
    424                         if (lp_security() == SEC_SHARE) {
    425                                 d_printf(" <processes do not show up in "
    426                                     "anonymous mode>\n");
    427                         }
    428 
    429                         db->traverse_read(db, traverse_sessionid, NULL);
    430                         TALLOC_FREE(db);
    431                 }
     415                d_printf("\nSamba version %s\n",samba_version_string());
     416                d_printf("PID     Username      Group         Machine                        \n");
     417                d_printf("-------------------------------------------------------------------\n");
     418                if (lp_security() == SEC_SHARE) {
     419                        d_printf(" <processes do not show up in "
     420                                 "anonymous mode>\n");
     421                }
     422
     423                sessionid_traverse_read(traverse_sessionid, NULL);
    432424
    433425                if (processes_only) {
     
    448440                d_printf("-------------------------------------------------------\n");
    449441
    450                 connections_forall(traverse_fn1, NULL);
     442                connections_forall_read(traverse_fn1, NULL);
    451443
    452444                d_printf("\n");
     
    461453                struct db_context *db;
    462454                db = db_open(NULL, lock_path("locking.tdb"), 0,
    463                              TDB_CLEAR_IF_FIRST, O_RDONLY, 0);
     455                             TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, O_RDONLY, 0);
    464456
    465457                if (!db) {
  • vendor/current/source3/utils/status_profile.c

    r414 r740  
    2020
    2121#include "includes.h"
     22#include "smbprofile.h"
    2223
    2324bool status_profile_dump(bool be_verbose);
     
    5859        d_printf("opendir_count:                  %u\n", profile_p->syscall_opendir_count);
    5960        d_printf("opendir_time:                   %u\n", profile_p->syscall_opendir_time);
     61        d_printf("fdopendir_count:                %u\n", profile_p->syscall_fdopendir_count);
     62        d_printf("fdopendir_time:                 %u\n", profile_p->syscall_fdopendir_time);
    6063        d_printf("readdir_count:                  %u\n", profile_p->syscall_readdir_count);
    6164        d_printf("readdir_time:                   %u\n", profile_p->syscall_readdir_time);
     
    8285        d_printf("pwrite_time:                    %u\n", profile_p->syscall_pwrite_time);
    8386        d_printf("pwrite_bytes:                   %u\n", profile_p->syscall_pwrite_bytes);
    84 #ifdef WITH_SENDFILE
    8587        d_printf("sendfile_count:                 %u\n", profile_p->syscall_sendfile_count);
    8688        d_printf("sendfile_time:                  %u\n", profile_p->syscall_sendfile_time);
    8789        d_printf("sendfile_bytes:                 %u\n", profile_p->syscall_sendfile_bytes);
    88 #endif
    8990        d_printf("lseek_count:                    %u\n", profile_p->syscall_lseek_count);
    9091        d_printf("lseek_time:                     %u\n", profile_p->syscall_lseek_time);
     
    401402        d_printf("election_count:                 %u\n", profile_p->election_count);
    402403        d_printf("election_time:                  %u\n", profile_p->election_time);
     404        profile_separator("SMB2 Calls");
     405        d_printf("smb2_negprot_count:             %u\n", profile_p->smb2_negprot_count);
     406        d_printf("smb2_negprot_time:              %u\n", profile_p->smb2_negprot_time);
     407        d_printf("smb2_sesssetup_count:           %u\n", profile_p->smb2_sesssetup_count);
     408        d_printf("smb2_sesssetup_time:            %u\n", profile_p->smb2_sesssetup_time);
     409        d_printf("smb2_logoff_count:              %u\n", profile_p->smb2_logoff_count);
     410        d_printf("smb2_logoff_time:               %u\n", profile_p->smb2_logoff_time);
     411        d_printf("smb2_tcon_count:                %u\n", profile_p->smb2_tcon_count);
     412        d_printf("smb2_tcon_time:                 %u\n", profile_p->smb2_tcon_time);
     413        d_printf("smb2_tdis_count:                %u\n", profile_p->smb2_tdis_count);
     414        d_printf("smb2_tdis_time:                 %u\n", profile_p->smb2_tdis_time);
     415        d_printf("smb2_create_count:              %u\n", profile_p->smb2_create_count);
     416        d_printf("smb2_create_time:               %u\n", profile_p->smb2_create_time);
     417        d_printf("smb2_close_count:               %u\n", profile_p->smb2_close_count);
     418        d_printf("smb2_close_time:                %u\n", profile_p->smb2_close_time);
     419        d_printf("smb2_flush_count:               %u\n", profile_p->smb2_flush_count);
     420        d_printf("smb2_flush_time:                %u\n", profile_p->smb2_flush_time);
     421        d_printf("smb2_read_count:                %u\n", profile_p->smb2_read_count);
     422        d_printf("smb2_read_time:                 %u\n", profile_p->smb2_read_time);
     423        d_printf("smb2_write_count:               %u\n", profile_p->smb2_write_count);
     424        d_printf("smb2_write_time:                %u\n", profile_p->smb2_write_time);
     425        d_printf("smb2_lock_count:                %u\n", profile_p->smb2_lock_count);
     426        d_printf("smb2_lock_time:                 %u\n", profile_p->smb2_lock_time);
     427        d_printf("smb2_ioctl_count:               %u\n", profile_p->smb2_ioctl_count);
     428        d_printf("smb2_ioctl_time:                %u\n", profile_p->smb2_ioctl_time);
     429        d_printf("smb2_cancel_count:              %u\n", profile_p->smb2_cancel_count);
     430        d_printf("smb2_cancel_time:               %u\n", profile_p->smb2_cancel_time);
     431        d_printf("smb2_keepalive_count:           %u\n", profile_p->smb2_keepalive_count);
     432        d_printf("smb2_keepalive_time:            %u\n", profile_p->smb2_keepalive_time);
     433        d_printf("smb2_find_count:                %u\n", profile_p->smb2_find_count);
     434        d_printf("smb2_find_time:                 %u\n", profile_p->smb2_find_time);
     435        d_printf("smb2_notify_count:              %u\n", profile_p->smb2_notify_count);
     436        d_printf("smb2_notify_time:               %u\n", profile_p->smb2_notify_time);
     437        d_printf("smb2_getinfo_count:             %u\n", profile_p->smb2_getinfo_count);
     438        d_printf("smb2_getinfo_time:              %u\n", profile_p->smb2_getinfo_time);
     439        d_printf("smb2_setinfo_count:             %u\n", profile_p->smb2_setinfo_count);
     440        d_printf("smb2_setinfo_time:              %u\n", profile_p->smb2_setinfo_time);
     441        d_printf("smb2_break_count:               %u\n", profile_p->smb2_break_count);
     442        d_printf("smb2_break_time:                %u\n", profile_p->smb2_break_time);
     443
    403444#else /* WITH_PROFILE */
     445
    404446        fprintf(stderr, "Profile data unavailable\n");
    405447#endif /* WITH_PROFILE */
  • vendor/current/source3/utils/testparm.c

    r414 r740  
    3333
    3434#include "includes.h"
    35 
    36 extern bool AllowDebugChange;
     35#include "system/filesys.h"
     36#include "popt_common.h"
    3737
    3838/*******************************************************************
     
    7878        }
    7979
     80        if (strequal(lp_workgroup(), global_myname())) {
     81                fprintf(stderr, "WARNING: 'workgroup' and 'netbios name' " \
     82                        "must differ.\n");
     83                ret = 1;
     84        }
     85
    8086        if (!directory_exist_stat(lp_lockdir(), &st)) {
    8187                fprintf(stderr, "ERROR: lock directory %s does not exist\n",
     
    123129         */
    124130
    125         if((lp_security() == SEC_SERVER || lp_security() >= SEC_DOMAIN) && !lp_passwordserver()) {
     131        if((lp_security() == SEC_SERVER || lp_security() >= SEC_DOMAIN) && !*lp_passwordserver()) {
    126132                const char *sec_setting;
    127133                if(lp_security() == SEC_SERVER)
     
    129135                else if(lp_security() == SEC_DOMAIN)
    130136                        sec_setting = "domain";
     137                else if(lp_security() == SEC_ADS)
     138                        sec_setting = "ads";
    131139                else
    132140                        sec_setting = "";
    133141
    134                 fprintf(stderr, "ERROR: The setting 'security=%s' requires the 'password server' parameter be set \
    135 to a valid password server.\n", sec_setting );
    136                 ret = 1;
     142                fprintf(stderr, "ERROR: The setting 'security=%s' requires the 'password server' parameter be set\n"
     143                        "to the default value * or a valid password server.\n", sec_setting );
     144                ret = 1;
     145        }
     146
     147        if((lp_security() >= SEC_DOMAIN) && (strcmp(lp_passwordserver(), "*") != 0)) {
     148                const char *sec_setting;
     149                if(lp_security() == SEC_DOMAIN)
     150                        sec_setting = "domain";
     151                else if(lp_security() == SEC_ADS)
     152                        sec_setting = "ads";
     153                else
     154                        sec_setting = "";
     155
     156                fprintf(stderr, "WARNING: The setting 'security=%s' should NOT be combined with the 'password server' parameter.\n"
     157                        "(by default Samba will discover the correct DC to contact automatically).\n", sec_setting );
    137158        }
    138159
     
    320341        static char *parameter_name = NULL;
    321342        static const char *section_name = NULL;
    322         static char *new_local_machine = NULL;
    323343        const char *cname;
    324344        const char *caddr;
     
    330350                {"suppress-prompt", 's', POPT_ARG_VAL, &silent_mode, 1, "Suppress prompt for enter"},
    331351                {"verbose", 'v', POPT_ARG_NONE, &show_defaults, 1, "Show default options too"},
    332                 {"server", 'L',POPT_ARG_STRING, &new_local_machine, 0, "Set %%L macro to servername\n"},
    333352                {"skip-logic-checks", 'l', POPT_ARG_NONE, &skip_logic_checks, 1, "Skip the global checks"},
    334353                {"show-all-parameters", '\0', POPT_ARG_VAL, &show_all_parameters, True, "Show the parameters, type, possible values" },
     
    337356                POPT_COMMON_VERSION
    338357                POPT_COMMON_DEBUGLEVEL
     358                POPT_COMMON_OPTION
    339359                POPT_TABLEEND
    340360        };
     
    348368         * not by smb.conf.
    349369         */
    350         DEBUGLEVEL_CLASS[DBGC_ALL] = 2;
     370        lp_set_cmdline("log level", "2");
    351371
    352372        pc = poptGetContext(NULL, argc, argv, long_options,
     
    361381        }
    362382
    363         setup_logging(poptGetArg(pc), True);
     383        setup_logging(poptGetArg(pc), DEBUG_STDERR);
    364384
    365385        if (poptPeekArg(pc))
     
    376396                goto done;
    377397        }
    378 
    379         if (new_local_machine) {
    380                 set_local_machine_name(new_local_machine, True);
    381         }
    382 
    383         dbf = x_stderr;
    384         /* Don't let the debuglevel be changed by smb.conf. */
    385         AllowDebugChange = False;
    386398
    387399        fprintf(stderr,"Load smb config files from %s\n",config_file);
Note: See TracChangeset for help on using the changeset viewer.