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

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source4/libnet/libnet_join.c

    r414 r745  
    2323#include "libnet/libnet.h"
    2424#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>
    2827#include "dsdb/samdb/samdb.h"
    2928#include "ldb_wrap.h"
    30 #include "../lib/util/util_ldb.h"
    3129#include "libcli/security/security.h"
    3230#include "auth/credentials/credentials.h"
     
    3533#include "param/param.h"
    3634#include "param/provision.h"
     35#include "system/kerberos.h"
     36#include "auth/kerberos/kerberos.h"
    3737
    3838/*
     
    9595        }
    9696                                                   
    97         drsuapi_binding = talloc(tmp_ctx, struct dcerpc_binding);
     97        drsuapi_binding = talloc_zero(tmp_ctx, struct dcerpc_binding);
    9898        if (!drsuapi_binding) {
    9999                r->out.error_string = NULL;
     
    134134        r_drsuapi_bind.out.bind_handle = &drsuapi_bind_handle;
    135135
    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;
    153144        } else if (!W_ERROR_IS_OK(r_drsuapi_bind.out.result)) {
    154145                r->out.error_string
     
    185176
    186177        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);
    188179        if (!r_crack_names.out.ctr || !r_crack_names.out.level_out) {
    189180                r->out.error_string = NULL;
     
    192183        }
    193184
    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;
    213194        } else if (!W_ERROR_IS_OK(r_crack_names.out.result)) {
    214195                r->out.error_string
     
    246227        }
    247228
    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,
    249230                                      remote_ldb_url,
    250                                       NULL, ctx->cred, 0, NULL);
     231                                      NULL, ctx->cred, 0);
    251232        if (!remote_ldb) {
    252233                r->out.error_string = NULL;
     
    256237
    257238        account_dn = ldb_dn_new(tmp_ctx, remote_ldb, account_dn_str);
    258         if (! ldb_dn_validate(account_dn)) {
     239        if (account_dn == NULL) {
    259240                r->out.error_string = talloc_asprintf(r, "Invalid account dn: %s",
    260241                                                      account_dn_str);
     
    290271
    291272        {
    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,
    296277                                                                            "%s.%s",
    297278                                                                            r->in.netbios_name,
     
    304285                }
    305286
    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);
    312291               
    313292                for (i=0; i < ARRAY_SIZE(service_principal_name); i++) {
     
    317296                                return NT_STATUS_NO_MEMORY;
    318297                        }
    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) {
    321301                                r->out.error_string = NULL;
    322302                                talloc_free(tmp_ctx);
     
    325305                }
    326306
    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) {
    329309                        r->out.error_string = NULL;
    330310                        talloc_free(tmp_ctx);
     
    332312                }
    333313
    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) {
    336316                        r->out.error_string
    337317                                = talloc_asprintf(r,
     
    343323        }
    344324                               
     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
    345353        /* DsCrackNames to find out the DN of the domain. */
    346354        r_crack_names.in.req->req1.format_offered = DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
     
    353361        }
    354362
    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;
    374372        } else if (!W_ERROR_IS_OK(r_crack_names.out.result)) {
    375373                r->out.error_string
     
    540538
    541539        /* 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        }
    543544        if (!NT_STATUS_IS_OK(status)) {
    544545                r->out.error_string = talloc_asprintf(mem_ctx,
     
    554555                        connect_with_info->out.domain_name = talloc_strdup(tmp_ctx, r->in.domain_name);
    555556                } else {
    556                         /* Bugger, we just lost our way to automaticly 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));
    559560                }
    560561        }
     
    570571                l.out.sid = &sid;
    571572               
    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                }
    573577                if (!NT_STATUS_IS_OK(status)) {
    574578                        r->out.error_string = talloc_asprintf(mem_ctx,
     
    589593
    590594        /* 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        }
    592599        if (!NT_STATUS_IS_OK(status)) {
    593600                r->out.error_string = talloc_asprintf(mem_ctx,
     
    611618
    612619        /* 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        }
    614624        status = cu_status;
    615625        if (NT_STATUS_EQUAL(status, NT_STATUS_USER_EXISTS)) {
     
    628638               
    629639                /* 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                }
    631644                if (!NT_STATUS_IS_OK(status)) {
    632645                        r->out.error_string = talloc_asprintf(mem_ctx,
     
    656669               
    657670                /* 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                }
    659675                if (!NT_STATUS_IS_OK(status)) {
    660676                        r->out.error_string = talloc_asprintf(mem_ctx,
     
    670686                        d.in.user_handle = u_handle;
    671687                        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                        }
    673692                        if (!NT_STATUS_IS_OK(status)) {
    674693                                r->out.error_string = talloc_asprintf(mem_ctx,
     
    683702                       
    684703                        /* &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                        }
    686708                        if (!NT_STATUS_IS_OK(status)) {
    687709                                r->out.error_string = talloc_asprintf(mem_ctx,
     
    705727        qui.out.info = &uinfo;
    706728       
    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        }
    708733        if (!NT_STATUS_IS_OK(status)) {
    709734                r->out.error_string = talloc_asprintf(mem_ctx,
     
    790815        pwp.out.info = &info;
    791816
    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        }
    793821        if (NT_STATUS_IS_OK(status)) {
    794822                policy_min_pw_len = pwp.out.info->min_password_length;
     
    797825        /* Grab a password of that minimum length */
    798826       
    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);
    800828
    801829        /* set full_name and reset flags */
     
    902930                netbios_name = r->in.netbios_name;
    903931        } 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));
    905933                if (!netbios_name) {
    906934                        r->out.error_string = NULL;
     
    944972        set_secrets->domain_name = r2->out.domain_name;
    945973        set_secrets->realm = r2->out.realm;
    946         set_secrets->account_name = account_name;
    947974        set_secrets->netbios_name = netbios_name;
    948975        set_secrets->secure_channel_type = r->in.join_type;
Note: See TracChangeset for help on using the changeset viewer.