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:
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source4/torture/ldap/basic.c

    r414 r745  
    55   Copyright (C) Stefan Metzmacher 2004
    66   Copyright (C) Simo Sorce 2004
    7    Copyright (C) Matthias Dieter Wallnöfer 2009
     7   Copyright (C) Matthias Dieter Wallnöfer 2009-2010
    88   
    99   This program is free software; you can redistribute it and/or modify
     
    2323
    2424#include "includes.h"
     25#include "ldb_wrap.h"
    2526#include "libcli/ldap/ldap_client.h"
    2627#include "lib/cmdline/popt_common.h"
     
    2930#include "torture/ldap/proto.h"
    3031
    31 #include "param/param.h"
    3232
    3333static bool test_bind_simple(struct ldap_connection *conn, const char *userdn, const char *password)
     
    6464        bool ret = true;
    6565
    66         printf("Testing multiple binds on a single connnection as anonymous and user\n");
     66        printf("Testing multiple binds on a single connection as anonymous and user\n");
    6767
    6868        ret = test_bind_simple(conn, NULL, NULL);
     
    8080}
    8181
    82 static bool test_search_rootDSE(struct ldap_connection *conn, char **basedn)
     82static bool test_search_rootDSE(struct ldap_connection *conn, const char **basedn,
     83        const char ***partitions)
    8384{
    8485        bool ret = true;
     
    9293
    9394        *basedn = NULL;
     95
     96        if (partitions != NULL) {
     97                *partitions = const_str_list(str_list_make_empty(conn));
     98        }
    9499
    95100        msg = new_ldap_message(conn);
     
    139144                                                          (char *)r->attributes[i].values[j].data);
    140145                        }
     146                        if ((partitions != NULL) &&
     147                            (strcasecmp("namingContexts", r->attributes[i].name) == 0)) {
     148                                char *entry = talloc_asprintf(conn, "%.*s",
     149                                                              (int)r->attributes[i].values[j].length,
     150                                                              (char *)r->attributes[i].values[j].data);
     151                                *partitions = str_list_add(*partitions, entry);
     152                        }
    141153                }
    142154        }
    143 
    144         talloc_free(req);
    145155
    146156        return ret;
     
    209219}
    210220
     221/* This has to be done using the LDAP API since the LDB API does only transmit
     222 * the error code and not the error message. */
    211223static bool test_error_codes(struct torture_context *tctx,
    212224        struct ldap_connection *conn, const char *basedn)
     
    214226        struct ldap_message *msg, *rep;
    215227        struct ldap_request *req;
    216         char *err_code_str, *endptr;
     228        const char *err_code_str;
     229        char *endptr;
    217230        WERROR err;
    218231        NTSTATUS status;
    219232
    220         printf("Testing error codes - to make this test pass against SAMBA 4 you have to specify the target!\n");
     233        printf("Testing the most important error code -> error message conversions!\n");
    221234
    222235        if (!basedn) {
     
    243256        status = ldap_result_one(req, &rep, LDAP_TAG_AddResponse);
    244257        if (!NT_STATUS_IS_OK(status)) {
    245                 printf("error in ldap addition request - %s\n", nt_errstr(status));
     258                printf("error in ldap add request - %s\n", nt_errstr(status));
    246259                return false;
    247260        }
     
    258271        err_code_str = win_errstr(err);
    259272        printf(" - Errorcode: %s; Reason: %s\n", err_code_str, endptr);
    260         if (!torture_setting_bool(tctx, "samba4", false)) {
    261                 if ((!W_ERROR_EQUAL(err, WERR_DS_REFERRAL))
    262                         || (rep->r.AddResponse.resultcode != 10)) {
     273        if ((!W_ERROR_EQUAL(err, WERR_DS_REFERRAL))
     274                        || (rep->r.AddResponse.resultcode != LDAP_REFERRAL)) {
    263275                        return false;
    264                 }
    265         } else {
    266                 if ((!W_ERROR_EQUAL(err, WERR_DS_GENERIC_ERROR))
    267                         || (rep->r.AddResponse.resultcode != 80)) {
     276        }
     277        if ((rep->r.AddResponse.referral == NULL)
     278                        || (strstr(rep->r.AddResponse.referral, basedn) == NULL)) {
    268279                        return false;
    269                 }
     280        }
     281
     282        printf(" Try another wrong addition\n");
     283
     284        msg->type = LDAP_TAG_AddRequest;
     285        msg->r.AddRequest.dn = "";
     286        msg->r.AddRequest.num_attributes = 0;
     287        msg->r.AddRequest.attributes = NULL;
     288
     289        req = ldap_request_send(conn, msg);
     290        if (!req) {
     291                return false;
     292        }
     293
     294        status = ldap_result_one(req, &rep, LDAP_TAG_AddResponse);
     295        if (!NT_STATUS_IS_OK(status)) {
     296                printf("error in ldap add request - %s\n", nt_errstr(status));
     297                return false;
     298        }
     299
     300        if ((rep->r.AddResponse.resultcode == 0)
     301                || (rep->r.AddResponse.errormessage == NULL)
     302                || (strtol(rep->r.AddResponse.errormessage, &endptr,16) <= 0)
     303                || (*endptr != ':')) {
     304                printf("Invalid error message!\n");
     305                return false;
     306        }
     307
     308        err = ad_error(rep->r.AddResponse.errormessage, &endptr);
     309        err_code_str = win_errstr(err);
     310        printf(" - Errorcode: %s; Reason: %s\n", err_code_str, endptr);
     311        if ((!W_ERROR_EQUAL(err, WERR_DS_ROOT_MUST_BE_NC) &&
     312             !W_ERROR_EQUAL(err, WERR_DS_NAMING_VIOLATION))
     313                || (rep->r.AddResponse.resultcode != LDAP_NAMING_VIOLATION)) {
     314                return false;
    270315        }
    271316
    272317        printf(" Try a wrong modification\n");
     318
     319        msg->type = LDAP_TAG_ModifyRequest;
     320        msg->r.ModifyRequest.dn = basedn;
     321        msg->r.ModifyRequest.num_mods = 0;
     322        msg->r.ModifyRequest.mods = NULL;
     323
     324        req = ldap_request_send(conn, msg);
     325        if (!req) {
     326                return false;
     327        }
     328
     329        status = ldap_result_one(req, &rep, LDAP_TAG_ModifyResponse);
     330        if (!NT_STATUS_IS_OK(status)) {
     331                printf("error in ldap modifification request - %s\n", nt_errstr(status));
     332                return false;
     333        }
     334
     335        if ((rep->r.ModifyResponse.resultcode == 0)
     336                || (rep->r.ModifyResponse.errormessage == NULL)
     337                || (strtol(rep->r.ModifyResponse.errormessage, &endptr,16) <= 0)
     338                || (*endptr != ':')) {
     339                printf("Invalid error message!\n");
     340                return false;
     341        }
     342
     343        err = ad_error(rep->r.ModifyResponse.errormessage, &endptr);
     344        err_code_str = win_errstr(err);
     345        printf(" - Errorcode: %s; Reason: %s\n", err_code_str, endptr);
     346        if ((!W_ERROR_EQUAL(err, WERR_INVALID_PARAM) &&
     347             !W_ERROR_EQUAL(err, WERR_DS_UNWILLING_TO_PERFORM))
     348                || (rep->r.ModifyResponse.resultcode != LDAP_UNWILLING_TO_PERFORM)) {
     349                return false;
     350        }
     351
     352        printf(" Try another wrong modification\n");
    273353
    274354        msg->type = LDAP_TAG_ModifyRequest;
     
    299379        err_code_str = win_errstr(err);
    300380        printf(" - Errorcode: %s; Reason: %s\n", err_code_str, endptr);
    301         if (!torture_setting_bool(tctx, "samba4", false)) {
    302                 if ((!W_ERROR_EQUAL(err, WERR_INVALID_PARAM))
    303                         || (rep->r.ModifyResponse.resultcode != 53)) {
    304                         return false;
    305                 }
    306         } else {
    307                 if ((!W_ERROR_EQUAL(err, WERR_DS_GENERIC_ERROR))
    308                         || (rep->r.ModifyResponse.resultcode != 80)) {
    309                         return false;
    310                 }
     381        if ((!W_ERROR_EQUAL(err, WERR_INVALID_PARAM) &&
     382             !W_ERROR_EQUAL(err, WERR_DS_UNWILLING_TO_PERFORM))
     383                || (rep->r.ModifyResponse.resultcode != LDAP_UNWILLING_TO_PERFORM)) {
     384                return false;
    311385        }
    312386
     
    314388
    315389        msg->type = LDAP_TAG_DelRequest;
    316         msg->r.DelRequest.dn = "";
     390        msg->r.DelRequest.dn = basedn;
    317391
    318392        req = ldap_request_send(conn, msg);
     
    334408                return false;
    335409        }
     410
     411        err = ad_error(rep->r.DelResponse.errormessage, &endptr);
     412        err_code_str = win_errstr(err);
     413        printf(" - Errorcode: %s; Reason: %s\n", err_code_str, endptr);
     414        if ((!W_ERROR_EQUAL(err, WERR_DS_CANT_DELETE) &&
     415             !W_ERROR_EQUAL(err, WERR_DS_UNWILLING_TO_PERFORM))
     416                || (rep->r.DelResponse.resultcode != LDAP_UNWILLING_TO_PERFORM)) {
     417                return false;
     418        }
     419
     420        printf(" Try another wrong removal\n");
     421
     422        msg->type = LDAP_TAG_DelRequest;
     423        msg->r.DelRequest.dn = "";
     424
     425        req = ldap_request_send(conn, msg);
     426        if (!req) {
     427                return false;
     428        }
     429
     430        status = ldap_result_one(req, &rep, LDAP_TAG_DelResponse);
     431        if (!NT_STATUS_IS_OK(status)) {
     432                printf("error in ldap removal request - %s\n", nt_errstr(status));
     433                return false;
     434        }
     435
     436        if ((rep->r.DelResponse.resultcode == 0)
     437                || (rep->r.DelResponse.errormessage == NULL)
     438                || (strtol(rep->r.DelResponse.errormessage, &endptr,16) <= 0)
     439                || (*endptr != ':')) {
     440                printf("Invalid error message!\n");
     441                return false;
     442        }
    336443       
    337444        err = ad_error(rep->r.DelResponse.errormessage, &endptr);
    338445        err_code_str = win_errstr(err);
    339446        printf(" - Errorcode: %s; Reason: %s\n", err_code_str, endptr);
    340         if (!torture_setting_bool(tctx, "samba4", false)) {
    341                 if ((!W_ERROR_EQUAL(err, WERR_DS_OBJ_NOT_FOUND))
    342                         || (rep->r.DelResponse.resultcode != 32)) {
     447        if ((!W_ERROR_EQUAL(err, WERR_DS_OBJ_NOT_FOUND) &&
     448             !W_ERROR_EQUAL(err, WERR_DS_NO_SUCH_OBJECT))
     449                || (rep->r.DelResponse.resultcode != LDAP_NO_SUCH_OBJECT)) {
     450                return false;
     451        }
     452
     453        printf(" Try a wrong rename\n");
     454
     455        msg->type = LDAP_TAG_ModifyDNRequest;
     456        msg->r.ModifyDNRequest.dn = basedn;
     457        msg->r.ModifyDNRequest.newrdn = "dc=test";
     458        msg->r.ModifyDNRequest.deleteolddn = true;
     459        msg->r.ModifyDNRequest.newsuperior = NULL;
     460
     461        req = ldap_request_send(conn, msg);
     462        if (!req) {
     463                return false;
     464        }
     465
     466        status = ldap_result_one(req, &rep, LDAP_TAG_ModifyDNResponse);
     467        if (!NT_STATUS_IS_OK(status)) {
     468                printf("error in ldap rename request - %s\n", nt_errstr(status));
     469                return false;
     470        }
     471
     472        if ((rep->r.ModifyDNResponse.resultcode == 0)
     473                || (rep->r.ModifyDNResponse.errormessage == NULL)
     474                || (strtol(rep->r.ModifyDNResponse.errormessage, &endptr,16) <= 0)
     475                || (*endptr != ':')) {
     476                printf("Invalid error message!\n");
     477                return false;
     478        }
     479
     480        err = ad_error(rep->r.ModifyDNResponse.errormessage, &endptr);
     481        err_code_str = win_errstr(err);
     482        printf(" - Errorcode: %s; Reason: %s\n", err_code_str, endptr);
     483        if ((!W_ERROR_EQUAL(err, WERR_DS_NO_PARENT_OBJECT) &&
     484             !W_ERROR_EQUAL(err, WERR_DS_GENERIC_ERROR))
     485                || (rep->r.ModifyDNResponse.resultcode != LDAP_OTHER)) {
     486                return false;
     487        }
     488
     489        printf(" Try another wrong rename\n");
     490
     491        msg->type = LDAP_TAG_ModifyDNRequest;
     492        msg->r.ModifyDNRequest.dn = basedn;
     493        msg->r.ModifyDNRequest.newrdn = basedn;
     494        msg->r.ModifyDNRequest.deleteolddn = true;
     495        msg->r.ModifyDNRequest.newsuperior = NULL;
     496
     497        req = ldap_request_send(conn, msg);
     498        if (!req) {
     499                return false;
     500        }
     501
     502        status = ldap_result_one(req, &rep, LDAP_TAG_ModifyDNResponse);
     503        if (!NT_STATUS_IS_OK(status)) {
     504                printf("error in ldap rename request - %s\n", nt_errstr(status));
     505                return false;
     506        }
     507
     508        if ((rep->r.ModifyDNResponse.resultcode == 0)
     509                || (rep->r.ModifyDNResponse.errormessage == NULL)
     510                || (strtol(rep->r.ModifyDNResponse.errormessage, &endptr,16) <= 0)
     511                || (*endptr != ':')) {
     512                printf("Invalid error message!\n");
     513                return false;
     514        }
     515
     516        err = ad_error(rep->r.ModifyDNResponse.errormessage, &endptr);
     517        err_code_str = win_errstr(err);
     518        printf(" - Errorcode: %s; Reason: %s\n", err_code_str, endptr);
     519        if ((!W_ERROR_EQUAL(err, WERR_INVALID_PARAM) &&
     520             !W_ERROR_EQUAL(err, WERR_DS_NAMING_VIOLATION))
     521                || (rep->r.ModifyDNResponse.resultcode != LDAP_NAMING_VIOLATION)) {
     522                return false;
     523        }
     524
     525        printf(" Try another wrong rename\n");
     526
     527        msg->type = LDAP_TAG_ModifyDNRequest;
     528        msg->r.ModifyDNRequest.dn = basedn;
     529        msg->r.ModifyDNRequest.newrdn = "";
     530        msg->r.ModifyDNRequest.deleteolddn = true;
     531        msg->r.ModifyDNRequest.newsuperior = NULL;
     532
     533        req = ldap_request_send(conn, msg);
     534        if (!req) {
     535                return false;
     536        }
     537
     538        status = ldap_result_one(req, &rep, LDAP_TAG_ModifyDNResponse);
     539        if (!NT_STATUS_IS_OK(status)) {
     540                printf("error in ldap rename request - %s\n", nt_errstr(status));
     541                return false;
     542        }
     543
     544        if ((rep->r.ModifyDNResponse.resultcode == 0)
     545                || (rep->r.ModifyDNResponse.errormessage == NULL)
     546                || (strtol(rep->r.ModifyDNResponse.errormessage, &endptr,16) <= 0)
     547                || (*endptr != ':')) {
     548                printf("Invalid error message!\n");
     549                return false;
     550        }
     551
     552        err = ad_error(rep->r.ModifyDNResponse.errormessage, &endptr);
     553        err_code_str = win_errstr(err);
     554        printf(" - Errorcode: %s; Reason: %s\n", err_code_str, endptr);
     555        if ((!W_ERROR_EQUAL(err, WERR_INVALID_PARAM) &&
     556             !W_ERROR_EQUAL(err, WERR_DS_PROTOCOL_ERROR))
     557                || (rep->r.ModifyDNResponse.resultcode != LDAP_PROTOCOL_ERROR)) {
     558                return false;
     559        }
     560
     561        printf(" Try another wrong rename\n");
     562
     563        msg->type = LDAP_TAG_ModifyDNRequest;
     564        msg->r.ModifyDNRequest.dn = "";
     565        msg->r.ModifyDNRequest.newrdn = "cn=temp";
     566        msg->r.ModifyDNRequest.deleteolddn = true;
     567        msg->r.ModifyDNRequest.newsuperior = NULL;
     568
     569        req = ldap_request_send(conn, msg);
     570        if (!req) {
     571                return false;
     572        }
     573
     574        status = ldap_result_one(req, &rep, LDAP_TAG_ModifyDNResponse);
     575        if (!NT_STATUS_IS_OK(status)) {
     576                printf("error in ldap rename request - %s\n", nt_errstr(status));
     577                return false;
     578        }
     579
     580        if ((rep->r.ModifyDNResponse.resultcode == 0)
     581                || (rep->r.ModifyDNResponse.errormessage == NULL)
     582                || (strtol(rep->r.ModifyDNResponse.errormessage, &endptr,16) <= 0)
     583                || (*endptr != ':')) {
     584                printf("Invalid error message!\n");
     585                return false;
     586        }
     587
     588        err = ad_error(rep->r.ModifyDNResponse.errormessage, &endptr);
     589        err_code_str = win_errstr(err);
     590        printf(" - Errorcode: %s; Reason: %s\n", err_code_str, endptr);
     591        if ((!W_ERROR_EQUAL(err, WERR_DS_OBJ_NOT_FOUND) &&
     592             !W_ERROR_EQUAL(err, WERR_DS_NO_SUCH_OBJECT))
     593                || (rep->r.ModifyDNResponse.resultcode != LDAP_NO_SUCH_OBJECT)) {
     594                return false;
     595        }
     596
     597        return true;
     598}
     599
     600static bool test_referrals(struct torture_context *tctx, TALLOC_CTX *mem_ctx,
     601        const char *url, const char *basedn, const char **partitions)
     602{
     603        struct ldb_context *ldb;
     604        struct ldb_result *res;
     605        const char * const *attrs = { NULL };
     606        struct ldb_dn *dn1, *dn2;
     607        int ret;
     608        int i, j, k;
     609        char *tempstr;
     610        bool found, l_found;
     611
     612        printf("Testing referrals\n");
     613
     614        if (partitions[0] == NULL) {
     615                printf("Partitions list empty!\n");
     616                return false;
     617        }
     618
     619        if (strcmp(partitions[0], basedn) != 0) {
     620                printf("The first (root) partition DN should be the base DN!\n");
     621                return false;
     622        }
     623
     624        ldb = ldb_wrap_connect(mem_ctx, tctx->ev, tctx->lp_ctx, url,
     625                               NULL, cmdline_credentials, 0);
     626
     627        /* "partitions[i]" are the partitions for which we search the parents */
     628        for (i = 1; partitions[i] != NULL; i++) {
     629                dn1 = ldb_dn_new(mem_ctx, ldb, partitions[i]);
     630                if (dn1 == NULL) {
     631                        printf("Out of memory\n");
     632                        talloc_free(ldb);
    343633                        return false;
    344634                }
    345         } else {
    346                 if ((!W_ERROR_EQUAL(err, WERR_DS_INVALID_DN_SYNTAX))
    347                         || (rep->r.DelResponse.resultcode != 34)) {
    348                         return false;
     635
     636                /* search using base scope */
     637                /* "partitions[j]" are the parent candidates */
     638                for (j = str_list_length(partitions) - 1; j >= 0; --j) {
     639                        dn2 = ldb_dn_new(mem_ctx, ldb, partitions[j]);
     640                        if (dn2 == NULL) {
     641                                printf("Out of memory\n");
     642                                talloc_free(ldb);
     643                                return false;
     644                        }
     645
     646                        ret = ldb_search(ldb, mem_ctx, &res, dn2,
     647                                         LDB_SCOPE_BASE, attrs,
     648                                         "(foo=bar)");
     649                        if (ret != LDB_SUCCESS) {
     650                                printf("%s", ldb_errstring(ldb));
     651                                talloc_free(ldb);
     652                                return false;
     653                        }
     654
     655                        if (res->refs != NULL) {
     656                                printf("There shouldn't be generated any referrals in the base scope!\n");
     657                                talloc_free(ldb);
     658                                return false;
     659                        }
     660
     661                        talloc_free(res);
     662                        talloc_free(dn2);
    349663                }
    350         }
     664
     665                /* search using onelevel scope */
     666                found = false;
     667                /* "partitions[j]" are the parent candidates */
     668                for (j = str_list_length(partitions) - 1; j >= 0; --j) {
     669                        dn2 = ldb_dn_new(mem_ctx, ldb, partitions[j]);
     670                        if (dn2 == NULL) {
     671                                printf("Out of memory\n");
     672                                talloc_free(ldb);
     673                                return false;
     674                        }
     675
     676                        ret = ldb_search(ldb, mem_ctx, &res, dn2,
     677                                         LDB_SCOPE_ONELEVEL, attrs,
     678                                         "(foo=bar)");
     679                        if (ret != LDB_SUCCESS) {
     680                                printf("%s", ldb_errstring(ldb));
     681                                talloc_free(ldb);
     682                                return false;
     683                        }
     684
     685                        tempstr = talloc_asprintf(mem_ctx, "/%s??base",
     686                                                  partitions[i]);
     687                        if (tempstr == NULL) {
     688                                printf("Out of memory\n");
     689                                talloc_free(ldb);
     690                                return false;
     691                        }
     692
     693                        /* Try to find or find not a matching referral */
     694                        l_found = false;
     695                        for (k = 0; (!l_found) && (res->refs != NULL)
     696                            && (res->refs[k] != NULL); k++) {
     697                                if (strstr(res->refs[k], tempstr) != NULL) {
     698                                        l_found = true;
     699                                }
     700                        }
     701
     702                        talloc_free(tempstr);
     703
     704                        if ((!found) && (ldb_dn_compare_base(dn2, dn1) == 0)
     705                            && (ldb_dn_compare(dn2, dn1) != 0)) {
     706                                /* This is a referral candidate */
     707                                if (!l_found) {
     708                                        printf("A required referral hasn't been found on onelevel scope (%s -> %s)!\n", partitions[j], partitions[i]);
     709                                        talloc_free(ldb);
     710                                        return false;
     711                                }
     712                                found = true;
     713                        } else {
     714                                /* This isn't a referral candidate */
     715                                if (l_found) {
     716                                        printf("A unrequired referral has been found on onelevel scope (%s -> %s)!\n", partitions[j], partitions[i]);
     717                                        talloc_free(ldb);
     718                                        return false;
     719                                }
     720                        }
     721
     722                        talloc_free(res);
     723                        talloc_free(dn2);
     724                }
     725
     726                /* search using subtree scope */
     727                found = false;
     728                /* "partitions[j]" are the parent candidates */
     729                for (j = str_list_length(partitions) - 1; j >= 0; --j) {
     730                        dn2 = ldb_dn_new(mem_ctx, ldb, partitions[j]);
     731                        if (dn2 == NULL) {
     732                                printf("Out of memory\n");
     733                                talloc_free(ldb);
     734                                return false;
     735                        }
     736
     737                        ret = ldb_search(ldb, mem_ctx, &res, dn2,
     738                                         LDB_SCOPE_SUBTREE, attrs,
     739                                         "(foo=bar)");
     740                        if (ret != LDB_SUCCESS) {
     741                                printf("%s", ldb_errstring(ldb));
     742                                talloc_free(ldb);
     743                                return false;
     744                        }
     745
     746                        tempstr = talloc_asprintf(mem_ctx, "/%s",
     747                                                  partitions[i]);
     748                        if (tempstr == NULL) {
     749                                printf("Out of memory\n");
     750                                talloc_free(ldb);
     751                                return false;
     752                        }
     753
     754                        /* Try to find or find not a matching referral */
     755                        l_found = false;
     756                        for (k = 0; (!l_found) && (res->refs != NULL)
     757                            && (res->refs[k] != NULL); k++) {
     758                                if (strstr(res->refs[k], tempstr) != NULL) {
     759                                        l_found = true;
     760                                }
     761                        }
     762
     763                        talloc_free(tempstr);
     764
     765                        if ((!found) && (ldb_dn_compare_base(dn2, dn1) == 0)
     766                            && (ldb_dn_compare(dn2, dn1) != 0)) {
     767                                /* This is a referral candidate */
     768                                if (!l_found) {
     769                                        printf("A required referral hasn't been found on subtree scope (%s -> %s)!\n", partitions[j], partitions[i]);
     770                                        talloc_free(ldb);
     771                                        return false;
     772                                }
     773                                found = true;
     774                        } else {
     775                                /* This isn't a referral candidate */
     776                                if (l_found) {
     777                                        printf("A unrequired referral has been found on subtree scope (%s -> %s)!\n", partitions[j], partitions[i]);
     778                                        talloc_free(ldb);
     779                                        return false;
     780                                }
     781                        }
     782
     783                        talloc_free(res);
     784                        talloc_free(dn2);
     785                }
     786
     787                talloc_free(dn1);
     788        }
     789
     790        talloc_free(ldb);
    351791
    352792        return true;
    353793}
     794
     795static bool test_abandom_request(struct torture_context *tctx,
     796        struct ldap_connection *conn, const char *basedn)
     797{
     798        struct ldap_message *msg;
     799        struct ldap_request *req;
     800        NTSTATUS status;
     801
     802        printf("Testing the AbandonRequest with an old message id!\n");
     803
     804        if (!basedn) {
     805                return false;
     806        }
     807
     808        msg = new_ldap_message(conn);
     809        if (!msg) {
     810                return false;
     811        }
     812
     813        printf(" Try a AbandonRequest for an old message id\n");
     814
     815        msg->type = LDAP_TAG_AbandonRequest;
     816        msg->r.AbandonRequest.messageid = 1;
     817
     818        req = ldap_request_send(conn, msg);
     819        if (!req) {
     820                return false;
     821        }
     822
     823        status = ldap_request_wait(req);
     824        if (!NT_STATUS_IS_OK(status)) {
     825                printf("error in ldap abandon request - %s\n", nt_errstr(status));
     826                return false;
     827        }
     828
     829        return true;
     830}
     831
    354832
    355833bool torture_ldap_basic(struct torture_context *torture)
     
    362840        const char *userdn = torture_setting_string(torture, "ldap_userdn", NULL);
    363841        const char *secret = torture_setting_string(torture, "ldap_secret", NULL);
    364         char *url;
    365         char *basedn;
     842        const char *url;
     843        const char *basedn;
     844        const char **partitions;
    366845
    367846        mem_ctx = talloc_init("torture_ldap_basic");
     
    374853        }
    375854
    376         if (!test_search_rootDSE(conn, &basedn)) {
     855        if (!test_search_rootDSE(conn, &basedn, &partitions)) {
    377856                ret = false;
    378857        }
     
    395874
    396875        if (!test_error_codes(torture, conn, basedn)) {
     876                ret = false;
     877        }
     878
     879        /* referrals test here */
     880
     881        if (!test_referrals(torture, mem_ctx, url, basedn, partitions)) {
     882                ret = false;
     883        }
     884
     885        if (!test_abandom_request(torture, conn, basedn)) {
    397886                ret = false;
    398887        }
  • trunk/server/source4/torture/ldap/cldap.c

    r414 r745  
    55   
    66   Copyright (C) Andrew Tridgell 2005
     7   Copyright (C) Matthias Dieter Wallnöfer 2009
    78   
    89   This program is free software; you can redistribute it and/or modify
     
    2324#include "includes.h"
    2425#include "libcli/cldap/cldap.h"
    25 #include "libcli/ldap/ldap.h"
    26 #include "librpc/gen_ndr/ndr_nbt.h"
     26#include "libcli/ldap/libcli_ldap.h"
    2727#include "librpc/gen_ndr/netlogon.h"
    2828#include "torture/torture.h"
    29 #include "lib/ldb/include/ldb.h"
    3029#include "param/param.h"
    3130#include "../lib/tsocket/tsocket.h"
     
    4746        struct GUID guid;
    4847        int i;
    49         struct smb_iconv_convenience *iconv_convenience = lp_iconv_convenience(tctx->lp_ctx);
    5048        struct tsocket_address *dest_addr;
    5149        int ret;
     
    5351        ret = tsocket_address_inet_from_strings(tctx, "ip",
    5452                                                dest,
    55                                                 lp_cldap_port(tctx->lp_ctx),
     53                                                lpcfg_cldap_port(tctx->lp_ctx),
    5654                                                &dest_addr);
    5755        CHECK_VAL(ret, 0);
     
    7169        printf("Trying without any attributes\n");
    7270        search = empty_search;
    73         status = cldap_netlogon(cldap, iconv_convenience, tctx, &search);
     71        status = cldap_netlogon(cldap, tctx, &search);
    7472        CHECK_STATUS(status, NT_STATUS_OK);
    7573
     
    8482                search.in.version = i;
    8583                printf("Trying netlogon level %d\n", i);
    86                 status = cldap_netlogon(cldap, iconv_convenience, tctx, &search);
     84                status = cldap_netlogon(cldap, tctx, &search);
    8785                CHECK_STATUS(status, NT_STATUS_OK);
    8886        }
     
    9290                search.in.version = (1<<i);
    9391                printf("Trying netlogon level 0x%x\n", i);
    94                 status = cldap_netlogon(cldap, iconv_convenience, tctx, &search);
     92                status = cldap_netlogon(cldap, tctx, &search);
    9593                CHECK_STATUS(status, NT_STATUS_OK);
    9694        }
    9795
    9896        search.in.version = NETLOGON_NT_VERSION_5|NETLOGON_NT_VERSION_5EX|NETLOGON_NT_VERSION_IP;
    99 
    100         status = cldap_netlogon(cldap, iconv_convenience, tctx, &search);
     97        status = cldap_netlogon(cldap, tctx, &search);
    10198        CHECK_STATUS(status, NT_STATUS_OK);
    10299
    103100        printf("Trying with User=NULL\n");
    104 
    105101        search.in.user = NULL;
    106         status = cldap_netlogon(cldap, iconv_convenience, tctx, &search);
    107         CHECK_STATUS(status, NT_STATUS_OK);
    108         CHECK_STRING(search.out.netlogon.data.nt5_ex.user_name, "");
    109         CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE_EX);
     102        status = cldap_netlogon(cldap, tctx, &search);
     103        CHECK_STATUS(status, NT_STATUS_OK);
     104        CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE_EX);
     105        CHECK_STRING(search.out.netlogon.data.nt5_ex.user_name, "");
    110106
    111107        printf("Trying with User=Administrator\n");
    112 
    113108        search.in.user = "Administrator";
    114         status = cldap_netlogon(cldap, iconv_convenience, tctx, &search);
    115         CHECK_STATUS(status, NT_STATUS_OK);
    116 
     109        status = cldap_netlogon(cldap, tctx, &search);
     110        CHECK_STATUS(status, NT_STATUS_OK);
     111        CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_USER_UNKNOWN_EX);
    117112        CHECK_STRING(search.out.netlogon.data.nt5_ex.user_name, search.in.user);
    118         CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_USER_UNKNOWN_EX);
    119113
    120114        search.in.version = NETLOGON_NT_VERSION_5;
    121         status = cldap_netlogon(cldap, iconv_convenience, tctx, &search);
     115        status = cldap_netlogon(cldap, tctx, &search);
    122116        CHECK_STATUS(status, NT_STATUS_OK);
    123117
    124118        printf("Trying with User=NULL\n");
    125 
    126119        search.in.user = NULL;
    127         status = cldap_netlogon(cldap, iconv_convenience, tctx, &search);
    128         CHECK_STATUS(status, NT_STATUS_OK);
    129         CHECK_STRING(search.out.netlogon.data.nt5_ex.user_name, "");
     120        status = cldap_netlogon(cldap, tctx, &search);
     121        CHECK_STATUS(status, NT_STATUS_OK);
    130122        CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE);
     123        CHECK_STRING(search.out.netlogon.data.nt5_ex.user_name, "");
    131124
    132125        printf("Trying with User=Administrator\n");
    133 
    134126        search.in.user = "Administrator";
    135         status = cldap_netlogon(cldap, iconv_convenience, tctx, &search);
    136         CHECK_STATUS(status, NT_STATUS_OK);
    137 
     127        status = cldap_netlogon(cldap, tctx, &search);
     128        CHECK_STATUS(status, NT_STATUS_OK);
     129        CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_USER_UNKNOWN);
    138130        CHECK_STRING(search.out.netlogon.data.nt5_ex.user_name, search.in.user);
    139         CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_USER_UNKNOWN);
    140131
    141132        search.in.version = NETLOGON_NT_VERSION_5 | NETLOGON_NT_VERSION_5EX;
     
    144135        search.in.realm       = NULL;
    145136        search.in.domain_guid = GUID_string(tctx, &n1.data.nt5_ex.domain_uuid);
    146         status = cldap_netlogon(cldap, iconv_convenience, tctx, &search);
     137        status = cldap_netlogon(cldap, tctx, &search);
    147138        CHECK_STATUS(status, NT_STATUS_OK);
    148139        CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_USER_UNKNOWN_EX);
     
    153144        search.in.user        = NULL;
    154145        search.in.domain_guid = GUID_string(tctx, &guid);
    155         status = cldap_netlogon(cldap, iconv_convenience, tctx, &search);
     146        status = cldap_netlogon(cldap, tctx, &search);
    156147        CHECK_STATUS(status, NT_STATUS_NOT_FOUND);
    157148
     
    159150        search.in.acct_control = ACB_WSTRUST|ACB_SVRTRUST;
    160151        search.in.realm = n1.data.nt5_ex.dns_domain;
    161         status = cldap_netlogon(cldap, iconv_convenience, tctx, &search);
     152        status = cldap_netlogon(cldap, tctx, &search);
    162153        CHECK_STATUS(status, NT_STATUS_OK);
    163154        CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE_EX);
     
    167158        search.in.acct_control = 0x0;
    168159        search.in.realm = n1.data.nt5_ex.dns_domain;
    169         status = cldap_netlogon(cldap, iconv_convenience, tctx, &search);
     160        status = cldap_netlogon(cldap, tctx, &search);
    170161        CHECK_STATUS(status, NT_STATUS_OK);
    171162        CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE_EX);
     
    176167        search.in.user = "Administrator";
    177168        search.in.realm = n1.data.nt5_ex.dns_domain;
    178         status = cldap_netlogon(cldap, iconv_convenience, tctx, &search);
     169        status = cldap_netlogon(cldap, tctx, &search);
    179170        CHECK_STATUS(status, NT_STATUS_OK);
    180171        CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_USER_UNKNOWN_EX);
     
    185176        search.in.acct_control = 0xFF00FF00;
    186177        search.in.realm = n1.data.nt5_ex.dns_domain;
    187         status = cldap_netlogon(cldap, iconv_convenience, tctx, &search);
     178        status = cldap_netlogon(cldap, tctx, &search);
    188179        CHECK_STATUS(status, NT_STATUS_OK);
    189180        CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE_EX);
     
    193184        search = empty_search;
    194185        search.in.user = "Administrator";
    195         status = cldap_netlogon(cldap, iconv_convenience, tctx, &search);
    196         CHECK_STATUS(status, NT_STATUS_OK);
     186        status = cldap_netlogon(cldap, tctx, &search);
     187        CHECK_STATUS(status, NT_STATUS_OK);
     188        CHECK_STRING(search.out.netlogon.data.nt5_ex.forest, n1.data.nt5_ex.dns_domain);
    197189        CHECK_STRING(search.out.netlogon.data.nt5_ex.dns_domain, n1.data.nt5_ex.dns_domain);
     190        CHECK_STRING(search.out.netlogon.data.nt5_ex.domain_name, n1.data.nt5_ex.domain_name);
     191        CHECK_STRING(search.out.netlogon.data.nt5_ex.pdc_name, n1.data.nt5_ex.pdc_name);
    198192        CHECK_STRING(search.out.netlogon.data.nt5_ex.user_name, search.in.user);
     193        CHECK_STRING(search.out.netlogon.data.nt5_ex.server_site, n1.data.nt5_ex.server_site);
     194        CHECK_STRING(search.out.netlogon.data.nt5_ex.client_site, n1.data.nt5_ex.client_site);
    199195
    200196        printf("Trying with just a bad username\n");
    201197        search.in.user = "___no_such_user___";
    202         status = cldap_netlogon(cldap, iconv_convenience, tctx, &search);
    203         CHECK_STATUS(status, NT_STATUS_OK);
     198        status = cldap_netlogon(cldap, tctx, &search);
     199        CHECK_STATUS(status, NT_STATUS_OK);
     200        CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_USER_UNKNOWN_EX);
     201        CHECK_STRING(search.out.netlogon.data.nt5_ex.forest, n1.data.nt5_ex.dns_domain);
     202        CHECK_STRING(search.out.netlogon.data.nt5_ex.dns_domain, n1.data.nt5_ex.dns_domain);
     203        CHECK_STRING(search.out.netlogon.data.nt5_ex.domain_name, n1.data.nt5_ex.domain_name);
     204        CHECK_STRING(search.out.netlogon.data.nt5_ex.pdc_name, n1.data.nt5_ex.pdc_name);
    204205        CHECK_STRING(search.out.netlogon.data.nt5_ex.user_name, search.in.user);
    205         CHECK_STRING(search.out.netlogon.data.nt5_ex.dns_domain, n1.data.nt5_ex.dns_domain);
    206         CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_USER_UNKNOWN_EX);
     206        CHECK_STRING(search.out.netlogon.data.nt5_ex.server_site, n1.data.nt5_ex.server_site);
     207        CHECK_STRING(search.out.netlogon.data.nt5_ex.client_site, n1.data.nt5_ex.client_site);
    207208
    208209        printf("Trying with just a bad domain\n");
    209210        search = empty_search;
    210211        search.in.realm = "___no_such_domain___";
    211         status = cldap_netlogon(cldap, iconv_convenience, tctx, &search);
     212        status = cldap_netlogon(cldap, tctx, &search);
    212213        CHECK_STATUS(status, NT_STATUS_NOT_FOUND);
    213214
    214215        printf("Trying with a incorrect domain and correct guid\n");
    215216        search.in.domain_guid = GUID_string(tctx, &n1.data.nt5_ex.domain_uuid);
    216         status = cldap_netlogon(cldap, iconv_convenience, tctx, &search);
    217         CHECK_STATUS(status, NT_STATUS_OK);
     217        status = cldap_netlogon(cldap, tctx, &search);
     218        CHECK_STATUS(status, NT_STATUS_OK);
     219        CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE_EX);
     220        CHECK_STRING(search.out.netlogon.data.nt5_ex.forest, n1.data.nt5_ex.dns_domain);
    218221        CHECK_STRING(search.out.netlogon.data.nt5_ex.dns_domain, n1.data.nt5_ex.dns_domain);
    219         CHECK_STRING(search.out.netlogon.data.nt5_ex.user_name, "");
    220         CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE_EX);
     222        CHECK_STRING(search.out.netlogon.data.nt5_ex.domain_name, n1.data.nt5_ex.domain_name);
     223        CHECK_STRING(search.out.netlogon.data.nt5_ex.pdc_name, n1.data.nt5_ex.pdc_name);
     224        CHECK_STRING(search.out.netlogon.data.nt5_ex.user_name, "");
     225        CHECK_STRING(search.out.netlogon.data.nt5_ex.server_site, n1.data.nt5_ex.server_site);
     226        CHECK_STRING(search.out.netlogon.data.nt5_ex.client_site, n1.data.nt5_ex.client_site);
    221227
    222228        printf("Trying with a incorrect domain and incorrect guid\n");
    223229        search.in.domain_guid = GUID_string(tctx, &guid);
    224         status = cldap_netlogon(cldap, iconv_convenience, tctx, &search);
     230        status = cldap_netlogon(cldap, tctx, &search);
    225231        CHECK_STATUS(status, NT_STATUS_NOT_FOUND);
     232        CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE_EX);
     233        CHECK_STRING(search.out.netlogon.data.nt5_ex.forest, n1.data.nt5_ex.dns_domain);
    226234        CHECK_STRING(search.out.netlogon.data.nt5_ex.dns_domain, n1.data.nt5_ex.dns_domain);
    227         CHECK_STRING(search.out.netlogon.data.nt5_ex.user_name, "");
    228         CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE_EX);
     235        CHECK_STRING(search.out.netlogon.data.nt5_ex.domain_name, n1.data.nt5_ex.domain_name);
     236        CHECK_STRING(search.out.netlogon.data.nt5_ex.pdc_name, n1.data.nt5_ex.pdc_name);
     237        CHECK_STRING(search.out.netlogon.data.nt5_ex.user_name, "");
     238        CHECK_STRING(search.out.netlogon.data.nt5_ex.server_site, n1.data.nt5_ex.server_site);
     239        CHECK_STRING(search.out.netlogon.data.nt5_ex.client_site, n1.data.nt5_ex.client_site);
    229240
    230241        printf("Trying with a incorrect GUID and correct domain\n");
    231242        search.in.domain_guid = GUID_string(tctx, &guid);
    232243        search.in.realm = n1.data.nt5_ex.dns_domain;
    233         status = cldap_netlogon(cldap, iconv_convenience, tctx, &search);
    234         CHECK_STATUS(status, NT_STATUS_OK);
     244        status = cldap_netlogon(cldap, tctx, &search);
     245        CHECK_STATUS(status, NT_STATUS_OK);
     246        CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE_EX);
     247        CHECK_STRING(search.out.netlogon.data.nt5_ex.forest, n1.data.nt5_ex.dns_domain);
    235248        CHECK_STRING(search.out.netlogon.data.nt5_ex.dns_domain, n1.data.nt5_ex.dns_domain);
    236         CHECK_STRING(search.out.netlogon.data.nt5_ex.user_name, "");
    237         CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE_EX);
     249        CHECK_STRING(search.out.netlogon.data.nt5_ex.domain_name, n1.data.nt5_ex.domain_name);
     250        CHECK_STRING(search.out.netlogon.data.nt5_ex.pdc_name, n1.data.nt5_ex.pdc_name);
     251        CHECK_STRING(search.out.netlogon.data.nt5_ex.user_name, "");
     252        CHECK_STRING(search.out.netlogon.data.nt5_ex.server_site, n1.data.nt5_ex.server_site);
     253        CHECK_STRING(search.out.netlogon.data.nt5_ex.client_site, n1.data.nt5_ex.client_site);
     254
     255        printf("Proof other results\n");
     256        search.in.user = "Administrator";
     257        status = cldap_netlogon(cldap, tctx, &search);
     258        CHECK_STATUS(status, NT_STATUS_OK);
     259        CHECK_STRING(search.out.netlogon.data.nt5_ex.forest, n1.data.nt5_ex.dns_domain);
     260        CHECK_STRING(search.out.netlogon.data.nt5_ex.dns_domain, n1.data.nt5_ex.dns_domain);
     261        CHECK_STRING(search.out.netlogon.data.nt5_ex.domain_name, n1.data.nt5_ex.domain_name);
     262        CHECK_STRING(search.out.netlogon.data.nt5_ex.pdc_name, n1.data.nt5_ex.pdc_name);
     263        CHECK_STRING(search.out.netlogon.data.nt5_ex.user_name, search.in.user);
     264        CHECK_STRING(search.out.netlogon.data.nt5_ex.server_site, n1.data.nt5_ex.server_site);
     265        CHECK_STRING(search.out.netlogon.data.nt5_ex.client_site, n1.data.nt5_ex.client_site);
    238266
    239267        return true;
     
    251279        struct netlogon_samlogon_response n1;
    252280        uint32_t server_type;
    253         struct smb_iconv_convenience *iconv_convenience = lp_iconv_convenience(tctx->lp_ctx);
     281        struct tsocket_address *dest_addr;
     282        int ret;
     283
     284        ret = tsocket_address_inet_from_strings(tctx, "ip",
     285                                                dest,
     286                                                lpcfg_cldap_port(tctx->lp_ctx),
     287                                                &dest_addr);
     288        CHECK_VAL(ret, 0);
    254289
    255290        /* cldap_socket_init should now know about the dest. address */
    256         status = cldap_socket_init(tctx, NULL, NULL, NULL, &cldap);
     291        status = cldap_socket_init(tctx, NULL, NULL, dest_addr, &cldap);
    257292        CHECK_STATUS(status, NT_STATUS_OK);
    258293
     
    260295
    261296        ZERO_STRUCT(search);
    262         search.in.dest_address = dest;
    263         search.in.dest_port = lp_cldap_port(tctx->lp_ctx);
     297        search.in.dest_address = NULL;
     298        search.in.dest_port = 0;
    264299        search.in.acct_control = -1;
    265300        search.in.version = NETLOGON_NT_VERSION_5 | NETLOGON_NT_VERSION_5EX;
    266301        search.in.map_response = true;
    267302
    268         status = cldap_netlogon(cldap, iconv_convenience, tctx, &search);
     303        status = cldap_netlogon(cldap, tctx, &search);
    269304        CHECK_STATUS(status, NT_STATUS_OK);
    270305
     
    304339        if (server_type & DS_DNS_DOMAIN)
    305340                printf("DS_DNS_DOMAIN ");
    306         if (server_type & DS_DNS_FOREST)
    307                 printf("DS_DNS_FOREST ");
     341        if (server_type & DS_DNS_FOREST_ROOT)
     342                printf("DS_DNS_FOREST_ROOT ");
    308343
    309344        printf("\n");
     
    353388
    354389/*
    355   test cldap netlogon server type flag "NBT_SERVER_DS_DNS_FOREST"
     390  test cldap netlogon server type flag "NBT_SERVER_FOREST_ROOT"
    356391*/
    357392static bool test_cldap_netlogon_flag_ds_dns_forest(struct torture_context *tctx,
     
    363398        uint32_t server_type;
    364399        struct netlogon_samlogon_response n1;
    365         struct smb_iconv_convenience *iconv_convenience = lp_iconv_convenience(tctx->lp_ctx);
    366400        bool result = true;
     401        struct tsocket_address *dest_addr;
     402        int ret;
     403
     404        ret = tsocket_address_inet_from_strings(tctx, "ip",
     405                                                dest,
     406                                                lpcfg_cldap_port(tctx->lp_ctx),
     407                                                &dest_addr);
     408        CHECK_VAL(ret, 0);
    367409
    368410        /* cldap_socket_init should now know about the dest. address */
    369         status = cldap_socket_init(tctx, NULL, NULL, NULL, &cldap);
    370         CHECK_STATUS(status, NT_STATUS_OK);
    371 
    372         printf("Testing netlogon server type flag NBT_SERVER_DS_DNS_FOREST: ");
     411        status = cldap_socket_init(tctx, NULL, NULL, dest_addr, &cldap);
     412        CHECK_STATUS(status, NT_STATUS_OK);
     413
     414        printf("Testing netlogon server type flag NBT_SERVER_FOREST_ROOT: ");
    373415
    374416        ZERO_STRUCT(search);
    375         search.in.dest_address = dest;
    376         search.in.dest_port = lp_cldap_port(tctx->lp_ctx);
     417        search.in.dest_address = NULL;
     418        search.in.dest_port = 0;
    377419        search.in.acct_control = -1;
    378420        search.in.version = NETLOGON_NT_VERSION_5 | NETLOGON_NT_VERSION_5EX;
    379421        search.in.map_response = true;
    380422
    381         status = cldap_netlogon(cldap, iconv_convenience, tctx, &search);
     423        status = cldap_netlogon(cldap, tctx, &search);
    382424        CHECK_STATUS(status, NT_STATUS_OK);
    383425
     
    388430                server_type = n1.data.nt5_ex.server_type;
    389431
    390         if (server_type & DS_DNS_FOREST) {
     432        if (server_type & DS_DNS_FOREST_ROOT) {
    391433                struct cldap_search search2;
    392434                const char *attrs[] = { "defaultNamingContext", "rootDomainNamingContext",
     
    399441                ZERO_STRUCT(search2);
    400442                search2.in.dest_address = dest;
    401                 search2.in.dest_port = lp_cldap_port(tctx->lp_ctx);
     443                search2.in.dest_port = lpcfg_cldap_port(tctx->lp_ctx);
    402444                search2.in.timeout = 10;
    403445                search2.in.retries = 3;
     
    439481        const char *attrs2[] = { "currentTime", "highestCommittedUSN", "netlogon", NULL };
    440482        const char *attrs3[] = { "netlogon", NULL };
     483        struct tsocket_address *dest_addr;
     484        int ret;
     485
     486        ret = tsocket_address_inet_from_strings(tctx, "ip",
     487                                                dest,
     488                                                lpcfg_cldap_port(tctx->lp_ctx),
     489                                                &dest_addr);
     490        CHECK_VAL(ret, 0);
    441491
    442492        /* cldap_socket_init should now know about the dest. address */
    443         status = cldap_socket_init(tctx, NULL, NULL, NULL, &cldap);
     493        status = cldap_socket_init(tctx, NULL, NULL, dest_addr, &cldap);
    444494        CHECK_STATUS(status, NT_STATUS_OK);
    445495
    446496        ZERO_STRUCT(search);
    447         search.in.dest_address = dest;
    448         search.in.dest_port = lp_cldap_port(tctx->lp_ctx);
     497        search.in.dest_address = NULL;
     498        search.in.dest_port = 0;
    449499        search.in.timeout = 10;
    450500        search.in.retries = 3;
  • trunk/server/source4/torture/ldap/cldapbench.c

    r414 r745  
    2121
    2222#include "includes.h"
    23 #include <tevent.h>
    2423#include "libcli/cldap/cldap.h"
    2524#include "libcli/resolve/resolve.h"
     
    4241        TALLOC_CTX *tmp_ctx = talloc_new(NULL);
    4342        io.in.version = 6;
    44         status = cldap_netlogon_recv(req,
    45                                      lp_iconv_convenience(state->tctx->lp_ctx),
    46                                      tmp_ctx, &io);
     43        status = cldap_netlogon_recv(req, tmp_ctx, &io);
    4744        talloc_free(req);
    4845        if (NT_STATUS_IS_OK(status)) {
     
    7168        ret = tsocket_address_inet_from_strings(tctx, "ip",
    7269                                                address,
    73                                                 lp_cldap_port(tctx->lp_ctx),
     70                                                lpcfg_cldap_port(tctx->lp_ctx),
    7471                                                &dest_addr);
    7572        CHECK_VAL(ret, 0);
     
    8279
    8380        ZERO_STRUCT(search);
    84         search.in.dest_address = address;
    85         search.in.dest_port     = lp_cldap_port(tctx->lp_ctx);
     81        search.in.dest_address = NULL;
     82        search.in.dest_port = 0;
    8683        search.in.acct_control = -1;
    8784        search.in.version = 6;
     
    149146        struct bench_state *state;
    150147        NTSTATUS status;
     148        struct tsocket_address *dest_addr;
     149        int ret;
     150
     151        ret = tsocket_address_inet_from_strings(tctx, "ip",
     152                                                address,
     153                                                lpcfg_cldap_port(tctx->lp_ctx),
     154                                                &dest_addr);
     155        CHECK_VAL(ret, 0);
    151156
    152157        /* cldap_socket_init should now know about the dest. address */
    153         status = cldap_socket_init(tctx, tctx->ev, NULL, NULL, &cldap);
     158        status = cldap_socket_init(tctx, tctx->ev, NULL, dest_addr, &cldap);
    154159        torture_assert_ntstatus_ok(tctx, status, "cldap_socket_init");
    155160
     
    157162
    158163        ZERO_STRUCT(search);
    159         search.in.dest_address  = address;
    160         search.in.dest_port     = lp_cldap_port(tctx->lp_ctx);
     164        search.in.dest_address  = NULL;
     165        search.in.dest_port     = 0;
    161166        search.in.filter        = "(objectClass=*)";
    162167        search.in.timeout       = 2;
     
    211216
    212217        /* do an initial name resolution to find its IP */
    213         status = resolve_name(lp_resolve_context(torture->lp_ctx), &name, torture, &address, torture->ev);
     218        status = resolve_name(lpcfg_resolve_context(torture->lp_ctx), &name, torture, &address, torture->ev);
    214219        if (!NT_STATUS_IS_OK(status)) {
    215220                printf("Failed to resolve %s - %s\n",
  • trunk/server/source4/torture/ldap/common.c

    r414 r745  
    9797NTSTATUS torture_ldap_close(struct ldap_connection *conn)
    9898{
     99        struct ldap_message *msg;
     100        struct ldap_request *req;
     101        NTSTATUS status;
     102
     103        printf("Testing the most important error code -> error message conversions!\n");
     104
     105        msg = new_ldap_message(conn);
     106        if (!msg) {
     107                talloc_free(conn);
     108                return NT_STATUS_NO_MEMORY;
     109        }
     110
     111        printf(" Try a AbandonRequest for an old message id\n");
     112
     113        msg->type = LDAP_TAG_UnbindRequest;
     114
     115        req = ldap_request_send(conn, msg);
     116        if (!req) {
     117                talloc_free(conn);
     118                return NT_STATUS_NO_MEMORY;
     119        }
     120
     121        status = ldap_request_wait(req);
     122        if (!NT_STATUS_IS_OK(status)) {
     123                printf("error in ldap unbind request - %s\n", nt_errstr(status));
     124                talloc_free(conn);
     125                return status;
     126        }
     127
    99128        talloc_free(conn);
    100129        return NT_STATUS_OK;
     
    103132NTSTATUS torture_ldap_init(void)
    104133{
    105         struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "LDAP");
    106         torture_suite_add_simple_test(suite, "BENCH-CLDAP", torture_bench_cldap);
    107         torture_suite_add_simple_test(suite, "BASIC", torture_ldap_basic);
    108         torture_suite_add_simple_test(suite, "SORT", torture_ldap_sort);
    109         torture_suite_add_simple_test(suite, "CLDAP", torture_cldap);
    110         torture_suite_add_simple_test(suite, "SCHEMA", torture_ldap_schema);
    111         torture_suite_add_simple_test(suite, "UPTODATEVECTOR", torture_ldap_uptodatevector);
     134        struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "ldap");
     135        torture_suite_add_simple_test(suite, "bench-cldap", torture_bench_cldap);
     136        torture_suite_add_simple_test(suite, "basic", torture_ldap_basic);
     137        torture_suite_add_simple_test(suite, "sort", torture_ldap_sort);
     138        torture_suite_add_simple_test(suite, "cldap", torture_cldap);
     139        torture_suite_add_simple_test(suite, "schema", torture_ldap_schema);
     140        torture_suite_add_simple_test(suite, "uptodatevector", torture_ldap_uptodatevector);
     141        torture_suite_add_simple_test(suite, "nested-search", test_ldap_nested_search);
    112142
    113143        suite->description = talloc_strdup(suite, "LDAP and CLDAP tests");
  • trunk/server/source4/torture/ldap/ldap_sort.c

    r414 r745  
    2323#include "includes.h"
    2424#include "lib/events/events.h"
    25 #include "lib/ldb/include/ldb.h"
    26 #include "lib/ldb/include/ldb_errors.h"
     25#include <ldb.h>
     26#include <ldb_errors.h>
    2727#include "ldb_wrap.h"
    2828#include "param/param.h"
     
    3131#include "torture/local/proto.h"
    3232#include <ctype.h>
     33
    3334bool torture_ldap_sort(struct torture_context *torture)
    3435{
    35 
    3636        struct ldb_context *ldb;
    3737
     
    4747        struct ldb_request *req;
    4848        struct ldb_result *ctx;
    49         struct ldb_val* prev = NULL;
     49        struct ldb_val *prev = NULL;
    5050        const char *prev_txt = NULL;
    5151        int prev_len = 0;
    52         struct ldb_val* cur = NULL;
     52        struct ldb_val *cur = NULL;
    5353        const char *cur_txt = NULL;
    5454        int cur_len = 0;
    55         struct ldb_dn* dn;
     55        struct ldb_dn *dn;
    5656                 
    5757                 
     
    6363                                                 NULL,
    6464                                                 cmdline_credentials,
    65                                                  0, NULL);
     65                                                 0);
    6666        torture_assert(torture, ldb, "Failed to make LDB connection to target");
    6767
     
    7575        control[1] = NULL;
    7676
    77         dn = ldb_get_root_basedn(ldb);
     77        dn = ldb_get_default_basedn(ldb);
    7878        ldb_dn_add_child_fmt(dn, "cn=users");
    7979        ret = ldb_build_search_req(&req, ldb, ctx,
     
    104104                        {
    105105                                /* Do only the ascii case right now ... */
    106                                 cur_txt=cur->data;
    107                                 cur_len=cur->length;
    108                                 prev_txt=prev->data;
    109                                 prev_len=prev->length;
     106                                cur_txt = (const char *) cur->data;
     107                                cur_len = cur->length;
     108                                prev_txt = (const char *) prev->data;
     109                                prev_len = prev->length;
    110110                                /* Remove leading whitespace as the sort function do so ... */
    111111                                while ( cur_txt[0] == cur_txt[1] ) { cur_txt++; cur_len--;}
  • trunk/server/source4/torture/ldap/schema.c

    r414 r745  
    2424#include "lib/cmdline/popt_common.h"
    2525#include "ldb_wrap.h"
    26 #include "lib/ldb/include/ldb.h"
    27 #include "lib/ldb/include/ldb_errors.h"
    2826#include "dsdb/samdb/samdb.h"
    2927#include "../lib/util/dlinklist.h"
    3028
    3129#include "torture/torture.h"
    32 #include "torture/ldap/proto.h"
    33 
    34 #include "param/param.h"
     30
    3531
    3632struct test_rootDSE {
     
    216212{
    217213        struct dsdb_schema *schema = talloc_get_type(ptr, struct dsdb_schema);
    218         struct dsdb_attribute *attr = NULL;
    219214        WERROR status;
    220215
    221         attr = talloc_zero(schema, struct dsdb_attribute);
    222         if (!attr) {
    223                 goto failed;
    224         }
    225 
    226         status = dsdb_attribute_from_ldb(ldb, schema, msg, attr, attr);
     216        status = dsdb_attribute_from_ldb(ldb, schema, msg);
    227217        if (!W_ERROR_IS_OK(status)) {
    228218                goto failed;
    229219        }
    230220
    231         DLIST_ADD_END(schema->attributes, attr, struct dsdb_attribute *);
    232221        return LDB_SUCCESS;
    233222failed:
    234         talloc_free(attr);
    235223        return LDB_ERR_OTHER;
    236224}
     
    239227{
    240228        struct dsdb_schema *schema = talloc_get_type(ptr, struct dsdb_schema);
    241         struct dsdb_class *obj;
    242229        WERROR status;
    243230
    244         obj = talloc_zero(schema, struct dsdb_class);
    245         if (!obj) {
    246                 goto failed;
    247         }
    248 
    249         status = dsdb_class_from_ldb(schema, msg, obj, obj);
     231        status = dsdb_class_from_ldb(schema, msg);
    250232        if (!W_ERROR_IS_OK(status)) {
    251233                goto failed;
    252234        }
    253235
    254         DLIST_ADD_END(schema->classes, obj, struct dsdb_class *);
    255236        return LDB_SUCCESS;
    256237failed:
     
    361342                        if (strcmp(syntaxes[i], a->attributeSyntax_oid) != 0) continue;
    362343
    363                         om_hex = data_blob_hex_string(ldb, &a->oMObjectClass);
     344                        om_hex = data_blob_hex_string_upper(ldb, &a->oMObjectClass);
    364345                        if (!om_hex) {
    365346                                return false;
     
    373354        }
    374355
     356        return true;
     357}
     358
     359static bool test_dump_not_in_filtered_replica(struct ldb_context *ldb, struct test_rootDSE *root, struct dsdb_schema *schema)
     360{
     361        struct dsdb_attribute *a;
     362        uint32_t a_i = 1;
     363
     364        d_printf("Dumping attributes not in filtered replica\n");
     365
     366        for (a=schema->attributes; a; a = a->next) {
     367                if (!dsdb_attribute_is_attr_in_filtered_replica(a)) {
     368                        d_printf("attr[%4u]: '%s'\n", a_i++,
     369                                 a->lDAPDisplayName);
     370                }
     371        }
    375372        return true;
    376373}
     
    392389                               NULL,
    393390                               cmdline_credentials,
    394                                0, NULL);
     391                               0);
    395392        if (!ldb) goto failed;
    396393
     
    404401        ret &= test_dump_contructed(ldb, &rootDSE, schema);
    405402        ret &= test_dump_sorted_syntax(ldb, &rootDSE, schema);
     403        ret &= test_dump_not_in_filtered_replica(ldb, &rootDSE, schema);
    406404
    407405failed:
  • trunk/server/source4/torture/ldap/uptodatevector.c

    r414 r745  
    2424#include "lib/cmdline/popt_common.h"
    2525#include "ldb_wrap.h"
    26 #include "lib/ldb/include/ldb.h"
    27 #include "lib/ldb/include/ldb_errors.h"
    2826#include "dsdb/samdb/samdb.h"
    29 #include "../lib/util/dlinklist.h"
    3027
    3128#include "torture/torture.h"
    32 #include "torture/ldap/proto.h"
    3329
    34 #include "librpc/ndr/libndr.h"
    3530#include "librpc/gen_ndr/ndr_drsblobs.h"
    3631
     
    7166        if (utdv_val1) {
    7267                ndr_err = ndr_pull_struct_blob_all(utdv_val1, torture,
    73                                                    lp_iconv_convenience(torture->lp_ctx), &utdv1,
     68                                                   &utdv1,
    7469                                                   (ndr_pull_flags_fn_t)ndr_pull_replUpToDateVectorBlob);
    7570                if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     
    117112                if (utdv_val) {
    118113                        ndr_err = ndr_pull_struct_blob_all(utdv_val, torture,
    119                                                            lp_iconv_convenience(torture->lp_ctx), &utdv,
     114                                                           &utdv,
    120115                                                           (ndr_pull_flags_fn_t)ndr_pull_replUpToDateVectorBlob);
    121116                        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     
    136131
    137132                torture_comment(torture, "[%u]: uSNChanged[%llu] description[%s] replUpToDateVector[%s]\n", i,
    138                                 (unsigned long long)samdb_result_uint64(r->msgs[0], "uSNChanged", 0),
    139                                 samdb_result_string(r->msgs[0], "description", NULL),
     133                                (unsigned long long)ldb_msg_find_attr_as_uint64(r->msgs[0], "uSNChanged", 0),
     134                                ldb_msg_find_attr_as_string(r->msgs[0], "description", NULL),
    140135                                (no_match ? "changed!: not ok" : "not changed: ok"));
    141136
     
    165160                               NULL,
    166161                               cmdline_credentials,
    167                                0, NULL);
     162                               0);
    168163        if (!ldb) goto failed;
    169164
    170         ret &= test_check_uptodatevector(torture, ldb, samdb_base_dn(ldb));
    171         ret &= test_check_uptodatevector(torture, ldb, samdb_config_dn(ldb));
    172         ret &= test_check_uptodatevector(torture, ldb, samdb_schema_dn(ldb));
     165        ret &= test_check_uptodatevector(torture, ldb, ldb_get_default_basedn(ldb));
     166        ret &= test_check_uptodatevector(torture, ldb, ldb_get_config_basedn(ldb));
     167        ret &= test_check_uptodatevector(torture, ldb, ldb_get_schema_basedn(ldb));
    173168
    174169        return ret;
Note: See TracChangeset for help on using the changeset viewer.