Changeset 740 for vendor/current/source3/utils
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (13 years ago)
- 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 21 21 22 22 #include "includes.h" 23 24 extern bool AllowDebugChange; 23 #include "system/filesys.h" 24 #include "dbwrap.h" 25 #include "messages.h" 25 26 26 27 typedef enum { OP_FETCH, OP_STORE, OP_DELETE, OP_ERASE, OP_LISTKEYS } dbwrap_op; … … 214 215 215 216 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); 219 219 lp_load(get_dyn_CONFIGFILE(), true, false, false, true); 220 220 … … 299 299 } 300 300 301 msg_ctx = messaging_init(mem_ctx, server_id_self(), evt_ctx);301 msg_ctx = messaging_init(mem_ctx, procid_self(), evt_ctx); 302 302 if (msg_ctx == NULL) { 303 303 d_fprintf(stderr, "ERROR: could not init messaging context\n"); -
vendor/current/source3/utils/eventlogadm.c
r414 r740 24 24 25 25 #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" 30 31 31 32 extern int optind; … … 41 42 printf( " -o dump <Eventlog Name> <starting_record>\t\t\t\t\tDump stored eventlog entries on STDOUT\n" ); 42 43 printf( "\nMiscellaneous options:\n" ); 44 printf( " -s <filename>\t\t\t\t\t\t\tUse configuration file <filename>.\n"); 43 45 printf( " -d\t\t\t\t\t\t\t\tturn debug on\n" ); 44 46 printf( " -h\t\t\t\t\t\t\t\tdisplay help\n\n" ); … … 51 53 52 54 elogs = lp_eventlog_list( ); 53 printf( "Active eventlog names (from smb.conf):\n" );55 printf( "Active eventlog names:\n" ); 54 56 printf( "--------------------------------------\n" ); 55 57 if ( elogs ) { … … 60 62 else 61 63 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 *********************************************************************/ 71 static 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; 62 257 } 63 258 … … 221 416 int opt, rc; 222 417 char *exename; 418 char *configfile = NULL; 223 419 TALLOC_CTX *frame = talloc_stackframe(); 224 420 … … 229 425 230 426 opt_debug = 0; /* todo set this from getopts */ 231 232 lp_load(get_dyn_CONFIGFILE(), True, False, False, True);233 427 234 428 exename = argv[0]; … … 241 435 eventlog_add_source( "System", "TestSourceX", "SomeTestPathX" ); 242 436 #endif 243 while ( ( opt = getopt( argc, argv, "dho: " ) ) != EOF ) {437 while ( ( opt = getopt( argc, argv, "dho:s:" ) ) != EOF ) { 244 438 switch ( opt ) { 245 439 … … 257 451 opt_debug = 1; 258 452 break; 453 case 's': 454 configfile = talloc_strdup(frame, optarg); 455 break; 456 259 457 } 260 458 } … … 266 464 printf( "\nNot enough arguments!\n" ); 267 465 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); 268 473 exit( 1 ); 269 474 } -
vendor/current/source3/utils/log2pcaphex.c
r414 r740 52 52 53 53 #include "includes.h" 54 #include "popt_common.h" 54 55 55 56 /* We don't care about the paranoid malloc checker in this standalone -
vendor/current/source3/utils/net.c
r427 r740 42 42 43 43 #include "includes.h" 44 #include "popt_common.h" 44 45 #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" 47 51 48 52 #ifdef WITH_FAKE_KASERVER … … 232 236 static int net_getlocalsid(struct net_context *c, int argc, const char **argv) 233 237 { 234 DOM_SIDsid;238 struct dom_sid sid; 235 239 const char *name; 236 240 fstring sid_str; … … 272 276 static int net_setlocalsid(struct net_context *c, int argc, const char **argv) 273 277 { 274 DOM_SIDsid;278 struct dom_sid sid; 275 279 276 280 if ( (argc != 1) … … 293 297 static int net_setdomainsid(struct net_context *c, int argc, const char **argv) 294 298 { 295 DOM_SIDsid;299 struct dom_sid sid; 296 300 297 301 if ( (argc != 1) … … 314 318 static int net_getdomainsid(struct net_context *c, int argc, const char **argv) 315 319 { 316 DOM_SIDdomain_sid;320 struct dom_sid domain_sid; 317 321 fstring sid_str; 318 322 … … 668 672 net_maxrid, 669 673 NET_TRANSPORT_LOCAL, 670 N_("Display the maximu lRID currently used"),674 N_("Display the maximum RID currently used"), 671 675 N_(" net maxrid") 672 676 }, … … 719 723 N_(" Use 'net help eventlog' to get more information about " 720 724 "'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.") 721 740 }, 722 741 … … 797 816 {"single-obj-repl", 0, POPT_ARG_NONE, &c->opt_single_obj_repl}, 798 817 {"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}, 800 823 POPT_COMMON_SAMBA 801 824 { 0, 0, 0, 0} … … 804 827 zero_sockaddr(&c->opt_dest_ip); 805 828 829 setup_logging(argv[0], DEBUG_STDERR); 830 806 831 load_case_tables(); 807 832 808 833 setlocale(LC_ALL, ""); 809 834 #if defined(HAVE_BINDTEXTDOMAIN) 810 bindtextdomain(MODULE_NAME, dyn_LOCALEDIR);835 bindtextdomain(MODULE_NAME, get_dyn_LOCALEDIR()); 811 836 #endif 812 837 #if defined(HAVE_TEXTDOMAIN) … … 815 840 816 841 /* 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"); 819 843 c->private_data = net_func; 820 844 … … 855 879 } 856 880 857 /*858 * Don't load debug level from smb.conf. It should be859 * set by cmdline arg or remain default (0)860 */861 AllowDebugChange = false;862 881 lp_load(get_dyn_CONFIGFILE(), true, false, false, true); 863 882 … … 898 917 899 918 /* this makes sure that when we do things like call scripts, 900 that it won't assert bec ouse we are not root */919 that it won't assert because we are not root */ 901 920 sec_init(); 902 921 … … 912 931 } 913 932 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 914 939 rc = net_run_function(c, argc_new-1, argv_new+1, "net", net_func); 915 940 -
vendor/current/source3/utils/net.h
r414 r740 23 23 */ 24 24 25 #include "lib/netapi/netapi.h" 26 #include "libnet/libnet.h" 27 #include "localedir.h" 25 struct cli_state; 28 26 27 #include "../librpc/gen_ndr/lsa.h" 28 29 #include "intl.h" 29 30 #ifdef HAVE_LIBINTL_H 30 31 #include <libintl.h> … … 76 77 int opt_single_obj_repl; 77 78 int opt_clean_old_entries; 79 const char *opt_db; 80 int opt_lock; 81 int opt_auto; 82 int opt_repair; 78 83 79 84 int opt_have_ip; … … 81 86 bool smb_encrypt; 82 87 struct libnetapi_ctx *netapi_ctx; 88 struct messaging_context *msg_ctx; 83 89 84 90 bool display_usage; … … 110 116 111 117 typedef NTSTATUS (*rpc_command_fn)(struct net_context *c, 112 const DOM_SID*,118 const struct dom_sid *, 113 119 const char *, 114 120 struct cli_state *cli, … … 130 136 struct cli_state *cli; 131 137 132 DOM_SID*domain_sid;138 struct dom_sid *domain_sid; 133 139 const char *domain_name; 134 140 -
vendor/current/source3/utils/net_ads.c
r594 r740 23 23 #include "includes.h" 24 24 #include "utils/net.h" 25 #include "rpc_client/cli_pipe.h" 25 26 #include "librpc/gen_ndr/ndr_krb5pac.h" 26 #include "../librpc/gen_ndr/ cli_spoolss.h"27 #include "../librpc/gen_ndr/ndr_spoolss.h" 27 28 #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" 28 40 29 41 #ifdef HAVE_ADS … … 104 116 printf(_("Domain Controller:\t%s\n"), reply.pdc_dns_name); 105 117 106 printf(_("Pre-Win2k Domain:\t%s\n"), reply.domain );118 printf(_("Pre-Win2k Domain:\t%s\n"), reply.domain_name); 107 119 printf(_("Pre-Win2k Hostname:\t%s\n"), reply.pdc_name); 108 120 … … 402 414 } 403 415 404 d_printf(_("Workgroup: %s\n"), reply.domain );416 d_printf(_("Workgroup: %s\n"), reply.domain_name); 405 417 406 418 ads_destroy(&ads); … … 476 488 ou_str = SMB_STRDUP(c->opt_container); 477 489 } 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); 479 491 } 480 492 … … 540 552 char *primary_group; 541 553 char *escaped_user; 542 DOM_SIDprimary_group_sid;554 struct dom_sid primary_group_sid; 543 555 uint32_t group_rid; 544 556 enum wbcSidType type; … … 770 782 ou_str = SMB_STRDUP(c->opt_container); 771 783 } 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); 773 785 } 774 786 … … 959 971 } 960 972 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 961 979 werr = libnet_init_UnjoinCtx(ctx, &r); 962 980 if (!W_ERROR_IS_OK(werr)) { … … 978 996 WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE; 979 997 r->in.delete_machine_account = true; 998 r->in.msg_ctx = c->msg_ctx; 980 999 981 1000 werr = libnet_Unjoin(ctx, r); … … 1104 1123 1105 1124 #if defined(WITH_DNS_UPDATES) 1106 #include " dns.h"1125 #include "../lib/addns/dns.h" 1107 1126 DNS_ERROR DoDNSUpdate(char *pszServerName, 1108 1127 const char *pszDomainName, const char *pszHostName, … … 1116 1135 { 1117 1136 struct dns_rr_ns *nameservers = NULL; 1118 int ns_count = 0 ;1137 int ns_count = 0, i; 1119 1138 NTSTATUS status = NT_STATUS_UNSUCCESSFUL; 1120 1139 DNS_ERROR dns_err; … … 1181 1200 } 1182 1201 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)); 1190 1225 status = NT_STATUS_UNSUCCESSFUL; 1226 goto done; 1191 1227 } 1192 1228 … … 1348 1384 d_fprintf(stderr, _("Please supply a valid domain name\n")); 1349 1385 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; 1350 1393 goto fail; 1351 1394 } … … 1368 1411 WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE | 1369 1412 WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED; 1413 r->in.msg_ctx = c->msg_ctx; 1370 1414 1371 1415 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 } 1372 1421 if (!W_ERROR_IS_OK(werr)) { 1373 1422 goto fail; … … 1438 1487 ads_destroy(&ads_dns); 1439 1488 } 1489 1490 done: 1440 1491 #endif 1441 1492 1442 done:1443 1493 TALLOC_FREE(r); 1444 1494 TALLOC_FREE( ctx ); … … 1583 1633 err = do_gethostbyname(argv[0], argv[1]); 1584 1634 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)); 1586 1637 #endif 1587 1638 return 0; … … 1783 1834 c->opt_password ? c->opt_password : "", 1784 1835 CLI_FULL_CONNECTION_USE_KERBEROS, 1785 Undefined , NULL);1836 Undefined); 1786 1837 1787 1838 if (NT_STATUS_IS_ERR(nt_status)) { 1788 d_fprintf(stderr, _("Unable to open a conn nection to %s to "1839 d_fprintf(stderr, _("Unable to open a connection to %s to " 1789 1840 "obtain data for %s\n"), 1790 1841 servername, printername); … … 1835 1886 nt_status = cli_rpc_pipe_open_noauth(cli, &ndr_table_spoolss.syntax_id, &pipe_hnd); 1836 1887 if (!NT_STATUS_IS_OK(nt_status)) { 1837 d_fprintf(stderr, _("Unable to open a conn nection to the spoolss pipe on %s\n"),1888 d_fprintf(stderr, _("Unable to open a connection to the spoolss pipe on %s\n"), 1838 1889 servername); 1839 1890 SAFE_FREE(prt_dn); … … 2265 2316 const char **attrs; 2266 2317 LDAPMessage *res = NULL; 2267 DOM_SIDsid;2318 struct dom_sid sid; 2268 2319 2269 2320 if (argc < 1 || c->display_usage) { … … 2463 2514 static int net_ads_kerberos_pac(struct net_context *c, int argc, const char **argv) 2464 2515 { 2465 struct PAC_DATA *pac = NULL;2466 2516 struct PAC_LOGON_INFO *info = NULL; 2467 2517 TALLOC_CTX *mem_ctx = NULL; … … 2493 2543 c->opt_user_name, 2494 2544 c->opt_password, 2495 2545 0, 2496 2546 NULL, 2497 2547 NULL, … … 2501 2551 2592000, /* one month */ 2502 2552 impersonate_princ_s, 2503 & pac);2553 &info); 2504 2554 if (!NT_STATUS_IS_OK(status)) { 2505 2555 d_printf(_("failed to query kerberos PAC: %s\n"), … … 2508 2558 } 2509 2559 2510 info = get_logon_info_from_pac(pac);2511 2560 if (info) { 2512 2561 const char *s; … … 2794 2843 } 2795 2844 2845 int net_ads_gpo(struct net_context *c, int argc, const char **argv) 2846 { 2847 return net_ads_noads(); 2848 } 2849 2796 2850 /* this one shouldn't display a message */ 2797 2851 int net_ads_check(struct net_context *c) -
vendor/current/source3/utils/net_ads_gpo.c
r414 r740 20 20 #include "includes.h" 21 21 #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" 22 26 23 27 #ifdef HAVE_ADS … … 35 39 struct GROUP_POLICY_OBJECT *gpo; 36 40 NTSTATUS result; 37 struct nt_user_token *token = NULL;41 struct security_token *token = NULL; 38 42 39 43 if (argc < 1 || c->display_usage) { … … 154 158 { 155 159 WERROR werr = gp_reg_state_read(mem_ctx, flags, 156 &token-> user_sids[0],160 &token->sids[0], 157 161 &read_list); 158 162 if (!W_ERROR_IS_OK(werr)) { … … 247 251 "(objectclass=groupPolicyContainer)", 248 252 attrs, 249 DACL_SECURITY_INFORMATION,253 SECINFO_DACL, 250 254 &res); 251 255 … … 290 294 static int net_ads_gpo_list(struct net_context *c, int argc, const char **argv) 291 295 { 292 ADS_STRUCT *ads ;296 ADS_STRUCT *ads = NULL; 293 297 ADS_STATUS status; 294 298 LDAPMessage *res = NULL; … … 298 302 uint32 flags = 0; 299 303 struct GROUP_POLICY_OBJECT *gpo_list; 300 struct nt_user_token *token = NULL;304 struct security_token *token = NULL; 301 305 302 306 if (argc < 1 || c->display_usage) { … … 359 363 } 360 364 361 #if 0362 365 static int net_ads_gpo_apply(struct net_context *c, int argc, const char **argv) 363 366 { … … 369 372 uint32 uac = 0; 370 373 uint32 flags = 0; 371 struct nt_user_token *token = NULL;374 struct security_token *token = NULL; 372 375 const char *filter = NULL; 373 376 … … 391 394 392 395 status = ads_startup(c, false, &ads); 396 /* filter = cse_gpo_name_to_guid_string("Security"); */ 397 393 398 if (!ADS_ERR_OK(status)) { 394 399 d_printf("got: %s\n", ads_errstr(status)); … … 443 448 return 0; 444 449 } 445 #endif446 450 447 451 static int net_ads_gpo_link_get(struct net_context *c, int argc, const char **argv) … … 625 629 { 626 630 struct functable func[] = { 627 #if 0628 631 { 629 632 "apply", … … 634 637 " Apply GPO to container" 635 638 }, 636 #endif637 639 { 638 640 "getgpo", -
vendor/current/source3/utils/net_afs.c
r427 r740 20 20 #include "includes.h" 21 21 #include "utils/net.h" 22 #include "secrets.h" 23 #include "system/filesys.h" 22 24 23 25 int net_afs_usage(struct net_context *c, int argc, const char **argv) … … 36 38 37 39 if (argc != 2) { 38 d_printf( _("Usage:")," net afs key <keyfile> cell\n");40 d_printf("%s net afs key <keyfile> cell\n", _("Usage:")); 39 41 return -1; 40 42 } … … 52 54 if (read(fd, &keyfile, sizeof(keyfile)) != sizeof(keyfile)) { 53 55 d_fprintf(stderr, _("Could not read keyfile\n")); 56 close(fd); 54 57 return -1; 55 58 } 59 close(fd); 56 60 57 61 if (!secrets_store_afs_keyfile(argv[1], &keyfile)) { … … 69 73 70 74 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:")); 72 77 exit(1); 73 78 } -
vendor/current/source3/utils/net_cache.c
r414 r740 34 34 * Both of them are defined by first arg of gencache_iterate() routine. 35 35 */ 36 static void print_cache_entry(const char* keystr, const char* datastr,36 static void print_cache_entry(const char* keystr, DATA_BLOB value, 37 37 const time_t timeout, void* dptr) 38 38 { 39 39 char *timeout_str; 40 40 char *alloc_str = NULL; 41 const char *datastr; 42 char *datastr_free = NULL; 41 43 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) { 48 49 return; 49 50 } 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) { 53 53 return; 54 54 } 55 55 56 56 /* 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) { 60 60 61 61 timeout_str = asctime(&timeout_tm); … … 72 72 } 73 73 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 74 86 d_printf(_("Key: %s\t Timeout: %s\t Value: %s %s\n"), keystr, 75 87 timeout_str, datastr, timeout > now_t ? "": _("(expired)")); … … 221 233 { 222 234 const char* keystr = argv[0]; 223 char* valuestr = NULL;235 DATA_BLOB value; 224 236 time_t timeout; 225 237 … … 231 243 } 232 244 233 if (gencache_get (keystr, &valuestr, &timeout)) {234 print_cache_entry(keystr, value str, 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); 236 248 return 0; 237 249 } … … 261 273 262 274 pattern = argv[0]; 263 gencache_iterate (print_cache_entry, NULL, pattern);275 gencache_iterate_blobs(print_cache_entry, NULL, pattern); 264 276 return 0; 265 277 } … … 285 297 return 0; 286 298 } 287 gencache_iterate (print_cache_entry, NULL, pattern);299 gencache_iterate_blobs(print_cache_entry, NULL, pattern); 288 300 return 0; 289 301 } -
vendor/current/source3/utils/net_conf.c
r478 r740 29 29 30 30 #include "includes.h" 31 #include "system/filesys.h" 31 32 #include "utils/net.h" 33 #include "lib/smbconf/smbconf.h" 34 #include "lib/smbconf/smbconf_init.h" 35 #include "lib/smbconf/smbconf_reg.h" 32 36 33 37 /********************************************************************** … … 171 175 * This functions process a service previously loaded with libsmbconf. 172 176 */ 173 static WERRORimport_process_service(struct net_context *c,177 static sbcErr import_process_service(struct net_context *c, 174 178 struct smbconf_ctx *conf_ctx, 175 179 struct smbconf_service *service) 176 180 { 177 181 uint32_t idx; 178 WERROR werr = WERR_OK;182 sbcErr err = SBC_ERR_OK; 179 183 uint32_t num_includes = 0; 180 184 char **includes = NULL; … … 197 201 198 202 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)) { 201 205 goto done; 202 206 } 203 207 } 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)) { 206 210 goto done; 207 211 } … … 214 218 num_includes+1); 215 219 if (includes == NULL) { 216 werr = WERR_NOMEM;220 err = SBC_ERR_NOMEM; 217 221 goto done; 218 222 } … … 220 224 service->param_values[idx]); 221 225 if (includes[num_includes] == NULL) { 222 werr = WERR_NOMEM;226 err = SBC_ERR_NOMEM; 223 227 goto done; 224 228 } 225 229 num_includes++; 226 230 } else { 227 werr = smbconf_set_parameter(conf_ctx,231 err = smbconf_set_parameter(conf_ctx, 228 232 service->name, 229 233 service->param_names[idx], 230 234 service->param_values[idx]); 231 if (! W_ERROR_IS_OK(werr)) {235 if (!SBC_ERROR_IS_OK(err)) { 232 236 d_fprintf(stderr, 233 237 _("Error in section [%s], parameter \"%s\": %s\n"), 234 238 service->name, service->param_names[idx], 235 win_errstr(werr));239 sbcErrorString(err)); 236 240 goto done; 237 241 } … … 239 243 } 240 244 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; 244 252 done: 245 253 TALLOC_FREE(mem_ctx); 246 return werr;254 return err; 247 255 } 248 256 … … 257 265 int argc, const char **argv) 258 266 { 259 WERROR werr = WERR_OK;267 sbcErr err; 260 268 int ret = -1; 261 269 TALLOC_CTX *mem_ctx; … … 271 279 } 272 280 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)) { 275 283 d_fprintf(stderr, _("Error getting config: %s\n"), 276 win_errstr(werr));284 sbcErrorString(err)); 277 285 goto done; 278 286 } … … 312 320 TALLOC_CTX *mem_ctx; 313 321 struct smbconf_ctx *txt_ctx; 314 WERROR werr;322 sbcErr err; 315 323 316 324 if (c->display_usage) … … 344 352 } 345 353 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)) { 348 356 d_printf(_("error loading file '%s': %s\n"), filename, 349 win_errstr(werr));357 sbcErrorString(err)); 350 358 goto done; 351 359 } … … 359 367 struct smbconf_service *service = NULL; 360 368 361 werr = smbconf_get_share(txt_ctx, mem_ctx,362 363 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)) { 365 373 goto cancel; 366 374 } 367 375 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)) { 370 378 d_printf(_("error starting transaction: %s\n"), 371 win_errstr(werr));379 sbcErrorString(err)); 372 380 goto done; 373 381 } 374 382 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)) { 377 385 goto cancel; 378 386 } … … 381 389 uint32_t num_shares, sidx; 382 390 383 werr = smbconf_get_config(txt_ctx, mem_ctx,391 err = smbconf_get_config(txt_ctx, mem_ctx, 384 392 &num_shares, 385 393 &services); 386 if (! W_ERROR_IS_OK(werr)) {394 if (!SBC_ERROR_IS_OK(err)) { 387 395 goto cancel; 388 396 } 389 397 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))) { 392 399 goto cancel; 393 400 } … … 396 403 /* 397 404 * Wrap the importing of shares into a transaction, 398 * but only 100 at a time, in order to s erve memory.405 * but only 100 at a time, in order to save memory. 399 406 * The allocated memory accumulates across the actions 400 407 * within the transaction, and for me, some 1500 … … 402 409 * was exceeded. 403 410 */ 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)) { 406 413 d_printf(_("error starting transaction: %s\n"), 407 win_errstr(werr));414 sbcErrorString(err)); 408 415 goto done; 409 416 } 410 417 411 418 for (sidx = 0; sidx < num_shares; sidx++) { 412 werr = import_process_service(c, conf_ctx,413 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)) { 415 422 goto cancel; 416 423 } … … 420 427 } 421 428 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)) { 424 431 d_printf(_("error committing transaction: " 425 432 "%s\n"), 426 win_errstr(werr));433 sbcErrorString(err)); 427 434 goto done; 428 435 } 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)) { 431 438 d_printf(_("error starting transaction: %s\n"), 432 win_errstr(werr));439 sbcErrorString(err)); 433 440 goto done; 434 441 } … … 436 443 } 437 444 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)) { 440 447 d_printf(_("error committing transaction: %s\n"), 441 win_errstr(werr));448 sbcErrorString(err)); 442 449 } else { 443 450 ret = 0; … … 447 454 448 455 cancel: 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)) { 451 458 d_printf(_("error cancelling transaction: %s\n"), 452 win_errstr(werr));459 sbcErrorString(err)); 453 460 } 454 461 … … 462 469 const char **argv) 463 470 { 464 WERROR werr = WERR_OK;471 sbcErr err; 465 472 int ret = -1; 466 473 uint32_t count, num_shares = 0; … … 475 482 } 476 483 477 werr = smbconf_get_share_names(conf_ctx, mem_ctx, &num_shares,478 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)) { 480 487 goto done; 481 488 } … … 497 504 { 498 505 int ret = -1; 499 WERROR werr;506 sbcErr err; 500 507 501 508 if (argc != 0 || c->display_usage) { … … 504 511 } 505 512 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)) { 508 515 d_fprintf(stderr, _("Error deleting configuration: %s\n"), 509 win_errstr(werr));516 sbcErrorString(err)); 510 517 goto done; 511 518 } … … 522 529 { 523 530 int ret = -1; 524 WERROR werr = WERR_OK;531 sbcErr err; 525 532 const char *sharename = NULL; 526 533 TALLOC_CTX *mem_ctx; … … 541 548 } 542 549 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)) { 545 552 d_printf(_("error getting share parameters: %s\n"), 546 win_errstr(werr));553 sbcErrorString(err)); 547 554 goto done; 548 555 } … … 573 580 { 574 581 int ret = -1; 575 WERROR werr = WERR_OK;582 sbcErr err; 576 583 char *sharename = NULL; 577 584 const char *path = NULL; … … 579 586 const char *guest_ok = "no"; 580 587 const char *writeable = "no"; 581 SMB_STRUCT_STAT sbuf;582 588 TALLOC_CTX *mem_ctx = talloc_stackframe(); 583 589 … … 679 685 } 680 686 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 697 687 /* 698 688 * start a transaction 699 689 */ 700 690 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)) { 703 693 d_printf("error starting transaction: %s\n", 704 win_errstr(werr));694 sbcErrorString(err)); 705 695 goto done; 706 696 } … … 710 700 */ 711 701 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)) { 714 704 d_fprintf(stderr, _("Error creating share %s: %s\n"), 715 sharename, win_errstr(werr));705 sharename, sbcErrorString(err)); 716 706 goto cancel; 717 707 } … … 721 711 */ 722 712 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)) { 725 715 d_fprintf(stderr, _("Error setting parameter %s: %s\n"), 726 "path", win_errstr(werr));716 "path", sbcErrorString(err)); 727 717 goto cancel; 728 718 } 729 719 730 720 if (comment != NULL) { 731 werr = smbconf_set_parameter(conf_ctx, sharename, "comment",732 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)) { 734 724 d_fprintf(stderr, _("Error setting parameter %s: %s\n"), 735 "comment", win_errstr(werr));725 "comment", sbcErrorString(err)); 736 726 goto cancel; 737 727 } 738 728 } 739 729 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)) { 742 732 d_fprintf(stderr, _("Error setting parameter %s: %s\n"), 743 "'guest ok'", win_errstr(werr));733 "'guest ok'", sbcErrorString(err)); 744 734 goto cancel; 745 735 } 746 736 747 werr = smbconf_set_parameter(conf_ctx, sharename, "writeable",748 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)) { 750 740 d_fprintf(stderr, _("Error setting parameter %s: %s\n"), 751 "writeable", win_errstr(werr));741 "writeable", sbcErrorString(err)); 752 742 goto cancel; 753 743 } … … 757 747 */ 758 748 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)) { 761 751 d_printf("error committing transaction: %s\n", 762 win_errstr(werr));752 sbcErrorString(err)); 763 753 } else { 764 754 ret = 0; … … 768 758 769 759 cancel: 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)) { 772 762 d_printf("error cancelling transaction: %s\n", 773 win_errstr(werr));763 sbcErrorString(err)); 774 764 } 775 765 … … 785 775 int ret = -1; 786 776 const char *sharename = NULL; 787 WERROR werr = WERR_OK;777 sbcErr err; 788 778 TALLOC_CTX *mem_ctx = talloc_stackframe(); 789 779 … … 798 788 } 799 789 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)) { 802 792 d_fprintf(stderr, _("Error deleting share %s: %s\n"), 803 sharename, win_errstr(werr));793 sharename, sbcErrorString(err)); 804 794 goto done; 805 795 } … … 815 805 { 816 806 int ret = -1; 817 WERROR werr = WERR_OK;807 sbcErr err; 818 808 char *service = NULL; 819 809 char *param = NULL; … … 843 833 value_str = argv[2]; 844 834 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)) { 847 837 d_printf(_("error starting transaction: %s\n"), 848 win_errstr(werr));838 sbcErrorString(err)); 849 839 goto done; 850 840 } 851 841 852 842 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)) { 855 845 d_fprintf(stderr, _("Error creating share '%s': %s\n"), 856 service, win_errstr(werr));846 service, sbcErrorString(err)); 857 847 goto cancel; 858 848 } 859 849 } 860 850 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)) { 864 853 d_fprintf(stderr, _("Error setting value '%s': %s\n"), 865 param, win_errstr(werr));854 param, sbcErrorString(err)); 866 855 goto cancel; 867 856 } 868 857 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)) { 871 860 d_printf(_("error committing transaction: %s\n"), 872 win_errstr(werr));861 sbcErrorString(err)); 873 862 } else { 874 863 ret = 0; … … 878 867 879 868 cancel: 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)) { 882 871 d_printf(_("error cancelling transaction: %s\n"), 883 win_errstr(werr));872 sbcErrorString(err)); 884 873 } 885 874 … … 893 882 { 894 883 int ret = -1; 895 WERROR werr = WERR_OK;884 sbcErr err; 896 885 char *service = NULL; 897 886 char *param = NULL; … … 922 911 } 923 912 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)) { 927 915 d_fprintf(stderr, 928 916 _("Error: given service '%s' does not exist.\n"), 929 917 service); 930 918 goto done; 931 } else if ( W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {919 } else if (SBC_ERROR_EQUAL(err, SBC_ERR_INVALID_PARAM)) { 932 920 d_fprintf(stderr, 933 921 _("Error: given parameter '%s' is not set.\n"), 934 922 param); 935 923 goto done; 936 } else if (! W_ERROR_IS_OK(werr)) {924 } else if (!SBC_ERROR_IS_OK(err)) { 937 925 d_fprintf(stderr, _("Error getting value '%s': %s.\n"), 938 param, win_errstr(werr));926 param, sbcErrorString(err)); 939 927 goto done; 940 928 } … … 952 940 { 953 941 int ret = -1; 954 WERROR werr = WERR_OK;942 sbcErr err; 955 943 char *service = NULL; 956 944 char *param = NULL; … … 978 966 } 979 967 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)) { 983 970 d_fprintf(stderr, 984 971 _("Error: given service '%s' does not exist.\n"), 985 972 service); 986 973 goto done; 987 } else if ( W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {974 } else if (SBC_ERROR_EQUAL(err, SBC_ERR_INVALID_PARAM)) { 988 975 d_fprintf(stderr, 989 976 _("Error: given parameter '%s' is not set.\n"), 990 977 param); 991 978 goto done; 992 } else if (! W_ERROR_IS_OK(werr)) {979 } else if (!SBC_ERROR_IS_OK(err)) { 993 980 d_fprintf(stderr, _("Error deleting value '%s': %s.\n"), 994 param, win_errstr(werr));981 param, sbcErrorString(err)); 995 982 goto done; 996 983 } … … 1007 994 int argc, const char **argv) 1008 995 { 1009 WERROR werr;996 sbcErr err; 1010 997 uint32_t num_includes; 1011 998 uint32_t count; … … 1026 1013 } 1027 1014 1028 werr = smbconf_get_includes(conf_ctx, mem_ctx, service,1015 err = smbconf_get_includes(conf_ctx, mem_ctx, service, 1029 1016 &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)); 1032 1019 goto done; 1033 1020 } … … 1048 1035 int argc, const char **argv) 1049 1036 { 1050 WERROR werr;1037 sbcErr err; 1051 1038 char *service; 1052 1039 uint32_t num_includes; … … 1073 1060 } 1074 1061 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)); 1078 1065 goto done; 1079 1066 } … … 1090 1077 int argc, const char **argv) 1091 1078 { 1092 WERROR werr;1079 sbcErr err; 1093 1080 char *service; 1094 1081 int ret = -1; … … 1106 1093 } 1107 1094 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)); 1111 1098 goto done; 1112 1099 } … … 1137 1124 int argc, const char **argv) 1138 1125 { 1139 WERROR werr;1126 sbcErr err; 1140 1127 TALLOC_CTX *mem_ctx = talloc_stackframe(); 1141 1128 struct smbconf_ctx *conf_ctx; 1142 1129 int ret = -1; 1143 1130 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)) { 1147 1133 return -1; 1148 1134 } -
vendor/current/source3/utils/net_dns.c
r414 r740 1 2 1 /* 3 2 Samba Unix/Linux Dynamic DNS Update … … 11 10 the Free Software Foundation; either version 3 of the License, or 12 11 (at your option) any later version. 13 12 14 13 This program is distributed in the hope that it will be useful, 15 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 16 GNU General Public License for more details. 18 17 19 18 You should have received a copy of the GNU General Public License 20 19 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 23 22 #include "includes.h" 24 23 #include "utils/net.h" 25 #include " dns.h"24 #include "../lib/addns/dns.h" 26 25 27 26 #if defined(WITH_DNS_UPDATES) 28 29 27 /* 30 28 * Silly prototype to get rid of a warning … … 56 54 return ERROR_DNS_NO_MEMORY; 57 55 } 58 56 59 57 err = dns_open_connection( pszServerName, DNS_TCP, mem_ctx, &conn ); 60 58 if (!ERR_DNS_IS_OK(err)) { … … 115 113 DNS_SRV_WIN2000 ); 116 114 } 117 115 118 116 if (!ERR_DNS_IS_OK(err)) 119 117 goto error; 120 121 118 122 119 err = dns_sign_update(req, gss_context, keyname, -
vendor/current/source3/utils/net_dom.c
r414 r740 20 20 #include "includes.h" 21 21 #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" 23 27 24 28 int net_dom_usage(struct net_context *c, int argc, const char **argv) … … 371 375 }; 372 376 373 status = libnetapi_ init(&c->netapi_ctx);377 status = libnetapi_net_init(&c->netapi_ctx); 374 378 if (status != 0) { 375 379 return -1; -
vendor/current/source3/utils/net_eventlog.c
r414 r740 22 22 #include "includes.h" 23 23 #include "utils/net.h" 24 #include "lib/eventlog/eventlog.h" 24 25 25 26 /** … … 55 56 } 56 57 57 ndr_err = ndr_pull_struct_blob(&blob, ctx, NULL,&evt,58 ndr_err = ndr_pull_struct_blob(&blob, ctx, &evt, 58 59 (ndr_pull_flags_fn_t)ndr_pull_EVENTLOG_EVT_FILE); 59 60 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { … … 113 114 114 115 /* 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, 116 117 (ndr_pull_flags_fn_t)ndr_pull_EVENTLOGHEADER); 117 118 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { … … 126 127 } 127 128 128 ndr_err = ndr_pull_struct_blob(&blob, ctx, NULL,&evt,129 ndr_err = ndr_pull_struct_blob(&blob, ctx, &evt, 129 130 (ndr_pull_flags_fn_t)ndr_pull_EVENTLOG_EVT_FILE); 130 131 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { -
vendor/current/source3/utils/net_g_lock.c
r453 r740 21 21 #include "net.h" 22 22 #include "g_lock.h" 23 #include "messages.h" 23 24 24 25 static bool net_g_lock_init(TALLOC_CTX *mem_ctx, … … 31 32 struct g_lock_ctx *g_ctx = NULL; 32 33 33 ev = tevent_context_init( talloc_tos());34 ev = tevent_context_init(mem_ctx); 34 35 if (ev == NULL) { 35 36 d_fprintf(stderr, "ERROR: could not init event context\n"); 36 37 goto fail; 37 38 } 38 msg = messaging_init( talloc_tos(), server_id_self(), ev);39 msg = messaging_init(mem_ctx, procid_self(), ev); 39 40 if (msg == NULL) { 40 41 d_fprintf(stderr, "ERROR: could not init messaging context\n"); 41 42 goto fail; 42 43 } 43 g_ctx = g_lock_ctx_init( talloc_tos(), msg);44 g_ctx = g_lock_ctx_init(mem_ctx, msg); 44 45 if (g_ctx == NULL) { 45 46 d_fprintf(stderr, "ERROR: could not init g_lock context\n"); … … 91 92 status = g_lock_do(name, G_LOCK_WRITE, 92 93 timeval_set(timeout / 1000, timeout % 1000), 93 net_g_lock_do_fn, &state);94 procid_self(), net_g_lock_do_fn, &state); 94 95 if (!NT_STATUS_IS_OK(status)) { 95 96 d_fprintf(stderr, "ERROR: g_lock_do failed: %s\n", -
vendor/current/source3/utils/net_group.c
r414 r740 64 64 return net_ads_group(c, argc, argv); 65 65 66 if (argc == 0 && net_rpc_check(c, NET_FLAGS_PDC))67 return net_rpc_group(c,argc, argv);68 69 66 return net_rap_group(c, argc, argv); 70 67 } -
vendor/current/source3/utils/net_groupmap.c
r414 r740 23 23 24 24 #include "includes.h" 25 #include "system/passwd.h" 25 26 #include "utils/net.h" 27 #include "../libcli/security/security.h" 28 #include "passdb.h" 26 29 27 30 /********************************************************* … … 29 32 Return the SID. 30 33 **********************************************************/ 31 static bool get_sid_from_input( DOM_SID*sid, char *input)34 static bool get_sid_from_input(struct dom_sid *sid, char *input) 32 35 { 33 36 GROUP_MAP map; … … 124 127 /* list a single group is given a name */ 125 128 if ( ntgroup[0] || sid_string[0] ) { 126 DOM_SIDsid;129 struct dom_sid sid; 127 130 GROUP_MAP map; 128 131 … … 166 169 static int net_groupmap_add(struct net_context *c, int argc, const char **argv) 167 170 { 168 DOM_SIDsid;171 struct dom_sid sid; 169 172 fstring ntgroup = ""; 170 173 fstring unixgrp = ""; … … 201 204 if ( !StrnCaseCmp(argv[i], "rid", strlen("rid")) ) { 202 205 rid = get_int_param(argv[i]); 203 if ( rid < DOMAIN_ GROUP_RID_ADMINS ) {206 if ( rid < DOMAIN_RID_ADMINS ) { 204 207 d_fprintf(stderr, 205 208 _("RID must be greater than %d\n"), 206 (uint32)DOMAIN_ GROUP_RID_ADMINS-1);209 (uint32)DOMAIN_RID_ADMINS-1); 207 210 return -1; 208 211 } … … 300 303 /* append the rid to our own domain/machine SID if we don't have a full SID */ 301 304 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); 304 306 sid_to_fstring(string_sid, &sid); 305 307 } … … 337 339 static int net_groupmap_modify(struct net_context *c, int argc, const char **argv) 338 340 { 339 DOM_SIDsid;341 struct dom_sid sid; 340 342 GROUP_MAP map; 341 343 fstring ntcomment = ""; … … 485 487 static int net_groupmap_delete(struct net_context *c, int argc, const char **argv) 486 488 { 487 DOM_SIDsid;489 struct dom_sid sid; 488 490 fstring ntgroup = ""; 489 491 fstring sid_string = ""; … … 582 584 583 585 if (!have_map) { 584 DOM_SIDsid;586 struct dom_sid sid; 585 587 have_map = ( (strncmp(ntgroup, "S-", 2) == 0) && 586 588 string_to_sid(&sid, ntgroup) && … … 613 615 } 614 616 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); 617 618 618 619 map.sid_name_use = SID_NAME_DOM_GRP; … … 708 709 static int net_groupmap_addmem(struct net_context *c, int argc, const char **argv) 709 710 { 710 DOM_SIDalias, member;711 struct dom_sid alias, member; 711 712 712 713 if ( (argc != 2) || … … 731 732 static int net_groupmap_delmem(struct net_context *c, int argc, const char **argv) 732 733 { 733 DOM_SIDalias, member;734 struct dom_sid alias, member; 734 735 735 736 if ( (argc != 2) || … … 754 755 static int net_groupmap_listmem(struct net_context *c, int argc, const char **argv) 755 756 { 756 DOM_SIDalias;757 DOM_SID*members;757 struct dom_sid alias; 758 struct dom_sid *members; 758 759 size_t i, num; 759 760 … … 787 788 788 789 static 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) 791 792 { 792 793 uint32 *alias_rids; … … 805 806 806 807 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]); 810 810 printf("%s\n", sid_string_tos(&alias)); 811 811 } … … 817 817 { 818 818 TALLOC_CTX *mem_ctx; 819 DOM_SID *domain_sid, *builtin_sid, member;819 struct dom_sid *domain_sid, member; 820 820 821 821 if ( (argc != 1) || … … 835 835 836 836 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) { 839 838 d_fprintf(stderr, _("Could not get domain sid\n")); 840 839 return -1; … … 842 841 843 842 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)) 845 844 return -1; 846 845 -
vendor/current/source3/utils/net_idmap.c
r414 r740 18 18 */ 19 19 20 #define FOO(x) (x)21 20 #include "includes.h" 21 #include "system/filesys.h" 22 22 #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" 23 29 24 30 #define ALLOC_CHECK(mem) do { \ … … 32 38 Helper function for net_idmap_dump. Dump one entry. 33 39 **********************************************************/ 34 static int net_idmap_dump_one_entry(TDB_CONTEXT *tdb, 35 TDB_DATA key, 36 TDB_DATA data, 40 static int net_idmap_dump_one_entry(struct db_record *rec, 37 41 void *unused) 38 42 { 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)); 41 45 return 0; 42 46 } 43 47 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)); 46 50 return 0; 47 51 } 48 52 49 if (strncmp((char *) key.dptr, "S-", 2) != 0)53 if (strncmp((char *)rec->key.dptr, "S-", 2) != 0) 50 54 return 0; 51 55 52 printf("%s %s\n", data.dptr,key.dptr);56 printf("%s %s\n", rec->value.dptr, rec->key.dptr); 53 57 return 0; 58 } 59 60 static 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; 54 97 } 55 98 … … 59 102 static int net_idmap_dump(struct net_context *c, int argc, const char **argv) 60 103 { 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) { 64 110 d_printf("%s\n%s", 65 111 _("Usage:"), 66 _("net idmap dump <inputfile>\n"112 _("net idmap dump [[--db=]<inputfile>]\n" 67 113 " Dump current ID mapping.\n" 68 114 " inputfile\tTDB file to read mappings from.\n")); … … 70 116 } 71 117 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 136 done: 137 talloc_free(mem_ctx); 138 return ret; 84 139 } 85 140 … … 88 143 **********************************************************/ 89 144 145 static 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 90 187 static int net_idmap_restore(struct net_context *c, int argc, const char **argv) 91 188 { 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; 94 194 95 195 if (c->display_usage) { 96 196 d_printf("%s\n%s", 97 197 _("Usage:"), 98 _("net idmap restore [ inputfile]\n"198 _("net idmap restore [--db=<TDB>] [<inputfile>]\n" 99 199 " 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")); 102 203 return 0; 103 204 } 104 205 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); 113 216 114 217 if (argc == 1) { 115 218 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 } 116 225 } else { 117 226 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; 118 241 } 119 242 … … 121 244 char line[128], sid_string[128]; 122 245 int len; 123 struct wbcDomainSid sid;124 enum id_type type = ID_TYPE_NOT_SPECIFIED;125 246 unsigned long idval; 126 wbcErr wbc_status;127 247 128 248 if (fgets(line, 127, input) == NULL) … … 134 254 line[len-1] = '\0'; 135 255 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 } 140 270 } 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) { 144 279 d_fprintf(stderr, 145 _("Could not s et USER HWM: %s\n"),146 wbcErrorString(wbc_status));280 _("Could not store GROUP HWM.\n")); 281 break; 147 282 } 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;158 283 } else { 159 284 d_fprintf(stderr, _("ignoring invalid line [%s]\n"), … … 161 286 continue; 162 287 } 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 301 done: 302 if ((input != NULL) && (input != stdin)) { 187 303 fclose(input); 188 304 } 189 305 190 talloc_free(ctx); 191 return 0; 306 talloc_free(mem_ctx); 307 return ret; 308 } 309 310 static 311 NTSTATUS 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 } 366 done: 367 TALLOC_FREE(rec1); 368 TALLOC_FREE(rec2); 369 return status; 370 } 371 372 static 373 NTSTATUS delete_mapping_action(struct db_context *db, void* data) 374 { 375 return dbwrap_delete_mapping(db, *(TDB_DATA*)data, false); 376 } 377 static 378 NTSTATUS delete_mapping_action_force(struct db_context *db, void* data) 379 { 380 return dbwrap_delete_mapping(db, *(TDB_DATA*)data, true); 192 381 } 193 382 … … 195 384 Delete a SID mapping from a winbindd_idmap.tdb 196 385 **********************************************************/ 386 static 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 197 399 static 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; 446 done: 447 talloc_free(mem_ctx); 448 return ret; 449 } 450 451 static int net_idmap_set(struct net_context *c, int argc, const char **argv) 198 452 { 199 453 d_printf("%s\n", _("Not implemented yet")); 200 454 return -1; 201 455 } 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) 456 static bool idmap_store_secret(const char *backend, 457 const char *domain, 458 const char *identity, 459 const char *secret) 211 460 { 212 461 char *tmp; … … 214 463 bool ret; 215 464 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); 221 466 222 467 if (r < 0) return false; … … 242 487 if (argc != 2 || c->display_usage) { 243 488 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" 248 492 " DOMAIN\tDomain to set secret for.\n" 249 " alloc\tSet secret for the alloc module\n"250 493 " secret\tNew secret to set.\n")); 251 494 return c->display_usage?0:-1; … … 257 500 ALLOC_CHECK(ctx); 258 501 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); 272 510 273 511 if ( ( ! backend) || ( ! strequal(backend, "ldap"))) { … … 278 516 } 279 517 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); 304 528 305 529 if ( ! ret) { … … 313 537 } 314 538 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; 539 static 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); 330 575 } 331 576 … … 334 579 TALLOC_CTX *mem_ctx; 335 580 int result = -1; 336 DOM_SIDsrc_sid, dst_sid;581 struct dom_sid src_sid, dst_sid; 337 582 char *src, *dst; 338 583 struct db_context *db; … … 428 673 net_idmap_delete, 429 674 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") 433 678 }, 434 679 { … … 437 682 NET_TRANSPORT_LOCAL, 438 683 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") 441 686 }, 442 687 { … … 448 693 " Set acl map") 449 694 }, 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 }, 450 703 {NULL, NULL, 0, NULL, NULL} 451 704 }; -
vendor/current/source3/utils/net_lookup.c
r414 r740 19 19 #include "includes.h" 20 20 #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" 21 27 22 28 int net_lookup_usage(struct net_context *c, int argc, const char **argv) … … 320 326 { 321 327 const char *dom, *name; 322 DOM_SIDsid;328 struct dom_sid sid; 323 329 enum lsa_SidType type; 324 330 … … 344 350 { 345 351 const char *dom, *name; 346 DOM_SIDsid;352 struct dom_sid sid; 347 353 enum lsa_SidType type; 348 354 … … 406 412 } 407 413 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, 409 421 flags, &info); 410 422 if (!NT_STATUS_IS_OK(status)) { -
vendor/current/source3/utils/net_proto.h
r427 r740 24 24 #define _NET_PROTO_H_ 25 25 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" 42 27 43 28 /* The following definitions come from utils/net.c */ … … 46 31 47 32 /* 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);33 struct ads_struct; 34 ADS_STATUS ads_startup(struct net_context *c, bool only_own_domain, struct ads_struct **ads); 35 ADS_STATUS ads_startup_nobind(struct net_context *c, bool only_own_domain, struct ads_struct **ads); 51 36 int net_ads_check_our_domain(struct net_context *c); 52 37 int net_ads_check(struct net_context *c); … … 103 88 /* The following definitions come from utils/net_idmap.c */ 104 89 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);109 90 int net_idmap(struct net_context *c, int argc, const char **argv); 110 91 … … 155 136 156 137 NTSTATUS net_get_remote_domain_sid(struct cli_state *cli, TALLOC_CTX *mem_ctx, 157 DOM_SID**domain_sid,138 struct dom_sid **domain_sid, 158 139 const char **domain_name); 159 140 int run_rpc_command(struct net_context *c, … … 167 148 int net_rpc_join(struct net_context *c, int argc, const char **argv); 168 149 NTSTATUS rpc_info_internals(struct net_context *c, 169 const DOM_SID*domain_sid,150 const struct dom_sid *domain_sid, 170 151 const char *domain_name, 171 152 struct cli_state *cli, … … 194 175 int net_rpc_file(struct net_context *c, int argc, const char **argv); 195 176 NTSTATUS rpc_init_shutdown_internals(struct net_context *c, 196 const DOM_SID*domain_sid,177 const struct dom_sid *domain_sid, 197 178 const char *domain_name, 198 179 struct cli_state *cli, … … 202 183 const char **argv); 203 184 NTSTATUS rpc_reg_shutdown_internals(struct net_context *c, 204 const DOM_SID*domain_sid,185 const struct dom_sid *domain_sid, 205 186 const char *domain_name, 206 187 struct cli_state *cli, … … 243 224 bool copy_timestamps, bool is_file); 244 225 NTSTATUS rpc_printer_list_internals(struct net_context *c, 245 const DOM_SID*domain_sid,226 const struct dom_sid *domain_sid, 246 227 const char *domain_name, 247 228 struct cli_state *cli, … … 251 232 const char **argv); 252 233 NTSTATUS rpc_printer_driver_list_internals(struct net_context *c, 253 const DOM_SID*domain_sid,234 const struct dom_sid *domain_sid, 254 235 const char *domain_name, 255 236 struct cli_state *cli, … … 259 240 const char **argv); 260 241 NTSTATUS rpc_printer_publish_publish_internals(struct net_context *c, 261 const DOM_SID*domain_sid,242 const struct dom_sid *domain_sid, 262 243 const char *domain_name, 263 244 struct cli_state *cli, … … 267 248 const char **argv); 268 249 NTSTATUS rpc_printer_publish_unpublish_internals(struct net_context *c, 269 const DOM_SID*domain_sid,250 const struct dom_sid *domain_sid, 270 251 const char *domain_name, 271 252 struct cli_state *cli, … … 275 256 const char **argv); 276 257 NTSTATUS rpc_printer_publish_update_internals(struct net_context *c, 277 const DOM_SID*domain_sid,258 const struct dom_sid *domain_sid, 278 259 const char *domain_name, 279 260 struct cli_state *cli, … … 283 264 const char **argv); 284 265 NTSTATUS rpc_printer_publish_list_internals(struct net_context *c, 285 const DOM_SID*domain_sid,266 const struct dom_sid *domain_sid, 286 267 const char *domain_name, 287 268 struct cli_state *cli, … … 291 272 const char **argv); 292 273 NTSTATUS rpc_printer_migrate_security_internals(struct net_context *c, 293 const DOM_SID*domain_sid,274 const struct dom_sid *domain_sid, 294 275 const char *domain_name, 295 276 struct cli_state *cli, … … 299 280 const char **argv); 300 281 NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c, 301 const DOM_SID*domain_sid,282 const struct dom_sid *domain_sid, 302 283 const char *domain_name, 303 284 struct cli_state *cli, … … 307 288 const char **argv); 308 289 NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c, 309 const DOM_SID*domain_sid,290 const struct dom_sid *domain_sid, 310 291 const char *domain_name, 311 292 struct cli_state *cli, … … 315 296 const char **argv); 316 297 NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c, 317 const DOM_SID*domain_sid,298 const struct dom_sid *domain_sid, 318 299 const char *domain_name, 319 300 struct cli_state *cli, … … 323 304 const char **argv); 324 305 NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c, 325 const DOM_SID*domain_sid,306 const struct dom_sid *domain_sid, 326 307 const char *domain_name, 327 308 struct cli_state *cli, … … 344 325 345 326 NTSTATUS rpc_samdump_internals(struct net_context *c, 346 const DOM_SID*domain_sid,327 const struct dom_sid *domain_sid, 347 328 const char *domain_name, 348 329 struct cli_state *cli, … … 352 333 const char **argv); 353 334 int 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);362 335 int rpc_vampire_passdb(struct net_context *c, int argc, const char **argv); 363 336 int 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);380 337 int rpc_vampire_keytab(struct net_context *c, int argc, const char **argv); 381 338 … … 428 385 int net_eventlog(struct net_context *c, int argc, const char **argv); 429 386 387 /* The following definitions come from utils/net_printing.c */ 388 389 int net_printing(struct net_context *c, int argc, const char **argv); 390 391 /* The following definitions come from utils/net_serverid.c */ 392 393 int net_serverid(struct net_context *c, int argc, const char **argv); 394 430 395 /* The following definitions come from utils/net_util.c */ 431 396 … … 433 398 TALLOC_CTX *mem_ctx, struct cli_state *cli, 434 399 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, 436 401 enum lsa_SidType *ret_type); 437 402 NTSTATUS connect_to_service(struct net_context *c, … … 487 452 NTSTATUS net_lookup_name_from_sid(struct net_context *c, 488 453 TALLOC_CTX *ctx, 489 DOM_SID*psid,454 struct dom_sid *psid, 490 455 const char **ppdomain, 491 456 const char **ppname); 492 457 NTSTATUS 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); 494 459 495 460 /* The following definitions come from utils/passwd_util.c */ … … 501 466 int net_g_lock(struct net_context *c, int argc, const char **argv); 502 467 468 /* The following definitions come from utils/net_rpc_trust.c */ 469 int net_rpc_trust(struct net_context *c, int argc, const char **argv); 470 503 471 #endif /* _NET_PROTO_H_ */ -
vendor/current/source3/utils/net_rap.c
r414 r740 24 24 25 25 #include "includes.h" 26 #include "../librpc/gen_ndr/rap.h" 27 #include "../librpc/gen_ndr/svcctl.h" 26 28 #include "utils/net.h" 29 #include "libsmb/libsmb.h" 30 #include "libsmb/clirap.h" 27 31 28 32 /* The following messages were for error checking that is not properly … … 227 231 int ret; 228 232 229 RAP_SHARE_INFO_2 sinfo;233 struct rap_share_info_2 sinfo; 230 234 char *p; 231 235 char *sharename; … … 246 250 } 247 251 *p = 0; 248 strlcpy( sinfo.share_name, sharename, sizeof(sinfo.share_name));252 strlcpy((char *)sinfo.share_name, sharename, sizeof(sinfo.share_name)); 249 253 sinfo.reserved1 = '\0'; 250 254 sinfo.share_type = 0; 251 sinfo.comment = smb_xstrdup(c->opt_comment);255 sinfo.comment = c->opt_comment ? smb_xstrdup(c->opt_comment) : ""; 252 256 sinfo.perms = 0; 253 257 sinfo.maximum_users = c->opt_maxusers; … … 813 817 struct cli_state *cli; 814 818 int ret; 815 RAP_USER_INFO_1 userinfo;819 struct rap_user_info_1 userinfo; 816 820 817 821 if (argc == 0 || c->display_usage) { … … 822 826 return -1; 823 827 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) 826 830 c->opt_flags = 0x21; 827 831 … … 957 961 struct cli_state *cli; 958 962 int ret; 959 RAP_GROUP_INFO_1 grinfo;963 struct rap_group_info_1 grinfo; 960 964 961 965 if (argc == 0 || c->display_usage) { … … 967 971 968 972 /* 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); 970 974 grinfo.reserved1 = '\0'; 971 975 grinfo.comment = smb_xstrdup(c->opt_comment ? c->opt_comment : ""); -
vendor/current/source3/utils/net_registry.c
r414 r740 21 21 22 22 #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" 23 27 #include "utils/net.h" 24 28 #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" 26 38 27 39 /* … … 40 52 { 41 53 WERROR werr; 42 NT_USER_TOKEN*token = NULL;54 struct security_token *token = NULL; 43 55 char *hivename = NULL; 44 56 char *tmp_subkeyname = NULL; … … 111 123 } 112 124 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; 125 static 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; 126 130 NTTIME modtime; 127 131 uint32_t count; 128 char *valname = NULL;132 char* valname = NULL; 129 133 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 } 157 154 } 158 155 … … 168 165 } 169 166 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 188 done: 189 TALLOC_FREE(ctx); 190 return werr; 191 } 192 193 194 195 /* 196 * 197 * the main "net registry" function implementations 198 * 199 */ 200 static 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 } 229 done: 230 TALLOC_FREE(ctx); 231 return ret; 232 } 233 234 static 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 } 263 done: 264 TALLOC_FREE(ctx); 265 return ret; 266 } 267 175 268 176 269 static int net_registry_createkey(struct net_context *c, int argc, … … 233 326 } 234 327 235 static int net_registry_deletekey(struct net_context *c, int argc, 236 const char **argv) 328 static int net_registry_deletekey_internal(struct net_context *c, int argc, 329 const char **argv, 330 bool recursive) 237 331 { 238 332 WERROR werr; … … 264 358 } 265 359 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 { 268 368 d_fprintf(stderr, "reg_deletekey %s: %s\n", _("failed"), 269 369 win_errstr(werr)); … … 276 376 TALLOC_FREE(ctx); 277 377 return ret; 378 } 379 380 static 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 386 static 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); 278 390 } 279 391 … … 290 402 d_fprintf(stderr, "%s\n%s", 291 403 _("Usage:"), 292 _("net r pc registry getvalue <key> <valuename>\n"));404 _("net registry getvalue <key> <valuename>\n")); 293 405 goto done; 294 406 } … … 326 438 { 327 439 return net_registry_getvalue_internal(c, argc, argv, true); 440 } 441 442 static 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 } 480 done: 481 TALLOC_FREE(ctx); 482 return ret; 328 483 } 329 484 … … 340 495 d_fprintf(stderr, "%s\n%s", 341 496 _("Usage:"), 342 _("net r pc registry setvalue <key> <valuename> "497 _("net registry setvalue <key> <valuename> " 343 498 "<type> [<val>]+\n")); 344 499 goto done; … … 351 506 352 507 if (strequal(argv[2], "dword")) { 508 uint32_t v = strtoul(argv[3], NULL, 10); 353 509 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); 355 512 } else if (strequal(argv[2], "sz")) { 356 513 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 } 359 517 } else if (strequal(argv[2], "multi_sz")) { 518 const char **array; 519 int count = argc - 3; 520 int i; 360 521 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 } 363 535 } else { 364 536 d_fprintf(stderr, _("type \"%s\" not implemented\n"), argv[2]); … … 383 555 done: 384 556 TALLOC_FREE(ctx); 557 return ret; 558 } 559 560 struct 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 568 static 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 615 done: 616 TALLOC_FREE(key); 617 return; 618 } 619 620 static 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 661 done: 385 662 return ret; 386 663 } … … 397 674 d_fprintf(stderr, "%s\n%s", 398 675 _("Usage:"), 399 _("net r pc registry deletevalue <key> <valuename>\n"));676 _("net registry deletevalue <key> <valuename>\n")); 400 677 goto done; 401 678 } … … 409 686 werr = reg_deletevalue(key, argv[1]); 410 687 if (!W_ERROR_IS_OK(werr)) { 411 d_fprintf(stderr, _("reg_delete keyfailed: %s\n"),688 d_fprintf(stderr, _("reg_deletevalue failed: %s\n"), 412 689 win_errstr(werr)); 413 690 goto done; … … 421 698 } 422 699 423 static int net_registry_getsd(struct net_context *c, int argc, 424 const char **argv) 425 { 426 WERROR werr; 427 int ret = -1; 700 static 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; 428 706 struct registry_key *key = NULL; 429 struct security_descriptor *secdesc = NULL;430 707 TALLOC_CTX *ctx = talloc_stackframe(); 431 708 uint32_t access_mask = REG_KEY_READ | … … 439 716 access_mask = REG_KEY_READ; 440 717 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 746 done: 747 TALLOC_FREE(ctx); 748 return werr; 749 } 750 751 static 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 441 759 if (argc != 1 || c->display_usage) { 442 760 d_printf("%s\n%s", … … 448 766 goto done; 449 767 } 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 778 done: 779 TALLOC_FREE(ctx); 780 return ret; 781 } 782 783 static 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 810 done: 811 TALLOC_FREE(ctx); 812 return ret; 813 } 814 815 static 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 855 done: 856 TALLOC_FREE(ctx); 857 return werr; 858 } 859 860 static 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 890 done: 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 906 struct import_ctx { 907 TALLOC_CTX *mem_ctx; 908 }; 909 910 911 static 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 956 done: 957 talloc_free(mem_ctx); 958 return werr; 959 } 960 961 static WERROR import_close_key(struct import_ctx* ctx, 962 struct registry_key* key) 963 { 964 return WERR_OK; 965 } 966 967 static 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 992 done: 993 talloc_free(mem_ctx); 994 return werr; 995 } 996 997 static 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 1015 static 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 1032 static 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 1095 static 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; 1147 done: 1148 return ret; 1149 } 1150 1151 static 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); 456 1172 if (!W_ERROR_IS_OK(werr)) { 457 1173 d_fprintf(stderr, _("open_key failed: %s\n"), win_errstr(werr)); … … 459 1175 } 460 1176 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 1185 done: 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 1198 static 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 /******************************************************************************/ 476 1245 477 1246 int net_registry(struct net_context *c, int argc, const char **argv) … … 489 1258 }, 490 1259 { 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 { 491 1268 "createkey", 492 1269 net_registry_createkey, … … 505 1282 }, 506 1283 { 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 { 507 1292 "getvalue", 508 1293 net_registry_getvalue, … … 521 1306 }, 522 1307 { 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 { 523 1316 "setvalue", 524 1317 net_registry_setvalue, … … 529 1322 }, 530 1323 { 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 { 531 1332 "deletevalue", 532 1333 net_registry_deletevalue, … … 544 1345 " Get security descriptor") 545 1346 }, 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 }, 546 1387 { NULL, NULL, 0, NULL, NULL } 547 1388 }; -
vendor/current/source3/utils/net_registry_util.c
r414 r740 21 21 22 22 #include "includes.h" 23 #include "registry.h" 23 24 #include "utils/net_registry_util.h" 24 25 #include "utils/net.h" 26 #include "../libcli/registry/util_reg.h" 25 27 26 28 void print_registry_key(const char *keyname, NTTIME *modtime) … … 38 40 if (!raw) { 39 41 d_printf(_("Type = %s\n"), 40 reg_type_lookup(valvalue->type));42 str_regtype(valvalue->type)); 41 43 } 42 44 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 } 44 50 if (!raw) { 45 51 d_printf(_("Value = ")); 46 52 } 47 d_printf("%d\n", v alvalue->v.dword);53 d_printf("%d\n", v); 48 54 break; 55 } 49 56 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 } 51 63 if (!raw) { 52 64 d_printf(_("Value = \"")); 53 65 } 54 d_printf("%s", valvalue->v.sz.str);66 d_printf("%s", s); 55 67 if (!raw) { 56 68 d_printf("\""); … … 58 70 d_printf("\n"); 59 71 break; 72 } 60 73 case REG_MULTI_SZ: { 61 74 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++) { 63 81 if (!raw) { 64 82 d_printf(_("Value[%3.3d] = \""), j); 65 83 } 66 d_printf("%s", valvalue->v.multi_sz.strings[j]);84 d_printf("%s", a[j]); 67 85 if (!raw) { 68 86 d_printf("\""); … … 76 94 d_printf(_("Value = ")); 77 95 } 78 d_printf(_("%d bytes\n"), (int)valvalue-> v.binary.length);96 d_printf(_("%d bytes\n"), (int)valvalue->data.length); 79 97 break; 80 98 default: … … 98 116 * Split path into hive name and subkeyname 99 117 * 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 '\\' 101 121 * - strip trailing '\\' chars 102 122 */ … … 115 135 } 116 136 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 118 143 if (*hivename == NULL) { 119 144 return WERR_NOMEM; -
vendor/current/source3/utils/net_rpc.c
r478 r740 23 23 #include "includes.h" 24 24 #include "utils/net.h" 25 #include "rpc_client/cli_pipe.h" 25 26 #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" 33 46 34 47 static int net_mode_share; 35 static boolsync_files(struct copy_clistate *cp_clistate, const char *mask);48 static NTSTATUS sync_files(struct copy_clistate *cp_clistate, const char *mask); 36 49 37 50 /** … … 60 73 61 74 NTSTATUS net_get_remote_domain_sid(struct cli_state *cli, TALLOC_CTX *mem_ctx, 62 DOM_SID**domain_sid,75 struct dom_sid **domain_sid, 63 76 const char **domain_name) 64 77 { 65 78 struct rpc_pipe_client *lsa_pipe = NULL; 66 79 struct policy_handle pol; 67 NTSTATUS result = NT_STATUS_OK;80 NTSTATUS status, result; 68 81 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, 71 85 &lsa_pipe); 72 if (!NT_STATUS_IS_OK( result)) {86 if (!NT_STATUS_IS_OK(status)) { 73 87 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, 78 94 SEC_FLAG_MAXIMUM_ALLOWED, 79 95 &pol); 80 if (!NT_STATUS_IS_OK( result)) {96 if (!NT_STATUS_IS_OK(status)) { 81 97 d_fprintf(stderr, "open_policy %s: %s\n", 82 98 _("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, 88 104 &pol, 89 105 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 } 91 114 if (!NT_STATUS_IS_OK(result)) { 92 115 d_fprintf(stderr, "lsaquery %s: %s\n", … … 99 122 *domain_sid = info->account_domain.sid; 100 123 101 rpccli_lsa_Close(lsa_pipe, mem_ctx, &pol);124 dcerpc_lsa_Close(b, mem_ctx, &pol, &result); 102 125 TALLOC_FREE(lsa_pipe); 103 126 … … 129 152 TALLOC_CTX *mem_ctx; 130 153 NTSTATUS nt_status; 131 DOM_SID*domain_sid;154 struct dom_sid *domain_sid; 132 155 const char *domain_name; 133 156 int ret = -1; … … 242 265 243 266 static NTSTATUS rpc_changetrustpw_internals(struct net_context *c, 244 const DOM_SID*domain_sid,267 const struct dom_sid *domain_sid, 245 268 const char *domain_name, 246 269 struct cli_state *cli, … … 310 333 311 334 static NTSTATUS rpc_oldjoin_internals(struct net_context *c, 312 const DOM_SID*domain_sid,335 const struct dom_sid *domain_sid, 313 336 const char *domain_name, 314 337 struct cli_state *cli, … … 489 512 490 513 NTSTATUS rpc_info_internals(struct net_context *c, 491 const DOM_SID*domain_sid,514 const struct dom_sid *domain_sid, 492 515 const char *domain_name, 493 516 struct cli_state *cli, … … 498 521 { 499 522 struct policy_handle connect_pol, domain_pol; 500 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;523 NTSTATUS status, result; 501 524 union samr_DomainInfo *info = NULL; 502 525 fstring sid_str; 526 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 503 527 504 528 sid_to_fstring(sid_str, domain_sid); 505 529 506 530 /* Get sam policy handle */ 507 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,531 status = dcerpc_samr_Connect2(b, mem_ctx, 508 532 pipe_hnd->desthost, 509 533 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 511 542 if (!NT_STATUS_IS_OK(result)) { 543 status = result; 512 544 d_fprintf(stderr, _("Could not connect to SAM: %s\n"), 513 545 nt_errstr(result)); … … 516 548 517 549 /* Get domain policy handle */ 518 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,550 status = dcerpc_samr_OpenDomain(b, mem_ctx, 519 551 &connect_pol, 520 552 MAXIMUM_ALLOWED_ACCESS, 521 553 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 } 523 561 if (!NT_STATUS_IS_OK(result)) { 562 status = result; 524 563 d_fprintf(stderr, _("Could not open domain: %s\n"), 525 564 nt_errstr(result)); … … 527 566 } 528 567 529 result = rpccli_samr_QueryDomainInfo(pipe_hnd, mem_ctx,568 status = dcerpc_samr_QueryDomainInfo(b, mem_ctx, 530 569 &domain_pol, 531 570 2, 532 &info); 571 &info, 572 &result); 573 if (!NT_STATUS_IS_OK(status)) { 574 goto done; 575 } 576 status = result; 533 577 if (NT_STATUS_IS_OK(result)) { 534 578 d_printf(_("Domain Name: %s\n"), … … 543 587 544 588 done: 545 return result;589 return status; 546 590 } 547 591 … … 586 630 587 631 static NTSTATUS rpc_getsid_internals(struct net_context *c, 588 const DOM_SID*domain_sid,632 const struct dom_sid *domain_sid, 589 633 const char *domain_name, 590 634 struct cli_state *cli, … … 728 772 } 729 773 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 787 static 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 } 730 825 return status; 731 826 } … … 894 989 uint32_t max_entries, max_size; 895 990 896 get_query_dispinfo_params(991 dcerpc_get_query_dispinfo_params( 897 992 loop_count, &max_entries, &max_size); 898 993 … … 956 1051 N_("List domain groups of user"), 957 1052 N_("net rpc user info\n" 958 " Lis domain groups of user")1053 " List domain groups of user") 959 1054 }, 960 1055 { … … 982 1077 " Rename specified user") 983 1078 }, 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 }, 984 1087 {NULL, NULL, 0, NULL, NULL} 985 1088 }; 986 1089 987 status = libnetapi_ init(&c->netapi_ctx);1090 status = libnetapi_net_init(&c->netapi_ctx); 988 1091 if (status != 0) { 989 1092 return -1; … … 1044 1147 { 1045 1148 struct policy_handle connect_pol, domain_pol, user_pol; 1046 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;1047 DOM_SIDsid;1149 NTSTATUS status, result; 1150 struct dom_sid sid; 1048 1151 uint32 rid; 1049 1152 enum lsa_SidType type; 1153 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 1050 1154 1051 1155 if (argc == 0) { … … 1059 1163 ZERO_STRUCT(user_pol); 1060 1164 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), 1062 1166 argv[0], NULL, NULL, &sid, &type); 1063 if (!NT_STATUS_IS_OK( result)) {1167 if (!NT_STATUS_IS_OK(status)) { 1064 1168 d_fprintf(stderr, _("Could not lookup %s: %s\n"), argv[0], 1065 nt_errstr( result));1169 nt_errstr(status)); 1066 1170 goto done; 1067 1171 } … … 1070 1174 d_fprintf(stderr, _("%s is a %s, not a user\n"), argv[0], 1071 1175 sid_type_lookup(type)); 1072 result= NT_STATUS_NO_SUCH_USER;1176 status = NT_STATUS_NO_SUCH_USER; 1073 1177 goto done; 1074 1178 } … … 1076 1180 if (!sid_peek_check_rid(ctx->domain_sid, &sid, &rid)) { 1077 1181 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, 1083 1187 pipe_hnd->desthost, 1084 1188 MAXIMUM_ALLOWED_ACCESS, 1085 &connect_pol); 1189 &connect_pol, 1190 &result); 1191 if (!NT_STATUS_IS_OK(status)) { 1192 goto done; 1193 } 1086 1194 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, 1091 1200 &connect_pol, 1092 1201 MAXIMUM_ALLOWED_ACCESS, 1093 1202 ctx->domain_sid, 1094 &domain_pol); 1203 &domain_pol, 1204 &result); 1205 if (!NT_STATUS_IS_OK(status)) { 1206 goto done; 1207 } 1095 1208 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, 1100 1214 &domain_pol, 1101 1215 MAXIMUM_ALLOWED_ACCESS, 1102 1216 rid, 1103 &user_pol); 1217 &user_pol, 1218 &result); 1219 if (!NT_STATUS_IS_OK(status)) { 1220 goto done; 1221 } 1104 1222 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); 1109 1228 1110 1229 done: 1111 1230 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); 1113 1232 } 1114 1233 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); 1116 1235 } 1117 1236 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; 1121 1240 } 1122 1241 … … 1128 1247 int argc, const char **argv) 1129 1248 { 1130 NTSTATUS result;1249 NTSTATUS status, result; 1131 1250 union samr_UserInfo *info = NULL; 1251 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 1132 1252 1133 1253 if (argc != 0) { … … 1137 1257 } 1138 1258 1139 result = rpccli_samr_QueryUserInfo(pipe_hnd, mem_ctx,1259 status = dcerpc_samr_QueryUserInfo(b, mem_ctx, 1140 1260 user_hnd, 1141 1261 21, 1142 &info); 1262 &info, 1263 &result); 1264 if (!NT_STATUS_IS_OK(status)) { 1265 return status; 1266 } 1143 1267 if (!NT_STATUS_IS_OK(result)) { 1144 1268 return result; … … 1180 1304 int argc, const char **argv) 1181 1305 { 1182 NTSTATUS result;1306 NTSTATUS status, result; 1183 1307 const char *username; 1184 1308 const char *oldval = ""; 1185 1309 union samr_UserInfo *info = NULL; 1310 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 1186 1311 1187 1312 if (argc > 1) { … … 1191 1316 } 1192 1317 1193 result = rpccli_samr_QueryUserInfo(pipe_hnd, mem_ctx,1318 status = dcerpc_samr_QueryUserInfo(b, mem_ctx, 1194 1319 user_hnd, 1195 1320 21, 1196 &info); 1321 &info, 1322 &result); 1323 if (!NT_STATUS_IS_OK(status)) { 1324 return status; 1325 } 1197 1326 if (!NT_STATUS_IS_OK(result)) { 1198 1327 return result; … … 1226 1355 SETSTR("description", description, DESCRIPTION); 1227 1356 1228 result = rpccli_samr_SetUserInfo(pipe_hnd, mem_ctx,1357 status = dcerpc_samr_SetUserInfo(b, mem_ctx, 1229 1358 user_hnd, 1230 1359 21, 1231 info); 1360 info, 1361 &result); 1362 if (!NT_STATUS_IS_OK(status)) { 1363 return status; 1364 } 1365 1366 status = result; 1232 1367 1233 1368 d_printf(_("Set %s's %s from [%s] to [%s]\n"), username, … … 1236 1371 done: 1237 1372 1238 return result;1373 return status; 1239 1374 } 1240 1375 … … 1265 1400 int argc, const char **argv) 1266 1401 { 1267 NTSTATUS result;1402 NTSTATUS status, result; 1268 1403 const char *username; 1269 1404 const char *oldval = "unknown"; … … 1271 1406 bool newval; 1272 1407 union samr_UserInfo *info = NULL; 1408 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 1273 1409 1274 1410 if ((argc > 1) || … … 1284 1420 newval = strequal(argv[0], "yes"); 1285 1421 1286 result = rpccli_samr_QueryUserInfo(pipe_hnd, mem_ctx,1422 status = dcerpc_samr_QueryUserInfo(b, mem_ctx, 1287 1423 user_hnd, 1288 1424 21, 1289 &info); 1425 &info, 1426 &result); 1427 if (!NT_STATUS_IS_OK(status)) { 1428 return status; 1429 } 1290 1430 if (!NT_STATUS_IS_OK(result)) { 1291 1431 return result; … … 1312 1452 info->info21.fields_present = SAMR_FIELD_ACCT_FLAGS; 1313 1453 1314 result = rpccli_samr_SetUserInfo(pipe_hnd, mem_ctx,1454 status = dcerpc_samr_SetUserInfo(b, mem_ctx, 1315 1455 user_hnd, 1316 1456 21, 1317 info); 1318 1457 info, 1458 &result); 1459 if (!NT_STATUS_IS_OK(status)) { 1460 goto done; 1461 } 1462 status = result; 1319 1463 if (NT_STATUS_IS_OK(result)) { 1320 1464 d_printf(_("Set %s's %s flag from [%s] to [%s]\n"), username, … … 1324 1468 done: 1325 1469 1326 return result;1470 return status; 1327 1471 } 1328 1472 … … 1434 1578 1435 1579 static NTSTATUS rpc_group_delete_internals(struct net_context *c, 1436 const DOM_SID*domain_sid,1580 const struct dom_sid *domain_sid, 1437 1581 const char *domain_name, 1438 1582 struct cli_state *cli, … … 1444 1588 struct policy_handle connect_pol, domain_pol, group_pol, user_pol; 1445 1589 bool group_is_primary = false; 1446 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;1590 NTSTATUS status, result; 1447 1591 uint32_t group_rid; 1448 struct samr_Rid TypeArray *rids = NULL;1592 struct samr_RidAttrArray *rids = NULL; 1449 1593 /* char **names; */ 1450 1594 int i; 1451 1595 /* struct samr_RidWithAttribute *user_gids; */ 1596 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 1452 1597 1453 1598 struct samr_Ids group_rids, name_types; … … 1460 1605 } 1461 1606 1462 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,1607 status = dcerpc_samr_Connect2(b, mem_ctx, 1463 1608 pipe_hnd->desthost, 1464 1609 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 } 1466 1616 1467 1617 if (!NT_STATUS_IS_OK(result)) { 1618 status = result; 1468 1619 d_fprintf(stderr, _("Request samr_Connect2 failed\n")); 1469 1620 goto done; 1470 1621 } 1471 1622 1472 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,1623 status = dcerpc_samr_OpenDomain(b, mem_ctx, 1473 1624 &connect_pol, 1474 1625 MAXIMUM_ALLOWED_ACCESS, 1475 1626 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 } 1477 1633 1478 1634 if (!NT_STATUS_IS_OK(result)) { 1635 status = result; 1479 1636 d_fprintf(stderr, _("Request open_domain failed\n")); 1480 1637 goto done; 1481 1638 } 1482 1639 1483 1640 init_lsa_String(&lsa_acct_name, argv[0]); 1484 1641 1485 result = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,1642 status = dcerpc_samr_LookupNames(b, mem_ctx, 1486 1643 &domain_pol, 1487 1644 1, 1488 1645 &lsa_acct_name, 1489 1646 &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 1491 1654 if (!NT_STATUS_IS_OK(result)) { 1655 status = result; 1492 1656 d_fprintf(stderr, _("Lookup of '%s' failed\n"),argv[0]); 1493 1657 goto done; 1494 1658 } 1495 1659 … … 1497 1661 { 1498 1662 case SID_NAME_DOM_GRP: 1499 result = rpccli_samr_OpenGroup(pipe_hnd, mem_ctx,1663 status = dcerpc_samr_OpenGroup(b, mem_ctx, 1500 1664 &domain_pol, 1501 1665 MAXIMUM_ALLOWED_ACCESS, 1502 1666 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 1504 1674 if (!NT_STATUS_IS_OK(result)) { 1675 status = result; 1505 1676 d_fprintf(stderr, _("Request open_group failed")); 1506 1677 goto done; 1507 1678 } 1508 1679 1509 1680 group_rid = group_rids.ids[0]; 1510 1681 1511 result = rpccli_samr_QueryGroupMember(pipe_hnd, mem_ctx,1682 status = dcerpc_samr_QueryGroupMember(b, mem_ctx, 1512 1683 &group_pol, 1513 &rids );1514 1515 if (!NT_STATUS_IS_OK( result)) {1684 &rids, 1685 &result); 1686 if (!NT_STATUS_IS_OK(status)) { 1516 1687 d_fprintf(stderr, 1517 1688 _("Unable to query group members of %s"), 1518 1689 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; 1520 1699 } 1521 1700 … … 1529 1708 for (i = 0; i < rids->count; i++) 1530 1709 { 1531 result = rpccli_samr_OpenUser(pipe_hnd, mem_ctx,1710 status = dcerpc_samr_OpenUser(b, mem_ctx, 1532 1711 &domain_pol, 1533 1712 MAXIMUM_ALLOWED_ACCESS, 1534 1713 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)) { 1538 1717 d_fprintf(stderr, 1539 1718 _("Unable to open group member %d\n"), 1540 1719 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, 1545 1732 &user_pol, 1546 1733 21, 1547 &info );1548 1549 if (!NT_STATUS_IS_OK(result)) {1734 &info, 1735 &result); 1736 if (!NT_STATUS_IS_OK(status)) { 1550 1737 d_fprintf(stderr, 1551 1738 _("Unable to lookup userinfo for group " 1552 1739 "member %d\n"), 1553 1740 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 } 1556 1752 1557 1753 if (info->info21.primary_gid == group_rid) { … … 1564 1760 } 1565 1761 1566 rpccli_samr_Close(pipe_hnd, mem_ctx, &user_pol);1762 dcerpc_samr_Close(b, mem_ctx, &user_pol, &result); 1567 1763 } 1568 1764 … … 1571 1767 "some of it's members have it as primary " 1572 1768 "group\n")); 1573 result= NT_STATUS_MEMBERS_PRIMARY_GROUP;1769 status = NT_STATUS_MEMBERS_PRIMARY_GROUP; 1574 1770 goto done; 1575 1771 } … … 1581 1777 d_printf(_("Remove group member %d..."), 1582 1778 rids->rids[i]); 1583 result = rpccli_samr_DeleteGroupMember(pipe_hnd, mem_ctx,1779 status = dcerpc_samr_DeleteGroupMember(b, mem_ctx, 1584 1780 &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; 1587 1787 if (NT_STATUS_IS_OK(result)) { 1588 1788 if (c->opt_verbose) … … 1595 1795 } 1596 1796 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; 1599 1805 1600 1806 break; 1601 1807 /* removing a local group is easier... */ 1602 1808 case SID_NAME_ALIAS: 1603 result = rpccli_samr_OpenAlias(pipe_hnd, mem_ctx,1809 status = dcerpc_samr_OpenAlias(b, mem_ctx, 1604 1810 &domain_pol, 1605 1811 MAXIMUM_ALLOWED_ACCESS, 1606 1812 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 } 1609 1819 if (!NT_STATUS_IS_OK(result)) { 1820 status = result; 1610 1821 d_fprintf(stderr, _("Request open_alias failed\n")); 1611 1822 goto done; 1612 1823 } 1613 1824 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 1616 1834 break; 1617 1835 default: … … 1619 1837 "for deleting local or global groups\n"), 1620 1838 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)) { 1626 1844 if (c->opt_verbose) 1627 1845 d_printf(_("Deleted %s '%s'\n"), … … 1629 1847 } else { 1630 1848 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)); 1632 1850 } 1633 1851 1634 1852 done: 1635 return result;1853 return status; 1636 1854 1637 1855 } … … 1720 1938 TALLOC_CTX *mem_ctx, 1721 1939 const char *name, 1722 DOM_SID*sid,1940 struct dom_sid *sid, 1723 1941 enum lsa_SidType *type) 1724 1942 { 1725 DOM_SID*sids = NULL;1943 struct dom_sid *sids = NULL; 1726 1944 enum lsa_SidType *types = NULL; 1727 1945 struct rpc_pipe_client *pipe_hnd = NULL; 1728 1946 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, 1732 1951 &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, 1738 1959 SEC_FLAG_MAXIMUM_ALLOWED, &lsa_pol); 1739 1960 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, 1745 1966 &name, NULL, 1, &sids, &types); 1746 1967 1747 if (NT_STATUS_IS_OK( result)) {1968 if (NT_STATUS_IS_OK(status)) { 1748 1969 sid_copy(sid, &sids[0]); 1749 1970 *type = types[0]; 1750 1971 } 1751 1972 1752 rpccli_lsa_Close(pipe_hnd, mem_ctx, &lsa_pol);1973 dcerpc_lsa_Close(b, mem_ctx, &lsa_pol, &result); 1753 1974 1754 1975 done: … … 1757 1978 } 1758 1979 1759 if (!NT_STATUS_IS_OK( result) && (StrnCaseCmp(name, "S-", 2) == 0)) {1980 if (!NT_STATUS_IS_OK(status) && (StrnCaseCmp(name, "S-", 2) == 0)) { 1760 1981 1761 1982 /* Try as S-1-5-whatever */ 1762 1983 1763 DOM_SIDtmp_sid;1984 struct dom_sid tmp_sid; 1764 1985 1765 1986 if (string_to_sid(&tmp_sid, name)) { 1766 1987 sid_copy(sid, &tmp_sid); 1767 1988 *type = SID_NAME_UNKNOWN; 1768 result= NT_STATUS_OK;1989 status = NT_STATUS_OK; 1769 1990 } 1770 1991 } 1771 1992 1772 return result;1993 return status; 1773 1994 } 1774 1995 1775 1996 static NTSTATUS rpc_add_groupmem(struct rpc_pipe_client *pipe_hnd, 1776 1997 TALLOC_CTX *mem_ctx, 1777 const DOM_SID*group_sid,1998 const struct dom_sid *group_sid, 1778 1999 const char *member) 1779 2000 { 1780 2001 struct policy_handle connect_pol, domain_pol; 1781 NTSTATUS result;2002 NTSTATUS status, result; 1782 2003 uint32 group_rid; 1783 2004 struct policy_handle group_pol; 2005 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 1784 2006 1785 2007 struct samr_Ids rids, rid_types; 1786 2008 struct lsa_String lsa_acct_name; 1787 2009 1788 DOM_SIDsid;2010 struct dom_sid sid; 1789 2011 1790 2012 sid_copy(&sid, group_sid); … … 1795 2017 1796 2018 /* Get sam policy handle */ 1797 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,2019 status = dcerpc_samr_Connect2(b, mem_ctx, 1798 2020 pipe_hnd->desthost, 1799 2021 MAXIMUM_ALLOWED_ACCESS, 1800 &connect_pol); 2022 &connect_pol, 2023 &result); 2024 if (!NT_STATUS_IS_OK(status)) { 2025 return status; 2026 } 1801 2027 if (!NT_STATUS_IS_OK(result)) { 1802 2028 return result; … … 1804 2030 1805 2031 /* Get domain policy handle */ 1806 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,2032 status = dcerpc_samr_OpenDomain(b, mem_ctx, 1807 2033 &connect_pol, 1808 2034 MAXIMUM_ALLOWED_ACCESS, 1809 2035 &sid, 1810 &domain_pol); 2036 &domain_pol, 2037 &result); 2038 if (!NT_STATUS_IS_OK(status)) { 2039 return status; 2040 } 1811 2041 if (!NT_STATUS_IS_OK(result)) { 1812 2042 return result; … … 1815 2045 init_lsa_String(&lsa_acct_name, member); 1816 2046 1817 result = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,2047 status = dcerpc_samr_LookupNames(b, mem_ctx, 1818 2048 &domain_pol, 1819 2049 1, 1820 2050 &lsa_acct_name, 1821 2051 &rids, 1822 &rid_types );1823 1824 if (!NT_STATUS_IS_OK( result)) {2052 &rid_types, 2053 &result); 2054 if (!NT_STATUS_IS_OK(status)) { 1825 2055 d_fprintf(stderr, _("Could not lookup up group member %s\n"), 1826 2056 member); … … 1828 2058 } 1829 2059 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, 1831 2068 &domain_pol, 1832 2069 MAXIMUM_ALLOWED_ACCESS, 1833 2070 group_rid, 1834 &group_pol); 2071 &group_pol, 2072 &result); 2073 if (!NT_STATUS_IS_OK(status)) { 2074 goto done; 2075 } 1835 2076 1836 2077 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, 1841 2083 &group_pol, 1842 2084 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; 1844 2092 1845 2093 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; 1848 2096 } 1849 2097 1850 2098 static NTSTATUS rpc_add_aliasmem(struct rpc_pipe_client *pipe_hnd, 1851 2099 TALLOC_CTX *mem_ctx, 1852 const DOM_SID*alias_sid,2100 const struct dom_sid *alias_sid, 1853 2101 const char *member) 1854 2102 { 1855 2103 struct policy_handle connect_pol, domain_pol; 1856 NTSTATUS result;2104 NTSTATUS status, result; 1857 2105 uint32 alias_rid; 1858 2106 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; 1861 2110 enum lsa_SidType member_type; 1862 2111 1863 DOM_SIDsid;2112 struct dom_sid sid; 1864 2113 1865 2114 sid_copy(&sid, alias_sid); … … 1879 2128 1880 2129 /* Get sam policy handle */ 1881 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,2130 status = dcerpc_samr_Connect2(b, mem_ctx, 1882 2131 pipe_hnd->desthost, 1883 2132 MAXIMUM_ALLOWED_ACCESS, 1884 &connect_pol); 2133 &connect_pol, 2134 &result); 2135 if (!NT_STATUS_IS_OK(status)) { 2136 goto done; 2137 } 1885 2138 if (!NT_STATUS_IS_OK(result)) { 2139 status = result; 1886 2140 goto done; 1887 2141 } 1888 2142 1889 2143 /* Get domain policy handle */ 1890 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,2144 status = dcerpc_samr_OpenDomain(b, mem_ctx, 1891 2145 &connect_pol, 1892 2146 MAXIMUM_ALLOWED_ACCESS, 1893 2147 &sid, 1894 &domain_pol); 2148 &domain_pol, 2149 &result); 2150 if (!NT_STATUS_IS_OK(status)) { 2151 goto done; 2152 } 1895 2153 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, 1900 2159 &domain_pol, 1901 2160 MAXIMUM_ALLOWED_ACCESS, 1902 2161 alias_rid, 1903 &alias_pol); 1904 2162 &alias_pol, 2163 &result); 2164 if (!NT_STATUS_IS_OK(status)) { 2165 return status; 2166 } 1905 2167 if (!NT_STATUS_IS_OK(result)) { 1906 2168 return result; 1907 2169 } 1908 2170 1909 result = rpccli_samr_AddAliasMember(pipe_hnd, mem_ctx,2171 status = dcerpc_samr_AddAliasMember(b, mem_ctx, 1910 2172 &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; 1916 2180 1917 2181 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; 1920 2184 } 1921 2185 1922 2186 static NTSTATUS rpc_group_addmem_internals(struct net_context *c, 1923 const DOM_SID*domain_sid,2187 const struct dom_sid *domain_sid, 1924 2188 const char *domain_name, 1925 2189 struct cli_state *cli, … … 1929 2193 const char **argv) 1930 2194 { 1931 DOM_SIDgroup_sid;2195 struct dom_sid group_sid; 1932 2196 enum lsa_SidType group_type; 1933 2197 … … 1987 2251 struct rpc_pipe_client *pipe_hnd, 1988 2252 TALLOC_CTX *mem_ctx, 1989 const DOM_SID*group_sid,2253 const struct dom_sid *group_sid, 1990 2254 const char *member) 1991 2255 { 1992 2256 struct policy_handle connect_pol, domain_pol; 1993 NTSTATUS result;2257 NTSTATUS status, result; 1994 2258 uint32 group_rid; 1995 2259 struct policy_handle group_pol; 2260 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 1996 2261 1997 2262 struct samr_Ids rids, rid_types; 1998 2263 struct lsa_String lsa_acct_name; 1999 2264 2000 DOM_SIDsid;2265 struct dom_sid sid; 2001 2266 2002 2267 sid_copy(&sid, group_sid); … … 2006 2271 2007 2272 /* Get sam policy handle */ 2008 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,2273 status = dcerpc_samr_Connect2(b, mem_ctx, 2009 2274 pipe_hnd->desthost, 2010 2275 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)) { 2013 2282 return result; 2283 } 2284 2014 2285 2015 2286 /* Get domain policy handle */ 2016 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,2287 status = dcerpc_samr_OpenDomain(b, mem_ctx, 2017 2288 &connect_pol, 2018 2289 MAXIMUM_ALLOWED_ACCESS, 2019 2290 &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)) { 2022 2297 return result; 2298 } 2023 2299 2024 2300 init_lsa_String(&lsa_acct_name, member); 2025 2301 2026 result = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,2302 status = dcerpc_samr_LookupNames(b, mem_ctx, 2027 2303 &domain_pol, 2028 2304 1, 2029 2305 &lsa_acct_name, 2030 2306 &rids, 2031 &rid_types); 2032 if (!NT_STATUS_IS_OK(result)) { 2307 &rid_types, 2308 &result); 2309 if (!NT_STATUS_IS_OK(status)) { 2033 2310 d_fprintf(stderr, _("Could not lookup up group member %s\n"), 2034 2311 member); … … 2036 2313 } 2037 2314 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, 2039 2323 &domain_pol, 2040 2324 MAXIMUM_ALLOWED_ACCESS, 2041 2325 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, 2048 2337 &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; 2051 2345 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; 2054 2348 } 2055 2349 2056 2350 static NTSTATUS rpc_del_aliasmem(struct rpc_pipe_client *pipe_hnd, 2057 2351 TALLOC_CTX *mem_ctx, 2058 const DOM_SID*alias_sid,2352 const struct dom_sid *alias_sid, 2059 2353 const char *member) 2060 2354 { 2061 2355 struct policy_handle connect_pol, domain_pol; 2062 NTSTATUS result;2356 NTSTATUS status, result; 2063 2357 uint32 alias_rid; 2064 2358 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; 2067 2362 enum lsa_SidType member_type; 2068 2363 2069 DOM_SIDsid;2364 struct dom_sid sid; 2070 2365 2071 2366 sid_copy(&sid, alias_sid); … … 2084 2379 2085 2380 /* Get sam policy handle */ 2086 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,2381 status = dcerpc_samr_Connect2(b, mem_ctx, 2087 2382 pipe_hnd->desthost, 2088 2383 MAXIMUM_ALLOWED_ACCESS, 2089 &connect_pol); 2384 &connect_pol, 2385 &result); 2386 if (!NT_STATUS_IS_OK(status)) { 2387 goto done; 2388 } 2090 2389 if (!NT_STATUS_IS_OK(result)) { 2390 status = result; 2091 2391 goto done; 2092 2392 } 2093 2393 2094 2394 /* Get domain policy handle */ 2095 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,2395 status = dcerpc_samr_OpenDomain(b, mem_ctx, 2096 2396 &connect_pol, 2097 2397 MAXIMUM_ALLOWED_ACCESS, 2098 2398 &sid, 2099 &domain_pol); 2399 &domain_pol, 2400 &result); 2401 if (!NT_STATUS_IS_OK(status)) { 2402 goto done; 2403 } 2100 2404 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, 2105 2410 &domain_pol, 2106 2411 MAXIMUM_ALLOWED_ACCESS, 2107 2412 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)) { 2111 2420 return result; 2112 2113 result = rpccli_samr_DeleteAliasMember(pipe_hnd, mem_ctx, 2421 } 2422 2423 status = dcerpc_samr_DeleteAliasMember(b, mem_ctx, 2114 2424 &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; 2119 2433 2120 2434 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; 2123 2437 } 2124 2438 2125 2439 static NTSTATUS rpc_group_delmem_internals(struct net_context *c, 2126 const DOM_SID*domain_sid,2440 const struct dom_sid *domain_sid, 2127 2441 const char *domain_name, 2128 2442 struct cli_state *cli, … … 2132 2446 const char **argv) 2133 2447 { 2134 DOM_SIDgroup_sid;2448 struct dom_sid group_sid; 2135 2449 enum lsa_SidType group_type; 2136 2450 … … 2204 2518 2205 2519 static NTSTATUS rpc_group_list_internals(struct net_context *c, 2206 const DOM_SID*domain_sid,2520 const struct dom_sid *domain_sid, 2207 2521 const char *domain_name, 2208 2522 struct cli_state *cli, … … 2213 2527 { 2214 2528 struct policy_handle connect_pol, domain_pol; 2215 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;2529 NTSTATUS status, result; 2216 2530 uint32 start_idx=0, max_entries=250, num_entries, i, loop_count = 0; 2217 2531 struct samr_SamArray *groups = NULL; … … 2219 2533 bool local = false; 2220 2534 bool builtin = false; 2535 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 2221 2536 2222 2537 if (c->display_usage) { … … 2253 2568 /* Get sam policy handle */ 2254 2569 2255 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,2570 status = dcerpc_samr_Connect2(b, mem_ctx, 2256 2571 pipe_hnd->desthost, 2257 2572 MAXIMUM_ALLOWED_ACCESS, 2258 &connect_pol); 2573 &connect_pol, 2574 &result); 2575 if (!NT_STATUS_IS_OK(status)) { 2576 goto done; 2577 } 2259 2578 if (!NT_STATUS_IS_OK(result)) { 2579 status = result; 2260 2580 goto done; 2261 2581 } … … 2263 2583 /* Get domain policy handle */ 2264 2584 2265 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,2585 status = dcerpc_samr_OpenDomain(b, mem_ctx, 2266 2586 &connect_pol, 2267 2587 MAXIMUM_ALLOWED_ACCESS, 2268 2588 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 } 2270 2594 if (!NT_STATUS_IS_OK(result)) { 2595 status = result; 2271 2596 goto done; 2272 2597 } … … 2282 2607 if (!global) break; 2283 2608 2284 get_query_dispinfo_params(2609 dcerpc_get_query_dispinfo_params( 2285 2610 loop_count, &max_entries, &max_size); 2286 2611 2287 result = rpccli_samr_QueryDisplayInfo(pipe_hnd, mem_ctx,2612 status = dcerpc_samr_QueryDisplayInfo(b, mem_ctx, 2288 2613 &domain_pol, 2289 2614 3, … … 2293 2618 &total_size, 2294 2619 &returned_size, 2295 &info); 2620 &info, 2621 &result); 2622 if (!NT_STATUS_IS_OK(status)) { 2623 goto done; 2624 } 2296 2625 num_entries = info.info3.count; 2297 2626 start_idx += info.info3.count; … … 2321 2650 if (!local) break; 2322 2651 2323 result = rpccli_samr_EnumDomainAliases(pipe_hnd, mem_ctx,2652 status = dcerpc_samr_EnumDomainAliases(b, mem_ctx, 2324 2653 &domain_pol, 2325 2654 &start_idx, 2326 2655 &groups, 2327 2656 0xffff, 2328 &num_entries); 2657 &num_entries, 2658 &result); 2659 if (!NT_STATUS_IS_OK(status)) { 2660 goto done; 2661 } 2329 2662 if (!NT_STATUS_IS_OK(result) && 2330 2663 !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES)) … … 2339 2672 struct policy_handle alias_pol; 2340 2673 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 } 2354 2696 } 2355 2697 } … … 2364 2706 } 2365 2707 } 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); 2367 2709 /* Get builtin policy handle */ 2368 2710 2369 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,2711 status = dcerpc_samr_OpenDomain(b, mem_ctx, 2370 2712 &connect_pol, 2371 2713 MAXIMUM_ALLOWED_ACCESS, 2372 2714 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 } 2374 2720 if (!NT_STATUS_IS_OK(result)) { 2375 goto done; 2376 } 2721 status = result; 2722 goto done; 2723 } 2724 2377 2725 /* query builtin aliases */ 2378 2726 start_idx = 0; … … 2380 2728 if (!builtin) break; 2381 2729 2382 result = rpccli_samr_EnumDomainAliases(pipe_hnd, mem_ctx,2730 status = dcerpc_samr_EnumDomainAliases(b, mem_ctx, 2383 2731 &domain_pol, 2384 2732 &start_idx, 2385 2733 &groups, 2386 2734 max_entries, 2387 &num_entries); 2735 &num_entries, 2736 &result); 2737 if (!NT_STATUS_IS_OK(status)) { 2738 break; 2739 } 2388 2740 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; 2390 2743 break; 2744 } 2391 2745 2392 2746 for (i = 0; i < num_entries; i++) { … … 2398 2752 struct policy_handle alias_pol; 2399 2753 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 } 2413 2776 } 2414 2777 } … … 2424 2787 } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES)); 2425 2788 2789 status = result; 2790 2426 2791 done: 2427 return result;2792 return status; 2428 2793 } 2429 2794 … … 2439 2804 TALLOC_CTX *mem_ctx, 2440 2805 const char *domain_name, 2441 const DOM_SID*domain_sid,2806 const struct dom_sid *domain_sid, 2442 2807 struct policy_handle *domain_pol, 2443 2808 uint32 rid) 2444 2809 { 2445 NTSTATUS result ;2810 NTSTATUS result, status; 2446 2811 struct policy_handle group_pol; 2447 2812 uint32 num_members, *group_rids; 2448 2813 int i; 2449 struct samr_Rid TypeArray *rids = NULL;2814 struct samr_RidAttrArray *rids = NULL; 2450 2815 struct lsa_Strings names; 2451 2816 struct samr_Ids types; 2817 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 2452 2818 2453 2819 fstring sid_str; 2454 2820 sid_to_fstring(sid_str, domain_sid); 2455 2821 2456 result = rpccli_samr_OpenGroup(pipe_hnd, mem_ctx,2822 status = dcerpc_samr_OpenGroup(b, mem_ctx, 2457 2823 domain_pol, 2458 2824 MAXIMUM_ALLOWED_ACCESS, 2459 2825 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)) { 2463 2832 return result; 2464 2465 result = rpccli_samr_QueryGroupMember(pipe_hnd, mem_ctx, 2833 } 2834 2835 status = dcerpc_samr_QueryGroupMember(b, mem_ctx, 2466 2836 &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)) { 2470 2843 return result; 2844 } 2471 2845 2472 2846 num_members = rids->count; … … 2479 2853 this_time = num_members; 2480 2854 2481 result = rpccli_samr_LookupRids(pipe_hnd, mem_ctx,2855 status = dcerpc_samr_LookupRids(b, mem_ctx, 2482 2856 domain_pol, 2483 2857 this_time, 2484 2858 group_rids, 2485 2859 &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)) { 2489 2866 return result; 2867 } 2490 2868 2491 2869 /* We only have users as members, but make the output … … 2518 2896 uint32 rid) 2519 2897 { 2520 NTSTATUS result ;2898 NTSTATUS result, status; 2521 2899 struct rpc_pipe_client *lsa_pipe; 2522 2900 struct policy_handle alias_pol, lsa_pol; 2523 2901 uint32 num_members; 2524 DOM_SID*alias_sids;2902 struct dom_sid *alias_sids; 2525 2903 char **domains; 2526 2904 char **names; … … 2528 2906 int i; 2529 2907 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, 2532 2911 domain_pol, 2533 2912 MAXIMUM_ALLOWED_ACCESS, 2534 2913 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)) { 2538 2920 return result; 2539 2540 result = rpccli_samr_GetMembersInAlias(pipe_hnd, mem_ctx, 2921 } 2922 2923 status = dcerpc_samr_GetMembersInAlias(b, mem_ctx, 2541 2924 &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 } 2544 2931 if (!NT_STATUS_IS_OK(result)) { 2545 2932 d_fprintf(stderr, _("Couldn't list alias members\n")); … … 2571 2958 } 2572 2959 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); 2574 2961 if (!alias_sids) { 2575 2962 d_fprintf(stderr, _("Out of memory\n")); … … 2614 3001 2615 3002 static NTSTATUS rpc_group_members_internals(struct net_context *c, 2616 const DOM_SID*domain_sid,3003 const struct dom_sid *domain_sid, 2617 3004 const char *domain_name, 2618 3005 struct cli_state *cli, … … 2622 3009 const char **argv) 2623 3010 { 2624 NTSTATUS result ;3011 NTSTATUS result, status; 2625 3012 struct policy_handle connect_pol, domain_pol; 2626 3013 struct samr_Ids rids, rid_types; 2627 3014 struct lsa_String lsa_acct_name; 3015 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 2628 3016 2629 3017 /* Get sam policy handle */ 2630 3018 2631 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,3019 status = dcerpc_samr_Connect2(b, mem_ctx, 2632 3020 pipe_hnd->desthost, 2633 3021 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)) { 2637 3028 return result; 3029 } 2638 3030 2639 3031 /* Get domain policy handle */ 2640 3032 2641 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,3033 status = dcerpc_samr_OpenDomain(b, mem_ctx, 2642 3034 &connect_pol, 2643 3035 MAXIMUM_ALLOWED_ACCESS, 2644 3036 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)) { 2648 3043 return result; 3044 } 2649 3045 2650 3046 init_lsa_String(&lsa_acct_name, argv[0]); /* sure? */ 2651 3047 2652 result = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,3048 status = dcerpc_samr_LookupNames(b, mem_ctx, 2653 3049 &domain_pol, 2654 3050 1, 2655 3051 &lsa_acct_name, 2656 3052 &rids, 2657 &rid_types); 3053 &rid_types, 3054 &result); 3055 if (!NT_STATUS_IS_OK(status)) { 3056 return status; 3057 } 2658 3058 2659 3059 if (!NT_STATUS_IS_OK(result)) { … … 2661 3061 /* Ok, did not find it in the global sam, try with builtin */ 2662 3062 2663 DOM_SIDsid_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); 2666 3066 2667 3067 sid_copy(&sid_Builtin, &global_sid_Builtin); 2668 3068 2669 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,3069 status = dcerpc_samr_OpenDomain(b, mem_ctx, 2670 3070 &connect_pol, 2671 3071 MAXIMUM_ALLOWED_ACCESS, 2672 3072 &sid_Builtin, 2673 &domain_pol); 2674 3073 &domain_pol, 3074 &result); 3075 if (!NT_STATUS_IS_OK(status)) { 3076 return status; 3077 } 2675 3078 if (!NT_STATUS_IS_OK(result)) { 2676 3079 d_fprintf(stderr, _("Couldn't find group %s\n"), … … 2679 3082 } 2680 3083 2681 result = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,3084 status = dcerpc_samr_LookupNames(b, mem_ctx, 2682 3085 &domain_pol, 2683 3086 1, 2684 3087 &lsa_acct_name, 2685 3088 &rids, 2686 &rid_types); 2687 3089 &rid_types, 3090 &result); 3091 if (!NT_STATUS_IS_OK(status)) { 3092 return status; 3093 } 2688 3094 if (!NT_STATUS_IS_OK(result)) { 2689 3095 d_fprintf(stderr, _("Couldn't find group %s\n"), … … 2834 3240 }; 2835 3241 2836 status = libnetapi_ init(&c->netapi_ctx);3242 status = libnetapi_net_init(&c->netapi_ctx); 2837 3243 if (status != 0) { 2838 3244 return -1; … … 2975 3381 NTSTATUS status; 2976 3382 union srvsvc_NetShareInfo info; 3383 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 2977 3384 2978 3385 /* no specific share requested, enumerate all */ … … 2985 3392 info_ctr->level = level; 2986 3393 2987 status = rpccli_srvsvc_NetShareEnumAll(pipe_hnd, mem_ctx,3394 status = dcerpc_srvsvc_NetShareEnumAll(b, mem_ctx, 2988 3395 pipe_hnd->desthost, 2989 3396 info_ctr, … … 2992 3399 &resume_handle, 2993 3400 &result); 3401 if (!NT_STATUS_IS_OK(status)) { 3402 return ntstatus_to_werror(status); 3403 } 2994 3404 return result; 2995 3405 } 2996 3406 2997 3407 /* request just one share */ 2998 status = rpccli_srvsvc_NetShareGetInfo(pipe_hnd, mem_ctx,3408 status = dcerpc_srvsvc_NetShareGetInfo(b, mem_ctx, 2999 3409 pipe_hnd->desthost, 3000 3410 argv[0], … … 3003 3413 &result); 3004 3414 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)) { 3006 3421 goto done; 3007 3422 } … … 3024 3439 3025 3440 info_ctr->ctr.ctr1 = ctr1; 3441 3442 break; 3026 3443 } 3027 3444 case 2: … … 3036 3453 3037 3454 info_ctr->ctr.ctr2 = ctr2; 3455 3456 break; 3038 3457 } 3039 3458 case 502: … … 3048 3467 3049 3468 info_ctr->ctr.ctr502 = ctr502; 3469 3470 break; 3050 3471 } 3051 3472 } /* switch */ … … 3105 3526 static bool check_share_availability(struct cli_state *cli, const char *netname) 3106 3527 { 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)) { 3108 3532 d_printf(_("skipping [%s]: not a file share.\n"), netname); 3109 3533 return false; 3110 3534 } 3111 3535 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)); 3113 3539 return false; 3540 } 3114 3541 3115 3542 return true; … … 3157 3584 3158 3585 static NTSTATUS rpc_share_migrate_shares_internals(struct net_context *c, 3159 const DOM_SID*domain_sid,3586 const struct dom_sid *domain_sid, 3160 3587 const char *domain_name, 3161 3588 struct cli_state *cli, … … 3173 3600 uint32 level = 502; /* includes secdesc */ 3174 3601 uint32_t parm_error = 0; 3602 struct dcerpc_binding_handle *b; 3175 3603 3176 3604 result = get_share_info(c, pipe_hnd, mem_ctx, level, argc, argv, … … 3185 3613 return nt_status; 3186 3614 3615 b = srvsvc_pipe->binding_handle; 3187 3616 3188 3617 for (i = 0; i < ctr_src.ctr.ctr502->count; i++) { … … 3206 3635 info.info502 = &info502; 3207 3636 3208 nt_status = rpccli_srvsvc_NetShareAdd(srvsvc_pipe, mem_ctx,3637 nt_status = dcerpc_srvsvc_NetShareAdd(b, mem_ctx, 3209 3638 srvsvc_pipe->desthost, 3210 3639 502, … … 3212 3641 &parm_error, 3213 3642 &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 } 3215 3648 if (W_ERROR_V(result) == W_ERROR_V(WERR_FILE_EXISTS)) { 3216 3649 printf(_(" [%s] does already exist\n"), … … 3219 3652 } 3220 3653 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)); 3223 3658 goto done; 3224 3659 } … … 3276 3711 * 3277 3712 **/ 3278 static void copy_fn(const char *mnt,file_info *f,3713 static NTSTATUS copy_fn(const char *mnt, struct file_info *f, 3279 3714 const char *mask, void *state) 3280 3715 { … … 3292 3727 3293 3728 if (strequal(f->name, ".") || strequal(f->name, "..")) 3294 return ;3729 return NT_STATUS_OK; 3295 3730 3296 3731 DEBUG(3,("got mask: %s, name: %s\n", mask, f->name)); 3297 3732 3298 3733 /* DIRECTORY */ 3299 if (f->mode & aDIR) {3734 if (f->mode & FILE_ATTRIBUTE_DIRECTORY) { 3300 3735 3301 3736 DEBUG(3,("got dir: %s\n", f->name)); … … 3320 3755 default: 3321 3756 d_fprintf(stderr, _("Unsupported mode %d\n"), net_mode_share); 3322 return ;3757 return NT_STATUS_INTERNAL_ERROR; 3323 3758 } 3324 3759 3325 if (!NT_STATUS_IS_OK(nt_status)) 3760 if (!NT_STATUS_IS_OK(nt_status)) { 3326 3761 printf(_("could not handle dir %s: %s\n"), 3327 3762 dir, nt_errstr(nt_status)); 3763 return nt_status; 3764 } 3328 3765 3329 3766 /* search below that directory */ … … 3333 3770 old_dir = local_state->cwd; 3334 3771 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)) { 3336 3774 printf(_("could not handle files\n")); 3775 } 3337 3776 local_state->cwd = old_dir; 3338 3777 3339 return ;3778 return nt_status; 3340 3779 } 3341 3780 … … 3363 3802 d_fprintf(stderr, _("Unsupported file mode %d\n"), 3364 3803 net_mode_share); 3365 return ;3804 return NT_STATUS_INTERNAL_ERROR; 3366 3805 } 3367 3806 … … 3369 3808 printf(_("could not handle file %s: %s\n"), 3370 3809 filename, nt_errstr(nt_status)); 3371 3810 return nt_status; 3372 3811 } 3373 3812 … … 3381 3820 * @return Boolean result 3382 3821 **/ 3383 static boolsync_files(struct copy_clistate *cp_clistate, const char *mask)3822 static NTSTATUS sync_files(struct copy_clistate *cp_clistate, const char *mask) 3384 3823 { 3385 3824 struct cli_state *targetcli; 3386 3825 char *targetpath = NULL; 3826 NTSTATUS status; 3387 3827 3388 3828 DEBUG(3,("calling cli_list with mask: %s\n", mask)); … … 3393 3833 "%s\n"), 3394 3834 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)) { 3399 3841 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; 3405 3846 } 3406 3847 … … 3462 3903 3463 3904 static NTSTATUS rpc_share_migrate_files_internals(struct net_context *c, 3464 const DOM_SID*domain_sid,3905 const struct dom_sid *domain_sid, 3465 3906 const char *domain_name, 3466 3907 struct cli_state *cli, … … 3529 3970 cp_clistate.cli_share_dst = NULL; 3530 3971 cp_clistate.cwd = NULL; 3531 cp_clistate.attribute = aSYSTEM | aHIDDEN | aDIR;3972 cp_clistate.attribute = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_DIRECTORY; 3532 3973 cp_clistate.c = c; 3533 3974 … … 3559 4000 } 3560 4001 3561 if (!sync_files(&cp_clistate, mask)) { 4002 nt_status = sync_files(&cp_clistate, mask); 4003 if (!NT_STATUS_IS_OK(nt_status)) { 3562 4004 d_fprintf(stderr, _("could not handle files for share: " 3563 4005 "%s\n"), info502.name); 3564 nt_status = NT_STATUS_UNSUCCESSFUL;3565 4006 goto done; 3566 4007 } … … 3620 4061 3621 4062 static NTSTATUS rpc_share_migrate_security_internals(struct net_context *c, 3622 const DOM_SID*domain_sid,4063 const struct dom_sid *domain_sid, 3623 4064 const char *domain_name, 3624 4065 struct cli_state *cli, … … 3637 4078 uint32 level = 502; /* includes secdesc */ 3638 4079 uint32_t parm_error = 0; 4080 struct dcerpc_binding_handle *b; 3639 4081 3640 4082 result = get_share_info(c, pipe_hnd, mem_ctx, level, argc, argv, … … 3650 4092 return nt_status; 3651 4093 4094 b = srvsvc_pipe->binding_handle; 3652 4095 3653 4096 for (i = 0; i < ctr_src.ctr.ctr502->count; i++) { … … 3673 4116 3674 4117 /* 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, 3676 4119 srvsvc_pipe->desthost, 3677 4120 info502.name, … … 3680 4123 &parm_error, 3681 4124 &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); 3683 4132 printf(_("cannot set share-acl: %s\n"), 3684 4133 win_errstr(result)); … … 3830 4279 3831 4280 struct full_alias { 3832 DOM_SIDsid;4281 struct dom_sid sid; 3833 4282 uint32 num_members; 3834 DOM_SID*members;4283 struct dom_sid *members; 3835 4284 }; 3836 4285 … … 3858 4307 TALLOC_CTX *mem_ctx, 3859 4308 struct policy_handle *connect_pol, 3860 const DOM_SID*domain_sid)4309 const struct dom_sid *domain_sid) 3861 4310 { 3862 4311 uint32 start_idx, max_entries, num_entries, i; 3863 4312 struct samr_SamArray *groups = NULL; 3864 NTSTATUS result ;4313 NTSTATUS result, status; 3865 4314 struct policy_handle domain_pol; 4315 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 3866 4316 3867 4317 /* Get domain policy handle */ 3868 4318 3869 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,4319 status = dcerpc_samr_OpenDomain(b, mem_ctx, 3870 4320 connect_pol, 3871 4321 MAXIMUM_ALLOWED_ACCESS, 3872 4322 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)) { 3875 4329 return result; 4330 } 3876 4331 3877 4332 start_idx = 0; … … 3879 4334 3880 4335 do { 3881 result = rpccli_samr_EnumDomainAliases(pipe_hnd, mem_ctx,4336 status = dcerpc_samr_EnumDomainAliases(b, mem_ctx, 3882 4337 &domain_pol, 3883 4338 &start_idx, 3884 4339 &groups, 3885 4340 max_entries, 3886 &num_entries); 4341 &num_entries, 4342 &result); 4343 if (!NT_STATUS_IS_OK(status)) { 4344 goto done; 4345 } 3887 4346 for (i = 0; i < num_entries; i++) { 3888 4347 … … 3891 4350 struct lsa_SidArray sid_array; 3892 4351 int j; 3893 3894 result = rpccli_samr_OpenAlias(pipe_hnd, mem_ctx, 4352 NTSTATUS _result; 4353 4354 status = dcerpc_samr_OpenAlias(b, mem_ctx, 3895 4355 &domain_pol, 3896 4356 MAXIMUM_ALLOWED_ACCESS, 3897 4357 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)) { 3900 4361 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, 3903 4369 &alias_pol, 3904 &sid_array); 3905 if (!NT_STATUS_IS_OK(result)) 4370 &sid_array, 4371 &_result); 4372 if (!NT_STATUS_IS_OK(status)) { 3906 4373 goto done; 4374 } 4375 if (!NT_STATUS_IS_OK(_result)) { 4376 status = _result; 4377 goto done; 4378 } 3907 4379 3908 4380 alias.num_members = sid_array.num_sids; 3909 4381 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)) { 3912 4384 goto done; 4385 } 4386 if (!NT_STATUS_IS_OK(_result)) { 4387 status = _result; 4388 goto done; 4389 } 3913 4390 3914 4391 alias.members = NULL; 3915 4392 3916 4393 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); 3918 4395 3919 4396 for (j = 0; j < alias.num_members; j++) … … 3922 4399 } 3923 4400 3924 sid_co py(&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); 3926 4403 3927 4404 push_alias(mem_ctx, &alias); … … 3929 4406 } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES)); 3930 4407 3931 result= NT_STATUS_OK;4408 status = NT_STATUS_OK; 3932 4409 3933 4410 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; 3937 4414 } 3938 4415 … … 3942 4419 3943 4420 static NTSTATUS rpc_aliaslist_dump(struct net_context *c, 3944 const DOM_SID*domain_sid,4421 const struct dom_sid *domain_sid, 3945 4422 const char *domain_name, 3946 4423 struct cli_state *cli, … … 3953 4430 NTSTATUS result; 3954 4431 struct policy_handle lsa_pol; 4432 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 3955 4433 3956 4434 result = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true, … … 3997 4475 } 3998 4476 3999 rpccli_lsa_Close(pipe_hnd, mem_ctx, &lsa_pol);4477 dcerpc_lsa_Close(b, mem_ctx, &lsa_pol, &result); 4000 4478 4001 4479 return NT_STATUS_OK; … … 4008 4486 4009 4487 static NTSTATUS rpc_aliaslist_internals(struct net_context *c, 4010 const DOM_SID*domain_sid,4488 const struct dom_sid *domain_sid, 4011 4489 const char *domain_name, 4012 4490 struct cli_state *cli, … … 4016 4494 const char **argv) 4017 4495 { 4018 NTSTATUS result ;4496 NTSTATUS result, status; 4019 4497 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, 4022 4501 pipe_hnd->desthost, 4023 4502 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, 4030 4514 &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, 4036 4520 domain_sid); 4037 4521 4038 rpccli_samr_Close(pipe_hnd, mem_ctx, &connect_pol);4522 dcerpc_samr_Close(b, mem_ctx, &connect_pol, &result); 4039 4523 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 4527 static void init_user_token(struct security_token *token, struct dom_sid *user_sid) 4044 4528 { 4045 4529 token->num_sids = 4; 4046 4530 4047 if (!(token-> user_sids = SMB_MALLOC_ARRAY(DOM_SID, 4))) {4531 if (!(token->sids = SMB_MALLOC_ARRAY(struct dom_sid, 4))) { 4048 4532 d_fprintf(stderr, "malloc %s\n",_("failed")); 4049 4533 token->num_sids = 0; … … 4051 4535 } 4052 4536 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 4543 static void free_user_token(struct security_token *token) 4544 { 4545 SAFE_FREE(token->sids); 4546 } 4547 4548 static void add_sid_to_token(struct security_token *token, struct dom_sid *sid) 4549 { 4550 if (security_token_has_sid(token, sid)) 4067 4551 return; 4068 4552 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) { 4071 4555 return; 4072 4556 } 4073 4557 4074 sid_copy(&token-> user_sids[token->num_sids], sid);4558 sid_copy(&token->sids[token->num_sids], sid); 4075 4559 4076 4560 token->num_sids += 1; … … 4079 4563 struct user_token { 4080 4564 fstring name; 4081 NT_USER_TOKENtoken;4565 struct security_token token; 4082 4566 }; 4083 4567 … … 4089 4573 4090 4574 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 4579 static bool is_alias_member(struct dom_sid *sid, struct full_alias *alias) 4096 4580 { 4097 4581 int i; 4098 4582 4099 4583 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) 4101 4585 return true; 4102 4586 } … … 4105 4589 } 4106 4590 4107 static void collect_sid_memberships( NT_USER_TOKEN *token, DOM_SIDsid)4591 static void collect_sid_memberships(struct security_token *token, struct dom_sid sid) 4108 4592 { 4109 4593 int i; … … 4122 4606 */ 4123 4607 4124 static void collect_alias_memberships( NT_USER_TOKEN*token)4608 static void collect_alias_memberships(struct security_token *token) 4125 4609 { 4126 4610 int num_global_sids = token->num_sids; … … 4128 4612 4129 4613 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 4618 static bool get_user_sids(const char *domain, const char *user, struct security_token *token) 4135 4619 { 4136 4620 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; … … 4138 4622 fstring full_name; 4139 4623 struct wbcDomainSid wsid; 4140 char *sid_str = NULL;4141 DOM_SIDuser_sid;4624 char sid_str[WBC_SID_STRING_BUFLEN]; 4625 struct dom_sid user_sid; 4142 4626 uint32_t num_groups; 4143 4627 gid_t *groups = NULL; … … 4157 4641 } 4158 4642 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) { 4166 4646 DEBUG(1, ("%s is not a user\n", full_name)); 4167 4647 return false; … … 4172 4652 return false; 4173 4653 } 4174 4175 wbcFreeMemory(sid_str);4176 sid_str = NULL;4177 4654 4178 4655 init_user_token(token, &user_sid); … … 4189 4666 for (i = 0; i < num_groups; i++) { 4190 4667 gid_t gid = groups[i]; 4191 DOM_SIDsid;4668 struct dom_sid sid; 4192 4669 4193 4670 wbc_status = wbcGidToSid(gid, &wsid); … … 4199 4676 } 4200 4677 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)); 4206 4679 4207 4680 DEBUG(3, (" %s\n", sid_str)); 4208 4681 4209 4682 string_to_sid(&sid, sid_str); 4210 wbcFreeMemory(sid_str);4211 sid_str = NULL;4212 4213 4683 add_sid_to_token(token, &sid); 4214 4684 } … … 4277 4747 4278 4748 get_user_sids(domain, user, &(result[i].token)); 4279 i+=1;4280 4749 } 4281 4750 TALLOC_FREE(frame); … … 4308 4777 /* We have a SID */ 4309 4778 4310 DOM_SIDsid;4779 struct dom_sid sid; 4311 4780 if(!string_to_sid(&sid, &line[1])) { 4312 4781 DEBUG(1,("get_user_tokens_from_file: Could " … … 4337 4806 fstrcpy(token->name, line); 4338 4807 token->token.num_sids = 0; 4339 token->token. user_sids = NULL;4808 token->token.sids = NULL; 4340 4809 continue; 4341 4810 } … … 4356 4825 { 4357 4826 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; 4360 4829 struct cli_state *cli = rpc_pipe_np_smb_conn(pipe_hnd); 4361 4830 int i; … … 4364 4833 NTSTATUS status; 4365 4834 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, 4368 4838 pipe_hnd->desthost, 4369 4839 netname, … … 4472 4942 4473 4943 static NTSTATUS rpc_share_allowedusers_internals(struct net_context *c, 4474 const DOM_SID*domain_sid,4944 const struct dom_sid *domain_sid, 4475 4945 const char *domain_name, 4476 4946 struct cli_state *cli, … … 4668 5138 }; 4669 5139 4670 status = libnetapi_ init(&c->netapi_ctx);5140 status = libnetapi_net_init(&c->netapi_ctx); 4671 5141 if (status != 0) { 4672 5142 return -1; … … 4761 5231 WERROR result; 4762 5232 NTSTATUS status; 5233 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 4763 5234 4764 5235 if (argc != 1) { … … 4767 5238 } 4768 5239 4769 status = rpccli_srvsvc_NetShareGetInfo(pipe_hnd, mem_ctx,5240 status = dcerpc_srvsvc_NetShareGetInfo(b, mem_ctx, 4770 5241 pipe_hnd->desthost, 4771 5242 argv[0], … … 4773 5244 &info, 4774 5245 &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)) { 4776 5251 goto done; 4777 5252 } … … 4944 5419 }; 4945 5420 4946 status = libnetapi_ init(&c->netapi_ctx);5421 status = libnetapi_net_init(&c->netapi_ctx); 4947 5422 if (status != 0) { 4948 5423 return -1; … … 4987 5462 4988 5463 static NTSTATUS rpc_shutdown_abort_internals(struct net_context *c, 4989 const DOM_SID*domain_sid,5464 const struct dom_sid *domain_sid, 4990 5465 const char *domain_name, 4991 5466 struct cli_state *cli, … … 4995 5470 const char **argv) 4996 5471 { 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)) { 5002 5481 d_printf(_("\nShutdown successfully aborted\n")); 5003 5482 DEBUG(5,("cmd_shutdown_abort: query succeeded\n")); … … 5005 5484 DEBUG(5,("cmd_shutdown_abort: query failed\n")); 5006 5485 5007 return result;5486 return werror_to_ntstatus(result); 5008 5487 } 5009 5488 … … 5026 5505 5027 5506 static NTSTATUS rpc_reg_shutdown_abort_internals(struct net_context *c, 5028 const DOM_SID*domain_sid,5507 const struct dom_sid *domain_sid, 5029 5508 const char *domain_name, 5030 5509 struct cli_state *cli, … … 5035 5514 { 5036 5515 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)) { 5041 5526 d_printf(_("\nShutdown successfully aborted\n")); 5042 5527 DEBUG(5,("cmd_reg_abort_shutdown: query succeeded\n")); … … 5044 5529 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n")); 5045 5530 5046 return result;5531 return werror_to_ntstatus(werr); 5047 5532 } 5048 5533 … … 5102 5587 5103 5588 NTSTATUS rpc_init_shutdown_internals(struct net_context *c, 5104 const DOM_SID*domain_sid,5589 const struct dom_sid *domain_sid, 5105 5590 const char *domain_name, 5106 5591 struct cli_state *cli, … … 5110 5595 const char **argv) 5111 5596 { 5112 NTSTATUS result = NT_STATUS_UNSUCCESSFUL; 5597 NTSTATUS status = NT_STATUS_UNSUCCESSFUL; 5598 WERROR result; 5113 5599 const char *msg = N_("This machine will be shutdown shortly"); 5114 5600 uint32 timeout = 20; 5115 5601 struct lsa_StringLarge msg_string; 5602 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 5116 5603 5117 5604 if (c->opt_comment) { … … 5125 5612 5126 5613 /* create an entry */ 5127 result = rpccli_initshutdown_Init(pipe_hnd, mem_ctx, NULL,5614 status = dcerpc_initshutdown_Init(b, mem_ctx, NULL, 5128 5615 &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)) { 5132 5621 d_printf(_("\nShutdown of remote machine succeeded\n")); 5133 5622 DEBUG(5,("Shutdown of remote machine succeeded\n")); … … 5135 5624 DEBUG(1,("Shutdown of remote machine failed!\n")); 5136 5625 } 5137 return result;5626 return werror_to_ntstatus(result); 5138 5627 } 5139 5628 … … 5156 5645 5157 5646 NTSTATUS rpc_reg_shutdown_internals(struct net_context *c, 5158 const DOM_SID*domain_sid,5647 const struct dom_sid *domain_sid, 5159 5648 const char *domain_name, 5160 5649 struct cli_state *cli, … … 5169 5658 NTSTATUS result; 5170 5659 WERROR werr; 5660 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 5171 5661 5172 5662 if (c->opt_comment) { … … 5180 5670 5181 5671 /* create an entry */ 5182 result = rpccli_winreg_InitiateSystemShutdown(pipe_hnd, mem_ctx, NULL,5672 result = dcerpc_winreg_InitiateSystemShutdown(b, mem_ctx, NULL, 5183 5673 &msg_string, timeout, c->opt_force, c->opt_reboot, 5184 5674 &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)) { 5187 5681 d_printf(_("\nShutdown of remote machine succeeded\n")); 5188 5682 } else { … … 5194 5688 } 5195 5689 5196 return result;5690 return werror_to_ntstatus(werr); 5197 5691 } 5198 5692 … … 5253 5747 5254 5748 static NTSTATUS rpc_trustdom_add_internals(struct net_context *c, 5255 const DOM_SID*domain_sid,5749 const struct dom_sid *domain_sid, 5256 5750 const char *domain_name, 5257 5751 struct cli_state *cli, … … 5262 5756 { 5263 5757 struct policy_handle connect_pol, domain_pol, user_pol; 5264 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;5758 NTSTATUS status, result; 5265 5759 char *acct_name; 5266 5760 struct lsa_String lsa_acct_name; … … 5271 5765 union samr_UserInfo info; 5272 5766 unsigned int orig_timeout; 5767 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 5273 5768 5274 5769 if (argc != 2) { … … 5293 5788 5294 5789 /* Get samr policy handle */ 5295 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,5790 status = dcerpc_samr_Connect2(b, mem_ctx, 5296 5791 pipe_hnd->desthost, 5297 5792 MAXIMUM_ALLOWED_ACCESS, 5298 &connect_pol); 5793 &connect_pol, 5794 &result); 5795 if (!NT_STATUS_IS_OK(status)) { 5796 goto done; 5797 } 5299 5798 if (!NT_STATUS_IS_OK(result)) { 5799 status = result; 5300 5800 goto done; 5301 5801 } 5302 5802 5303 5803 /* Get domain policy handle */ 5304 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,5804 status = dcerpc_samr_OpenDomain(b, mem_ctx, 5305 5805 &connect_pol, 5306 5806 MAXIMUM_ALLOWED_ACCESS, 5307 5807 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 } 5309 5813 if (!NT_STATUS_IS_OK(result)) { 5814 status = result; 5310 5815 goto done; 5311 5816 } … … 5324 5829 SAMR_USER_ACCESS_SET_ATTRIBUTES; 5325 5830 5326 result = rpccli_samr_CreateUser2(pipe_hnd, mem_ctx,5831 status = dcerpc_samr_CreateUser2(b, mem_ctx, 5327 5832 &domain_pol, 5328 5833 &lsa_acct_name, … … 5331 5836 &user_pol, 5332 5837 &access_granted, 5333 &user_rid); 5334 5838 &user_rid, 5839 &result); 5840 if (!NT_STATUS_IS_OK(status)) { 5841 goto done; 5842 } 5335 5843 /* And restore our original timeout. */ 5336 5844 rpccli_set_timeout(pipe_hnd, orig_timeout); 5337 5845 5338 5846 if (!NT_STATUS_IS_OK(result)) { 5847 status = result; 5339 5848 d_printf(_("net rpc trustdom add: create user %s failed %s\n"), 5340 5849 acct_name, nt_errstr(result)); … … 5356 5865 info.info23.password = crypt_pwd; 5357 5866 5358 result = rpccli_samr_SetUserInfo2(pipe_hnd, mem_ctx,5867 status = dcerpc_samr_SetUserInfo2(b, mem_ctx, 5359 5868 &user_pol, 5360 5869 23, 5361 &info); 5870 &info, 5871 &result); 5872 if (!NT_STATUS_IS_OK(status)) { 5873 goto done; 5874 } 5362 5875 5363 5876 if (!NT_STATUS_IS_OK(result)) { 5877 status = result; 5364 5878 DEBUG(0,("Could not set trust account password: %s\n", 5365 5879 nt_errstr(result))); … … 5370 5884 done: 5371 5885 SAFE_FREE(acct_name); 5372 return result;5886 return status; 5373 5887 } 5374 5888 … … 5414 5928 5415 5929 static NTSTATUS rpc_trustdom_del_internals(struct net_context *c, 5416 const DOM_SID*domain_sid,5930 const struct dom_sid *domain_sid, 5417 5931 const char *domain_name, 5418 5932 struct cli_state *cli, … … 5423 5937 { 5424 5938 struct policy_handle connect_pol, domain_pol, user_pol; 5425 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;5939 NTSTATUS status, result; 5426 5940 char *acct_name; 5427 DOM_SIDtrust_acct_sid;5941 struct dom_sid trust_acct_sid; 5428 5942 struct samr_Ids user_rids, name_types; 5429 5943 struct lsa_String lsa_acct_name; 5944 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 5430 5945 5431 5946 if (argc != 1) { … … 5447 5962 5448 5963 /* Get samr policy handle */ 5449 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,5964 status = dcerpc_samr_Connect2(b, mem_ctx, 5450 5965 pipe_hnd->desthost, 5451 5966 MAXIMUM_ALLOWED_ACCESS, 5452 &connect_pol); 5967 &connect_pol, 5968 &result); 5969 if (!NT_STATUS_IS_OK(status)) { 5970 goto done; 5971 } 5453 5972 if (!NT_STATUS_IS_OK(result)) { 5973 status = result; 5454 5974 goto done; 5455 5975 } 5456 5976 5457 5977 /* Get domain policy handle */ 5458 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,5978 status = dcerpc_samr_OpenDomain(b, mem_ctx, 5459 5979 &connect_pol, 5460 5980 MAXIMUM_ALLOWED_ACCESS, 5461 5981 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 } 5463 5987 if (!NT_STATUS_IS_OK(result)) { 5988 status = result; 5464 5989 goto done; 5465 5990 } … … 5467 5992 init_lsa_String(&lsa_acct_name, acct_name); 5468 5993 5469 result = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,5994 status = dcerpc_samr_LookupNames(b, mem_ctx, 5470 5995 &domain_pol, 5471 5996 1, 5472 5997 &lsa_acct_name, 5473 5998 &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 } 5476 6007 if (!NT_STATUS_IS_OK(result)) { 6008 status = result; 5477 6009 d_printf(_("net rpc trustdom del: LookupNames on user %s " 5478 6010 "failed %s\n"), … … 5481 6013 } 5482 6014 5483 result = rpccli_samr_OpenUser(pipe_hnd, mem_ctx,6015 status = dcerpc_samr_OpenUser(b, mem_ctx, 5484 6016 &domain_pol, 5485 6017 MAXIMUM_ALLOWED_ACCESS, 5486 6018 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 } 5488 6027 5489 6028 if (!NT_STATUS_IS_OK(result)) { 6029 status = result; 5490 6030 d_printf(_("net rpc trustdom del: OpenUser on user %s failed " 5491 6031 "%s\n"), … … 5495 6035 5496 6036 /* 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])) { 5499 6038 goto done; 5500 6039 } … … 5502 6041 /* remove the sid */ 5503 6042 5504 result = rpccli_samr_RemoveMemberFromForeignDomain(pipe_hnd, mem_ctx,6043 status = dcerpc_samr_RemoveMemberFromForeignDomain(b, mem_ctx, 5505 6044 &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 } 5507 6053 if (!NT_STATUS_IS_OK(result)) { 6054 status = result; 5508 6055 d_printf(_("net rpc trustdom del: RemoveMemberFromForeignDomain" 5509 6056 " on user %s failed %s\n"), … … 5512 6059 } 5513 6060 6061 5514 6062 /* Delete user */ 5515 6063 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 } 5518 6073 5519 6074 if (!NT_STATUS_IS_OK(result)) { 6075 result = status; 5520 6076 d_printf(_("net rpc trustdom del: DeleteUser on user %s failed " 5521 6077 "%s\n"), … … 5531 6087 5532 6088 done: 5533 return result;6089 return status; 5534 6090 } 5535 6091 … … 5565 6121 struct rpc_pipe_client *netr; 5566 6122 NTSTATUS status; 6123 WERROR result; 6124 struct dcerpc_binding_handle *b; 5567 6125 5568 6126 /* Use NetServerEnum2 */ … … 5584 6142 } 5585 6143 5586 status = rpccli_netr_GetDcName(netr, mem_ctx, 6144 b = netr->binding_handle; 6145 6146 status = dcerpc_netr_GetDcName(b, mem_ctx, 5587 6147 cli->desthost, 5588 6148 domain_name, 5589 6149 &buffer, 5590 NULL);6150 &result); 5591 6151 TALLOC_FREE(netr); 5592 6152 5593 if (NT_STATUS_IS_OK(status) ) {6153 if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(result)) { 5594 6154 return status; 5595 6155 } … … 5598 6158 for domain %s\n", domain_name)); 5599 6159 5600 return status; 6160 if (!NT_STATUS_IS_OK(status)) { 6161 return status; 6162 } 6163 6164 return werror_to_ntstatus(result); 5601 6165 } 5602 6166 … … 5620 6184 struct policy_handle connect_hnd; 5621 6185 TALLOC_CTX *mem_ctx; 5622 NTSTATUS nt_status ;5623 DOM_SID*domain_sid;6186 NTSTATUS nt_status, result; 6187 struct dom_sid *domain_sid; 5624 6188 5625 6189 char* domain_name; … … 5627 6191 fstring pdc_name; 5628 6192 union lsa_PolicyInformation *info = NULL; 6193 struct dcerpc_binding_handle *b; 5629 6194 5630 6195 /* … … 5719 6284 return -1; 5720 6285 } 6286 6287 b = pipe_hnd->binding_handle; 5721 6288 5722 6289 nt_status = rpccli_lsa_open_policy2(pipe_hnd, mem_ctx, true, KEY_QUERY_VALUE, … … 5732 6299 /* Querying info level 5 */ 5733 6300 5734 nt_status = rpccli_lsa_QueryInfoPolicy(pipe_hnd, mem_ctx,6301 nt_status = dcerpc_lsa_QueryInfoPolicy(b, mem_ctx, 5735 6302 &connect_hnd, 5736 6303 LSA_POLICY_INFO_ACCOUNT_DOMAIN, 5737 &info); 6304 &info, 6305 &result); 5738 6306 if (NT_STATUS_IS_ERR(nt_status)) { 5739 6307 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n", … … 5743 6311 return -1; 5744 6312 } 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 } 5745 6320 5746 6321 domain_sid = info->account_domain.sid; … … 5764 6339 */ 5765 6340 5766 nt_status = rpccli_lsa_Close(pipe_hnd, mem_ctx, &connect_hnd);6341 nt_status = dcerpc_lsa_Close(b, mem_ctx, &connect_hnd, &result); 5767 6342 if (NT_STATUS_IS_ERR(nt_status)) { 5768 6343 DEBUG(0, ("Couldn't close LSA pipe. Error was %s\n", … … 5824 6399 5825 6400 static NTSTATUS rpc_query_domain_sid(struct net_context *c, 5826 const DOM_SID*domain_sid,6401 const struct dom_sid *domain_sid, 5827 6402 const char *domain_name, 5828 6403 struct cli_state *cli, … … 5840 6415 } 5841 6416 5842 static void print_trusted_domain( DOM_SID*dom_sid, const char *trusted_dom_name)6417 static void print_trusted_domain(struct dom_sid *dom_sid, const char *trusted_dom_name) 5843 6418 { 5844 6419 fstring ascii_sid; … … 5853 6428 TALLOC_CTX *mem_ctx, 5854 6429 struct policy_handle *pol, 5855 DOM_SIDdom_sid,6430 struct dom_sid dom_sid, 5856 6431 const char *trusted_dom_name) 5857 6432 { 5858 NTSTATUS nt_status ;6433 NTSTATUS nt_status, result; 5859 6434 union lsa_TrustedDomainInfo *info = NULL; 5860 6435 char *cleartextpwd = NULL; … … 5862 6437 DATA_BLOB session_key_blob; 5863 6438 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, 5866 6442 pol, 5867 6443 &dom_sid, 5868 6444 LSA_TRUSTED_DOMAIN_INFO_PASSWORD, 5869 &info); 6445 &info, 6446 &result); 5870 6447 if (NT_STATUS_IS_ERR(nt_status)) { 5871 6448 DEBUG(0,("Could not query trusted domain info. Error was %s\n", 5872 6449 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))); 5873 6456 goto done; 5874 6457 } … … 5917 6500 struct cli_state *cli = NULL; 5918 6501 struct rpc_pipe_client *pipe_hnd = NULL; 5919 NTSTATUS nt_status ;6502 NTSTATUS nt_status, result; 5920 6503 const char *domain_name = NULL; 5921 DOM_SID*queried_dom_sid;6504 struct dom_sid *queried_dom_sid; 5922 6505 struct policy_handle connect_hnd; 5923 6506 union lsa_PolicyInformation *info = NULL; … … 5928 6511 struct lsa_DomainList dom_list; 5929 6512 fstring pdc_name; 6513 struct dcerpc_binding_handle *b; 5930 6514 5931 6515 if (c->display_usage) { … … 5977 6561 }; 5978 6562 6563 b = pipe_hnd->binding_handle; 6564 5979 6565 nt_status = rpccli_lsa_open_policy2(pipe_hnd, mem_ctx, false, KEY_QUERY_VALUE, 5980 6566 &connect_hnd); … … 5988 6574 5989 6575 /* 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, 5991 6577 &connect_hnd, 5992 6578 LSA_POLICY_INFO_ACCOUNT_DOMAIN, 5993 &info); 6579 &info, 6580 &result); 5994 6581 5995 6582 if (NT_STATUS_IS_ERR(nt_status)) { … … 6000 6587 return -1; 6001 6588 } 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 } 6002 6596 6003 6597 queried_dom_sid = info->account_domain.sid; … … 6011 6605 6012 6606 do { 6013 nt_status = rpccli_lsa_EnumTrustDom(pipe_hnd, mem_ctx,6607 nt_status = dcerpc_lsa_EnumTrustDom(b, mem_ctx, 6014 6608 &connect_hnd, 6015 6609 &enum_ctx, 6016 6610 &dom_list, 6017 (uint32_t)-1); 6611 (uint32_t)-1, 6612 &result); 6018 6613 if (NT_STATUS_IS_ERR(nt_status)) { 6019 6614 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n", … … 6023 6618 return -1; 6024 6619 }; 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 6025 6629 6026 6630 for (i = 0; i < dom_list.count; i++) { … … 6048 6652 6049 6653 /* 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); 6051 6655 if (NT_STATUS_IS_ERR(nt_status)) { 6052 6656 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n", … … 6070 6674 struct cli_state *cli = NULL, *remote_cli = NULL; 6071 6675 struct rpc_pipe_client *pipe_hnd = NULL; 6072 NTSTATUS nt_status ;6676 NTSTATUS nt_status, result; 6073 6677 const char *domain_name = NULL; 6074 DOM_SID*queried_dom_sid;6678 struct dom_sid *queried_dom_sid; 6075 6679 int ascii_dom_name_len; 6076 6680 struct policy_handle connect_hnd; 6077 6681 union lsa_PolicyInformation *info = NULL; 6682 struct dcerpc_binding_handle *b = NULL; 6078 6683 6079 6684 /* trusted domains listing variables */ … … 6135 6740 return -1; 6136 6741 }; 6742 6743 b = pipe_hnd->binding_handle; 6137 6744 6138 6745 nt_status = rpccli_lsa_open_policy2(pipe_hnd, mem_ctx, false, KEY_QUERY_VALUE, … … 6147 6754 6148 6755 /* 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, 6150 6757 &connect_hnd, 6151 6758 LSA_POLICY_INFO_ACCOUNT_DOMAIN, 6152 &info); 6759 &info, 6760 &result); 6153 6761 6154 6762 if (NT_STATUS_IS_ERR(nt_status)) { … … 6159 6767 return -1; 6160 6768 } 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 } 6161 6776 6162 6777 queried_dom_sid = info->account_domain.sid; … … 6172 6787 6173 6788 do { 6174 nt_status = rpccli_lsa_EnumTrustDom(pipe_hnd, mem_ctx,6789 nt_status = dcerpc_lsa_EnumTrustDom(b, mem_ctx, 6175 6790 &connect_hnd, 6176 6791 &enum_ctx, 6177 6792 &dom_list, 6178 (uint32_t)-1); 6793 (uint32_t)-1, 6794 &result); 6179 6795 if (NT_STATUS_IS_ERR(nt_status)) { 6180 6796 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n", … … 6184 6800 return -1; 6185 6801 }; 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 6186 6810 6187 6811 for (i = 0; i < dom_list.count; i++) { … … 6203 6827 6204 6828 /* 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); 6206 6830 if (NT_STATUS_IS_ERR(nt_status)) { 6207 6831 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n", … … 6232 6856 }; 6233 6857 6858 b = pipe_hnd->binding_handle; 6859 6234 6860 /* SamrConnect2 */ 6235 nt_status = rpccli_samr_Connect2(pipe_hnd, mem_ctx,6861 nt_status = dcerpc_samr_Connect2(b, mem_ctx, 6236 6862 pipe_hnd->desthost, 6237 6863 SAMR_ACCESS_LOOKUP_DOMAIN, 6238 &connect_hnd); 6864 &connect_hnd, 6865 &result); 6239 6866 if (!NT_STATUS_IS_OK(nt_status)) { 6240 6867 DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n", … … 6244 6871 return -1; 6245 6872 }; 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 }; 6246 6881 6247 6882 /* SamrOpenDomain - we have to open domain policy handle in order to be 6248 6883 able to enumerate accounts*/ 6249 nt_status = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,6884 nt_status = dcerpc_samr_OpenDomain(b, mem_ctx, 6250 6885 &connect_hnd, 6251 6886 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS, 6252 6887 queried_dom_sid, 6253 &domain_hnd); 6888 &domain_hnd, 6889 &result); 6254 6890 if (!NT_STATUS_IS_OK(nt_status)) { 6255 6891 DEBUG(0, ("Couldn't open domain object. Error was %s\n", … … 6259 6895 return -1; 6260 6896 }; 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 }; 6261 6905 6262 6906 /* … … 6269 6913 do { 6270 6914 6271 nt_status = rpccli_samr_EnumDomainUsers(pipe_hnd, mem_ctx,6915 nt_status = dcerpc_samr_EnumDomainUsers(b, mem_ctx, 6272 6916 &domain_hnd, 6273 6917 &enum_ctx, … … 6275 6919 &trusts, 6276 6920 0xffff, 6277 &num_domains); 6921 &num_domains, 6922 &result); 6278 6923 if (NT_STATUS_IS_ERR(nt_status)) { 6279 6924 DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n", 6280 6925 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))); 6281 6934 cli_shutdown(cli); 6282 6935 talloc_destroy(mem_ctx); … … 6331 6984 } 6332 6985 6333 } while (NT_STATUS_EQUAL( nt_status, STATUS_MORE_ENTRIES));6986 } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES)); 6334 6987 6335 6988 if (!found_domain) { … … 6338 6991 6339 6992 /* 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); 6341 6994 if (!NT_STATUS_IS_OK(nt_status)) { 6342 6995 DEBUG(0, ("Couldn't properly close domain policy handle for domain %s\n", domain_name)); 6343 6996 }; 6344 6997 6345 nt_status = rpccli_samr_Close(pipe_hnd, mem_ctx, &connect_hnd);6998 nt_status = dcerpc_samr_Close(b, mem_ctx, &connect_hnd, &result); 6346 6999 if (!NT_STATUS_IS_OK(nt_status)) { 6347 7000 DEBUG(0, ("Couldn't properly close samr policy handle for domain %s\n", domain_name)); … … 6521 7174 } 6522 7175 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); 6527 7177 } 6528 7178 … … 7349 7999 " Open interactive shell on remote server") 7350 8000 }, 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 }, 7351 8009 {NULL, NULL, 0, NULL, NULL} 7352 8010 }; 7353 8011 7354 status = libnetapi_ init(&c->netapi_ctx);8012 status = libnetapi_net_init(&c->netapi_ctx); 7355 8013 if (status != 0) { 7356 8014 return -1; -
vendor/current/source3/utils/net_rpc_audit.c
r414 r740 19 19 #include "includes.h" 20 20 #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" 22 24 23 25 /******************************************************************** … … 56 58 57 59 static NTSTATUS rpc_audit_get_internal(struct net_context *c, 58 const DOM_SID*domain_sid,60 const struct dom_sid *domain_sid, 59 61 const char *domain_name, 60 62 struct cli_state *cli, … … 65 67 { 66 68 struct policy_handle pol; 67 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;69 NTSTATUS status, result; 68 70 union lsa_PolicyInformation *info = NULL; 69 71 int i; 70 72 uint32_t audit_category; 73 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 71 74 72 75 if (argc < 1 || argc > 2) { … … 81 84 } 82 85 83 result= rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,86 status = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true, 84 87 SEC_FLAG_MAXIMUM_ALLOWED, 85 88 &pol); 86 89 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, 92 95 &pol, 93 96 LSA_POLICY_INFO_AUDIT_EVENTS, 94 &info); 95 97 &info, 98 &result); 99 if (!NT_STATUS_IS_OK(status)) { 100 goto done; 101 } 96 102 if (!NT_STATUS_IS_OK(result)) { 103 status = result; 97 104 goto done; 98 105 } … … 112 119 113 120 done: 114 if (!NT_STATUS_IS_OK( result)) {121 if (!NT_STATUS_IS_OK(status)) { 115 122 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; 120 127 } 121 128 … … 124 131 125 132 static NTSTATUS rpc_audit_set_internal(struct net_context *c, 126 const DOM_SID*domain_sid,133 const struct dom_sid *domain_sid, 127 134 const char *domain_name, 128 135 struct cli_state *cli, … … 133 140 { 134 141 struct policy_handle pol; 135 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;142 NTSTATUS status, result; 136 143 union lsa_PolicyInformation *info = NULL; 137 144 uint32_t audit_policy, audit_category; 145 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 138 146 139 147 if (argc < 2 || argc > 3) { … … 163 171 } 164 172 165 result= rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,173 status = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true, 166 174 SEC_FLAG_MAXIMUM_ALLOWED, 167 175 &pol); 168 176 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, 174 182 &pol, 175 183 LSA_POLICY_INFO_AUDIT_EVENTS, 176 &info); 177 184 &info, 185 &result); 186 if (!NT_STATUS_IS_OK(status)) { 187 goto done; 188 } 178 189 if (!NT_STATUS_IS_OK(result)) { 190 status = result; 179 191 goto done; 180 192 } … … 182 194 info->audit_events.settings[audit_category] = audit_policy; 183 195 184 result = rpccli_lsa_SetInfoPolicy(pipe_hnd, mem_ctx,196 status = dcerpc_lsa_SetInfoPolicy(b, mem_ctx, 185 197 &pol, 186 198 LSA_POLICY_INFO_AUDIT_EVENTS, 187 info); 188 199 info, 200 &result); 201 if (!NT_STATUS_IS_OK(status)) { 202 goto done; 203 } 189 204 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, 194 210 &pol, 195 211 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 197 220 { 198 221 const char *val = audit_policy_str(mem_ctx, info->audit_events.settings[audit_category]); … … 202 225 203 226 done: 204 if (!NT_STATUS_IS_OK( result)) {227 if (!NT_STATUS_IS_OK(status)) { 205 228 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; 210 233 } 211 234 … … 220 243 { 221 244 struct policy_handle pol; 222 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;245 NTSTATUS status, result; 223 246 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, 226 250 SEC_FLAG_MAXIMUM_ALLOWED, 227 251 &pol); 228 252 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, 234 258 &pol, 235 259 LSA_POLICY_INFO_AUDIT_EVENTS, 236 &info); 260 &info, 261 &result); 262 if (!NT_STATUS_IS_OK(status)) { 263 goto done; 264 } 237 265 if (!NT_STATUS_IS_OK(result)) { 266 status = result; 238 267 goto done; 239 268 } … … 241 270 info->audit_events.auditing_mode = enable; 242 271 243 result = rpccli_lsa_SetInfoPolicy(pipe_hnd, mem_ctx,272 status = dcerpc_lsa_SetInfoPolicy(b, mem_ctx, 244 273 &pol, 245 274 LSA_POLICY_INFO_AUDIT_EVENTS, 246 info); 247 275 info, 276 &result); 277 if (!NT_STATUS_IS_OK(status)) { 278 goto done; 279 } 248 280 if (!NT_STATUS_IS_OK(result)) { 281 status = result; 249 282 goto done; 250 283 } 251 284 252 285 done: 253 if (!NT_STATUS_IS_OK( result)) {286 if (!NT_STATUS_IS_OK(status)) { 254 287 d_printf(_("%s: %s\n"), 255 288 enable ? _("failed to enable audit policy"): 256 289 _("failed to disable audit policy"), 257 nt_errstr( result));258 } 259 260 return result;290 nt_errstr(status)); 291 } 292 293 return status; 261 294 } 262 295 … … 265 298 266 299 static NTSTATUS rpc_audit_disable_internal(struct net_context *c, 267 const DOM_SID*domain_sid,300 const struct dom_sid *domain_sid, 268 301 const char *domain_name, 269 302 struct cli_state *cli, … … 281 314 282 315 static NTSTATUS rpc_audit_enable_internal(struct net_context *c, 283 const DOM_SID*domain_sid,316 const struct dom_sid *domain_sid, 284 317 const char *domain_name, 285 318 struct cli_state *cli, … … 297 330 298 331 static NTSTATUS rpc_audit_list_internal(struct net_context *c, 299 const DOM_SID*domain_sid,332 const struct dom_sid *domain_sid, 300 333 const char *domain_name, 301 334 struct cli_state *cli, … … 306 339 { 307 340 struct policy_handle pol; 308 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;341 NTSTATUS status, result; 309 342 union lsa_PolicyInformation *info = NULL; 310 343 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, 313 347 SEC_FLAG_MAXIMUM_ALLOWED, 314 348 &pol); 315 349 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, 321 355 &pol, 322 356 LSA_POLICY_INFO_AUDIT_EVENTS, 323 &info); 357 &info, 358 &result); 359 if (!NT_STATUS_IS_OK(status)) { 360 goto done; 361 } 324 362 if (!NT_STATUS_IS_OK(result)) { 363 status = result; 325 364 goto done; 326 365 } … … 351 390 352 391 done: 353 if (!NT_STATUS_IS_OK( result)) {392 if (!NT_STATUS_IS_OK(status)) { 354 393 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; 359 398 } 360 399 -
vendor/current/source3/utils/net_rpc_join.c
r414 r740 21 21 #include "includes.h" 22 22 #include "utils/net.h" 23 #include "rpc_client/cli_pipe.h" 23 24 #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" 26 34 27 35 /* Macro for checking RPC error codes to make things more readable */ 28 36 29 37 #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))); \ 32 40 goto done; \ 33 41 } 34 42 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 35 55 #define CHECK_RPC_ERR_DEBUG(rpc, debug_args) \ 36 if (!NT_STATUS_IS_OK( result= rpc)) { \56 if (!NT_STATUS_IS_OK(status = rpc)) { \ 37 57 DEBUG(0, debug_args); \ 38 58 goto done; \ 39 59 } 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 40 72 41 73 /** … … 143 175 enum netr_SchannelType sec_channel_type; 144 176 struct rpc_pipe_client *pipe_hnd = NULL; 177 struct dcerpc_binding_handle *b = NULL; 145 178 146 179 /* rpc variables */ 147 180 148 181 struct policy_handle lsa_pol, sam_pol, domain_pol, user_pol; 149 DOM_SID*domain_sid;182 struct dom_sid *domain_sid; 150 183 uint32 user_rid; 151 184 … … 159 192 /* Misc */ 160 193 161 NTSTATUS result;194 NTSTATUS status, result; 162 195 int retval = 1; 163 196 const char *domain = NULL; … … 169 202 struct samr_Ids user_rids; 170 203 struct samr_Ids name_types; 204 171 205 172 206 /* check what type of join */ … … 197 231 /* Make authenticated connection to remote machine */ 198 232 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)) { 201 235 return 1; 202 236 } … … 209 243 /* Fetch domain sid */ 210 244 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, 212 246 &pipe_hnd); 213 if (!NT_STATUS_IS_OK( result)) {247 if (!NT_STATUS_IS_OK(status)) { 214 248 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; 219 254 220 255 CHECK_RPC_ERR(rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true, … … 223 258 "error opening lsa policy handle"); 224 259 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), 229 265 "error querying info policy"); 230 266 … … 232 268 domain_sid = info->account_domain.sid; 233 269 234 rpccli_lsa_Close(pipe_hnd, mem_ctx, &lsa_pol);270 dcerpc_lsa_Close(b, mem_ctx, &lsa_pol, &result); 235 271 TALLOC_FREE(pipe_hnd); /* Done with this pipe */ 236 272 … … 242 278 243 279 /* 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, 245 281 &pipe_hnd); 246 if (!NT_STATUS_IS_OK( result)) {282 if (!NT_STATUS_IS_OK(status)) { 247 283 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), 257 296 "could not connect to SAM database"); 258 297 259 298 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), 267 307 "could not open domain"); 268 308 269 309 /* Create domain user */ 270 310 if ((acct_name = talloc_asprintf(mem_ctx, "%s$", global_myname())) == NULL) { 271 result= NT_STATUS_NO_MEMORY;311 status = NT_STATUS_NO_MEMORY; 272 312 goto done; 273 313 } … … 284 324 DEBUG(10, ("Creating account with flags: %d\n",acct_flags)); 285 325 286 result = rpccli_samr_CreateUser2(pipe_hnd, mem_ctx,326 status = dcerpc_samr_CreateUser2(b, mem_ctx, 287 327 &domain_pol, 288 328 &lsa_acct_name, … … 291 331 &user_pol, 292 332 &access_granted, 293 &user_rid); 294 333 &user_rid, 334 &result); 335 if (!NT_STATUS_IS_OK(status)) { 336 goto done; 337 } 295 338 if (!NT_STATUS_IS_OK(result) && 296 339 !NT_STATUS_EQUAL(result, NT_STATUS_USER_EXISTS)) { 340 status = result; 297 341 d_fprintf(stderr,_("Creation of workstation account failed\n")); 298 342 … … 311 355 312 356 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))); 324 369 325 370 if (name_types.ids[0] != SID_NAME_USER) { … … 332 377 /* Open handle on user */ 333 378 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, 336 381 &domain_pol, 337 382 SEC_FLAG_MAXIMUM_ALLOWED, 338 383 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))); 342 388 343 389 /* Create a random machine account password */ … … 355 401 set_info.info24.password_expired = PASS_DONT_CHANGE_AT_NEXT_LOGON; 356 402 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), 361 408 "error setting trust account password"); 362 409 … … 375 422 as a normal user with "Add workstation to domain" privilege. */ 376 423 377 result = rpccli_samr_SetUserInfo(pipe_hnd, mem_ctx,424 status = dcerpc_samr_SetUserInfo(b, mem_ctx, 378 425 &user_pol, 379 426 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); 383 431 TALLOC_FREE(pipe_hnd); /* Done with this pipe */ 384 432 385 433 /* Now check the whole process from top-to-bottom */ 386 434 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, 388 436 &pipe_hnd); 389 if (!NT_STATUS_IS_OK( result)) {437 if (!NT_STATUS_IS_OK(status)) { 390 438 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, 396 444 cli->desthost, /* server name */ 397 445 domain, /* domain */ … … 402 450 &neg_flags); 403 451 404 if (!NT_STATUS_IS_OK( result)) {452 if (!NT_STATUS_IS_OK(status)) { 405 453 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) && 409 457 (sec_channel_type == SEC_CHAN_BDC) ) { 410 458 d_fprintf(stderr, _("Please make sure that no computer " … … 425 473 struct rpc_pipe_client *netlogon_schannel_pipe; 426 474 427 result= cli_rpc_pipe_open_schannel_with_key(475 status = cli_rpc_pipe_open_schannel_with_key( 428 476 cli, &ndr_table_netlogon.syntax_id, NCACN_NP, 429 477 DCERPC_AUTH_LEVEL_PRIVACY, domain, &pipe_hnd->dc, 430 478 &netlogon_schannel_pipe); 431 479 432 if (!NT_STATUS_IS_OK( result)) {480 if (!NT_STATUS_IS_OK(status)) { 433 481 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) && 437 485 (sec_channel_type == SEC_CHAN_BDC) ) { 438 486 d_fprintf(stderr, _("Please make sure that no " … … 464 512 465 513 /* 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; 468 516 469 517 done: -
vendor/current/source3/utils/net_rpc_printer.c
r597 r740 18 18 */ 19 19 #include "includes.h" 20 #include "system/filesys.h" 20 21 #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" 22 31 23 32 /* support itanium as well */ … … 62 71 printf(_("\tHelpfile: [%s]\n\n"), r->help_file); 63 72 64 for (i=0; r->dependent_files [i] != NULL; i++) {73 for (i=0; r->dependent_files && r->dependent_files[i] != NULL; i++) { 65 74 printf(_("\tDependentfiles: [%s]\n"), r->dependent_files[i]); 66 75 } … … 72 81 } 73 82 74 static void display_reg_value(const char *subkey, struct regval_blob value)83 static void display_reg_value(const char *subkey, struct regval_blob *value) 75 84 { 76 85 const char *text; 77 86 DATA_BLOB blob; 78 87 79 switch( value.type) {88 switch(regval_type(value)) { 80 89 case REG_DWORD: 81 90 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))); 83 92 break; 84 93 85 94 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)); 87 96 pull_reg_sz(talloc_tos(), &blob, &text); 88 97 if (!text) { 89 98 break; 90 99 } 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), 92 101 text); 93 102 break; … … 96 105 d_printf(_("\t[%s:%s]: REG_BINARY: unknown length value not " 97 106 "displayed\n"), 98 subkey, value.valuename);107 subkey, regval_name(value)); 99 108 break; 100 109 … … 102 111 uint32_t i; 103 112 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)); 105 114 106 115 if (!pull_reg_multi_sz(NULL, &blob, &values)) { … … 109 118 } 110 119 111 printf("%s: REG_MULTI_SZ: \n", value.valuename);120 printf("%s: REG_MULTI_SZ: \n", regval_name(value)); 112 121 for (i=0; values[i] != NULL; i++) { 113 122 d_printf("%s\n", values[i]); … … 118 127 119 128 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)); 122 131 } 123 132 … … 153 162 uint16_t fnum_src = 0; 154 163 uint16_t fnum_dst = 0; 155 SEC_DESC*sd = NULL;164 struct security_descriptor *sd = NULL; 156 165 uint16_t attr; 157 166 time_t f_atime, f_ctime, f_mtime; … … 226 235 227 236 if (copy_acls) { 237 NTSTATUS status; 228 238 229 239 /* 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; 234 245 goto out; 235 246 } … … 377 388 378 389 /* copying file */ 379 int n , ret;390 int n; 380 391 n = cli_read(cli_share_src, fnum_src, data, nread, 381 392 read_size); … … 384 395 break; 385 396 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)) { 390 401 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)); 393 403 goto out; 394 404 } … … 487 497 const char *file, const char *short_archi) { 488 498 489 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;490 499 const char *p; 491 500 char *src_name; 492 501 char *dst_name; 493 char *version ;494 char *filename ;502 char *version = NULL; 503 char *filename = NULL; 495 504 char *tok; 496 505 … … 509 518 } 510 519 520 if (version == NULL || filename == NULL) { 521 return NT_STATUS_UNSUCCESSFUL; 522 } 523 511 524 /* 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) { 513 528 return NT_STATUS_NO_MEMORY; 514 529 } 515 530 516 531 /* 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 } 519 536 520 537 521 538 /* 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); 534 541 } 535 542 … … 752 759 union spoolss_PrinterInfo *info) 753 760 { 761 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 754 762 WERROR result; 755 763 NTSTATUS status; … … 812 820 } 813 821 814 status = rpccli_spoolss_SetPrinter(pipe_hnd, mem_ctx,822 status = dcerpc_spoolss_SetPrinter(b, mem_ctx, 815 823 hnd, 816 824 &info_ctr, … … 819 827 0, /* command */ 820 828 &result); 821 829 if (!NT_STATUS_IS_OK(status)) { 830 printf(_("cannot set printer-info: %s\n"), nt_errstr(status)); 831 return false; 832 } 822 833 if (!W_ERROR_IS_OK(result)) { 823 834 printf(_("cannot set printer-info: %s\n"), win_errstr(result)); … … 837 848 uint32_t offered) 838 849 { 850 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 839 851 WERROR result; 840 852 NTSTATUS status; 841 853 842 854 /* setprinterdata call */ 843 status = rpccli_spoolss_SetPrinterData(pipe_hnd, mem_ctx,855 status = dcerpc_spoolss_SetPrinterData(b, mem_ctx, 844 856 hnd, 845 857 value_name, … … 848 860 offered, 849 861 &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 } 851 867 if (!W_ERROR_IS_OK(result)) { 852 868 printf (_("unable to set printerdata: %s\n"), … … 911 927 struct regval_blob *value) 912 928 { 929 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 913 930 WERROR result; 914 931 NTSTATUS status; 915 932 916 933 /* setprinterdataex call */ 917 status = rpccli_spoolss_SetPrinterDataEx(pipe_hnd, mem_ctx,934 status = dcerpc_spoolss_SetPrinterDataEx(b, mem_ctx, 918 935 hnd, 919 936 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), 924 941 &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 } 926 947 if (!W_ERROR_IS_OK(result)) { 927 948 printf(_("could not set printerdataex: %s\n"), … … 974 995 info); 975 996 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 } 978 1005 } 979 1006 … … 1021 1048 union spoolss_DriverInfo *info) 1022 1049 { 1050 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 1023 1051 WERROR result; 1024 1052 NTSTATUS status; … … 1042 1070 1043 1071 /* addprinterdriver call */ 1044 status = rpccli_spoolss_AddPrinterDriver(pipe_hnd, mem_ctx,1072 status = dcerpc_spoolss_AddPrinterDriver(b, mem_ctx, 1045 1073 pipe_hnd->srv_name_slash, 1046 1074 &info_ctr, 1047 1075 &result); 1076 if (!NT_STATUS_IS_OK(status)) { 1077 printf(_("cannot add driver: %s\n"), nt_errstr(status)); 1078 return false; 1079 } 1048 1080 /* be more verbose */ 1049 1081 if (W_ERROR_V(result) == W_ERROR_V(WERR_ACCESS_DENIED)) { … … 1072 1104 union spoolss_PrinterInfo **info_p) 1073 1105 { 1106 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 1074 1107 struct policy_handle hnd; 1108 WERROR werr; 1075 1109 1076 1110 /* no arguments given, enumerate all printers */ … … 1098 1132 1099 1133 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); 1101 1135 return false; 1102 1136 } 1103 1137 1104 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);1138 dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &werr); 1105 1139 1106 1140 *num_printers = 1; … … 1131 1165 1132 1166 NTSTATUS rpc_printer_list_internals(struct net_context *c, 1133 const DOM_SID*domain_sid,1167 const struct dom_sid *domain_sid, 1134 1168 const char *domain_name, 1135 1169 struct cli_state *cli, … … 1183 1217 1184 1218 NTSTATUS rpc_printer_driver_list_internals(struct net_context *c, 1185 const DOM_SID*domain_sid,1219 const struct dom_sid *domain_sid, 1186 1220 const char *domain_name, 1187 1221 struct cli_state *cli, … … 1254 1288 uint32_t action) 1255 1289 { 1290 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 1256 1291 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; 1257 1292 uint32_t i, num_printers; … … 1301 1336 default: 1302 1337 action_str = N_("unknown action"); 1303 printf(_("unk own action: %d\n"), action);1338 printf(_("unknown action: %d\n"), action); 1304 1339 break; 1305 1340 } … … 1313 1348 ZERO_STRUCT(secdesc_ctr); 1314 1349 1315 nt_status = rpccli_spoolss_SetPrinter(pipe_hnd, mem_ctx,1350 nt_status = dcerpc_spoolss_SetPrinter(b, mem_ctx, 1316 1351 &hnd, 1317 1352 &info_ctr, … … 1320 1355 0, /* command */ 1321 1356 &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)) { 1324 1358 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); 1326 1370 goto done; 1327 1371 } … … 1334 1378 1335 1379 done: 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 } 1338 1383 1339 1384 return nt_status; … … 1341 1386 1342 1387 NTSTATUS rpc_printer_publish_publish_internals(struct net_context *c, 1343 const DOM_SID*domain_sid,1388 const struct dom_sid *domain_sid, 1344 1389 const char *domain_name, 1345 1390 struct cli_state *cli, … … 1353 1398 1354 1399 NTSTATUS rpc_printer_publish_unpublish_internals(struct net_context *c, 1355 const DOM_SID*domain_sid,1400 const struct dom_sid *domain_sid, 1356 1401 const char *domain_name, 1357 1402 struct cli_state *cli, … … 1365 1410 1366 1411 NTSTATUS rpc_printer_publish_update_internals(struct net_context *c, 1367 const DOM_SID*domain_sid,1412 const struct dom_sid *domain_sid, 1368 1413 const char *domain_name, 1369 1414 struct cli_state *cli, … … 1394 1439 1395 1440 NTSTATUS rpc_printer_publish_list_internals(struct net_context *c, 1396 const DOM_SID*domain_sid,1441 const struct dom_sid *domain_sid, 1397 1442 const char *domain_name, 1398 1443 struct cli_state *cli, … … 1402 1447 const char **argv) 1403 1448 { 1449 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 1404 1450 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; 1405 1451 uint32_t i, num_printers; … … 1410 1456 struct policy_handle hnd; 1411 1457 int state; 1458 WERROR werr; 1412 1459 1413 1460 if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &info_enum)) … … 1454 1501 break; 1455 1502 default: 1456 printf(_("unk own state: %d\n"), state);1503 printf(_("unknown state: %d\n"), state); 1457 1504 break; 1458 1505 } … … 1462 1509 1463 1510 done: 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 } 1466 1514 1467 1515 return nt_status; … … 1486 1534 1487 1535 NTSTATUS rpc_printer_migrate_security_internals(struct net_context *c, 1488 const DOM_SID*domain_sid,1536 const struct dom_sid *domain_sid, 1489 1537 const char *domain_name, 1490 1538 struct cli_state *cli, … … 1494 1542 const char **argv) 1495 1543 { 1544 struct dcerpc_binding_handle *b_src = pipe_hnd->binding_handle; 1496 1545 /* TODO: what now, info2 or info3 ? 1497 1546 convince jerry that we should add clientside setacls level 3 at least … … 1503 1552 const char *printername, *sharename; 1504 1553 struct rpc_pipe_client *pipe_hnd_dst = NULL; 1554 struct dcerpc_binding_handle *b_dst = NULL; 1505 1555 struct policy_handle hnd_src, hnd_dst; 1506 1556 union spoolss_PrinterInfo *info_enum; 1507 1557 struct cli_state *cli_dst = NULL; 1508 1558 union spoolss_PrinterInfo info_src, info_dst; 1559 WERROR werr; 1509 1560 1510 1561 DEBUG(3,("copying printer ACLs\n")); … … 1513 1564 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst, 1514 1565 &ndr_table_spoolss.syntax_id); 1515 if (!NT_STATUS_IS_OK(nt_status)) 1566 if (!NT_STATUS_IS_OK(nt_status)) { 1516 1567 return nt_status; 1517 1568 } 1569 b_dst = pipe_hnd_dst->binding_handle; 1518 1570 1519 1571 /* enum source printers */ … … 1589 1641 /* close printer handles here */ 1590 1642 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); 1592 1644 } 1593 1645 1594 1646 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); 1596 1648 } 1597 1649 … … 1603 1655 1604 1656 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); 1606 1658 } 1607 1659 1608 1660 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); 1610 1662 } 1611 1663 … … 1634 1686 1635 1687 NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c, 1636 const DOM_SID*domain_sid,1688 const struct dom_sid *domain_sid, 1637 1689 const char *domain_name, 1638 1690 struct cli_state *cli, … … 1642 1694 const char **argv) 1643 1695 { 1696 struct dcerpc_binding_handle *b_src = pipe_hnd->binding_handle; 1644 1697 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; 1645 1698 WERROR result; … … 1649 1702 const char *printername, *sharename; 1650 1703 struct rpc_pipe_client *pipe_hnd_dst = NULL; 1704 struct dcerpc_binding_handle *b_dst = NULL; 1651 1705 struct policy_handle hnd_src, hnd_dst; 1652 1706 union spoolss_PrinterInfo *info_enum; … … 1661 1715 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst, 1662 1716 &ndr_table_spoolss.syntax_id); 1663 if (!NT_STATUS_IS_OK(nt_status)) 1717 if (!NT_STATUS_IS_OK(nt_status)) { 1664 1718 return nt_status; 1719 } 1720 b_dst = pipe_hnd_dst->binding_handle; 1665 1721 1666 1722 /* enum src printers */ … … 1737 1793 /* FIXME: there might be something wrong with samba's 1738 1794 builtin-forms */ 1739 status = rpccli_spoolss_AddForm(pipe_hnd_dst, mem_ctx,1795 status = dcerpc_spoolss_AddForm(b_dst, mem_ctx, 1740 1796 &hnd_dst, 1741 1797 1, 1742 1798 info, 1743 1799 &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 } 1744 1805 if (!W_ERROR_IS_OK(result)) { 1745 1806 d_printf(_("\tAddForm form %d: [%s] refused.\n"), … … 1755 1816 /* close printer handles here */ 1756 1817 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); 1758 1819 } 1759 1820 1760 1821 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); 1762 1823 } 1763 1824 } … … 1767 1828 done: 1768 1829 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 } 1774 1837 1775 1838 if (cli_dst) { … … 1797 1860 1798 1861 NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c, 1799 const DOM_SID*domain_sid,1862 const struct dom_sid *domain_sid, 1800 1863 const char *domain_name, 1801 1864 struct cli_state *cli, … … 1805 1868 const char **argv) 1806 1869 { 1870 struct dcerpc_binding_handle *b_src = pipe_hnd->binding_handle; 1807 1871 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; 1808 1872 uint32_t i, p; … … 1813 1877 bool got_dst_driver_share = false; 1814 1878 struct rpc_pipe_client *pipe_hnd_dst = NULL; 1879 struct dcerpc_binding_handle *b_dst = NULL; 1815 1880 struct policy_handle hnd_src, hnd_dst; 1816 1881 union spoolss_DriverInfo drv_info_src; … … 1821 1886 struct cli_state *cli_share_dst = NULL; 1822 1887 const char *drivername = NULL; 1888 WERROR werr; 1823 1889 1824 1890 DEBUG(3,("copying printer-drivers\n")); … … 1826 1892 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst, 1827 1893 &ndr_table_spoolss.syntax_id); 1828 if (!NT_STATUS_IS_OK(nt_status)) 1894 if (!NT_STATUS_IS_OK(nt_status)) { 1829 1895 return nt_status; 1896 } 1897 b_dst = pipe_hnd_dst->binding_handle; 1830 1898 1831 1899 /* open print$-share on the src server */ … … 1956 2024 /* close dst */ 1957 2025 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); 1959 2027 } 1960 2028 1961 2029 /* close src */ 1962 2030 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); 1964 2032 } 1965 2033 } … … 1969 2037 done: 1970 2038 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 } 1976 2047 1977 2048 if (cli_dst) { … … 2008 2079 2009 2080 NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c, 2010 const DOM_SID*domain_sid,2081 const struct dom_sid *domain_sid, 2011 2082 const char *domain_name, 2012 2083 struct cli_state *cli, … … 2016 2087 const char **argv) 2017 2088 { 2089 struct dcerpc_binding_handle *b_src = pipe_hnd->binding_handle; 2018 2090 WERROR result; 2019 2091 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; … … 2026 2098 const char *printername, *sharename; 2027 2099 struct rpc_pipe_client *pipe_hnd_dst = NULL; 2100 struct dcerpc_binding_handle *b_dst = NULL; 2028 2101 struct spoolss_SetPrinterInfoCtr info_ctr; 2029 2102 … … 2033 2106 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst, 2034 2107 &ndr_table_spoolss.syntax_id); 2035 if (!NT_STATUS_IS_OK(nt_status)) 2108 if (!NT_STATUS_IS_OK(nt_status)) { 2036 2109 return nt_status; 2110 } 2111 b_dst = pipe_hnd_dst->binding_handle; 2037 2112 2038 2113 /* enum printers */ … … 2082 2157 /* close printer handle here - dst only, not got src yet. */ 2083 2158 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); 2085 2160 } 2086 2161 continue; … … 2125 2200 /* close printer handles here */ 2126 2201 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); 2128 2203 } 2129 2204 2130 2205 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); 2132 2207 } 2133 2208 } … … 2136 2211 2137 2212 done: 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 } 2143 2220 2144 2221 if (cli_dst) { … … 2167 2244 2168 2245 NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c, 2169 const DOM_SID*domain_sid,2246 const struct dom_sid *domain_sid, 2170 2247 const char *domain_name, 2171 2248 struct cli_state *cli, … … 2175 2252 const char **argv) 2176 2253 { 2254 struct dcerpc_binding_handle *b_src = pipe_hnd->binding_handle; 2177 2255 2178 2256 /* FIXME: Here the nightmare begins */ … … 2180 2258 WERROR result; 2181 2259 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; 2182 uint32_t i = 0, p = 0,j = 0;2260 uint32_t i = 0, j = 0; 2183 2261 uint32_t num_printers; 2184 2262 uint32_t level = 2; 2185 2263 const char *printername, *sharename; 2186 2264 struct rpc_pipe_client *pipe_hnd_dst = NULL; 2265 struct dcerpc_binding_handle *b_dst = NULL; 2187 2266 struct policy_handle hnd_src, hnd_dst; 2188 2267 union spoolss_PrinterInfo *info_enum; … … 2202 2281 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst, 2203 2282 &ndr_table_spoolss.syntax_id); 2204 if (!NT_STATUS_IS_OK(nt_status)) 2283 if (!NT_STATUS_IS_OK(nt_status)) { 2205 2284 return nt_status; 2285 } 2286 b_dst = pipe_hnd_dst->binding_handle; 2206 2287 2207 2288 /* enum src printers */ … … 2228 2309 for (i = 0; i < num_printers; i++) { 2229 2310 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; 2232 2313 enum winreg_Type type; 2233 uint8_t *buffer = NULL; 2234 const char *value_name = NULL; 2314 struct spoolss_EnumPrinterData r; 2235 2315 2236 2316 /* do some initialization */ … … 2324 2404 */ 2325 2405 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 2326 2416 /* 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); 2343 2423 2344 2424 /* 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 2358 2431 /* 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)) { 2362 2433 2363 2434 /* display_value */ 2364 2435 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 2369 2448 display_reg_value(SPOOL_PRINTERDATA_KEY, v); 2449 talloc_free(v); 2370 2450 } 2371 2451 2372 2452 /* set_value */ 2373 2453 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)) 2376 2456 goto done; 2377 2457 2378 2458 DEBUGADD(1,("\tSetPrinterData of [%s] succeeded\n", 2379 v.valuename));2459 r.out.value_name)); 2380 2460 } 2381 2461 } … … 2416 2496 for (j=0; j < count; j++) { 2417 2497 2418 struct regval_blob value;2498 struct regval_blob *value; 2419 2499 DATA_BLOB blob; 2500 2501 ZERO_STRUCT(blob); 2420 2502 2421 2503 /* although samba replies with sane data in most cases we … … 2432 2514 /* although windows uses a multi-sz, we use a sz */ 2433 2515 push_reg_sz(mem_ctx, &blob, SAMBA_PRINTER_PORT_NAME); 2434 fstrcpy(value.valuename, SPOOL_REG_PORTNAME);2435 2516 } 2436 2517 … … 2442 2523 } 2443 2524 push_reg_sz(mem_ctx, &blob, unc_name); 2444 fstrcpy(value.valuename, SPOOL_REG_UNCNAME);2445 2525 } 2446 2526 … … 2455 2535 goto done; 2456 2536 } 2457 push_reg_sz(mem_ctx, &blob, url);2537 push_reg_sz(mem_ctx, NULL, &blob, url); 2458 2538 fstrcpy(value.valuename, SPOOL_REG_URL); 2459 2539 #endif … … 2463 2543 2464 2544 push_reg_sz(mem_ctx, &blob, longname); 2465 fstrcpy(value.valuename, SPOOL_REG_SERVERNAME);2466 2545 } 2467 2546 … … 2469 2548 2470 2549 push_reg_sz(mem_ctx, &blob, global_myname()); 2471 fstrcpy(value.valuename, SPOOL_REG_SHORTSERVERNAME);2472 2550 } 2473 2551 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; 2480 2560 } 2481 2561 … … 2485 2565 /* here we have to set all subkeys on the dst server */ 2486 2566 if (!net_spoolss_setprinterdataex(pipe_hnd_dst, mem_ctx, &hnd_dst, 2487 subkey, &value)) 2567 subkey, value)) 2568 { 2569 talloc_free(value); 2488 2570 goto done; 2489 2571 } 2572 2573 talloc_free(value); 2490 2574 } else { 2491 2575 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 } 2498 2587 2499 2588 if (c->opt_verbose) { … … 2503 2592 /* here we have to set all subkeys on the dst server */ 2504 2593 if (!net_spoolss_setprinterdataex(pipe_hnd_dst, mem_ctx, &hnd_dst, 2505 subkey, &v)) {2594 subkey, v)) { 2506 2595 goto done; 2507 2596 } 2508 2597 2598 talloc_free(v); 2509 2599 } 2510 2600 … … 2519 2609 /* close printer handles here */ 2520 2610 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); 2522 2612 } 2523 2613 2524 2614 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 } 2528 2617 } 2529 2618 … … 2535 2624 SAFE_FREE(unc_name); 2536 2625 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 } 2542 2633 2543 2634 if (cli_dst) { -
vendor/current/source3/utils/net_rpc_registry.c
r587 r740 19 19 20 20 #include "includes.h" 21 #include "system/filesys.h" 22 #include "rpc_client/rpc_client.h" 23 #include "registry.h" 21 24 #include "utils/net.h" 22 25 #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 26 36 27 37 /******************************************************************* … … 29 39 *******************************************************************/ 30 40 31 static NTSTATUS rpccli_winreg_Connect(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,41 static NTSTATUS dcerpc_winreg_Connect(struct dcerpc_binding_handle *b, TALLOC_CTX *mem_ctx, 32 42 uint32_t reg_type, uint32_t access_mask, 33 struct policy_handle *reg_hnd )43 struct policy_handle *reg_hnd, WERROR *werr) 34 44 { 35 45 ZERO_STRUCTP(reg_hnd); … … 38 48 { 39 49 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); 42 52 43 53 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); 46 56 47 57 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); 50 60 51 61 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); 54 64 55 65 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); 58 68 59 69 default: … … 125 135 uint32 hive; 126 136 NTSTATUS status; 137 WERROR werr; 127 138 struct winreg_String key; 139 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 128 140 129 141 ZERO_STRUCT(key); … … 133 145 } 134 146 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); 137 149 if (!(NT_STATUS_IS_OK(status))) { 138 150 return status; 139 151 } 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); 143 158 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); 145 160 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); 146 166 } 147 167 … … 157 177 TALLOC_CTX *mem_ctx; 158 178 NTSTATUS status; 179 WERROR werr; 159 180 uint32 num_subkeys, max_subkeylen, max_classlen; 160 181 uint32 num_values, max_valnamelen, max_valbufsize; … … 165 186 char **names, **classes; 166 187 NTTIME **modtimes; 188 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 167 189 168 190 if (!(mem_ctx = talloc_new(ctx))) { … … 171 193 172 194 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, 175 197 &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); 179 205 goto error; 180 206 } … … 199 225 struct winreg_StringBuf name_buf; 200 226 NTTIME modtime; 201 WERROR werr;202 227 203 228 c = '\0'; … … 211 236 ZERO_STRUCT(modtime); 212 237 213 status = rpccli_winreg_EnumKey(pipe_hnd, mem_ctx, key_hnd,238 status = dcerpc_winreg_EnumKey(b, mem_ctx, key_hnd, 214 239 i, &name_buf, &class_buf, 215 240 &modtime, &werr); 216 241 if (!NT_STATUS_IS_OK(status)) { 242 goto error; 243 } 217 244 if (W_ERROR_EQUAL(werr, 218 245 WERR_NO_MORE_ITEMS) ) { … … 220 247 break; 221 248 } 222 if (!NT_STATUS_IS_OK(status)) { 249 if (!W_ERROR_IS_OK(werr)) { 250 status = werror_to_ntstatus(werr); 223 251 goto error; 224 252 } … … 271 299 TALLOC_CTX *mem_ctx; 272 300 NTSTATUS status; 301 WERROR werr; 273 302 uint32 num_subkeys, max_subkeylen, max_classlen; 274 303 uint32 num_values, max_valnamelen, max_valbufsize; … … 279 308 struct registry_value **values; 280 309 char **names; 310 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 281 311 282 312 if (!(mem_ctx = talloc_new(ctx))) { … … 285 315 286 316 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, 289 319 &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); 293 327 goto error; 294 328 } … … 325 359 value_length = 0; 326 360 327 status = rpccli_winreg_EnumValue(pipe_hnd, mem_ctx, key_hnd,361 status = dcerpc_winreg_EnumValue(b, mem_ctx, key_hnd, 328 362 i, &name_buf, &type, 329 363 data, &data_size, 330 364 &value_length, &err); 365 if (!(NT_STATUS_IS_OK(status))) { 366 goto error; 367 } 331 368 332 369 if ( W_ERROR_EQUAL(err, … … 336 373 } 337 374 338 if (!(NT_STATUS_IS_OK(status))) { 375 if (!W_ERROR_IS_OK(err)) { 376 status = werror_to_ntstatus(err); 339 377 goto error; 340 378 } … … 350 388 } 351 389 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 416 static 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 354 497 if (!W_ERROR_IS_OK(err)) { 355 498 status = werror_to_ntstatus(err); 356 499 goto error; 357 500 } 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 } 358 522 } 359 523 … … 375 539 376 540 static NTSTATUS registry_getsd(TALLOC_CTX *mem_ctx, 377 struct rpc_pipe_client *pipe_hnd,541 struct dcerpc_binding_handle *b, 378 542 struct policy_handle *key_hnd, 379 543 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); 384 549 } 385 550 … … 392 557 { 393 558 struct winreg_String name_string; 394 DATA_BLOB blob;395 559 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; 402 562 403 563 ZERO_STRUCT(name_string); 404 564 405 565 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, 407 567 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); 411 574 } 412 575 413 576 static NTSTATUS rpc_registry_setvalue_internal(struct net_context *c, 414 const DOM_SID*domain_sid,577 const struct dom_sid *domain_sid, 415 578 const char *domain_name, 416 579 struct cli_state *cli, … … 422 585 struct policy_handle hive_hnd, key_hnd; 423 586 NTSTATUS status; 587 WERROR werr; 424 588 struct registry_value value; 589 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 425 590 426 591 status = registry_openkey(mem_ctx, pipe_hnd, argv[0], … … 439 604 440 605 if (strequal(argv[2], "dword")) { 606 uint32_t v = strtoul(argv[3], NULL, 10); 441 607 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); 443 610 } 444 611 else if (strequal(argv[2], "sz")) { 445 612 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 } 448 617 } 449 618 else { … … 462 631 463 632 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); 466 635 467 636 return NT_STATUS_OK; … … 484 653 485 654 static NTSTATUS rpc_registry_deletevalue_internal(struct net_context *c, 486 const DOM_SID*domain_sid,655 const struct dom_sid *domain_sid, 487 656 const char *domain_name, 488 657 struct cli_state *cli, … … 494 663 struct policy_handle hive_hnd, key_hnd; 495 664 NTSTATUS status; 665 WERROR werr; 496 666 struct winreg_String valuename; 667 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 497 668 498 669 ZERO_STRUCT(valuename); … … 509 680 valuename.name = argv[1]; 510 681 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); 514 684 if (!NT_STATUS_IS_OK(status)) { 515 685 d_fprintf(stderr, _("registry_deletevalue failed: %s\n"), 516 686 nt_errstr(status)); 517 687 } 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); 521 696 522 697 return status; … … 538 713 539 714 static NTSTATUS rpc_registry_getvalue_internal(struct net_context *c, 540 const DOM_SID*domain_sid,715 const struct dom_sid *domain_sid, 541 716 const char *domain_name, 542 717 struct cli_state *cli, … … 553 728 struct registry_value *value = NULL; 554 729 enum winreg_Type type = REG_NONE; 555 uint8_t *data = NULL;556 730 uint32_t data_size = 0; 557 731 uint32_t value_length = 0; 558 732 TALLOC_CTX *tmp_ctx = talloc_stackframe(); 733 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 559 734 560 735 ZERO_STRUCT(valuename); … … 570 745 571 746 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 } 572 752 573 753 /* … … 576 756 * data buffer and call again. 577 757 */ 578 status = rpccli_winreg_QueryValue(pipe_hnd, tmp_ctx, &key_hnd,758 status = dcerpc_winreg_QueryValue(b, tmp_ctx, &key_hnd, 579 759 &valuename, 580 760 &type, 581 data,761 NULL, 582 762 &data_size, 583 763 &value_length, 584 NULL);764 &werr); 585 765 586 766 if (!NT_STATUS_IS_OK(status)) { … … 589 769 goto done; 590 770 } 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, 596 781 &valuename, 597 782 &type, 598 data,783 value->data.data, 599 784 &data_size, 600 785 &value_length, 601 NULL);786 &werr); 602 787 603 788 if (!NT_STATUS_IS_OK(status)) { … … 606 791 goto done; 607 792 } 608 609 werr = registry_pull_value(tmp_ctx, &value, type, data,610 data_size, value_length);611 793 if (!W_ERROR_IS_OK(werr)) { 612 794 status = werror_to_ntstatus(werr); 795 d_fprintf(stderr, _("registry_queryvalue failed: %s\n"), 796 win_errstr(werr)); 613 797 goto done; 614 798 } 615 799 800 801 value->type = type; 802 616 803 print_registry_value(value, raw); 617 804 618 805 done: 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); 621 808 622 809 TALLOC_FREE(tmp_ctx); … … 626 813 627 814 static NTSTATUS rpc_registry_getvalue_full(struct net_context *c, 628 const DOM_SID*domain_sid,815 const struct dom_sid *domain_sid, 629 816 const char *domain_name, 630 817 struct cli_state *cli, … … 654 841 655 842 static NTSTATUS rpc_registry_getvalue_raw(struct net_context *c, 656 const DOM_SID*domain_sid,843 const struct dom_sid *domain_sid, 657 844 const char *domain_name, 658 845 struct cli_state *cli, … … 682 869 683 870 static NTSTATUS rpc_registry_createkey_internal(struct net_context *c, 684 const DOM_SID*domain_sid,871 const struct dom_sid *domain_sid, 685 872 const char *domain_name, 686 873 struct cli_state *cli, … … 695 882 enum winreg_CreateAction action; 696 883 NTSTATUS status; 884 WERROR werr; 885 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 697 886 698 887 ZERO_STRUCT(key); … … 703 892 } 704 893 705 status = rpccli_winreg_Connect(pipe_hnd, mem_ctx, hive,894 status = dcerpc_winreg_Connect(b, mem_ctx, hive, 706 895 SEC_FLAG_MAXIMUM_ALLOWED, 707 &hive_hnd );896 &hive_hnd, &werr); 708 897 if (!(NT_STATUS_IS_OK(status))) { 709 898 return status; 710 899 } 900 if (!W_ERROR_IS_OK(werr)) { 901 return werror_to_ntstatus(werr); 902 } 711 903 712 904 action = REG_ACTION_NONE; 713 905 keyclass.name = ""; 714 906 715 status = rpccli_winreg_CreateKey(pipe_hnd, mem_ctx, &hive_hnd, key,907 status = dcerpc_winreg_CreateKey(b, mem_ctx, &hive_hnd, key, 716 908 keyclass, 0, REG_KEY_READ, NULL, 717 &key_hnd, &action, NULL);909 &key_hnd, &action, &werr); 718 910 if (!NT_STATUS_IS_OK(status)) { 719 911 d_fprintf(stderr, _("createkey returned %s\n"), 720 912 nt_errstr(status)); 721 rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &hive_hnd, NULL);913 dcerpc_winreg_CloseKey(b, mem_ctx, &hive_hnd, &werr); 722 914 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); 723 922 } 724 923 … … 735 934 } 736 935 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); 739 938 740 939 return status; … … 756 955 757 956 static NTSTATUS rpc_registry_deletekey_internal(struct net_context *c, 758 const DOM_SID*domain_sid,957 const struct dom_sid *domain_sid, 759 958 const char *domain_name, 760 959 struct cli_state *cli, … … 768 967 struct winreg_String key; 769 968 NTSTATUS status; 969 WERROR werr; 970 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 770 971 771 972 ZERO_STRUCT(key); … … 775 976 } 776 977 777 status = rpccli_winreg_Connect(pipe_hnd, mem_ctx, hive,978 status = dcerpc_winreg_Connect(b, mem_ctx, hive, 778 979 SEC_FLAG_MAXIMUM_ALLOWED, 779 &hive_hnd );980 &hive_hnd, &werr); 780 981 if (!(NT_STATUS_IS_OK(status))) { 781 982 return status; 782 983 } 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 } 786 993 787 994 if (!NT_STATUS_IS_OK(status)) { 788 995 d_fprintf(stderr, _("deletekey returned %s\n"), 789 996 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); 790 1004 } 791 1005 … … 810 1024 811 1025 static NTSTATUS rpc_registry_enumerate_internal(struct net_context *c, 812 const DOM_SID*domain_sid,1026 const struct dom_sid *domain_sid, 813 1027 const char *domain_name, 814 1028 struct cli_state *cli, … … 820 1034 struct policy_handle pol_hive, pol_key; 821 1035 NTSTATUS status; 1036 WERROR werr; 822 1037 uint32 num_subkeys = 0; 823 1038 uint32 num_values = 0; … … 826 1041 uint32 i; 827 1042 struct registry_value **values = NULL; 1043 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 828 1044 829 1045 if (argc != 1 || c->display_usage) { … … 868 1084 } 869 1085 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); 872 1088 873 1089 return status; … … 888 1104 889 1105 static NTSTATUS rpc_registry_save_internal(struct net_context *c, 890 const DOM_SID*domain_sid,1106 const struct dom_sid *domain_sid, 891 1107 const char *domain_name, 892 1108 struct cli_state *cli, … … 900 1116 NTSTATUS status = NT_STATUS_UNSUCCESSFUL; 901 1117 struct winreg_String filename; 1118 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 902 1119 903 1120 if (argc != 2 || c->display_usage) { … … 917 1134 918 1135 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)) { 921 1138 d_fprintf(stderr, _("Unable to save [%s] to %s:%s\n"), argv[0], 922 1139 cli->desthost, argv[1]); 923 1140 } 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 } 924 1146 925 1147 /* cleanup */ 926 1148 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); 929 1151 930 1152 return status; … … 956 1178 for ( i=0; i<nk->num_values; i++ ) { 957 1179 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 ) ); 959 1181 960 1182 data_size = nk->values[i].data_size & ~VK_DATA_IN_OFFSET; … … 1038 1260 } 1039 1261 1040 if ( !(values = TALLOC_ZERO_P( subkeys, struct regval_ctr )) ) { 1262 werr = regval_ctr_init(subkeys, &values); 1263 if (!W_ERROR_IS_OK(werr)) { 1041 1264 DEBUG(0,("write_registry_tree: talloc() failed!\n")); 1042 1265 TALLOC_FREE(subkeys); … … 1048 1271 for ( i=0; i<nk->num_values; i++ ) { 1049 1272 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) ); 1051 1274 } 1052 1275 … … 1191 1414 1192 1415 static NTSTATUS rpc_registry_getsd_internal(struct net_context *c, 1193 const DOM_SID*domain_sid,1416 const struct dom_sid *domain_sid, 1194 1417 const char *domain_name, 1195 1418 struct cli_state *cli, … … 1201 1424 struct policy_handle pol_hive, pol_key; 1202 1425 NTSTATUS status; 1426 WERROR werr; 1203 1427 enum ndr_err_code ndr_err; 1204 1428 struct KeySecurityData *sd = NULL; … … 1206 1430 DATA_BLOB blob; 1207 1431 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 | 1210 1433 SEC_FLAG_SYSTEM_SECURITY; 1434 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 1211 1435 1212 1436 if (argc <1 || argc > 2 || c->display_usage) { … … 1242 1466 } 1243 1467 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); 1245 1469 if (!NT_STATUS_IS_OK(status)) { 1246 1470 d_fprintf(stderr, _("getting sd failed: %s\n"), 1247 1471 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)); 1248 1478 goto out; 1249 1479 } … … 1252 1482 blob.length = sd->size; 1253 1483 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, 1255 1485 (ndr_pull_flags_fn_t)ndr_pull_security_descriptor); 1256 1486 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { … … 1263 1493 1264 1494 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); 1267 1497 1268 1498 return status; … … 1277 1507 1278 1508 /******************************************************************** 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 1520 static 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 } 1600 done: 1601 talloc_free(mem_ctx); 1602 return status; 1603 } 1604 1605 static 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 1656 static 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 1674 struct import_ctx { 1675 struct rpc_pipe_client *pipe_hnd; 1676 TALLOC_CTX *mem_ctx; 1677 }; 1678 1679 static 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 1767 done: 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 1782 static 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 1833 done: 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 1843 static 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; 1865 done: 1866 talloc_free(mem_ctx); 1867 return werr; 1868 } 1869 1870 static 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 1902 done: 1903 talloc_free(mem_ctx); 1904 return werr; 1905 } 1906 1907 static 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 1938 done: 1939 talloc_free(mem_ctx); 1940 return werr; 1941 } 1942 1943 1944 1945 static 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 1994 static 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 ********************************************************************/ 1280 2004 1281 2005 int net_rpc_registry(struct net_context *c, int argc, const char **argv) … … 1370 2094 " Get security descriptior") 1371 2095 }, 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 }, 1372 2112 {NULL, NULL, 0, NULL, NULL} 1373 2113 }; 1374 1375 2114 return net_run_function(c, argc, argv, "net rpc registry", func); 1376 2115 } -
vendor/current/source3/utils/net_rpc_rights.c
r414 r740 20 20 #include "includes.h" 21 21 #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" 23 27 24 28 /******************************************************************** … … 27 31 static NTSTATUS sid_to_name(struct rpc_pipe_client *pipe_hnd, 28 32 TALLOC_CTX *mem_ctx, 29 DOM_SID*sid,33 struct dom_sid *sid, 30 34 fstring name) 31 35 { 32 36 struct policy_handle pol; 33 37 enum lsa_SidType *sid_types = NULL; 34 NTSTATUS result;38 NTSTATUS status, result; 35 39 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, 38 43 SEC_FLAG_MAXIMUM_ALLOWED, &pol); 39 44 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) ) { 46 51 if ( *domains[0] ) 47 52 fstr_sprintf( name, "%s\\%s", domains[0], names[0] ); … … 50 55 } 51 56 52 rpccli_lsa_Close(pipe_hnd, mem_ctx, &pol);53 return result;57 dcerpc_lsa_Close(b, mem_ctx, &pol, &result); 58 return status; 54 59 } 55 60 … … 59 64 static NTSTATUS name_to_sid(struct rpc_pipe_client *pipe_hnd, 60 65 TALLOC_CTX *mem_ctx, 61 DOM_SID*sid, const char *name)66 struct dom_sid *sid, const char *name) 62 67 { 63 68 struct policy_handle pol; 64 69 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; 67 73 68 74 /* maybe its a raw SID */ … … 71 77 } 72 78 73 result= rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,79 status = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true, 74 80 SEC_FLAG_MAXIMUM_ALLOWED, &pol); 75 81 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, 80 86 NULL, 1, &sids, &sid_types); 81 87 82 if ( NT_STATUS_IS_OK( result) )88 if ( NT_STATUS_IS_OK(status) ) 83 89 sid_copy( sid, &sids[0] ); 84 90 85 rpccli_lsa_Close(pipe_hnd, mem_ctx, &pol);86 return result;91 dcerpc_lsa_Close(b, mem_ctx, &pol, &result); 92 return status; 87 93 } 88 94 … … 94 100 struct policy_handle *pol ) 95 101 { 96 NTSTATUS result;102 NTSTATUS status, result; 97 103 uint32 enum_context = 0; 98 104 uint32 pref_max_length=0x1000; … … 103 109 struct lsa_StringLarge *description = NULL; 104 110 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, 107 114 pol, 108 115 &enum_context, 109 116 &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)) { 113 123 return result; 124 } 114 125 115 126 /* Print results */ … … 126 137 init_lsa_String(&lsa_name, priv_array.privs[i].name.string); 127 138 128 result = rpccli_lsa_LookupPrivDisplayName(pipe_hnd, ctx,139 status = dcerpc_lsa_LookupPrivDisplayName(b, ctx, 129 140 pol, 130 141 &lsa_name, … … 132 143 lang_id_sys, 133 144 &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 } 136 151 if (!NT_STATUS_IS_OK(result)) { 137 152 d_printf("??????\n"); … … 151 166 TALLOC_CTX *ctx, 152 167 struct policy_handle *pol, 153 DOM_SID*sid,168 struct dom_sid *sid, 154 169 const char *right) 155 170 { 156 NTSTATUS result;171 NTSTATUS status, result; 157 172 struct lsa_RightSet rights; 158 173 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, 161 177 pol, 162 178 sid, 163 &rights); 164 179 &rights, 180 &result); 181 if (!NT_STATUS_IS_OK(status)) { 182 return status; 183 } 165 184 if (!NT_STATUS_IS_OK(result)) { 166 185 return result; … … 186 205 TALLOC_CTX *ctx, 187 206 struct policy_handle *pol, 188 DOM_SID*sid )189 { 190 NTSTATUS result;207 struct dom_sid *sid ) 208 { 209 NTSTATUS status, result; 191 210 struct lsa_RightSet rights; 192 211 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, 195 215 pol, 196 216 sid, 197 &rights); 198 217 &rights, 218 &result); 219 if (!NT_STATUS_IS_OK(status)) 220 return status; 199 221 if (!NT_STATUS_IS_OK(result)) 200 222 return result; … … 219 241 const char *privilege) 220 242 { 221 NTSTATUS result;243 NTSTATUS status, result; 222 244 uint32 enum_context=0; 223 245 uint32 pref_max_length=0x1000; … … 225 247 int i; 226 248 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, 229 252 pol, 230 253 &enum_context, 231 254 &sid_array, 232 pref_max_length); 233 255 pref_max_length, 256 &result); 257 if (!NT_STATUS_IS_OK(status)) 258 return status; 234 259 if (!NT_STATUS_IS_OK(result)) 235 260 return result; … … 239 264 for ( i=0; i<sid_array.num_sids; i++ ) { 240 265 241 result= check_privilege_for_user(pipe_hnd, ctx, pol,266 status = check_privilege_for_user(pipe_hnd, ctx, pol, 242 267 sid_array.sids[i].sid, 243 268 privilege); 244 269 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; 248 273 } 249 274 continue; … … 252 277 /* try to convert the SID to a name. Fall back to 253 278 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) ) 256 281 sid_to_fstring(name, sid_array.sids[i].sid); 257 282 … … 269 294 struct policy_handle *pol) 270 295 { 271 NTSTATUS result;296 NTSTATUS status, result; 272 297 uint32 enum_context=0; 273 298 uint32 pref_max_length=0x1000; … … 275 300 int i; 276 301 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, 279 305 pol, 280 306 &enum_context, 281 307 &sid_array, 282 pref_max_length); 283 308 pref_max_length, 309 &result); 310 if (!NT_STATUS_IS_OK(status)) 311 return status; 284 312 if (!NT_STATUS_IS_OK(result)) 285 313 return result; … … 290 318 printing the raw SID if necessary */ 291 319 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) ) 294 322 sid_to_fstring(name, sid_array.sids[i].sid); 295 323 296 324 d_printf("%s\n", name); 297 325 298 result= enum_privileges_for_user(pipe_hnd, ctx, pol,326 status = enum_privileges_for_user(pipe_hnd, ctx, pol, 299 327 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; 302 330 303 331 d_printf("\n"); … … 311 339 312 340 static NTSTATUS rpc_rights_list_internal(struct net_context *c, 313 const DOM_SID*domain_sid,341 const struct dom_sid *domain_sid, 314 342 const char *domain_name, 315 343 struct cli_state *cli, … … 320 348 { 321 349 struct policy_handle pol; 322 NTSTATUS result;323 DOM_SIDsid;350 NTSTATUS status, result; 351 struct dom_sid sid; 324 352 fstring privname; 325 353 struct lsa_String lsa_name; … … 328 356 uint16 lang_id_sys = 0; 329 357 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, 332 361 SEC_FLAG_MAXIMUM_ALLOWED, &pol); 333 362 334 if ( !NT_STATUS_IS_OK( result) )335 return result;363 if ( !NT_STATUS_IS_OK(status) ) 364 return status; 336 365 337 366 /* backwards compatibility; just list available privileges if no arguement */ 338 367 339 368 if (argc == 0) { 340 result= enum_privileges(pipe_hnd, mem_ctx, &pol );369 status = enum_privileges(pipe_hnd, mem_ctx, &pol ); 341 370 goto done; 342 371 } … … 346 375 347 376 if (argv[1] == NULL) { 348 result= enum_privileges(pipe_hnd, mem_ctx, &pol );377 status = enum_privileges(pipe_hnd, mem_ctx, &pol ); 349 378 goto done; 350 379 } … … 356 385 357 386 /* 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, 359 388 &pol, 360 389 &lsa_name, … … 362 391 lang_id_sys, 363 392 &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; 366 399 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)) 368 401 d_fprintf(stderr, _("No such privilege " 369 402 "exists: %s.\n"), privname); … … 376 409 } 377 410 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)) { 380 413 d_fprintf(stderr, _("Error enumerating " 381 414 "accounts for privilege %s [%s].\n"), 382 privname, nt_errstr( result));415 privname, nt_errstr(status)); 383 416 continue; 384 417 } … … 393 426 394 427 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); 396 429 goto done; 397 430 } 398 431 399 432 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)) { 402 435 goto done; 403 436 } 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)) { 406 439 goto done; 407 440 } … … 416 449 d_printf("%s net rpc rights list [[accounts|privileges] " 417 450 "[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 ); 427 460 428 461 done: 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; 432 465 } 433 466 … … 436 469 437 470 static NTSTATUS rpc_rights_grant_internal(struct net_context *c, 438 const DOM_SID*domain_sid,471 const struct dom_sid *domain_sid, 439 472 const char *domain_name, 440 473 struct cli_state *cli, … … 445 478 { 446 479 struct policy_handle dom_pol; 447 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;480 NTSTATUS status, result; 448 481 struct lsa_RightSet rights; 449 482 int i; 450 451 DOM_SID sid; 483 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 484 485 struct dom_sid sid; 452 486 453 487 if (argc < 2 ) { … … 458 492 } 459 493 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, 468 502 SEC_FLAG_MAXIMUM_ALLOWED, 469 503 &dom_pol); 470 504 471 if (!NT_STATUS_IS_OK( result))472 return result;505 if (!NT_STATUS_IS_OK(status)) 506 return status; 473 507 474 508 rights.count = argc-1; … … 483 517 } 484 518 485 result = rpccli_lsa_AddAccountRights(pipe_hnd, mem_ctx,519 status = dcerpc_lsa_AddAccountRights(b, mem_ctx, 486 520 &dom_pol, 487 521 &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 } 492 530 493 531 d_printf(_("Successfully granted rights.\n")); 494 532 495 533 done: 496 if ( !NT_STATUS_IS_OK( result) ) {534 if ( !NT_STATUS_IS_OK(status) ) { 497 535 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; 504 542 } 505 543 … … 508 546 509 547 static NTSTATUS rpc_rights_revoke_internal(struct net_context *c, 510 const DOM_SID*domain_sid,548 const struct dom_sid *domain_sid, 511 549 const char *domain_name, 512 550 struct cli_state *cli, … … 517 555 { 518 556 struct policy_handle dom_pol; 519 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;557 NTSTATUS status, result; 520 558 struct lsa_RightSet rights; 521 DOM_SIDsid;559 struct dom_sid sid; 522 560 int i; 561 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 523 562 524 563 if (argc < 2 ) { … … 529 568 } 530 569 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, 536 575 SEC_FLAG_MAXIMUM_ALLOWED, 537 576 &dom_pol); 538 577 539 if (!NT_STATUS_IS_OK( result))540 return result;578 if (!NT_STATUS_IS_OK(status)) 579 return status; 541 580 542 581 rights.count = argc-1; … … 551 590 } 552 591 553 result = rpccli_lsa_RemoveAccountRights(pipe_hnd, mem_ctx,592 status = dcerpc_lsa_RemoveAccountRights(b, mem_ctx, 554 593 &dom_pol, 555 594 &sid, 556 595 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 } 561 604 562 605 d_printf(_("Successfully revoked rights.\n")); 563 606 564 607 done: 565 if ( !NT_STATUS_IS_OK( result) ) {608 if ( !NT_STATUS_IS_OK(status) ) { 566 609 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; 573 616 } 574 617 -
vendor/current/source3/utils/net_rpc_samsync.c
r594 r740 26 26 #include "includes.h" 27 27 #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" 28 34 29 35 static void parse_samsync_partial_replication_objects(TALLOC_CTX *mem_ctx, … … 104 110 /* dump sam database via samsync rpc calls */ 105 111 NTSTATUS rpc_samdump_internals(struct net_context *c, 106 const DOM_SID*domain_sid,112 const struct dom_sid *domain_sid, 107 113 const char *domain_name, 108 114 struct cli_state *cli, … … 170 176 } 171 177 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())) { 178 static 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())) { 187 191 d_printf(_("Cannot import users from %s at this time, " 188 192 "as the current domain:\n\t%s: %s\nconflicts " … … 199 203 } 200 204 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 */ 232 static 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 201 259 result = libnet_samsync_init_context(mem_ctx, 202 260 domain_sid, … … 232 290 233 291 /* 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); 235 293 ctx->domain_sid_str = sid_string_talloc(mem_ctx, ctx->domain_sid); 236 294 result = libnet_samsync(SAM_DATABASE_BUILTIN, ctx); … … 252 310 int rpc_vampire_passdb(struct net_context *c, int argc, const char **argv) 253 311 { 312 int ret = 0; 313 NTSTATUS status; 314 struct cli_state *cli = NULL; 315 struct net_dc_info dc_info; 316 254 317 if (c->display_usage) { 255 318 d_printf( "%s\n" … … 261 324 } 262 325 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 367 static 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) 275 375 { 276 376 NTSTATUS status; … … 315 415 316 416 /* 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); 318 418 ctx->domain_sid_str = sid_string_talloc(mem_ctx, ctx->domain_sid); 319 419 status = libnet_samsync(SAM_DATABASE_BUILTIN, ctx); … … 350 450 351 451 352 NTSTATUS rpc_vampire_keytab_internals(struct net_context *c,353 const DOM_SID*domain_sid,354 355 356 357 358 359 452 static 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) 360 460 { 361 461 NTSTATUS status; … … 411 511 412 512 static NTSTATUS rpc_vampire_keytab_ds_internals(struct net_context *c, 413 const DOM_SID*domain_sid,513 const struct dom_sid *domain_sid, 414 514 const char *domain_name, 415 515 struct cli_state *cli, -
vendor/current/source3/utils/net_rpc_service.c
r414 r740 19 19 #include "includes.h" 20 20 #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" 22 24 23 25 struct svc_state_msg { … … 60 62 ********************************************************************/ 61 63 64 static 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 98 static 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 62 133 static WERROR query_service_state(struct rpc_pipe_client *pipe_hnd, 63 134 TALLOC_CTX *mem_ctx, … … 70 141 WERROR result = WERR_GENERAL_FAILURE; 71 142 NTSTATUS status; 143 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 72 144 73 145 /* now cycle until the status is actually 'watch_state' */ 74 146 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) ) { 84 151 return result; 85 152 } 86 153 87 status = rpccli_svcctl_QueryServiceStatus(pipe_hnd, mem_ctx,154 status = dcerpc_svcctl_QueryServiceStatus(b, mem_ctx, 88 155 &hService, 89 156 &service_status, 90 157 &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 } 97 173 98 174 return result; … … 149 225 struct SERVICE_STATUS service_status; 150 226 uint32 state = 0; 227 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 151 228 152 229 /* Open the Service */ 153 230 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; 165 236 } 166 237 167 238 /* get the status */ 168 239 169 status = rpccli_svcctl_ControlService(pipe_hnd, mem_ctx,240 status = dcerpc_svcctl_ControlService(b, mem_ctx, 170 241 &hService, 171 242 control, … … 173 244 &result); 174 245 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) ) { 176 253 d_fprintf(stderr, _("Control service request failed. [%s]\n"), 177 254 win_errstr(result)); … … 186 263 187 264 done: 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 } 189 269 190 270 return result; … … 195 275 196 276 static NTSTATUS rpc_service_list_internal(struct net_context *c, 197 const DOM_SID*domain_sid,277 const struct dom_sid *domain_sid, 198 278 const char *domain_name, 199 279 struct cli_state *cli, … … 208 288 NTSTATUS status; 209 289 int i; 290 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 210 291 211 292 uint8_t *buffer = NULL; … … 220 301 } 221 302 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)) { 232 307 return werror_to_ntstatus(result); 233 308 } 234 309 235 310 do { 236 status = rpccli_svcctl_EnumServicesStatusW(pipe_hnd, mem_ctx,311 status = dcerpc_svcctl_EnumServicesStatusW(b, mem_ctx, 237 312 &hSCM, 238 313 SERVICE_TYPE_WIN32, … … 245 320 &result); 246 321 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); 248 337 d_fprintf(stderr, 249 338 _("Failed to enumerate services. [%s]\n"), … … 252 341 } 253 342 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 260 343 if ( num_services == 0 ) { 261 344 d_printf(_("No services returned\n")); … … 277 360 } 278 361 279 ndr = ndr_pull_init_blob(&blob, mem_ctx , NULL);362 ndr = ndr_pull_init_blob(&blob, mem_ctx); 280 363 if (ndr == NULL) { 281 364 status = NT_STATUS_NO_MEMORY; … … 299 382 } while (W_ERROR_EQUAL(result, WERR_MORE_DATA)); 300 383 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 } 302 388 303 389 return status; … … 308 394 309 395 static NTSTATUS rpc_service_status_internal(struct net_context *c, 310 const DOM_SID*domain_sid,396 const struct dom_sid *domain_sid, 311 397 const char *domain_name, 312 398 struct cli_state *cli, … … 323 409 uint32_t buf_size = sizeof(config); 324 410 uint32_t ret_size = 0; 411 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 325 412 326 413 if (argc != 1 ) { … … 330 417 331 418 /* 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)) { 342 423 return werror_to_ntstatus(result); 343 424 } … … 345 426 /* Open the Service */ 346 427 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) ) { 357 432 goto done; 358 433 } … … 360 435 /* get the status */ 361 436 362 status = rpccli_svcctl_QueryServiceStatus(pipe_hnd, mem_ctx,437 status = dcerpc_svcctl_QueryServiceStatus(b, mem_ctx, 363 438 &hService, 364 439 &service_status, 365 440 &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) ) { 368 449 d_fprintf(stderr, _("Query status request failed. [%s]\n"), 369 450 win_errstr(result)); … … 376 457 /* get the config */ 377 458 378 status = rpccli_svcctl_QueryServiceConfigW(pipe_hnd, mem_ctx,459 status = dcerpc_svcctl_QueryServiceConfigW(b, mem_ctx, 379 460 &hService, 380 461 &config, … … 382 463 &ret_size, 383 464 &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 384 472 if (W_ERROR_EQUAL(result, WERR_INSUFFICIENT_BUFFER)) { 385 473 buf_size = ret_size; 386 status = rpccli_svcctl_QueryServiceConfigW(pipe_hnd, mem_ctx,474 status = dcerpc_svcctl_QueryServiceConfigW(b, mem_ctx, 387 475 &hService, 388 476 &config, … … 390 478 &ret_size, 391 479 &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) ) { 395 489 d_fprintf(stderr, _("Query config request failed. [%s]\n"), 396 490 win_errstr(result)); … … 433 527 434 528 done: 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 } 437 537 438 538 return werror_to_ntstatus(result); … … 443 543 444 544 static NTSTATUS rpc_service_stop_internal(struct net_context *c, 445 const DOM_SID*domain_sid,545 const struct dom_sid *domain_sid, 446 546 const char *domain_name, 447 547 struct cli_state *cli, … … 453 553 struct policy_handle hSCM; 454 554 WERROR result = WERR_GENERAL_FAILURE; 455 NTSTATUS status; 456 fstring servicename; 555 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 457 556 458 557 if (argc != 1 ) { … … 461 560 } 462 561 463 fstrcpy( servicename, argv[0] );464 465 562 /* 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)) { 476 567 return werror_to_ntstatus(result); 477 568 } 478 569 479 result = control_service(pipe_hnd, mem_ctx, &hSCM, servicename,570 result = control_service(pipe_hnd, mem_ctx, &hSCM, argv[0], 480 571 SVCCTL_CONTROL_STOP, SVCCTL_STOPPED ); 481 572 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 } 483 577 484 578 return werror_to_ntstatus(result); … … 489 583 490 584 static NTSTATUS rpc_service_pause_internal(struct net_context *c, 491 const DOM_SID*domain_sid,585 const struct dom_sid *domain_sid, 492 586 const char *domain_name, 493 587 struct cli_state *cli, … … 499 593 struct policy_handle hSCM; 500 594 WERROR result = WERR_GENERAL_FAILURE; 501 NTSTATUS status; 502 fstring servicename; 595 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 503 596 504 597 if (argc != 1 ) { … … 507 600 } 508 601 509 fstrcpy( servicename, argv[0] );510 511 602 /* 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)) { 522 607 return werror_to_ntstatus(result); 523 608 } 524 609 525 result = control_service(pipe_hnd, mem_ctx, &hSCM, servicename,610 result = control_service(pipe_hnd, mem_ctx, &hSCM, argv[0], 526 611 SVCCTL_CONTROL_PAUSE, SVCCTL_PAUSED ); 527 612 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 } 529 617 530 618 return werror_to_ntstatus(result); … … 535 623 536 624 static NTSTATUS rpc_service_resume_internal(struct net_context *c, 537 const DOM_SID*domain_sid,625 const struct dom_sid *domain_sid, 538 626 const char *domain_name, 539 627 struct cli_state *cli, … … 545 633 struct policy_handle hSCM; 546 634 WERROR result = WERR_GENERAL_FAILURE; 547 NTSTATUS status; 548 fstring servicename; 635 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 549 636 550 637 if (argc != 1 ) { … … 553 640 } 554 641 555 fstrcpy( servicename, argv[0] );556 557 642 /* 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)) { 568 647 return werror_to_ntstatus(result); 569 648 } 570 649 571 result = control_service(pipe_hnd, mem_ctx, &hSCM, servicename,650 result = control_service(pipe_hnd, mem_ctx, &hSCM, argv[0], 572 651 SVCCTL_CONTROL_CONTINUE, SVCCTL_RUNNING ); 573 652 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 } 575 657 576 658 return werror_to_ntstatus(result); … … 581 663 582 664 static NTSTATUS rpc_service_start_internal(struct net_context *c, 583 const DOM_SID*domain_sid,665 const struct dom_sid *domain_sid, 584 666 const char *domain_name, 585 667 struct cli_state *cli, … … 593 675 NTSTATUS status; 594 676 uint32 state = 0; 677 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 595 678 596 679 if (argc != 1 ) { … … 600 683 601 684 /* 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)) { 612 689 return werror_to_ntstatus(result); 613 690 } 614 691 692 615 693 /* Open the Service */ 616 694 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) ) { 627 699 goto done; 628 700 } … … 630 702 /* get the status */ 631 703 632 status = rpccli_svcctl_StartServiceW(pipe_hnd, mem_ctx,704 status = dcerpc_svcctl_StartServiceW(b, mem_ctx, 633 705 &hService, 634 706 0, … … 636 708 &result); 637 709 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) ) { 639 717 d_fprintf(stderr, _("Query status request failed. [%s]\n"), 640 718 win_errstr(result)); … … 652 730 653 731 done: 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 } 656 740 657 741 return werror_to_ntstatus(result); … … 662 746 663 747 static NTSTATUS rpc_service_delete_internal(struct net_context *c, 664 const DOM_SID*domain_sid,748 const struct dom_sid *domain_sid, 665 749 const char *domain_name, 666 750 struct cli_state *cli, … … 673 757 WERROR result = WERR_GENERAL_FAILURE; 674 758 NTSTATUS status; 759 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 675 760 676 761 if (argc != 1 ) { … … 679 764 } 680 765 766 ZERO_STRUCT(hSCM); 767 ZERO_STRUCT(hService); 768 681 769 /* 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)) { 692 774 return werror_to_ntstatus(result); 693 775 } … … 695 777 /* Open the Service */ 696 778 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) ) { 707 783 goto done; 708 784 } … … 710 786 /* Delete the Service */ 711 787 712 status = rpccli_svcctl_DeleteService(pipe_hnd, mem_ctx,788 status = dcerpc_svcctl_DeleteService(b, mem_ctx, 713 789 &hService, 714 790 &result); 715 791 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)) { 717 799 d_fprintf(stderr, _("Delete service request failed. [%s]\n"), 718 800 win_errstr(result)); … … 724 806 done: 725 807 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); 727 810 } 728 811 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); 730 814 } 731 815 … … 737 821 738 822 static NTSTATUS rpc_service_create_internal(struct net_context *c, 739 const DOM_SID*domain_sid,823 const struct dom_sid *domain_sid, 740 824 const char *domain_name, 741 825 struct cli_state *cli, … … 751 835 const char *DisplayName; 752 836 const char *binary_path; 837 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 753 838 754 839 if (argc != 3) { … … 758 843 } 759 844 845 ZERO_STRUCT(hSCM); 846 ZERO_STRUCT(hService); 847 760 848 /* 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)) { 771 853 return werror_to_ntstatus(result); 772 854 } … … 778 860 binary_path = argv[2]; 779 861 780 status = rpccli_svcctl_CreateServiceW(pipe_hnd, mem_ctx,862 status = dcerpc_svcctl_CreateServiceW(b, mem_ctx, 781 863 &hSCM, 782 864 ServiceName, … … 796 878 &hService, 797 879 &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); 800 882 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)); 802 889 goto done; 803 890 } … … 807 894 done: 808 895 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); 810 898 } 811 899 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); 813 902 } 814 903 -
vendor/current/source3/utils/net_rpc_sh_acct.c
r414 r740 19 19 #include "includes.h" 20 20 #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" 22 24 23 25 /* … … 41 43 { 42 44 struct policy_handle connect_pol, domain_pol; 43 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;45 NTSTATUS status, result; 44 46 union samr_DomainInfo *info1 = NULL; 45 47 union samr_DomainInfo *info3 = NULL; 46 48 union samr_DomainInfo *info12 = NULL; 47 49 int store; 50 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; 48 51 49 52 ZERO_STRUCT(connect_pol); … … 52 55 /* Get sam policy handle */ 53 56 54 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,57 status = dcerpc_samr_Connect2(b, mem_ctx, 55 58 pipe_hnd->desthost, 56 59 MAXIMUM_ALLOWED_ACCESS, 57 &connect_pol); 60 &connect_pol, 61 &result); 62 if (!NT_STATUS_IS_OK(status)) { 63 goto done; 64 } 58 65 if (!NT_STATUS_IS_OK(result)) { 66 status = result; 59 67 goto done; 60 68 } … … 62 70 /* Get domain policy handle */ 63 71 64 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,72 status = dcerpc_samr_OpenDomain(b, mem_ctx, 65 73 &connect_pol, 66 74 MAXIMUM_ALLOWED_ACCESS, 67 75 ctx->domain_sid, 68 &domain_pol); 76 &domain_pol, 77 &result); 78 if (!NT_STATUS_IS_OK(status)) { 79 goto done; 80 } 69 81 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, 74 87 &domain_pol, 75 88 1, 76 &info1); 77 89 &info1, 90 &result); 91 if (!NT_STATUS_IS_OK(status)) { 92 goto done; 93 } 78 94 if (!NT_STATUS_IS_OK(result)) { 95 status = result; 79 96 d_fprintf(stderr, _("query_domain_info level 1 failed: %s\n"), 80 97 nt_errstr(result)); … … 82 99 } 83 100 84 result = rpccli_samr_QueryDomainInfo(pipe_hnd, mem_ctx,101 status = dcerpc_samr_QueryDomainInfo(b, mem_ctx, 85 102 &domain_pol, 86 103 3, 87 &info3); 88 104 &info3, 105 &result); 106 if (!NT_STATUS_IS_OK(status)) { 107 goto done; 108 } 89 109 if (!NT_STATUS_IS_OK(result)) { 110 status = result; 90 111 d_fprintf(stderr, _("query_domain_info level 3 failed: %s\n"), 91 112 nt_errstr(result)); … … 93 114 } 94 115 95 result = rpccli_samr_QueryDomainInfo(pipe_hnd, mem_ctx,116 status = dcerpc_samr_QueryDomainInfo(b, mem_ctx, 96 117 &domain_pol, 97 118 12, 98 &info12); 99 119 &info12, 120 &result); 121 if (!NT_STATUS_IS_OK(status)) { 122 goto done; 123 } 100 124 if (!NT_STATUS_IS_OK(result)) { 125 status = result; 101 126 d_fprintf(stderr, _("query_domain_info level 12 failed: %s\n"), 102 127 nt_errstr(result)); … … 114 139 switch (store) { 115 140 case 1: 116 result = rpccli_samr_SetDomainInfo(pipe_hnd, mem_ctx,141 status = dcerpc_samr_SetDomainInfo(b, mem_ctx, 117 142 &domain_pol, 118 143 1, 119 info1); 144 info1, 145 &result); 120 146 break; 121 147 case 3: 122 result = rpccli_samr_SetDomainInfo(pipe_hnd, mem_ctx,148 status = dcerpc_samr_SetDomainInfo(b, mem_ctx, 123 149 &domain_pol, 124 150 3, 125 info3); 151 info3, 152 &result); 126 153 break; 127 154 case 12: 128 result = rpccli_samr_SetDomainInfo(pipe_hnd, mem_ctx,155 status = dcerpc_samr_SetDomainInfo(b, mem_ctx, 129 156 &domain_pol, 130 157 12, 131 info12); 158 info12, 159 &result); 132 160 break; 133 161 default: 134 162 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; 138 172 139 173 done: 140 174 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); 142 176 } 143 177 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; 148 182 } 149 183 -
vendor/current/source3/utils/net_rpc_shell.c
r414 r740 20 20 21 21 #include "includes.h" 22 #include "popt_common.h" 22 23 #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" 23 30 24 31 static NTSTATUS rpc_sh_info(struct net_context *c, … … 219 226 } 220 227 221 if (libnetapi_ init(&c->netapi_ctx) != 0) {228 if (libnetapi_net_init(&c->netapi_ctx) != 0) { 222 229 return -1; 223 230 } -
vendor/current/source3/utils/net_sam.c
r594 r740 20 20 21 21 #include "includes.h" 22 #include "system/passwd.h" 22 23 #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" 23 30 24 31 /* … … 32 39 { 33 40 struct samu *sam_acct = NULL; 34 DOM_SIDsid;41 struct dom_sid sid; 35 42 enum lsa_SidType type; 36 43 const char *dom, *name; … … 135 142 { 136 143 struct samu *sam_acct = NULL; 137 DOM_SIDsid;144 struct dom_sid sid; 138 145 enum lsa_SidType type; 139 146 const char *dom, *name; … … 228 235 { 229 236 struct samu *sam_acct = NULL; 230 DOM_SIDsid;237 struct dom_sid sid; 231 238 enum lsa_SidType type; 232 239 const char *dom, *name; … … 294 301 { 295 302 GROUP_MAP map; 296 DOM_SIDsid;303 struct dom_sid sid; 297 304 enum lsa_SidType type; 298 305 const char *dom, *name; … … 631 638 } 632 639 633 extern PRIVS privs[];634 635 640 static int net_sam_rights_list(struct net_context *c, int argc, 636 641 const char **argv) 637 642 { 638 SE_PRIV mask;643 enum sec_privilege privilege; 639 644 640 645 if (argc > 1 || c->display_usage) { … … 647 652 if (argc == 0) { 648 653 int i; 649 int num = count_all_privileges();654 int num = num_privileges_in_short_list(); 650 655 651 656 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)); 653 658 } 654 659 return 0; 655 660 } 656 661 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; 659 666 int i, num_sids; 660 667 NTSTATUS status; 661 668 662 status = privilege_enum_sids( &mask, talloc_tos(),669 status = privilege_enum_sids(privilege, talloc_tos(), 663 670 &sids, &num_sids); 664 671 if (!NT_STATUS_IS_OK(status)) { … … 689 696 const char **argv) 690 697 { 691 DOM_SIDsid;698 struct dom_sid sid; 692 699 enum lsa_SidType type; 693 700 const char *dom, *name; 694 SE_PRIV mask;695 701 int i; 696 702 … … 709 715 710 716 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) { 712 719 d_fprintf(stderr, _("%s unknown\n"), argv[i]); 713 720 return -1; 714 721 } 715 722 716 if (!grant_privilege (&sid, &mask)) {723 if (!grant_privilege_by_name(&sid, argv[i])) { 717 724 d_fprintf(stderr, _("Could not grant privilege\n")); 718 725 return -1; … … 728 735 const char **argv) 729 736 { 730 DOM_SIDsid;737 struct dom_sid sid; 731 738 enum lsa_SidType type; 732 739 const char *dom, *name; 733 SE_PRIV mask;734 740 int i; 735 741 … … 748 754 749 755 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) { 752 758 d_fprintf(stderr, _("%s unknown\n"), argv[i]); 753 759 return -1; 754 760 } 755 761 756 if (!revoke_privilege (&sid, &mask)) {762 if (!revoke_privilege_by_name(&sid, argv[i])) { 757 763 d_fprintf(stderr, _("Could not revoke privilege\n")); 758 764 return -1; … … 895 901 static NTSTATUS unmap_unix_group(const struct group *grp, GROUP_MAP *pmap) 896 902 { 897 NTSTATUS status;898 903 GROUP_MAP map; 899 904 const char *grpname; 900 DOM_SIDdom_sid;905 struct dom_sid dom_sid; 901 906 902 907 map.gid = grp->gr_gid; … … 915 920 } 916 921 917 status = pdb_delete_group_mapping_entry(dom_sid); 918 919 return status; 922 return pdb_delete_group_mapping_entry(dom_sid); 920 923 } 921 924 … … 990 993 const char **argv) 991 994 { 992 DOM_SIDsid;995 struct dom_sid sid; 993 996 uint32_t rid; 994 997 enum lsa_SidType type; … … 1071 1074 static int net_sam_deletelocalgroup(struct net_context *c, int argc, const char **argv) 1072 1075 { 1073 DOM_SIDsid;1076 struct dom_sid sid; 1074 1077 enum lsa_SidType type; 1075 1078 const char *dom, *name; … … 1118 1121 enum lsa_SidType type; 1119 1122 fstring groupname; 1120 DOM_SIDsid;1123 struct dom_sid sid; 1121 1124 1122 1125 if (argc != 1 || c->display_usage) { … … 1170 1173 { 1171 1174 const char *groupdomain, *groupname, *memberdomain, *membername; 1172 DOM_SIDgroup, member;1175 struct dom_sid group, member; 1173 1176 enum lsa_SidType grouptype, membertype; 1174 1177 NTSTATUS status; … … 1259 1262 const char *memberdomain = NULL; 1260 1263 const char *membername = NULL; 1261 DOM_SIDgroup, member;1264 struct dom_sid group, member; 1262 1265 enum lsa_SidType grouptype; 1263 1266 NTSTATUS status; … … 1331 1334 { 1332 1335 const char *groupdomain, *groupname; 1333 DOM_SIDgroup;1334 DOM_SID*members = NULL;1336 struct dom_sid group; 1337 struct dom_sid *members = NULL; 1335 1338 size_t i, num_members = 0; 1336 1339 enum lsa_SidType grouptype; … … 1543 1546 static int net_sam_show(struct net_context *c, int argc, const char **argv) 1544 1547 { 1545 DOM_SIDsid;1548 struct dom_sid sid; 1546 1549 enum lsa_SidType type; 1547 1550 const char *dom, *name; … … 1581 1584 struct smbldap_state *ls; 1582 1585 GROUP_MAP gmap; 1583 DOM_SIDgsid;1586 struct dom_sid gsid; 1584 1587 gid_t domusers_gid = -1; 1585 1588 gid_t domadmins_gid = -1; 1586 1589 struct samu *samuser; 1587 1590 struct passwd *pwd; 1591 bool is_ipa = false; 1588 1592 1589 1593 if (c->display_usage) { … … 1616 1620 trim_char(ldap_bk, ' ', ' '); 1617 1621 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 ) { 1619 1627 d_fprintf(stderr, 1620 1628 _("Provisioning works only with ldapsam backend\n")); … … 1630 1638 } 1631 1639 1632 if (! winbind_ping()) {1640 if (!is_ipa && !winbind_ping()) { 1633 1641 d_fprintf(stderr, _("winbind seems not to run. Provisioning " 1634 1642 "LDAP only works when winbind runs.\n")); … … 1643 1651 d_printf(_("Checking for Domain Users group.\n")); 1644 1652 1645 sid_compose(&gsid, get_global_sam_sid(), DOMAIN_ GROUP_RID_USERS);1653 sid_compose(&gsid, get_global_sam_sid(), DOMAIN_RID_USERS); 1646 1654 1647 1655 if (!pdb_getgrsid(&gmap, gsid)) { … … 1657 1665 1658 1666 /* 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 } 1663 1675 } 1664 1676 … … 1676 1688 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXGROUP); 1677 1689 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 } 1678 1695 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", uname); 1679 1696 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", wname); … … 1691 1708 "to ldap directory\n")); 1692 1709 } 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 } 1693 1720 } else { 1694 1721 domusers_gid = gmap.gid; … … 1700 1727 d_printf(_("Checking for Domain Admins group.\n")); 1701 1728 1702 sid_compose(&gsid, get_global_sam_sid(), DOMAIN_ GROUP_RID_ADMINS);1729 sid_compose(&gsid, get_global_sam_sid(), DOMAIN_RID_ADMINS); 1703 1730 1704 1731 if (!pdb_getgrsid(&gmap, gsid)) { … … 1714 1741 1715 1742 /* 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 } 1720 1751 } 1721 1752 … … 1733 1764 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXGROUP); 1734 1765 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 } 1735 1771 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", uname); 1736 1772 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", wname); … … 1748 1784 "to ldap directory\n")); 1749 1785 } 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 } 1750 1796 } else { 1751 1797 domadmins_gid = gmap.gid; … … 1765 1811 if (!pdb_getsampwnam(samuser, "Administrator")) { 1766 1812 LDAPMod **mods = NULL; 1767 DOM_SIDsid;1813 struct dom_sid sid; 1768 1814 char *dn; 1769 1815 char *name; … … 1772 1818 char *shell; 1773 1819 char *dir; 1820 char *princ; 1774 1821 uid_t uid; 1775 1822 int rc; … … 1783 1830 goto done; 1784 1831 } 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 1791 1844 name = talloc_strdup(tc, "Administrator"); 1792 1845 dn = talloc_asprintf(tc, "uid=Administrator,%s", lp_ldap_user_suffix()); … … 1807 1860 } 1808 1861 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 } 1810 1870 1811 1871 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_ACCOUNT); 1812 1872 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXACCOUNT); 1813 1873 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 } 1814 1889 smbldap_set_mod(&mods, LDAP_MOD_ADD, "uid", name); 1815 1890 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", name); … … 1833 1908 "to ldap directory\n")); 1834 1909 } 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 } 1835 1918 } else { 1836 1919 d_printf(_("found!\n")); … … 1847 1930 if (!pdb_getsampwnam(samuser, lp_guestaccount())) { 1848 1931 LDAPMod **mods = NULL; 1849 DOM_SIDsid;1932 struct dom_sid sid; 1850 1933 char *dn; 1851 1934 char *uidstr; … … 1854 1937 1855 1938 d_printf(_("Adding the Guest user.\n")); 1939 1940 sid_compose(&sid, get_global_sam_sid(), DOMAIN_RID_GUEST); 1856 1941 1857 1942 pwd = Get_Pwnam_alloc(tc, lp_guestaccount()); … … 1869 1954 } 1870 1955 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 } 1876 1966 } 1877 1967 pwd->pw_gid = domusers_gid; … … 1884 1974 } 1885 1975 1886 sid_compose(&sid, get_global_sam_sid(), DOMAIN_USER_RID_GUEST);1887 1888 1976 dn = talloc_asprintf(tc, "uid=%s,%s", pwd->pw_name, lp_ldap_user_suffix ()); 1889 1977 uidstr = talloc_asprintf(tc, "%u", (unsigned int)pwd->pw_uid); … … 1897 1985 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXACCOUNT); 1898 1986 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 } 1899 1996 smbldap_set_mod(&mods, LDAP_MOD_ADD, "uid", pwd->pw_name); 1900 1997 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", pwd->pw_name); … … 1922 2019 "ldap directory\n")); 1923 2020 } 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 } 1924 2029 } else { 1925 2030 d_printf(_("found!\n")); … … 1928 2033 d_printf(_("Checking Guest's group.\n")); 1929 2034 1930 pwd = Get_Pwnam_alloc(t alloc_autofree_context(), lp_guestaccount());2035 pwd = Get_Pwnam_alloc(tc, lp_guestaccount()); 1931 2036 if (!pwd) { 1932 2037 d_fprintf(stderr, … … 1963 2068 } 1964 2069 1965 sid_compose(&gsid, get_global_sam_sid(), DOMAIN_ GROUP_RID_GUESTS);2070 sid_compose(&gsid, get_global_sam_sid(), DOMAIN_RID_GUESTS); 1966 2071 1967 2072 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXGROUP); 1968 2073 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 } 1969 2079 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", uname); 1970 2080 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", wname); -
vendor/current/source3/utils/net_share.c
r427 r740 63 63 int net_share(struct net_context *c, int argc, const char **argv) 64 64 { 65 66 65 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; 69 68 } 70 69 -
vendor/current/source3/utils/net_status.c
r414 r740 19 19 #include "includes.h" 20 20 #include "utils/net.h" 21 #include "session.h" 22 #include "messages.h" 21 23 22 24 int net_status_usage(struct net_context *c, int argc, const char **argv) … … 29 31 } 30 32 31 static int show_session(struct db_record *rec, void *private_data) 33 static int show_session(const char *key, struct sessionid *session, 34 void *private_data) 32 35 { 33 36 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)) { 42 39 return 0; 43 40 } … … 45 42 if (*parseable) { 46 43 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); 50 48 } else { 51 49 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); 55 54 } 56 55 … … 60 59 static int net_status_sessions(struct net_context *c, int argc, const char **argv) 61 60 { 62 struct db_context *db;63 61 bool parseable; 64 62 … … 89 87 } 90 88 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); 102 90 return 0; 103 91 } … … 128 116 }; 129 117 130 static int collect_pid(struct db_record *rec, void *private_data) 118 static int collect_pids(const char *key, struct sessionid *session, 119 void *private_data) 131 120 { 132 121 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)) 141 124 return 0; 142 125 … … 147 130 return 0; 148 131 } 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 137 static int show_share_parseable(const struct connections_key *key, 156 138 const struct connections_data *crec, 157 139 void *state) … … 190 172 { 191 173 struct sessionids ids; 192 struct db_context *db;193 174 194 175 ids.num_entries = 0; 195 176 ids.entries = NULL; 196 177 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); 209 181 210 182 SAFE_FREE(ids.entries); -
vendor/current/source3/utils/net_time.c
r414 r740 19 19 #include "includes.h" 20 20 #include "utils/net.h" 21 #include "libsmb/nmblib.h" 22 #include "libsmb/libsmb.h" 21 23 22 24 /* … … 104 106 } 105 107 106 /* try to set the system clock using /bin/date*/108 /* try to set the system clock */ 107 109 static int net_time_set(struct net_context *c, int argc, const char **argv) 108 110 { 109 time_t t = nettime(c, NULL); 110 char *cmd; 111 struct timeval tv; 111 112 int result; 112 113 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 122 121 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)); 126 124 127 125 return result; -
vendor/current/source3/utils/net_usershare.c
r414 r740 20 20 21 21 #include "includes.h" 22 #include "system/passwd.h" 23 #include "system/filesys.h" 22 24 #include "utils/net.h" 25 #include "../libcli/security/security.h" 23 26 24 27 struct { … … 38 41 {N_("Path is not a directory"), USERSHARE_PATH_NOT_DIRECTORY}, 39 42 {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}, 40 45 {NULL,(enum usershare_err)-1} 41 46 }; … … 329 334 int fd = -1; 330 335 int numlines = 0; 331 SEC_DESC*psd = NULL;336 struct security_descriptor *psd = NULL; 332 337 char *basepath; 333 338 char *sharepath = NULL; 334 339 char *comment = NULL; 340 char *cp_sharename = NULL; 335 341 char *acl_str; 336 342 int num_aces; … … 393 399 &sharepath, 394 400 &comment, 401 &cp_sharename, 395 402 &psd, 396 403 &guest_ok); … … 474 481 /* NOTE: This is smb.conf-like output. Do not translate. */ 475 482 if (pi->op == US_INFO_OP) { 476 d_printf("[%s]\n", fl->pathname );483 d_printf("[%s]\n", cp_sharename ); 477 484 d_printf("path=%s\n", sharepath ); 478 485 d_printf("comment=%s\n", comment); … … 480 487 d_printf("guest_ok=%c\n\n", guest_ok ? 'y' : 'n'); 481 488 } else if (pi->op == US_LIST_OP) { 482 d_printf("%s\n", fl->pathname);489 d_printf("%s\n", cp_sharename); 483 490 } 484 491 … … 618 625 SMB_STRUCT_STAT lsbuf; 619 626 char *sharename; 627 const char *cp_sharename; 620 628 char *full_path; 621 629 char *full_path_tmp; … … 646 654 return net_usershare_add_usage(c, argc, argv); 647 655 case 2: 656 cp_sharename = argv[0]; 648 657 sharename = strlower_talloc(ctx, argv[0]); 649 658 us_path = argv[1]; 650 659 break; 651 660 case 3: 661 cp_sharename = argv[0]; 652 662 sharename = strlower_talloc(ctx, argv[0]); 653 663 us_path = argv[1]; … … 655 665 break; 656 666 case 4: 667 cp_sharename = argv[0]; 657 668 sharename = strlower_talloc(ctx, argv[0]); 658 669 us_path = argv[1]; … … 661 672 break; 662 673 case 5: 674 cp_sharename = argv[0]; 663 675 sharename = strlower_talloc(ctx, argv[0]); 664 676 us_path = argv[1]; … … 798 810 799 811 for (i = 0; i < num_aces; i++) { 800 DOM_SIDsid;812 struct dom_sid sid; 801 813 const char *pcolon = strchr_m(pacl, ':'); 802 814 const char *name; … … 898 910 full_path_tmp ); 899 911 TALLOC_FREE(ctx); 912 close(tmpfd); 900 913 return -1; 901 914 } … … 907 920 full_path_tmp ); 908 921 TALLOC_FREE(ctx); 922 close(tmpfd); 909 923 return -1; 910 924 } … … 916 930 full_path_tmp ); 917 931 TALLOC_FREE(ctx); 932 close(tmpfd); 918 933 return -1; 919 934 } … … 925 940 full_path_tmp ); 926 941 TALLOC_FREE(ctx); 942 close(tmpfd); 927 943 return -1; 928 944 } … … 930 946 /* Create the in-memory image of the file. */ 931 947 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); 934 956 935 957 to_write = strlen(file_img); … … 942 964 unlink(full_path_tmp); 943 965 TALLOC_FREE(ctx); 966 close(tmpfd); 944 967 return -1; 945 968 } -
vendor/current/source3/utils/net_util.c
r414 r740 22 22 #include "includes.h" 23 23 #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" 26 31 27 32 NTSTATUS net_rpc_lookup_name(struct net_context *c, 28 33 TALLOC_CTX *mem_ctx, struct cli_state *cli, 29 34 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, 31 36 enum lsa_SidType *ret_type) 32 37 { 33 38 struct rpc_pipe_client *lsa_pipe = NULL; 34 39 struct policy_handle pol; 35 NTSTATUS result = NT_STATUS_OK;40 NTSTATUS status, result; 36 41 const char **dom_names; 37 DOM_SID*sids;42 struct dom_sid *sids; 38 43 enum lsa_SidType *types; 44 struct dcerpc_binding_handle *b; 39 45 40 46 ZERO_STRUCT(pol); 41 47 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, 43 49 &lsa_pipe); 44 if (!NT_STATUS_IS_OK( result)) {50 if (!NT_STATUS_IS_OK(status)) { 45 51 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, 50 58 SEC_FLAG_MAXIMUM_ALLOWED, 51 59 &pol); 52 if (!NT_STATUS_IS_OK( result)) {60 if (!NT_STATUS_IS_OK(status)) { 53 61 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, 59 67 &name, &dom_names, 1, &sids, &types); 60 68 61 if (!NT_STATUS_IS_OK( result)) {69 if (!NT_STATUS_IS_OK(status)) { 62 70 /* This can happen easily, don't log an error */ 63 71 goto done; … … 79 87 done: 80 88 if (is_valid_policy_hnd(&pol)) { 81 rpccli_lsa_Close(lsa_pipe, mem_ctx, &pol);89 dcerpc_lsa_Close(b, mem_ctx, &pol, &result); 82 90 } 83 91 TALLOC_FREE(lsa_pipe); 84 92 85 return result;93 return status; 86 94 } 87 95 … … 118 126 service_name, service_type, 119 127 c->opt_user_name, c->opt_workgroup, 120 c->opt_password, flags, Undefined , NULL);128 c->opt_password, flags, Undefined); 121 129 if (!NT_STATUS_IS_OK(nt_status)) { 122 130 d_fprintf(stderr, _("Could not connect to server %s\n"), … … 202 210 "IPC$", "IPC", 203 211 "", "", 204 "", 0, Undefined , NULL);212 "", 0, Undefined); 205 213 206 214 if (NT_STATUS_IS_OK(nt_status)) { … … 262 270 c->opt_password, 263 271 CLI_FULL_CONNECTION_USE_KERBEROS, 264 Undefined , NULL);272 Undefined); 265 273 266 274 SAFE_FREE(user_and_realm); … … 416 424 } 417 425 418 if (is_zero_addr( (struct sockaddr *)&pdc_ss)) {426 if (is_zero_addr(&pdc_ss)) { 419 427 return false; 420 428 } … … 473 481 return false; 474 482 } 475 if (is_zero_addr( (struct sockaddr *)server_ss)) {483 if (is_zero_addr(server_ss)) { 476 484 return false; 477 485 } … … 619 627 } 620 628 629 static 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 621 693 NTSTATUS net_scan_dc(struct net_context *c, 622 694 struct cli_state *cli, … … 625 697 TALLOC_CTX *mem_ctx = talloc_tos(); 626 698 struct rpc_pipe_client *dssetup_pipe = NULL; 699 struct dcerpc_binding_handle *dssetup_handle = NULL; 627 700 union dssetup_DsRoleInfo info; 628 701 NTSTATUS status; 702 WERROR werr; 629 703 630 704 ZERO_STRUCTP(dc_info); … … 633 707 &dssetup_pipe); 634 708 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, 639 716 DS_ROLE_BASIC_INFORMATION, 640 717 &info, 641 NULL);718 &werr); 642 719 TALLOC_FREE(dssetup_pipe); 643 720 721 if (NT_STATUS_IS_OK(status)) { 722 status = werror_to_ntstatus(werr); 723 } 644 724 if (!NT_STATUS_IS_OK(status)) { 645 725 return status; -
vendor/current/source3/utils/netlookup.c
r414 r740 22 22 #include "includes.h" 23 23 #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" 24 28 25 29 /******************************************************** … … 108 112 #endif 109 113 0, 110 Undefined, 111 NULL); 114 Undefined); 112 115 113 116 if (!NT_STATUS_IS_OK(nt_status)) { … … 156 159 NTSTATUS net_lookup_name_from_sid(struct net_context *c, 157 160 TALLOC_CTX *ctx, 158 DOM_SID*psid,161 struct dom_sid *psid, 159 162 const char **ppdomain, 160 163 const char **ppname) … … 198 201 199 202 NTSTATUS 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) 201 204 { 202 205 NTSTATUS nt_status; 203 206 struct con_struct *csp = NULL; 204 DOM_SID*sids = NULL;207 struct dom_sid *sids = NULL; 205 208 enum lsa_SidType *types = NULL; 206 209 -
vendor/current/source3/utils/nmblookup.c
r414 r740 21 21 22 22 #include "includes.h" 23 24 extern bool AllowDebugChange; 23 #include "popt_common.h" 24 #include "libsmb/nmblib.h" 25 25 26 26 static bool give_flags = false; … … 108 108 ****************************************************************************/ 109 109 110 static void do_node_status(int fd, 111 const char *name, 110 static void do_node_status(const char *name, 112 111 int type, 113 112 struct sockaddr_storage *pss) … … 115 114 struct nmb_name nname; 116 115 int count, i, j; 117 NODE_STATUS_STRUCT *status;116 struct node_status *addrs; 118 117 struct node_status_extra extra; 119 118 fstring cleanname; 120 119 char addr[INET6_ADDRSTRLEN]; 120 NTSTATUS status; 121 121 122 122 print_sockaddr(addr, sizeof(addr), pss); 123 123 d_printf("Looking up status of %s\n",addr); 124 124 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)) { 127 128 for (i=0;i<count;i++) { 128 pull_ascii_fstring(cleanname, status[i].name);129 pull_ascii_fstring(cleanname, addrs[i].name); 129 130 for (j=0;cleanname[j];j++) { 130 131 if (!isprint((int)cleanname[j])) { … … 133 134 } 134 135 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)); 137 138 } 138 139 d_printf("\n\tMAC Address = %02X-%02X-%02X-%02X-%02X-%02X\n", … … 141 142 extra.mac_addr[4], extra.mac_addr[5]); 142 143 d_printf("\n"); 143 SAFE_FREE(status);144 TALLOC_FREE(addrs); 144 145 } else { 145 146 d_printf("No reply from %s\n\n",addr); … … 154 155 static bool query_one(const char *lookup, unsigned int lookup_type) 155 156 { 156 int j, count, flags = 0; 157 int j, count; 158 uint8_t flags; 157 159 struct sockaddr_storage *ip_list=NULL; 160 NTSTATUS status = NT_STATUS_NOT_FOUND; 158 161 159 162 if (got_bcast) { … … 161 164 print_sockaddr(addr, sizeof(addr), &bcast_addr); 162 165 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); 166 170 } else { 167 171 const struct in_addr *bcast; … … 180 184 d_printf("querying %s on %s\n", 181 185 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)) { 190 195 return false; 191 196 } … … 215 220 */ 216 221 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); 225 229 } 226 230 … … 259 263 load_case_tables(); 260 264 261 setup_logging(argv[0], True);265 setup_logging(argv[0], DEBUG_STDOUT); 262 266 263 267 pc = poptGetContext("nmblookup", argc, (const char **)argv, … … 336 340 in_addr_to_sockaddr_storage(&ss, ip); 337 341 fstrcpy(lookup,"*"); 338 do_node_status( ServerFD,lookup, lookup_type, &ss);342 do_node_status(lookup, lookup_type, &ss); 339 343 continue; 340 344 } -
vendor/current/source3/utils/ntlm_auth.c
r597 r740 25 25 26 26 #include "includes.h" 27 #include "popt_common.h" 27 28 #include "utils/ntlm_auth.h" 28 29 #include "../libcli/auth/libcli_auth.h" 29 30 #include "../libcli/auth/spnego.h" 31 #include "../libcli/auth/ntlmssp.h" 30 32 #include "smb_krb5.h" 31 33 #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" 32 39 33 40 #ifndef PAM_WINBIND_CONFIG_FILE … … 225 232 if (opt_challenge.length) 226 233 return opt_challenge; 227 234 228 235 chal = data_blob(NULL, 8); 229 236 … … 244 251 return False; 245 252 } 246 253 247 254 fstrcpy(user, p+1); 248 255 fstrcpy(domain, domuser); … … 302 309 int ctrl = 0; 303 310 dictionary *d = NULL; 304 311 305 312 if (!opt_pam_winbind_conf || !*opt_pam_winbind_conf) { 306 313 opt_pam_winbind_conf = PAM_WINBIND_CONFIG_FILE; … … 308 315 309 316 d = iniparser_load(CONST_DISCARD(char *, opt_pam_winbind_conf)); 310 317 311 318 if (!d) { 312 319 return 0; 313 320 } 314 321 315 322 if (iniparser_getboolean(d, CONST_DISCARD(char *, "global:krb5_auth"), false)) { 316 323 ctrl |= WINBIND_KRB5_AUTH; … … 318 325 319 326 iniparser_freedict(d); 320 327 321 328 return ctrl; 322 329 } … … 440 447 request.data.auth_crap.nt_resp_len = nt_response->length; 441 448 } 442 449 443 450 result = winbindd_request_response(WINBINDD_PAM_AUTH_CRAP, &request, &response); 444 451 SAFE_FREE(request.extra_data.data); … … 453 460 return nt_status; 454 461 } 455 462 456 463 nt_status = (NT_STATUS(response.data.auth.nt_status)); 457 464 if (!NT_STATUS_IS_OK(nt_status)) { … … 535 542 request.data.chng_pswd_auth_crap.old_lm_hash_enc_len = old_lm_hash_enc.length; 536 543 } 537 544 538 545 result = winbindd_request_response(WINBINDD_PAM_CHNG_PSWD_AUTH_CRAP, &request, &response); 539 546 … … 548 555 return nt_status; 549 556 } 550 557 551 558 nt_status = (NT_STATUS(response.data.auth.nt_status)); 552 559 if (!NT_STATUS_IS_OK(nt_status)) … … 559 566 560 567 winbindd_free_response(&response); 561 568 562 569 return nt_status; 563 570 } 564 571 565 static NTSTATUS winbind_pw_check(struct ntlmssp_state *ntlmssp_state, DATA_BLOB *user_session_key, DATA_BLOB *lm_session_key) 572 static NTSTATUS winbind_pw_check(struct ntlmssp_state *ntlmssp_state, TALLOC_CTX *mem_ctx, 573 DATA_BLOB *user_session_key, DATA_BLOB *lm_session_key) 566 574 { 567 575 static const char zeros[16] = { 0, }; … … 573 581 574 582 nt_status = contact_winbind_auth_crap(ntlmssp_state->user, ntlmssp_state->domain, 575 ntlmssp_state-> workstation,583 ntlmssp_state->client.netbios_name, 576 584 &ntlmssp_state->chal, 577 585 &ntlmssp_state->lm_resp, … … 583 591 if (NT_STATUS_IS_OK(nt_status)) { 584 592 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); 586 594 memcpy(lm_session_key->data, lm_key, 8); 587 595 memset(lm_session_key->data+8, '\0', 8); 588 596 } 589 597 590 598 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 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); 595 603 } else { 596 604 DEBUG(NT_STATUS_EQUAL(nt_status, NT_STATUS_ACCESS_DENIED) ? 0 : 3, 597 605 ("Login for user [%s]\\[%s]@[%s] failed due to [%s]\n", 598 606 ntlmssp_state->domain, ntlmssp_state->user, 599 ntlmssp_state-> workstation,607 ntlmssp_state->client.netbios_name, 600 608 error_string ? error_string : "unknown error (NULL)")); 601 ntlmssp_state-> auth_context= NULL;609 ntlmssp_state->callback_private = NULL; 602 610 } 603 611 … … 607 615 } 608 616 609 static NTSTATUS local_pw_check(struct ntlmssp_state *ntlmssp_state, DATA_BLOB *user_session_key, DATA_BLOB *lm_session_key) 617 static NTSTATUS local_pw_check(struct ntlmssp_state *ntlmssp_state, TALLOC_CTX *mem_ctx, 618 DATA_BLOB *user_session_key, DATA_BLOB *lm_session_key) 610 619 { 611 620 NTSTATUS nt_status; … … 613 622 614 623 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, 617 626 true, true, 0, 618 627 &ntlmssp_state->chal, … … 623 632 ntlmssp_state->domain, 624 633 &lm_pw, &nt_pw, user_session_key, lm_session_key); 625 634 626 635 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, 628 637 "%s%c%s", ntlmssp_state->domain, 629 638 *lp_winbind_separator(), … … 631 640 } else { 632 641 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, 634 644 nt_errstr(nt_status))); 635 ntlmssp_state-> auth_context= NULL;645 ntlmssp_state->callback_private = NULL; 636 646 } 637 647 return nt_status; 638 648 } 639 649 640 static NTSTATUS ntlm_auth_start_ntlmssp_client( NTLMSSP_STATE **client_ntlmssp_state)650 static NTSTATUS ntlm_auth_start_ntlmssp_client(struct ntlmssp_state **client_ntlmssp_state) 641 651 { 642 652 NTSTATUS status; … … 647 657 } 648 658 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); 650 664 651 665 if (!NT_STATUS_IS_OK(status)) { 652 666 DEBUG(1, ("Could not start NTLMSSP client: %s\n", 653 667 nt_errstr(status))); 654 ntlmssp_end(client_ntlmssp_state);668 TALLOC_FREE(*client_ntlmssp_state); 655 669 return status; 656 670 } … … 661 675 DEBUG(1, ("Could not set username: %s\n", 662 676 nt_errstr(status))); 663 ntlmssp_end(client_ntlmssp_state);677 TALLOC_FREE(*client_ntlmssp_state); 664 678 return status; 665 679 } … … 670 684 DEBUG(1, ("Could not set domain: %s\n", 671 685 nt_errstr(status))); 672 ntlmssp_end(client_ntlmssp_state);686 TALLOC_FREE(*client_ntlmssp_state); 673 687 return status; 674 688 } … … 676 690 if (opt_password) { 677 691 status = ntlmssp_set_password(*client_ntlmssp_state, opt_password); 678 692 679 693 if (!NT_STATUS_IS_OK(status)) { 680 694 DEBUG(1, ("Could not set password: %s\n", 681 695 nt_errstr(status))); 682 ntlmssp_end(client_ntlmssp_state);696 TALLOC_FREE(*client_ntlmssp_state); 683 697 return status; 684 698 } … … 688 702 } 689 703 690 static NTSTATUS ntlm_auth_start_ntlmssp_server(NTLMSSP_STATE **ntlmssp_state) 691 { 692 NTSTATUS status = ntlmssp_server_start(ntlmssp_state); 693 704 static 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); 694 734 if (!NT_STATUS_IS_OK(status)) { 695 735 DEBUG(1, ("Could not start NTLMSSP server: %s\n", … … 701 741 if (opt_password) { 702 742 (*ntlmssp_state)->check_password = local_pw_check; 703 (*ntlmssp_state)->get_domain = lp_workgroup;704 (*ntlmssp_state)->get_global_myname = global_myname;705 743 } else { 706 744 (*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;709 745 } 710 746 return NT_STATUS_OK; … … 733 769 * ntlm_ccache_auth, it will fail. So, we have to ask the trusted 734 770 * domain's child for ccache_ntlm_auth. that is to say, we have to 735 * set WBF ALG_PAM_CONTACT_TRUSTDOM in request.flags.771 * set WBFLAG_PAM_CONTACT_TRUSTDOM in request.flags. 736 772 */ 737 773 ctrl = get_pam_winbind_config(); … … 829 865 830 866 if (strncmp(buf, "YR", 2) == 0) { 831 if (state->ntlmssp_state) 832 ntlmssp_end(&state->ntlmssp_state); 867 TALLOC_FREE(state->ntlmssp_state); 833 868 state->svr_state = SERVER_INITIAL; 834 869 } else if (strncmp(buf, "KK", 2) == 0) { … … 896 931 DEBUG(0, ("NTLMSSP BH: %s\n", nt_errstr(nt_status))); 897 932 898 ntlmssp_end(&state->ntlmssp_state);933 TALLOC_FREE(state->ntlmssp_state); 899 934 } else if (!NT_STATUS_IS_OK(nt_status)) { 900 935 *response = talloc_asprintf(mem_ctx, "NA %s", … … 904 939 *response = talloc_asprintf( 905 940 mem_ctx, "AF %s", 906 (char *)state->ntlmssp_state-> auth_context);941 (char *)state->ntlmssp_state->callback_private); 907 942 DEBUG(10, ("NTLMSSP OK!\n")); 908 943 … … 1007 1042 1008 1043 if (strncmp(buf, "YR", 2) == 0) { 1009 if (state->ntlmssp_state) 1010 ntlmssp_end(&state->ntlmssp_state); 1044 TALLOC_FREE(state->ntlmssp_state); 1011 1045 state->cli_state = CLIENT_INITIAL; 1012 1046 } else if (strncmp(buf, "TT", 2) == 0) { … … 1099 1133 DEBUG(10, ("NTLMSSP OK!\n")); 1100 1134 state->cli_state = CLIENT_FINISHED; 1101 if (state->ntlmssp_state) 1102 ntlmssp_end(&state->ntlmssp_state); 1135 TALLOC_FREE(state->ntlmssp_state); 1103 1136 } else { 1104 1137 x_fprintf(x_stdout, "BH %s\n", nt_errstr(nt_status)); 1105 1138 DEBUG(0, ("NTLMSSP BH: %s\n", nt_errstr(nt_status))); 1106 1139 state->cli_state = CLIENT_ERROR; 1107 if (state->ntlmssp_state) 1108 ntlmssp_end(&state->ntlmssp_state); 1140 TALLOC_FREE(state->ntlmssp_state); 1109 1141 } 1110 1142 … … 1117 1149 char *user, *pass; 1118 1150 user=buf; 1119 1151 1120 1152 pass=(char *)memchr(buf,' ',length); 1121 1153 if (!pass) { … … 1126 1158 *pass='\0'; 1127 1159 pass++; 1128 1160 1129 1161 if (state->helper_mode == SQUID_2_5_BASIC) { 1130 1162 rfc1738_unescape(user); 1131 1163 rfc1738_unescape(pass); 1132 1164 } 1133 1165 1134 1166 if (check_plaintext_auth(user, pass, False)) { 1135 1167 x_fprintf(x_stdout, "OK\n"); … … 1197 1229 } 1198 1230 1199 static bool _spnego_parse_krb5_wrap(TALLOC_CTX *ctx, DATA_BLOB blob, DATA_BLOB *ticket, uint8 tok_id[2])1231 bool spnego_parse_krb5_wrap(TALLOC_CTX *ctx, DATA_BLOB blob, DATA_BLOB *ticket, uint8 tok_id[2]) 1200 1232 { 1201 1233 bool ret; … … 1262 1294 1263 1295 if (strncmp(buf, "YR", 2) == 0) { 1264 if (state->ntlmssp_state) 1265 ntlmssp_end(&state->ntlmssp_state); 1296 TALLOC_FREE(state->ntlmssp_state); 1266 1297 TALLOC_FREE(state->spnego_mech); 1267 1298 TALLOC_FREE(state->spnego_mech_oid); … … 1396 1427 "NTLMSSP challenge, but " 1397 1428 "already got one\n"); 1398 ntlmssp_end(&state->ntlmssp_state);1429 TALLOC_FREE(state->ntlmssp_state); 1399 1430 return; 1400 1431 } … … 1473 1504 } 1474 1505 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { 1475 ntlmssp_end(&state->ntlmssp_state);1506 TALLOC_FREE(state->ntlmssp_state); 1476 1507 } 1477 1508 #ifdef HAVE_KRB5 … … 1480 1511 DATA_BLOB ap_rep; 1481 1512 DATA_BLOB session_key; 1482 struct PAC_ DATA *pac_data= NULL;1513 struct PAC_LOGON_INFO *logon_info = NULL; 1483 1514 DATA_BLOB ticket; 1484 1515 uint8_t tok_id[2]; 1485 1516 1486 if (! _spnego_parse_krb5_wrap(ctx, raw_in_token,1487 1517 if (!spnego_parse_krb5_wrap(ctx, raw_in_token, 1518 &ticket, tok_id)) { 1488 1519 DEBUG(1, ("spnego_parse_krb5_wrap failed\n")); 1489 1520 x_fprintf(x_stdout, "BH spnego_parse_krb5_wrap failed\n"); … … 1493 1524 status = ads_verify_ticket(ctx, lp_realm(), 0, 1494 1525 &ticket, 1495 &principal, & pac_data, &ap_rep,1526 &principal, &logon_info, &ap_rep, 1496 1527 &session_key, True); 1497 1528 … … 1515 1546 user = talloc_strdup(ctx, principal); 1516 1547 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); 1526 1551 } 1527 1552 … … 1587 1612 } 1588 1613 1589 static NTLMSSP_STATE*client_ntlmssp_state = NULL;1614 static struct ntlmssp_state *client_ntlmssp_state = NULL; 1590 1615 1591 1616 static bool manage_client_ntlmssp_init(struct spnego_data spnego) … … 1638 1663 DEBUG(1, ("Expected OK or MORE_PROCESSING_REQUIRED, got: %s\n", 1639 1664 nt_errstr(status))); 1640 ntlmssp_end(&client_ntlmssp_state);1665 TALLOC_FREE(client_ntlmssp_state); 1641 1666 return False; 1642 1667 } … … 1671 1696 if (spnego.negTokenTarg.negResult == SPNEGO_REJECT) { 1672 1697 x_fprintf(x_stdout, "NA\n"); 1673 ntlmssp_end(&client_ntlmssp_state);1698 TALLOC_FREE(client_ntlmssp_state); 1674 1699 return; 1675 1700 } … … 1677 1702 if (spnego.negTokenTarg.negResult == SPNEGO_ACCEPT_COMPLETED) { 1678 1703 x_fprintf(x_stdout, "AF\n"); 1679 ntlmssp_end(&client_ntlmssp_state);1704 TALLOC_FREE(client_ntlmssp_state); 1680 1705 return; 1681 1706 } … … 1684 1709 spnego.negTokenTarg.responseToken, 1685 1710 &request); 1686 1711 1687 1712 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { 1688 1713 DEBUG(1, ("Expected MORE_PROCESSING_REQUIRED from " … … 1692 1717 "ntlmssp_client_update\n"); 1693 1718 data_blob_free(&request); 1694 ntlmssp_end(&client_ntlmssp_state);1719 TALLOC_FREE(client_ntlmssp_state); 1695 1720 return; 1696 1721 } … … 1701 1726 spnego.negTokenTarg.responseToken = request; 1702 1727 spnego.negTokenTarg.mechListMIC = null_blob; 1703 1728 1704 1729 spnego_write_data(ctx, &to_server, &spnego); 1705 1730 data_blob_free(&request); … … 1745 1770 principal[spnego.negTokenInit.mechListMIC.length] = '\0'; 1746 1771 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); 1749 1775 if (retval) { 1750 1776 char *user = NULL; … … 1769 1795 } 1770 1796 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); 1773 1800 if (retval) { 1774 1801 DEBUG(10, ("Kinit suceeded, but getting a ticket failed: %s\n", error_message(retval))); … … 1855 1882 1856 1883 opt_password = SMB_STRNDUP((const char *)request.data, request.length); 1857 1884 1858 1885 if (opt_password == NULL) { 1859 1886 DEBUG(1, ("Out of memory\n")); … … 1941 1968 } 1942 1969 1943 ntlmssp_end(&client_ntlmssp_state);1970 TALLOC_FREE(client_ntlmssp_state); 1944 1971 goto out; 1945 1972 } … … 1983 2010 static bool ntlm_server_1_user_session_key; 1984 2011 static bool ntlm_server_1_lm_session_key; 1985 2012 1986 2013 if (strequal(buf, ".")) { 1987 2014 if (!full_username && !username) { … … 2013 2040 fstring fstr_user; 2014 2041 fstring fstr_domain; 2015 2042 2016 2043 if (!parse_ntlm_auth_domain_user(full_username, fstr_user, fstr_domain)) { 2017 2044 /* username might be 'tainted', don't print into our new-line deleimianted stream */ … … 2030 2057 if (ntlm_server_1_lm_session_key) 2031 2058 flags |= WBFLAG_PAM_LMKEY; 2032 2059 2033 2060 if (ntlm_server_1_user_session_key) 2034 2061 flags |= WBFLAG_PAM_USER_SESSION_KEY; … … 2099 2126 if (!parameter) { 2100 2127 parameter = strstr_m(request, ": "); 2101 2128 2102 2129 if (!parameter) { 2103 2130 DEBUG(0, ("Parameter not found!\n")); … … 2105 2132 return; 2106 2133 } 2107 2134 2108 2135 parameter[0] ='\0'; 2109 2136 parameter++; … … 2186 2213 new_nt_pswd = data_blob(NULL, 516); 2187 2214 old_nt_hash_enc = data_blob(NULL, 16); 2188 2215 2189 2216 /* Calculate the MD4 hash (NT compatible) of the 2190 2217 * password */ … … 2194 2221 /* E_deshash returns false for 'long' 2195 2222 passwords (> 14 DOS chars). 2196 2223 2197 2224 Therefore, don't send a buffer 2198 2225 encrypted with the truncated hash … … 2223 2250 encode_pw_buffer(new_nt_pswd.data, newpswd, 2224 2251 STR_UNICODE); 2225 2252 2226 2253 arcfour_crypt(new_nt_pswd.data, old_nt_hash, 516); 2227 2254 E_old_pw_hash(new_nt_hash, old_nt_hash, 2228 2255 old_nt_hash_enc.data); 2229 2256 } 2230 2257 2231 2258 if (!full_username && !username) { 2232 2259 x_fprintf(x_stdout, "Error: No username supplied!\n"); … … 2237 2264 } else { 2238 2265 char *error_string = NULL; 2239 2266 2240 2267 if (full_username && !username) { 2241 2268 fstring fstr_user; 2242 2269 fstring fstr_domain; 2243 2270 2244 2271 if (!parse_ntlm_auth_domain_user(full_username, 2245 2272 fstr_user, … … 2259 2286 domain = smb_xstrdup(fstr_domain); 2260 2287 } 2261 2288 2262 2289 } 2263 2290 … … 2299 2326 if (!parameter) { 2300 2327 parameter = strstr_m(request, ": "); 2301 2328 2302 2329 if (!parameter) { 2303 2330 DEBUG(0, ("Parameter not found!\n")); … … 2305 2332 return; 2306 2333 } 2307 2334 2308 2335 parameter[0] ='\0'; 2309 2336 parameter++; … … 2581 2608 { "request-nt-key", 0, POPT_ARG_NONE, &request_user_session_key, OPT_USER_SESSION_KEY, "Retrieve User (NT) session key"}, 2582 2609 { "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"}, 2584 2613 { "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" }, 2585 2614 { "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" }, … … 2592 2621 load_case_tables(); 2593 2622 2594 dbf = x_stderr;2623 setup_logging("ntlm_auth", DEBUG_STDERR); 2595 2624 2596 2625 /* Parse options */ -
vendor/current/source3/utils/ntlm_auth_diagnostics.c
r414 r740 25 25 #include "utils/ntlm_auth.h" 26 26 #include "../libcli/auth/libcli_auth.h" 27 #include "nsswitch/winbind_client.h" 27 28 28 29 #undef DBGC_CLASS -
vendor/current/source3/utils/pdbedit.c
r414 r740 22 22 23 23 #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" 24 28 25 29 #define BIT_BACKEND 0x00000004 … … 56 60 #define MASK_USER_GOOD 0x60405FE0 57 61 58 static int get_sid_from_cli_string( DOM_SID*sid, const char *str_sid)62 static int get_sid_from_cli_string(struct dom_sid *sid, const char *str_sid) 59 63 { 60 64 uint32_t rid; … … 69 73 return -1; 70 74 } 71 sid_copy(sid, get_global_sam_sid()); 72 sid_append_rid(sid, rid); 75 sid_compose(sid, get_global_sam_sid(), rid); 73 76 } 74 77 … … 105 108 struct samu *user; 106 109 struct samu *account; 107 DOM_SIDuser_sid;110 struct dom_sid user_sid; 108 111 109 112 DEBUG(4, ("Processing account %s\n", userentry.account_name)); … … 203 206 204 207 for (i=1; decode_account_policy_name(i) != NULL; i++) { 205 uint32 policy_value;208 uint32_t policy_value; 206 209 if (!account_policy_get_default(i, &policy_value)) { 207 210 fprintf(stderr, "Can't get default account policy\n"); … … 227 230 228 231 for ( i=1; decode_account_policy_name(i) != NULL; i++ ) { 229 uint32 policy_value;232 uint32_t policy_value; 230 233 NTSTATUS status; 231 234 … … 263 266 if (verbosity) { 264 267 char temp[44]; 265 const uint8 *hours;268 const uint8_t *hours; 266 269 267 270 printf ("Unix username: %s\n", pdb_get_username(sam_pwent)); … … 330 333 nt_passwd, 331 334 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))); 333 336 } else { 334 337 uid = nametouid(pdb_get_username(sam_pwent)); … … 378 381 struct samu *sam_pwent; 379 382 TALLOC_CTX *tosctx; 380 DOM_SIDuser_sid;383 struct dom_sid user_sid; 381 384 bool bret; 382 385 int ret; … … 436 439 struct samu *sam_pwent; 437 440 TALLOC_CTX *tosctx; 438 DOM_SIDuser_sid;441 struct dom_sid user_sid; 439 442 NTSTATUS status; 440 443 bool bret; … … 506 509 uint32_t not_settable; 507 510 uint32_t new_flags; 508 DOM_SIDu_sid;511 struct dom_sid u_sid; 509 512 bool ret; 510 513 … … 525 528 memset(hours_array, 0xff, hours_len); 526 529 527 pdb_set_hours(sam_pwent, hours_array, PDB_CHANGED);530 pdb_set_hours(sam_pwent, hours_array, hours_len, PDB_CHANGED); 528 531 } 529 532 … … 594 597 } 595 598 596 value = convert_uint32_t o_time_t(num);599 value = convert_uint32_t_to_time_t(num); 597 600 } 598 601 … … 620 623 uint32_t not_settable; 621 624 uint32_t new_flags; 622 DOM_SIDm_sid;625 struct dom_sid m_sid; 623 626 char *name; 624 627 int len; … … 711 714 TALLOC_CTX *tosctx; 712 715 NTSTATUS status; 713 DOM_SIDu_sid;716 struct dom_sid u_sid; 714 717 int flags; 715 718 int ret; … … 808 811 TALLOC_CTX *tosctx; 809 812 NTSTATUS status; 810 DOM_SIDm_sid;813 struct dom_sid m_sid; 811 814 char *compatpwd; 812 815 char *name; … … 1057 1060 load_case_tables(); 1058 1061 1059 setup_logging("pdbedit", True);1062 setup_logging("pdbedit", DEBUG_STDOUT); 1060 1063 1061 1064 pc = poptGetContext(NULL, argc, (const char **) argv, long_options, … … 1134 1137 /* account policy operations */ 1135 1138 if ((checkparms & BIT_ACCPOLICY) && !(checkparms & ~(BIT_ACCPOLICY + BIT_ACCPOLVAL))) { 1136 uint32 value;1139 uint32_t value; 1137 1140 enum pdb_policy_type field = account_policy_name_to_typenum(account_policy); 1138 1141 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 7 7 8 8 This program is free software; you can redistribute it and/or modify … … 10 10 the Free Software Foundation; either version 3 of the License, or 11 11 (at your option) any later version. 12 12 13 13 This program is distributed in the hope that it will be useful, 14 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 16 GNU General Public License for more details. 17 17 18 18 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/>. 20 20 */ 21 21 22 22 #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" 24 28 25 29 /* GLOBAL VARIABLES */ 26 30 27 DOM_SIDold_sid, new_sid;31 struct dom_sid old_sid, new_sid; 28 32 int change = 0, new_val = 0; 29 33 int opt_verbose = False; … … 56 60 ********************************************************************/ 57 61 58 static bool swap_sid_in_acl( SEC_DESC *sd, DOM_SID *s1, DOM_SID*s2 )62 static bool swap_sid_in_acl( struct security_descriptor *sd, struct dom_sid *s1, struct dom_sid *s2 ) 59 63 { 60 SEC_ACL*theacl;64 struct security_acl *theacl; 61 65 int i; 62 66 bool update = False; 63 67 64 68 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 ) ) { 66 70 sid_copy( sd->owner_sid, s2 ); 67 71 update = True; 68 verbose_output(" New Owner SID: %s\n", 72 verbose_output(" New Owner SID: %s\n", 69 73 sid_string_tos(sd->owner_sid)); 70 74 … … 72 76 73 77 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 ) ) { 75 79 sid_copy( sd->group_sid, s2 ); 76 80 update = True; 77 verbose_output(" New Group SID: %s\n", 81 verbose_output(" New Group SID: %s\n", 78 82 sid_string_tos(sd->group_sid)); 79 83 } … … 82 86 verbose_output(" DACL: %d entries:\n", theacl->num_aces); 83 87 for ( i=0; i<theacl->num_aces; i++ ) { 84 verbose_output(" Trustee SID: %s\n", 88 verbose_output(" Trustee SID: %s\n", 85 89 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 ) ) { 87 91 sid_copy( &theacl->aces[i].trustee, s2 ); 88 92 update = True; 89 verbose_output(" New Trustee SID: %s\n", 93 verbose_output(" New Trustee SID: %s\n", 90 94 sid_string_tos(&theacl->aces[i].trustee)); 91 95 } … … 96 100 verbose_output(" SACL: %d entries: \n", theacl->num_aces); 97 101 for ( i=0; i<theacl->num_aces; i++ ) { 98 verbose_output(" Trustee SID: %s\n", 102 verbose_output(" Trustee SID: %s\n", 99 103 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 ) ) { 101 105 sid_copy( &theacl->aces[i].trustee, s2 ); 102 106 update = True; 103 verbose_output(" New Trustee SID: %s\n", 107 verbose_output(" New Trustee SID: %s\n", 104 108 sid_string_tos(&theacl->aces[i].trustee)); 105 109 } … … 117 121 { 118 122 REGF_NK_REC *key, *subkey; 119 SEC_DESC*new_sd;123 struct security_descriptor *new_sd; 120 124 struct regval_ctr *values; 121 125 struct regsubkey_ctr *subkeys; … … 140 144 } 141 145 142 if ( !(values = TALLOC_ZERO_P( subkeys, struct regval_ctr )) ) { 146 werr = regval_ctr_init(subkeys, &values); 147 if (!W_ERROR_IS_OK(werr)) { 143 148 TALLOC_FREE( subkeys ); 144 149 DEBUG(0,("copy_registry_tree: talloc() failure!\n")); … … 150 155 for ( i=0; i<nk->num_values; i++ ) { 151 156 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) ); 153 158 } 154 159 … … 212 217 /* setup logging options */ 213 218 214 setup_logging( "profiles", True ); 215 dbf = x_stderr; 216 x_setbuf( x_stderr, NULL ); 219 setup_logging( "profiles", DEBUG_STDERR); 217 220 218 221 pc = poptGetContext("profiles", argc, (const char **)argv, long_options, -
vendor/current/source3/utils/sharesec.c
r414 r740 24 24 25 25 #include "includes.h" 26 #include "popt_common.h" 27 #include "../libcli/security/security.h" 28 #include "passdb/machine_sid.h" 26 29 27 30 static TALLOC_CTX *ctx; … … 65 68 ********************************************************************/ 66 69 67 static void print_ace(FILE *f, SEC_ACE*ace)70 static void print_ace(FILE *f, struct security_ace *ace) 68 71 { 69 72 const struct perm_value *v; … … 125 128 ********************************************************************/ 126 129 127 static void sec_desc_print(FILE *f, SEC_DESC*sd)130 static void sec_desc_print(FILE *f, struct security_descriptor *sd) 128 131 { 129 132 uint32 i; … … 139 142 /* Print aces */ 140 143 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]; 142 145 fprintf(f, "ACL:"); 143 146 print_ace(f, ace); … … 150 153 ********************************************************************/ 151 154 152 static bool parse_ace( SEC_ACE*ace, const char *orig_str)155 static bool parse_ace(struct security_ace *ace, const char *orig_str) 153 156 { 154 157 char *p; … … 158 161 unsigned int aflags = 0; 159 162 unsigned int amask = 0; 160 DOM_SIDsid;163 struct dom_sid sid; 161 164 uint32_t mask; 162 165 const struct perm_value *v; … … 295 298 ********************************************************************/ 296 299 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;300 static 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; 302 305 int num_ace; 303 306 const char *pacl; … … 310 313 num_ace = count_chars( pacl, ',' ) + 1; 311 314 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 )) ) 313 316 return NULL; 314 317 … … 330 333 return NULL; 331 334 332 sd = make_sec_desc( mem_ctx, S EC_DESC_REVISION, SEC_DESC_SELF_RELATIVE,335 sd = make_sec_desc( mem_ctx, SD_REVISION, SEC_DESC_SELF_RELATIVE, 333 336 NULL, NULL, NULL, theacl, sd_size); 334 337 … … 336 339 } 337 340 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 */ 342 static 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; 343 346 if (! *the_acl) { 344 347 return (((*the_acl) = make_sec_acl(mem_ctx, 3, 1, ace)) != NULL); 345 348 } 346 349 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)); 352 356 new_ace = make_sec_acl(mem_ctx,(*the_acl)->revision,1+(*the_acl)->num_aces, aces); 353 357 SAFE_FREE(aces); … … 361 365 allowed ACEs. */ 362 366 363 static int ace_compare( SEC_ACE *ace1, SEC_ACE*ace2)367 static int ace_compare(struct security_ace *ace1, struct security_ace *ace2) 364 368 { 365 369 if (sec_ace_equal(ace1, ace2)) … … 369 373 return ace2->type - ace1->type; 370 374 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); 373 377 374 378 if (ace1->flags != ace2->flags) … … 381 385 return ace1->size - ace2->size; 382 386 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 390 static void sort_acl(struct security_acl *the_acl) 387 391 { 388 392 uint32 i; 389 393 if (!the_acl) return; 390 394 391 qsort(the_acl->aces, the_acl->num_aces, sizeof(the_acl->aces[0]), QSORT_CASTace_compare);395 TYPESAFE_QSORT(the_acl->aces, the_acl->num_aces, ace_compare); 392 396 393 397 for (i=1;i<the_acl->num_aces;) { … … 407 411 static int change_share_sec(TALLOC_CTX *mem_ctx, const char *sharename, char *the_acl, enum acl_mode mode) 408 412 { 409 SEC_DESC*sd = NULL;410 SEC_DESC*old = NULL;413 struct security_descriptor *sd = NULL; 414 struct security_descriptor *old = NULL; 411 415 size_t sd_size = 0; 412 416 uint32 i, j; … … 458 462 459 463 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, 461 465 &old->dacl->aces[j].trustee)) { 462 466 old->dacl->aces[j] = sd->dacl->aces[i]; … … 541 545 542 546 /* 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"); 547 552 548 553 pc = poptGetContext("sharesec", argc, argv, long_options, 0); … … 592 597 setlinebuf(stdout); 593 598 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 ); 597 601 598 602 /* check for initializing secrets.tdb first */ 599 603 600 604 if ( initialize_sid ) { 601 DOM_SID*sid = get_global_sam_sid();605 struct dom_sid *sid = get_global_sam_sid(); 602 606 603 607 if ( !sid ) { -
vendor/current/source3/utils/smbcacls.c
r414 r740 1 /* 1 /* 2 2 Unix SMB/CIFS implementation. 3 3 ACL get/set utility 4 4 5 5 Copyright (C) Andrew Tridgell 2000 6 6 Copyright (C) Tim Potter 2000 7 7 Copyright (C) Jeremy Allison 2000 8 8 Copyright (C) Jelmer Vernooij 2003 9 9 10 10 This program is free software; you can redistribute it and/or modify 11 11 it under the terms of the GNU General Public License as published by 12 12 the Free Software Foundation; either version 3 of the License, or 13 13 (at your option) any later version. 14 14 15 15 This program is distributed in the hope that it will be useful, 16 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 18 GNU General Public License for more details. 19 19 20 20 You should have received a copy of the GNU General Public License 21 21 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 23 23 24 24 #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" 27 33 28 34 static int test_args; … … 34 40 static int numeric; 35 41 42 static int sddl; 43 36 44 enum acl_mode {SMB_ACL_SET, SMB_ACL_DELETE, SMB_ACL_MODIFY, SMB_ACL_ADD }; 37 enum chown_mode {REQUEST_NONE, REQUEST_CHOWN, REQUEST_CHGRP };45 enum chown_mode {REQUEST_NONE, REQUEST_CHOWN, REQUEST_CHGRP, REQUEST_INHERIT}; 38 46 enum exit_values {EXIT_OK, EXIT_FAILED, EXIT_PARSE_ERROR}; 39 47 … … 65 73 66 74 static NTSTATUS cli_lsa_lookup_sid(struct cli_state *cli, 67 const DOM_SID*sid,75 const struct dom_sid *sid, 68 76 TALLOC_CTX *mem_ctx, 69 77 enum lsa_SidType *type, … … 118 126 const char *name, 119 127 enum lsa_SidType *type, 120 DOM_SID*sid)128 struct dom_sid *sid) 121 129 { 122 130 uint16 orig_cnum = cli->cnum; … … 125 133 NTSTATUS status; 126 134 TALLOC_CTX *frame = talloc_stackframe(); 127 DOM_SID*sids;135 struct dom_sid *sids; 128 136 enum lsa_SidType *types; 129 137 … … 164 172 165 173 /* 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)174 static void SidToString(struct cli_state *cli, fstring str, const struct dom_sid *sid) 167 175 { 168 176 char *domain = NULL; … … 193 201 194 202 /* 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)203 static bool StringToSid(struct cli_state *cli, struct dom_sid *sid, const char *str) 196 204 { 197 205 enum lsa_SidType type; 198 206 199 if (str ncmp(str, "S-", 2) == 0) {200 return string_to_sid(sid, str);207 if (string_to_sid(sid, str)) { 208 return true; 201 209 } 202 210 … … 265 273 266 274 /* 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)275 static void print_ace(struct cli_state *cli, FILE *f, struct security_ace *ace) 268 276 { 269 277 const struct perm_value *v; … … 353 361 } 354 362 355 if (*p != '|' && *p != '\0') { 363 switch (*p) { 364 case '|': 365 p++; 366 case '\0': 367 continue; 368 default: 356 369 return false; 357 370 } … … 361 374 362 375 /* parse an ACE in the same format as print_ace() */ 363 static bool parse_ace(struct cli_state *cli, SEC_ACE*ace,376 static bool parse_ace(struct cli_state *cli, struct security_ace *ace, 364 377 const char *orig_str) 365 378 { … … 370 383 unsigned int aflags = 0; 371 384 unsigned int amask = 0; 372 DOM_SIDsid;385 struct dom_sid sid; 373 386 uint32_t mask; 374 387 const struct perm_value *v; … … 527 540 } 528 541 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 */ 543 static bool add_ace(struct security_acl **the_acl, struct security_ace *ace) 544 { 545 struct security_acl *new_ace; 546 struct security_ace *aces; 534 547 if (! *the_acl) { 535 548 return (((*the_acl) = make_sec_acl(talloc_tos(), 3, 1, ace)) … … 537 550 } 538 551 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))) { 540 553 return False; 541 554 } 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)); 544 558 new_ace = make_sec_acl(talloc_tos(),(*the_acl)->revision,1+(*the_acl)->num_aces, aces); 545 559 SAFE_FREE(aces); … … 549 563 550 564 /* parse a ascii version of a security descriptor */ 551 static SEC_DESC*sec_desc_parse(TALLOC_CTX *ctx, struct cli_state *cli, char *str)565 static struct security_descriptor *sec_desc_parse(TALLOC_CTX *ctx, struct cli_state *cli, char *str) 552 566 { 553 567 const char *p = str; 554 568 char *tok; 555 SEC_DESC*ret = NULL;569 struct security_descriptor *ret = NULL; 556 570 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; 559 573 int revision=1; 560 574 … … 570 584 goto done; 571 585 } 572 owner_sid = SMB_CALLOC_ARRAY( DOM_SID, 1);586 owner_sid = SMB_CALLOC_ARRAY(struct dom_sid, 1); 573 587 if (!owner_sid || 574 588 !StringToSid(cli, owner_sid, tok+6)) { … … 584 598 goto done; 585 599 } 586 grp_sid = SMB_CALLOC_ARRAY( DOM_SID, 1);600 grp_sid = SMB_CALLOC_ARRAY(struct dom_sid, 1); 587 601 if (!grp_sid || 588 602 !StringToSid(cli, grp_sid, tok+6)) { … … 594 608 595 609 if (strncmp(tok,"ACL:", 4) == 0) { 596 SEC_ACEace;610 struct security_ace ace; 597 611 if (!parse_ace(cli, &ace, tok+4)) { 598 612 goto done; … … 621 635 622 636 /* 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)637 static void sec_desc_print(struct cli_state *cli, FILE *f, struct security_descriptor *sd) 624 638 { 625 639 fstring sidstr; … … 649 663 /* Print aces */ 650 664 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]; 652 666 fprintf(f, "ACL:"); 653 667 print_ace(cli, f, ace); … … 657 671 } 658 672 659 /***************************************************** 673 /***************************************************** 674 get fileinfo for filename 675 *******************************************************/ 676 static 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 /***************************************************** 706 get sec desc for filename 707 *******************************************************/ 708 static 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 /***************************************************** 737 set sec desc for filename 738 *******************************************************/ 739 static 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 /***************************************************** 660 770 dump the acls for a file 661 771 *******************************************************/ 662 static int cacl_dump(struct cli_state *cli, c har *filename)772 static int cacl_dump(struct cli_state *cli, const char *filename) 663 773 { 664 774 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) 669 778 return EXIT_OK; 670 779 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 } 691 791 692 792 return result; … … 701 801 const char *filename, const char *new_username) 702 802 { 703 uint16_t fnum; 704 DOM_SID sid; 705 SEC_DESC *sd, *old; 803 struct dom_sid sid; 804 struct security_descriptor *sd, *old; 706 805 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 }713 806 714 807 if (!StringToSid(cli, &sid, new_username)) 715 808 return EXIT_PARSE_ERROR; 716 809 717 old = cli_query_secdesc(cli, fnum, talloc_tos()); 718 719 cli_close(cli, fnum); 810 old = get_secdesc(cli, filename); 720 811 721 812 if (!old) { 722 printf("owner_set: Failed to query old descriptor\n");723 813 return EXIT_FAILED; 724 814 } … … 729 819 NULL, NULL, &sd_size); 730 820 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)) { 734 822 return EXIT_FAILED; 735 823 } 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);744 824 745 825 return EXIT_OK; … … 755 835 Inherited ACEs unchanged" */ 756 836 757 static int ace_compare( SEC_ACE *ace1, SEC_ACE*ace2)837 static int ace_compare(struct security_ace *ace1, struct security_ace *ace2) 758 838 { 759 839 if (sec_ace_equal(ace1, ace2)) … … 773 853 return ace2->type - ace1->type; 774 854 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); 777 857 778 858 if (ace1->flags != ace2->flags) … … 785 865 return ace1->size - ace2->size; 786 866 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 870 static void sort_acl(struct security_acl *the_acl) 791 871 { 792 872 uint32 i; 793 873 if (!the_acl) return; 794 874 795 qsort(the_acl->aces, the_acl->num_aces, sizeof(the_acl->aces[0]), QSORT_CASTace_compare);875 TYPESAFE_QSORT(the_acl->aces, the_acl->num_aces, ace_compare); 796 876 797 877 for (i=1;i<the_acl->num_aces;) { … … 812 892 *******************************************************/ 813 893 814 static int cacl_set(struct cli_state *cli, c har *filename,894 static int cacl_set(struct cli_state *cli, const char *filename, 815 895 char *the_acl, enum acl_mode mode) 816 896 { 817 uint16_t fnum; 818 SEC_DESC *sd, *old; 897 struct security_descriptor *sd, *old; 819 898 uint32 i, j; 820 899 size_t sd_size; 821 900 int result = EXIT_OK; 822 901 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 } 824 907 825 908 if (!sd) return EXIT_PARSE_ERROR; 826 909 if (test_args) return EXIT_OK; 827 910 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) { 834 914 return EXIT_FAILED; 835 915 } 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);845 916 846 917 /* the logic here is rather more complex than I would like */ … … 876 947 877 948 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, 879 950 &old->dacl->aces[j].trustee)) { 880 951 old->dacl->aces[j] = sd->dacl->aces[i]; … … 929 1000 NULL, old->dacl, &sd_size); 930 1001 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 /***************************************************** 1010 set the inherit on a file 1011 *******************************************************/ 1012 static 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) { 934 1023 return EXIT_FAILED; 935 1024 } 936 1025 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)) { 939 1122 result = EXIT_FAILED; 940 1123 } 941 1124 942 /* Clean up */943 944 cli_close(cli, fnum);945 946 1125 return result; 947 1126 } 948 949 1127 950 1128 /***************************************************** … … 980 1158 get_cmdline_auth_info_password(auth_info), 981 1159 flags, 982 get_cmdline_auth_info_signing_state(auth_info), 983 NULL); 1160 get_cmdline_auth_info_signing_state(auth_info)); 984 1161 if (!NT_STATUS_IS_OK(nt_status)) { 985 1162 DEBUG(0,("cli_full_connection failed! (%s)\n", nt_errstr(nt_status))); … … 1024 1201 { "chown", 'C', POPT_ARG_STRING, NULL, 'C', "Change ownership of a file", "USERNAME" }, 1025 1202 { "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" }, 1026 1204 { "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" }, 1027 1206 { "test-args", 't', POPT_ARG_NONE, &test_args, 1, "Test arguments"}, 1028 1207 POPT_COMMON_SAMBA … … 1040 1219 load_case_tables(); 1041 1220 1042 1043 1221 /* 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"); 1049 1224 1050 1225 setlinebuf(stdout); … … 1094 1269 owner_username = poptGetOptArg(pc); 1095 1270 change_mode = REQUEST_CHGRP; 1271 break; 1272 1273 case 'I': 1274 owner_username = poptGetOptArg(pc); 1275 change_mode = REQUEST_INHERIT; 1096 1276 break; 1097 1277 } … … 1155 1335 /* Perform requested action */ 1156 1336 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) { 1158 1340 result = owner_set(cli, change_mode, filename, owner_username); 1159 1341 } else if (the_acl) { -
vendor/current/source3/utils/smbcontrol.c
r414 r740 9 9 Copyright (C) Simo Sorce 2002 10 10 Copyright (C) James Peach 2006 11 11 12 12 This program is free software; you can redistribute it and/or modify 13 13 it under the terms of the GNU General Public License as published by 14 14 the Free Software Foundation; either version 3 of the License, or 15 15 (at your option) any later version. 16 16 17 17 This program is distributed in the hope that it will be useful, 18 18 but WITHOUT ANY WARRANTY; without even the implied warranty of 19 19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 20 GNU General Public License for more details. 21 21 22 22 You should have received a copy of the GNU General Public License 23 23 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 25 25 26 26 #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" 27 35 28 36 #if HAVE_LIBUNWIND_H … … 62 70 DEBUG(10,("smbcontrol/send_message: broadcast message to " 63 71 "%d processes\n", n_sent)); 64 72 65 73 return ret; 66 74 } … … 110 118 DATA_BLOB *data) 111 119 { 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); 114 126 num_replies++; 115 127 } … … 123 135 DATA_BLOB *data) 124 136 { 125 printf("% .*s", (int)data->length, (const char *)data->data);137 printf("%*s", (int)data->length, (const char *)data->data); 126 138 num_replies++; 127 139 } … … 158 170 strlen(argv[1]) + 1); 159 171 } 172 173 174 static 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 160 220 161 221 #if defined(HAVE_LIBUNWIND_PTRACE) && defined(HAVE_LINUX_PTRACE) … … 260 320 } 261 321 262 static int stack_trace_connection(struct db_record *rec, 263 const struct connections_key *key, 322 static int stack_trace_connection(const struct connections_key *key, 264 323 const struct connections_data *crec, 265 324 void *priv) … … 292 351 print_stack_trace(dest, &count); 293 352 } else { 294 connections_forall (stack_trace_connection, &count);353 connections_forall_read(stack_trace_connection, &count); 295 354 } 296 355 … … 477 536 break; 478 537 } 479 538 480 539 printf("Profiling %s on pid %u\n",s,(unsigned int)procid_to_pid(&pid)); 481 540 } … … 573 632 fprintf(stderr, "\tprinter <printername> <comment|port|" 574 633 "driver> <value>\n"); 575 634 576 635 return False; 577 636 } … … 586 645 return False; 587 646 } 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); 590 651 591 652 goto send; … … 598 659 return False; 599 660 } 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); 602 665 603 666 goto send; … … 615 678 616 679 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, 618 682 SPOOLSS_NOTIFY_MSG_UNIX_JOBID); 619 683 … … 632 696 633 697 notify_job_status_byname( 698 messaging_event_context(msg_ctx), msg_ctx, 634 699 argv[2], jobid, JOB_STATUS_QUEUED, 635 700 SPOOLSS_NOTIFY_MSG_UNIX_JOBID); … … 649 714 650 715 notify_job_status_byname( 716 messaging_event_context(msg_ctx), msg_ctx, 651 717 argv[2], jobid, JOB_STATUS_DELETING, 652 718 SPOOLSS_NOTIFY_MSG_UNIX_JOBID); 653 719 654 720 notify_job_status_byname( 721 messaging_event_context(msg_ctx), msg_ctx, 655 722 argv[2], jobid, JOB_STATUS_DELETING| 656 723 JOB_STATUS_DELETED, … … 661 728 } else if (strcmp(cmd, "printer") == 0) { 662 729 uint32 attribute; 663 730 664 731 if (argc != 5) { 665 732 fprintf(stderr, "Usage: smbcontrol <dest> printnotify " … … 681 748 } 682 749 683 notify_printer_byname(argv[2], attribute, 750 notify_printer_byname(messaging_event_context(msg_ctx), 751 msg_ctx, argv[2], attribute, 684 752 CONST_DISCARD(char *, argv[4])); 685 753 … … 708 776 709 777 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 783 static 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], 710 794 strlen(argv[1]) + 1); 711 795 } … … 903 987 tdb = tdb_open_log(cache_path("winbindd_cache.tdb"), 904 988 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); 906 991 907 992 if (!tdb) { … … 935 1020 /* Check that the entry "WINBINDD_OFFLINE" still exists. */ 936 1021 d = tdb_fetch_bystring( tdb, "WINBINDD_OFFLINE" ); 937 1022 938 1023 if (!d.dptr || d.dsize != 4) { 939 1024 SAFE_FREE(d.dptr); … … 955 1040 struct server_id myid; 956 1041 957 myid = pid_to_procid(sys_getpid());1042 myid = messaging_server_id(msg_ctx); 958 1043 959 1044 if (argc != 1) { … … 987 1072 struct server_id myid; 988 1073 989 myid = pid_to_procid(sys_getpid());1074 myid = messaging_server_id(msg_ctx); 990 1075 991 1076 if (argc != 1) { … … 1007 1092 int buf_len = 0; 1008 1093 1009 myid = pid_to_procid(sys_getpid());1094 myid = messaging_server_id(msg_ctx); 1010 1095 1011 1096 if (argc < 1 || argc > 2) { 1012 fprintf(stderr, "Usage: smbcontrol <dest> dump _domain_list "1097 fprintf(stderr, "Usage: smbcontrol <dest> dump-domain-list " 1013 1098 "<domain>\n"); 1014 1099 return false; … … 1070 1155 const int argc, const char **argv) 1071 1156 { 1072 struct server_id myid = pid_to_procid(sys_getpid()); 1157 struct server_id myid; 1158 1159 myid = messaging_server_id(msg_ctx); 1073 1160 1074 1161 if (argc != 1) { … … 1166 1253 } msg_types[] = { 1167 1254 { "debug", do_debug, "Set debuglevel" }, 1255 { "idmap", do_idmap, "Manipulate idmap cache" }, 1168 1256 { "force-election", do_election, 1169 1257 "Force a browse election" }, … … 1178 1266 { "printnotify", do_printnotify, "Send a print notify message" }, 1179 1267 { "close-share", do_closeshare, "Forcibly disconnect a share" }, 1268 { "ip-dropped", do_ip_dropped, "Tell winbind that an IP got dropped" }, 1180 1269 { "lockretry", do_lockretry, "Force a blocking lock retry" }, 1181 1270 { "brl-revalidate", do_brl_revalidate, "Revalidate all brl entries" }, … … 1226 1315 /* Return the pid number for a string destination */ 1227 1316 1228 static struct server_id parse_dest(const char *dest) 1317 static struct server_id parse_dest(struct messaging_context *msg, 1318 const char *dest) 1229 1319 { 1230 1320 struct server_id result = {-1}; … … 1240 1330 1241 1331 if (strequal(dest, "self")) { 1242 return pid_to_procid(sys_getpid());1332 return messaging_server_id(msg); 1243 1333 } 1244 1334 … … 1278 1368 /* Check destination */ 1279 1369 1280 pid = parse_dest( dest);1370 pid = parse_dest(msg_ctx, dest); 1281 1371 if (!procid_valid(&pid)) { 1282 1372 return False; … … 1343 1433 load_case_tables(); 1344 1434 1345 setup_logging(argv[0], True);1346 1435 setup_logging(argv[0], DEBUG_STDOUT); 1436 1347 1437 /* Parse command line arguments using popt */ 1348 1438 … … 1387 1477 * routines mostly return True==1 for success, but 1388 1478 * shell needs 0. */ 1389 1479 1390 1480 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))) { 1392 1482 fprintf(stderr, "could not init messaging context\n"); 1393 1483 TALLOC_FREE(frame); 1394 1484 exit(1); 1395 1485 } 1396 1486 1397 1487 ret = !do_command(msg_ctx, argc, argv); 1398 1488 TALLOC_FREE(frame); -
vendor/current/source3/utils/smbcquotas.c
r414 r740 2 2 Unix SMB/CIFS implementation. 3 3 QUOTA get/set utility 4 4 5 5 Copyright (C) Andrew Tridgell 2000 6 6 Copyright (C) Tim Potter 2000 7 7 Copyright (C) Jeremy Allison 2000 8 8 Copyright (C) Stefan (metze) Metzmacher 2003 9 9 10 10 This program is free software; you can redistribute it and/or modify 11 11 it under the terms of the GNU General Public License as published by 12 12 the Free Software Foundation; either version 3 of the License, or 13 13 (at your option) any later version. 14 14 15 15 This program is distributed in the hope that it will be useful, 16 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 18 GNU General Public License for more details. 19 19 20 20 You should have received a copy of the GNU General Public License 21 21 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 23 23 24 24 #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" 25 32 26 33 static char *server; … … 73 80 got_policy_hnd = True; 74 81 } 75 82 76 83 return True; 77 84 } 78 85 79 86 /* convert a SID to a string, either numeric or username/group */ 80 static void SidToString(fstring str, DOM_SID*sid, bool _numeric)87 static void SidToString(fstring str, struct dom_sid *sid, bool _numeric) 81 88 { 82 89 char **domains = NULL; … … 103 110 domains[0], lp_winbind_separator(), 104 111 names[0]); 105 106 112 } 107 113 108 114 /* convert a string to a SID, either numeric or username/group */ 109 static bool StringToSid( DOM_SID*sid, const char *str)115 static bool StringToSid(struct dom_sid *sid, const char *str) 110 116 { 111 117 enum lsa_SidType *types = NULL; 112 DOM_SID*sids = NULL;118 struct dom_sid *sids = NULL; 113 119 bool result = True; 114 120 115 if (str ncmp(str, "S-", 2) == 0) {116 return string_to_sid(sid, str);121 if (string_to_sid(sid, str)) { 122 return true; 117 123 } 118 124 … … 224 230 } 225 231 232 233 static 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 245 static 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"AS_ENABLED) 269 ||(qt->qflags"AS_DENY_DISK))?"On":"Off"); 270 d_printf(" Deny Disk: %s\n", 271 (qt->qflags"AS_DENY_DISK)?"On":"Off"); 272 d_printf(" Log Soft Limit: %s\n", 273 (qt->qflags"AS_LOG_THRESHOLD)?"On":"Off"); 274 d_printf(" Log Hard Limit: %s\n", 275 (qt->qflags"AS_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 316 static 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 226 331 static int do_quota(struct cli_state *cli, 227 332 enum SMB_QUOTA_TYPE qtype, … … 234 339 SMB_NTQUOTA_LIST *qtl = NULL; 235 340 SMB_NTQUOTA_STRUCT qt; 341 NTSTATUS status; 342 236 343 ZERO_STRUCT(qt); 237 344 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)) { 239 347 d_printf("Failed to get the filesystem attributes %s.\n", 240 cli_errstr(cli));348 nt_errstr(status)); 241 349 return -1; 242 350 } … … 247 355 } 248 356 249 if (!NT_STATUS_IS_OK(cli_get_quota_handle(cli, "a_fnum))) { 357 status = cli_get_quota_handle(cli, "a_fnum); 358 if (!NT_STATUS_IS_OK(status)) { 250 359 d_printf("Quotas are not enabled on this share.\n"); 251 360 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)); 253 363 return -1; 254 364 } … … 263 373 switch(cmd) { 264 374 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)) { 266 378 d_printf("%s cli_get_user_quota %s\n", 267 cli_errstr(cli),username_str); 379 nt_errstr(status), 380 username_str); 268 381 return -1; 269 382 } … … 272 385 case QUOTA_SETLIM: 273 386 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)) { 275 390 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)) { 280 398 d_printf("%s cli_get_user_quota %s\n", 281 cli_errstr(cli),username_str); 399 nt_errstr(status), 400 username_str); 282 401 return -1; 283 402 } … … 285 404 break; 286 405 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)) { 288 409 d_printf("%s cli_set_user_quota %s\n", 289 cli_errstr(cli),username_str); 410 nt_errstr(status), 411 username_str); 290 412 return -1; 291 413 } … … 301 423 switch(cmd) { 302 424 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)) { 304 428 d_printf("%s cli_get_fs_quota_info\n", 305 cli_errstr(cli));429 nt_errstr(status)); 306 430 return -1; 307 431 } … … 309 433 break; 310 434 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)) { 312 438 d_printf("%s cli_get_fs_quota_info\n", 313 cli_errstr(cli));439 nt_errstr(status)); 314 440 return -1; 315 441 } 316 442 qt.softlim = pqt->softlim; 317 443 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)) { 319 447 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)) { 324 454 d_printf("%s cli_get_fs_quota_info\n", 325 cli_errstr(cli));455 nt_errstr(status)); 326 456 return -1; 327 457 } … … 329 459 break; 330 460 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)) { 332 464 d_printf("%s cli_get_fs_quota_info\n", 333 cli_errstr(cli));465 nt_errstr(status)); 334 466 return -1; 335 467 } 336 468 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)) { 338 472 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)) { 343 479 d_printf("%s cli_get_fs_quota_info\n", 344 cli_errstr(cli));480 nt_errstr(status)); 345 481 return -1; 346 482 } … … 395 531 get_cmdline_auth_info_password(smbcquotas_auth_info), 396 532 flags, 397 get_cmdline_auth_info_signing_state(smbcquotas_auth_info), 398 NULL); 533 get_cmdline_auth_info_signing_state(smbcquotas_auth_info)); 399 534 if (!NT_STATUS_IS_OK(nt_status)) { 400 535 DEBUG(0,("cli_full_connection failed! (%s)\n", nt_errstr(nt_status))); … … 460 595 461 596 /* 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"); 466 599 467 600 setlinebuf(stdout); … … 608 741 break; 609 742 default: 610 611 743 result = EXIT_FAILED; 612 744 break; -
vendor/current/source3/utils/smbfilter.c
r591 r740 3 3 SMB filter/socket plugin 4 4 Copyright (C) Andrew Tridgell 1999 5 5 6 6 This program is free software; you can redistribute it and/or modify 7 7 it under the terms of the GNU General Public License as published by 8 8 the Free Software Foundation; either version 3 of the License, or 9 9 (at your option) any later version. 10 10 11 11 This program is distributed in the hope that it will be useful, 12 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 14 GNU General Public License for more details. 15 15 16 16 You should have received a copy of the GNU General Public License 17 17 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 19 19 20 20 #include "includes.h" 21 #include "system/filesys.h" 22 #include "system/select.h" 23 #include "../lib/util/select.h" 24 #include "libsmb/nmblib.h" 21 25 22 26 #define SECURITY_MASK 0 … … 44 48 if (write(fd, ppacket, length) != length) { 45 49 fprintf(stderr,"Failed to write %s\n", fname); 50 close(fd); 46 51 return; 47 52 } … … 190 195 191 196 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))))) { 203 229 size_t len; 204 230 if (!NT_STATUS_IS_OK(receive_smb_raw( … … 214 240 } 215 241 } 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))))) { 217 251 size_t len; 218 252 if (!NT_STATUS_IS_OK(receive_smb_raw( … … 246 280 zero_sockaddr(&my_ss); 247 281 s = open_socket_in(SOCK_STREAM, 445, 0, &my_ss, True); 248 282 249 283 if (s == -1) { 250 284 d_printf("bind failed\n"); … … 262 296 263 297 while (1) { 264 fd_set fds; 265 int num; 298 int num, revents; 266 299 struct sockaddr_storage ss; 267 300 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))) { 277 304 c = accept(s, (struct sockaddr *)&ss, &in_addrlen); 278 305 if (c != -1) { … … 298 325 load_case_tables(); 299 326 300 setup_logging(argv[0], True);327 setup_logging(argv[0], DEBUG_STDOUT); 301 328 302 329 configfile = get_dyn_CONFIGFILE(); -
vendor/current/source3/utils/smbget.c
r597 r740 8 8 the Free Software Foundation; either version 3 of the License, or 9 9 (at your option) any later version. 10 10 11 11 This program is distributed in the hope that it will be useful, 12 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 14 GNU General Public License for more details. 15 15 16 16 You should have received a copy of the GNU General Public License 17 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 18 18 19 19 #include "includes.h" 20 #include "system/filesys.h" 21 #include "popt_common.h" 20 22 #include "libsmbclient.h" 21 23 … … 50 52 static int blocksize = SMB_DEFAULT_BLOCKSIZE; 51 53 52 static int smb_download_file(const char *base, const char *name, int recursive, int resume, char *outfile); 54 static int smb_download_file(const char *base, const char *name, int recursive, 55 int resume, int toplevel, char *outfile); 53 56 54 57 static int get_num_cols(void) … … 75 78 static void human_readable(off_t s, char *buffer, int l) 76 79 { 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 } 83 89 } 84 90 … … 138 144 dirhandle = smbc_opendir(path); 139 145 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 } 141 150 fprintf(stderr, "Can't open directory %s: %s\n", path, strerror(errno)); 142 151 return 1; … … 145 154 while(*relname == '/')relname++; 146 155 mkdir(relname, 0755); 147 156 148 157 tmpname = SMB_STRDUP(name); 149 158 … … 168 177 169 178 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); 171 181 break; 172 182 … … 182 192 if(!quiet)printf("Ignoring comms share %s\n", dirent->name); 183 193 break; 184 194 185 195 case SMBC_IPC_SHARE: 186 196 if(!quiet)printf("Ignoring ipc$ share %s\n", dirent->name); … … 201 211 return 1; 202 212 } 203 213 204 214 if(chmod(relname, remotestat.st_mode) < 0) { 205 215 fprintf(stderr, "Unable to change mode of local dir %s to %o\n", relname, … … 250 260 return; 251 261 } 252 262 253 263 if(columns) { 254 264 int required = strlen(name), available = columns - len - strlen("[] "); … … 269 279 /* Return 1 on error, 0 on success. */ 270 280 271 static int smb_download_file(const char *base, const char *name, int recursive, int resume, char *outfile) { 281 static int smb_download_file(const char *base, const char *name, int recursive, 282 int resume, int toplevel, char *outfile) 283 { 272 284 int remotehandle, localhandle; 273 time_t start_time = time (NULL);285 time_t start_time = time_mono(NULL); 274 286 const char *newpath; 275 287 char path[SMB_MAXPATHLEN]; … … 280 292 281 293 snprintf(path, SMB_MAXPATHLEN-1, "%s%s%s", base, (*base && *name && name[0] != '/' && base[strlen(base)-1] != '/')?"/":"", name); 282 294 283 295 remotehandle = smbc_open(path, O_RDONLY, 0755); 284 296 … … 325 337 } else newpath = name; 326 338 327 if(newpath[0] == '/')newpath++; 328 339 if (!toplevel && (newpath[0] == '/')) { 340 newpath++; 341 } 342 329 343 /* Open local file according to the mode */ 330 344 if(update) { … … 353 367 return 1; 354 368 } 355 369 356 370 if (fstat(localhandle, &localstat) != 0) { 357 371 fprintf(stderr, "Can't fstat %s: %s\n", newpath, strerror(errno)); … … 404 418 (OFF_T_FORMAT_CAST)off1, 405 419 (OFF_T_FORMAT_CAST)off2); 420 smbc_close(remotehandle); close(localhandle); 406 421 return 1; 407 422 } … … 435 450 436 451 readbuf = (char *)SMB_MALLOC(blocksize); 452 if (!readbuf) { 453 return 1; 454 } 437 455 438 456 /* Now, download all bytes from offset_download to the end */ … … 459 477 if(dots)fputc('.', stderr); 460 478 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); 462 481 } 463 482 } … … 499 518 human_readable(total_bytes, bs, sizeof(bs)); 500 519 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)); 502 521 exit(0); 503 522 } … … 655 674 "require"); 656 675 } 657 676 658 677 columns = get_num_cols(); 659 678 660 total_start_time = time (NULL);679 total_start_time = time_mono(NULL); 661 680 662 681 while ( (file = poptGetArg(pc)) ) { 663 682 if (!recursive) 664 ret = smb_download_file(file, "", recursive, resume, outputfile); 683 ret = smb_download_file(file, "", recursive, resume, 684 1, outputfile); 665 685 else 666 686 ret = smb_download_dir(file, "", resume); -
vendor/current/source3/utils/smbpasswd.c
r414 r740 18 18 19 19 #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" 22 25 23 26 /* … … 153 156 break; 154 157 case 'D': 155 DEBUGLEVEL = atoi(optarg);158 lp_set_cmdline("log level", optarg); 156 159 break; 157 160 case 'U': { … … 341 344 } 342 345 343 if (!user_name[0] && (pwd = getpwuid_alloc(talloc_ autofree_context(), geteuid()))) {346 if (!user_name[0] && (pwd = getpwuid_alloc(talloc_tos(), geteuid()))) { 344 347 fstrcpy(user_name, pwd->pw_name); 345 348 TALLOC_FREE(pwd); … … 506 509 507 510 if (!user_name[0]) { 508 pwd = getpwuid_alloc(talloc_ autofree_context(), getuid());511 pwd = getpwuid_alloc(talloc_tos(), getuid()); 509 512 if (pwd) { 510 513 fstrcpy(user_name,pwd->pw_name); … … 569 572 int ret; 570 573 571 AllowDebugChange = False;572 573 574 #if defined(HAVE_SET_AUTH_PARAMETERS) 574 575 set_auth_parameters(argc, argv); … … 583 584 local_flags = process_options(argc, argv, local_flags); 584 585 585 setup_logging("smbpasswd", True);586 setup_logging("smbpasswd", DEBUG_STDERR); 586 587 587 588 /* -
vendor/current/source3/utils/smbtree.c
r414 r740 21 21 22 22 #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" 24 28 25 29 static int use_bcast; … … 158 162 uint32_t resume_handle = 0; 159 163 uint32_t total_entries = 0; 164 struct dcerpc_binding_handle *b; 160 165 161 166 mem_ctx = talloc_new(NULL); … … 175 180 } 176 181 182 b = pipe_hnd->binding_handle; 183 177 184 ZERO_STRUCT(info_ctr); 178 185 ZERO_STRUCT(ctr1); … … 181 188 info_ctr.ctr.ctr1 = &ctr1; 182 189 183 status = rpccli_srvsvc_NetShareEnumAll(pipe_hnd, mem_ctx,190 status = dcerpc_srvsvc_NetShareEnumAll(b, mem_ctx, 184 191 pipe_hnd->desthost, 185 192 &info_ctr, … … 291 298 setlinebuf(stdout); 292 299 293 dbf = x_stderr; 294 295 setup_logging(argv[0],True); 300 setup_logging(argv[0], DEBUG_STDERR); 296 301 297 302 auth_info = user_auth_info_init(frame); -
vendor/current/source3/utils/status.c
r414 r740 32 32 33 33 #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" 34 41 35 42 #define SMB_MAXPIDS 2048 … … 233 240 } 234 241 235 static int traverse_fn1(struct db_record *rec, 236 const struct connections_key *key, 242 static int traverse_fn1(const struct connections_key *key, 237 243 const struct connections_data *crec, 238 244 void *state) … … 253 259 } 254 260 255 static int traverse_sessionid( struct db_record *db, void *state)256 { 257 struct sessionid sessionid; 261 static int traverse_sessionid(const char *key, struct sessionid *session, 262 void *private_data) 263 { 258 264 fstring uid_str, gid_str; 259 265 260 if (db->value.dsize != sizeof(sessionid)) 266 if (!process_exists(session->pid) 267 || !Ucrit_checkUid(session->uid)) { 261 268 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); 273 275 274 276 d_printf("%-7s %-12s %-12s %-12s (%s)\n", 275 procid_str_static(&session id.pid),276 numeric_only ? uid_str : uidtoname(session id.uid),277 numeric_only ? gid_str : gidtoname(session id.gid),278 session id.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); 279 281 280 282 return 0; … … 312 314 load_case_tables(); 313 315 314 setup_logging(argv[0],True); 315 316 dbf = x_stderr; 316 setup_logging(argv[0], DEBUG_STDERR); 317 317 318 318 if (getuid() != geteuid()) { … … 413 413 414 414 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); 432 424 433 425 if (processes_only) { … … 448 440 d_printf("-------------------------------------------------------\n"); 449 441 450 connections_forall (traverse_fn1, NULL);442 connections_forall_read(traverse_fn1, NULL); 451 443 452 444 d_printf("\n"); … … 461 453 struct db_context *db; 462 454 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); 464 456 465 457 if (!db) { -
vendor/current/source3/utils/status_profile.c
r414 r740 20 20 21 21 #include "includes.h" 22 #include "smbprofile.h" 22 23 23 24 bool status_profile_dump(bool be_verbose); … … 58 59 d_printf("opendir_count: %u\n", profile_p->syscall_opendir_count); 59 60 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); 60 63 d_printf("readdir_count: %u\n", profile_p->syscall_readdir_count); 61 64 d_printf("readdir_time: %u\n", profile_p->syscall_readdir_time); … … 82 85 d_printf("pwrite_time: %u\n", profile_p->syscall_pwrite_time); 83 86 d_printf("pwrite_bytes: %u\n", profile_p->syscall_pwrite_bytes); 84 #ifdef WITH_SENDFILE85 87 d_printf("sendfile_count: %u\n", profile_p->syscall_sendfile_count); 86 88 d_printf("sendfile_time: %u\n", profile_p->syscall_sendfile_time); 87 89 d_printf("sendfile_bytes: %u\n", profile_p->syscall_sendfile_bytes); 88 #endif89 90 d_printf("lseek_count: %u\n", profile_p->syscall_lseek_count); 90 91 d_printf("lseek_time: %u\n", profile_p->syscall_lseek_time); … … 401 402 d_printf("election_count: %u\n", profile_p->election_count); 402 403 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 403 444 #else /* WITH_PROFILE */ 445 404 446 fprintf(stderr, "Profile data unavailable\n"); 405 447 #endif /* WITH_PROFILE */ -
vendor/current/source3/utils/testparm.c
r414 r740 33 33 34 34 #include "includes.h" 35 36 extern bool AllowDebugChange; 35 #include "system/filesys.h" 36 #include "popt_common.h" 37 37 38 38 /******************************************************************* … … 78 78 } 79 79 80 if (strequal(lp_workgroup(), global_myname())) { 81 fprintf(stderr, "WARNING: 'workgroup' and 'netbios name' " \ 82 "must differ.\n"); 83 ret = 1; 84 } 85 80 86 if (!directory_exist_stat(lp_lockdir(), &st)) { 81 87 fprintf(stderr, "ERROR: lock directory %s does not exist\n", … … 123 129 */ 124 130 125 if((lp_security() == SEC_SERVER || lp_security() >= SEC_DOMAIN) && ! lp_passwordserver()) {131 if((lp_security() == SEC_SERVER || lp_security() >= SEC_DOMAIN) && !*lp_passwordserver()) { 126 132 const char *sec_setting; 127 133 if(lp_security() == SEC_SERVER) … … 129 135 else if(lp_security() == SEC_DOMAIN) 130 136 sec_setting = "domain"; 137 else if(lp_security() == SEC_ADS) 138 sec_setting = "ads"; 131 139 else 132 140 sec_setting = ""; 133 141 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 ); 137 158 } 138 159 … … 320 341 static char *parameter_name = NULL; 321 342 static const char *section_name = NULL; 322 static char *new_local_machine = NULL;323 343 const char *cname; 324 344 const char *caddr; … … 330 350 {"suppress-prompt", 's', POPT_ARG_VAL, &silent_mode, 1, "Suppress prompt for enter"}, 331 351 {"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"},333 352 {"skip-logic-checks", 'l', POPT_ARG_NONE, &skip_logic_checks, 1, "Skip the global checks"}, 334 353 {"show-all-parameters", '\0', POPT_ARG_VAL, &show_all_parameters, True, "Show the parameters, type, possible values" }, … … 337 356 POPT_COMMON_VERSION 338 357 POPT_COMMON_DEBUGLEVEL 358 POPT_COMMON_OPTION 339 359 POPT_TABLEEND 340 360 }; … … 348 368 * not by smb.conf. 349 369 */ 350 DEBUGLEVEL_CLASS[DBGC_ALL] = 2;370 lp_set_cmdline("log level", "2"); 351 371 352 372 pc = poptGetContext(NULL, argc, argv, long_options, … … 361 381 } 362 382 363 setup_logging(poptGetArg(pc), True);383 setup_logging(poptGetArg(pc), DEBUG_STDERR); 364 384 365 385 if (poptPeekArg(pc)) … … 376 396 goto done; 377 397 } 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;386 398 387 399 fprintf(stderr,"Load smb config files from %s\n",config_file);
Note:
See TracChangeset
for help on using the changeset viewer.