Changeset 745 for trunk/server/source4/libnet/libnet_join.c
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/source4/libnet/libnet_join.c
r414 r745 23 23 #include "libnet/libnet.h" 24 24 #include "librpc/gen_ndr/ndr_drsuapi_c.h" 25 #include "lib/ldb/include/ldb.h" 26 #include "lib/ldb/include/ldb_errors.h" 27 #include "param/secrets.h" 25 #include <ldb.h> 26 #include <ldb_errors.h> 28 27 #include "dsdb/samdb/samdb.h" 29 28 #include "ldb_wrap.h" 30 #include "../lib/util/util_ldb.h"31 29 #include "libcli/security/security.h" 32 30 #include "auth/credentials/credentials.h" … … 35 33 #include "param/param.h" 36 34 #include "param/provision.h" 35 #include "system/kerberos.h" 36 #include "auth/kerberos/kerberos.h" 37 37 38 38 /* … … 95 95 } 96 96 97 drsuapi_binding = talloc (tmp_ctx, struct dcerpc_binding);97 drsuapi_binding = talloc_zero(tmp_ctx, struct dcerpc_binding); 98 98 if (!drsuapi_binding) { 99 99 r->out.error_string = NULL; … … 134 134 r_drsuapi_bind.out.bind_handle = &drsuapi_bind_handle; 135 135 136 status = dcerpc_drsuapi_DsBind(drsuapi_pipe, tmp_ctx, &r_drsuapi_bind); 137 if (!NT_STATUS_IS_OK(status)) { 138 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) { 139 r->out.error_string 140 = talloc_asprintf(r, 141 "dcerpc_drsuapi_DsBind failed - %s", 142 dcerpc_errstr(tmp_ctx, drsuapi_pipe->last_fault_code)); 143 talloc_free(tmp_ctx); 144 return status; 145 } else { 146 r->out.error_string 147 = talloc_asprintf(r, 148 "dcerpc_drsuapi_DsBind failed - %s", 149 nt_errstr(status)); 150 talloc_free(tmp_ctx); 151 return status; 152 } 136 status = dcerpc_drsuapi_DsBind_r(drsuapi_pipe->binding_handle, tmp_ctx, &r_drsuapi_bind); 137 if (!NT_STATUS_IS_OK(status)) { 138 r->out.error_string 139 = talloc_asprintf(r, 140 "dcerpc_drsuapi_DsBind failed - %s", 141 nt_errstr(status)); 142 talloc_free(tmp_ctx); 143 return status; 153 144 } else if (!W_ERROR_IS_OK(r_drsuapi_bind.out.result)) { 154 145 r->out.error_string … … 185 176 186 177 r_crack_names.out.ctr = talloc(r, union drsuapi_DsNameCtr); 187 r_crack_names.out.level_out = talloc(r, int32_t);178 r_crack_names.out.level_out = talloc(r, uint32_t); 188 179 if (!r_crack_names.out.ctr || !r_crack_names.out.level_out) { 189 180 r->out.error_string = NULL; … … 192 183 } 193 184 194 status = dcerpc_drsuapi_DsCrackNames(drsuapi_pipe, tmp_ctx, &r_crack_names); 195 if (!NT_STATUS_IS_OK(status)) { 196 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) { 197 r->out.error_string 198 = talloc_asprintf(r, 199 "dcerpc_drsuapi_DsCrackNames for [%s] failed - %s", 200 names[0].str, 201 dcerpc_errstr(tmp_ctx, drsuapi_pipe->last_fault_code)); 202 talloc_free(tmp_ctx); 203 return status; 204 } else { 205 r->out.error_string 206 = talloc_asprintf(r, 207 "dcerpc_drsuapi_DsCrackNames for [%s] failed - %s", 208 names[0].str, 209 nt_errstr(status)); 210 talloc_free(tmp_ctx); 211 return status; 212 } 185 status = dcerpc_drsuapi_DsCrackNames_r(drsuapi_pipe->binding_handle, tmp_ctx, &r_crack_names); 186 if (!NT_STATUS_IS_OK(status)) { 187 r->out.error_string 188 = talloc_asprintf(r, 189 "dcerpc_drsuapi_DsCrackNames for [%s] failed - %s", 190 names[0].str, 191 nt_errstr(status)); 192 talloc_free(tmp_ctx); 193 return status; 213 194 } else if (!W_ERROR_IS_OK(r_crack_names.out.result)) { 214 195 r->out.error_string … … 246 227 } 247 228 248 remote_ldb = ldb_wrap_connect(tmp_ctx, ctx->event_ctx, ctx->lp_ctx, 229 remote_ldb = ldb_wrap_connect(tmp_ctx, ctx->event_ctx, ctx->lp_ctx, 249 230 remote_ldb_url, 250 NULL, ctx->cred, 0 , NULL);231 NULL, ctx->cred, 0); 251 232 if (!remote_ldb) { 252 233 r->out.error_string = NULL; … … 256 237 257 238 account_dn = ldb_dn_new(tmp_ctx, remote_ldb, account_dn_str); 258 if ( ! ldb_dn_validate(account_dn)) {239 if (account_dn == NULL) { 259 240 r->out.error_string = talloc_asprintf(r, "Invalid account dn: %s", 260 241 account_dn_str); … … 290 271 291 272 { 292 int i;293 const char *service_principal_name[ 6];294 const char *dns_host_name = strlower_talloc( tmp_ctx,295 talloc_asprintf( tmp_ctx,273 unsigned int i; 274 const char *service_principal_name[2]; 275 const char *dns_host_name = strlower_talloc(msg, 276 talloc_asprintf(msg, 296 277 "%s.%s", 297 278 r->in.netbios_name, … … 304 285 } 305 286 306 service_principal_name[0] = talloc_asprintf(tmp_ctx, "host/%s", dns_host_name); 307 service_principal_name[1] = talloc_asprintf(tmp_ctx, "host/%s", strlower_talloc(tmp_ctx, r->in.netbios_name)); 308 service_principal_name[2] = talloc_asprintf(tmp_ctx, "host/%s/%s", dns_host_name, realm); 309 service_principal_name[3] = talloc_asprintf(tmp_ctx, "host/%s/%s", strlower_talloc(tmp_ctx, r->in.netbios_name), realm); 310 service_principal_name[4] = talloc_asprintf(tmp_ctx, "host/%s/%s", dns_host_name, r->out.domain_name); 311 service_principal_name[5] = talloc_asprintf(tmp_ctx, "host/%s/%s", strlower_talloc(tmp_ctx, r->in.netbios_name), r->out.domain_name); 287 service_principal_name[0] = talloc_asprintf(msg, "HOST/%s", 288 dns_host_name); 289 service_principal_name[1] = talloc_asprintf(msg, "HOST/%s", 290 r->in.netbios_name); 312 291 313 292 for (i=0; i < ARRAY_SIZE(service_principal_name); i++) { … … 317 296 return NT_STATUS_NO_MEMORY; 318 297 } 319 rtn = samdb_msg_add_string(remote_ldb, tmp_ctx, msg, "servicePrincipalName", service_principal_name[i]); 320 if (rtn == -1) { 298 rtn = ldb_msg_add_string(msg, "servicePrincipalName", 299 service_principal_name[i]); 300 if (rtn != LDB_SUCCESS) { 321 301 r->out.error_string = NULL; 322 302 talloc_free(tmp_ctx); … … 325 305 } 326 306 327 rtn = samdb_msg_add_string(remote_ldb, tmp_ctx,msg, "dNSHostName", dns_host_name);328 if (rtn == -1) {307 rtn = ldb_msg_add_string(msg, "dNSHostName", dns_host_name); 308 if (rtn != LDB_SUCCESS) { 329 309 r->out.error_string = NULL; 330 310 talloc_free(tmp_ctx); … … 332 312 } 333 313 334 rtn = samdb_replace(remote_ldb, tmp_ctx, msg);335 if (rtn != 0) {314 rtn = dsdb_replace(remote_ldb, msg, 0); 315 if (rtn != LDB_SUCCESS) { 336 316 r->out.error_string 337 317 = talloc_asprintf(r, … … 343 323 } 344 324 325 msg = ldb_msg_new(tmp_ctx); 326 if (!msg) { 327 r->out.error_string = NULL; 328 talloc_free(tmp_ctx); 329 return NT_STATUS_NO_MEMORY; 330 } 331 msg->dn = res->msgs[0]->dn; 332 333 rtn = samdb_msg_add_uint(remote_ldb, msg, msg, 334 "msDS-SupportedEncryptionTypes", ENC_ALL_TYPES); 335 if (rtn != LDB_SUCCESS) { 336 r->out.error_string = NULL; 337 talloc_free(tmp_ctx); 338 return NT_STATUS_NO_MEMORY; 339 } 340 341 rtn = dsdb_replace(remote_ldb, msg, 0); 342 /* The remote server may not support this attribute, if it 343 * isn't a modern schema */ 344 if (rtn != LDB_SUCCESS && rtn != LDB_ERR_NO_SUCH_ATTRIBUTE) { 345 r->out.error_string 346 = talloc_asprintf(r, 347 "Failed to replace msDS-SupportedEncryptionTypes on %s", 348 ldb_dn_get_linearized(msg->dn)); 349 talloc_free(tmp_ctx); 350 return NT_STATUS_INTERNAL_DB_CORRUPTION; 351 } 352 345 353 /* DsCrackNames to find out the DN of the domain. */ 346 354 r_crack_names.in.req->req1.format_offered = DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT; … … 353 361 } 354 362 355 status = dcerpc_drsuapi_DsCrackNames(drsuapi_pipe, tmp_ctx, &r_crack_names); 356 if (!NT_STATUS_IS_OK(status)) { 357 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) { 358 r->out.error_string 359 = talloc_asprintf(r, 360 "dcerpc_drsuapi_DsCrackNames for [%s] failed - %s", 361 r->in.domain_name, 362 dcerpc_errstr(tmp_ctx, drsuapi_pipe->last_fault_code)); 363 talloc_free(tmp_ctx); 364 return status; 365 } else { 366 r->out.error_string 367 = talloc_asprintf(r, 368 "dcerpc_drsuapi_DsCrackNames for [%s] failed - %s", 369 r->in.domain_name, 370 nt_errstr(status)); 371 talloc_free(tmp_ctx); 372 return status; 373 } 363 status = dcerpc_drsuapi_DsCrackNames_r(drsuapi_pipe->binding_handle, tmp_ctx, &r_crack_names); 364 if (!NT_STATUS_IS_OK(status)) { 365 r->out.error_string 366 = talloc_asprintf(r, 367 "dcerpc_drsuapi_DsCrackNames for [%s] failed - %s", 368 r->in.domain_name, 369 nt_errstr(status)); 370 talloc_free(tmp_ctx); 371 return status; 374 372 } else if (!W_ERROR_IS_OK(r_crack_names.out.result)) { 375 373 r->out.error_string … … 540 538 541 539 /* 2. do a samr_Connect to get a policy handle */ 542 status = dcerpc_samr_Connect(samr_pipe, tmp_ctx, &sc); 540 status = dcerpc_samr_Connect_r(samr_pipe->binding_handle, tmp_ctx, &sc); 541 if (NT_STATUS_IS_OK(status) && !NT_STATUS_IS_OK(sc.out.result)) { 542 status = sc.out.result; 543 } 543 544 if (!NT_STATUS_IS_OK(status)) { 544 545 r->out.error_string = talloc_asprintf(mem_ctx, … … 554 555 connect_with_info->out.domain_name = talloc_strdup(tmp_ctx, r->in.domain_name); 555 556 } else { 556 /* Bugger, we just lost our way to automatic ly find the domain name */557 connect_with_info->out.domain_name = talloc_strdup(tmp_ctx, lp _workgroup(ctx->lp_ctx));558 connect_with_info->out.realm = talloc_strdup(tmp_ctx, lp _realm(ctx->lp_ctx));557 /* Bugger, we just lost our way to automatically find the domain name */ 558 connect_with_info->out.domain_name = talloc_strdup(tmp_ctx, lpcfg_workgroup(ctx->lp_ctx)); 559 connect_with_info->out.realm = talloc_strdup(tmp_ctx, lpcfg_realm(ctx->lp_ctx)); 559 560 } 560 561 } … … 570 571 l.out.sid = &sid; 571 572 572 status = dcerpc_samr_LookupDomain(samr_pipe, tmp_ctx, &l); 573 status = dcerpc_samr_LookupDomain_r(samr_pipe->binding_handle, tmp_ctx, &l); 574 if (NT_STATUS_IS_OK(status) && !NT_STATUS_IS_OK(l.out.result)) { 575 status = l.out.result; 576 } 573 577 if (!NT_STATUS_IS_OK(status)) { 574 578 r->out.error_string = talloc_asprintf(mem_ctx, … … 589 593 590 594 /* do a samr_OpenDomain to get a domain handle */ 591 status = dcerpc_samr_OpenDomain(samr_pipe, tmp_ctx, &od); 595 status = dcerpc_samr_OpenDomain_r(samr_pipe->binding_handle, tmp_ctx, &od); 596 if (NT_STATUS_IS_OK(status) && !NT_STATUS_IS_OK(od.out.result)) { 597 status = od.out.result; 598 } 592 599 if (!NT_STATUS_IS_OK(status)) { 593 600 r->out.error_string = talloc_asprintf(mem_ctx, … … 611 618 612 619 /* do a samr_CreateUser2 to get an account handle, or an error */ 613 cu_status = dcerpc_samr_CreateUser2(samr_pipe, tmp_ctx, &cu); 620 cu_status = dcerpc_samr_CreateUser2_r(samr_pipe->binding_handle, tmp_ctx, &cu); 621 if (NT_STATUS_IS_OK(cu_status) && !NT_STATUS_IS_OK(cu.out.result)) { 622 cu_status = cu.out.result; 623 } 614 624 status = cu_status; 615 625 if (NT_STATUS_EQUAL(status, NT_STATUS_USER_EXISTS)) { … … 628 638 629 639 /* 5. do a samr_LookupNames to get the users rid */ 630 status = dcerpc_samr_LookupNames(samr_pipe, tmp_ctx, &ln); 640 status = dcerpc_samr_LookupNames_r(samr_pipe->binding_handle, tmp_ctx, &ln); 641 if (NT_STATUS_IS_OK(status) && !NT_STATUS_IS_OK(ln.out.result)) { 642 status = ln.out.result; 643 } 631 644 if (!NT_STATUS_IS_OK(status)) { 632 645 r->out.error_string = talloc_asprintf(mem_ctx, … … 656 669 657 670 /* 6. do a samr_OpenUser to get a user handle */ 658 status = dcerpc_samr_OpenUser(samr_pipe, tmp_ctx, &ou); 671 status = dcerpc_samr_OpenUser_r(samr_pipe->binding_handle, tmp_ctx, &ou); 672 if (NT_STATUS_IS_OK(status) && !NT_STATUS_IS_OK(ou.out.result)) { 673 status = ou.out.result; 674 } 659 675 if (!NT_STATUS_IS_OK(status)) { 660 676 r->out.error_string = talloc_asprintf(mem_ctx, … … 670 686 d.in.user_handle = u_handle; 671 687 d.out.user_handle = u_handle; 672 status = dcerpc_samr_DeleteUser(samr_pipe, mem_ctx, &d); 688 status = dcerpc_samr_DeleteUser_r(samr_pipe->binding_handle, mem_ctx, &d); 689 if (NT_STATUS_IS_OK(status) && !NT_STATUS_IS_OK(d.out.result)) { 690 status = d.out.result; 691 } 673 692 if (!NT_STATUS_IS_OK(status)) { 674 693 r->out.error_string = talloc_asprintf(mem_ctx, … … 683 702 684 703 /* &cu filled in above */ 685 status = dcerpc_samr_CreateUser2(samr_pipe, tmp_ctx, &cu); 704 status = dcerpc_samr_CreateUser2_r(samr_pipe->binding_handle, tmp_ctx, &cu); 705 if (NT_STATUS_IS_OK(status) && !NT_STATUS_IS_OK(cu.out.result)) { 706 status = cu.out.result; 707 } 686 708 if (!NT_STATUS_IS_OK(status)) { 687 709 r->out.error_string = talloc_asprintf(mem_ctx, … … 705 727 qui.out.info = &uinfo; 706 728 707 status = dcerpc_samr_QueryUserInfo(samr_pipe, tmp_ctx, &qui); 729 status = dcerpc_samr_QueryUserInfo_r(samr_pipe->binding_handle, tmp_ctx, &qui); 730 if (NT_STATUS_IS_OK(status) && !NT_STATUS_IS_OK(qui.out.result)) { 731 status = qui.out.result; 732 } 708 733 if (!NT_STATUS_IS_OK(status)) { 709 734 r->out.error_string = talloc_asprintf(mem_ctx, … … 790 815 pwp.out.info = &info; 791 816 792 status = dcerpc_samr_GetUserPwInfo(samr_pipe, tmp_ctx, &pwp); 817 status = dcerpc_samr_GetUserPwInfo_r(samr_pipe->binding_handle, tmp_ctx, &pwp); 818 if (NT_STATUS_IS_OK(status) && !NT_STATUS_IS_OK(pwp.out.result)) { 819 status = pwp.out.result; 820 } 793 821 if (NT_STATUS_IS_OK(status)) { 794 822 policy_min_pw_len = pwp.out.info->min_password_length; … … 797 825 /* Grab a password of that minimum length */ 798 826 799 password_str = generate_random_ str(tmp_ctx, MAX(8, policy_min_pw_len));827 password_str = generate_random_password(tmp_ctx, MAX(8, policy_min_pw_len), 255); 800 828 801 829 /* set full_name and reset flags */ … … 902 930 netbios_name = r->in.netbios_name; 903 931 } else { 904 netbios_name = talloc_strdup(tmp_mem, lp _netbios_name(ctx->lp_ctx));932 netbios_name = talloc_strdup(tmp_mem, lpcfg_netbios_name(ctx->lp_ctx)); 905 933 if (!netbios_name) { 906 934 r->out.error_string = NULL; … … 944 972 set_secrets->domain_name = r2->out.domain_name; 945 973 set_secrets->realm = r2->out.realm; 946 set_secrets->account_name = account_name;947 974 set_secrets->netbios_name = netbios_name; 948 975 set_secrets->secure_channel_type = r->in.join_type;
Note:
See TracChangeset
for help on using the changeset viewer.