s3-passdb: Implement new pdb trust calls for the default backend
[idra/samba.git] / source3 / torture / pdbtest.c
index 950177c3ca97a636af2f964981f49d8b67ed0422..33419db2753e2446b752c6b5b37825217e98b46b 100644 (file)
 
 
 #include "includes.h"
+#include "popt_common.h"
+#include "passdb.h"
+
+#include "../librpc/gen_ndr/drsblobs.h"
+#include "../librpc/gen_ndr/ndr_drsblobs.h"
+#include "../libcli/security/dom_sid.h"
+
+#define TRUST_DOM "trustdom"
+#define TRUST_PWD "trustpwd1232"
+#define TRUST_SID "S-1-5-21-1111111111-2222222222-3333333333"
 
 static bool samu_correct(struct samu *s1, struct samu *s2)
 {
@@ -247,7 +257,7 @@ int main(int argc, char **argv)
 
        load_case_tables();
 
-       pc = poptGetContext("vfstest", argc, (const char **) argv,
+       pc = poptGetContext("pdbtest", argc, (const char **) argv,
                            long_options, 0);
 
        poptSetOtherOptionHelp(pc, "backend[:settings] username");
@@ -258,7 +268,7 @@ int main(int argc, char **argv)
 
        /* Load configuration */
        lp_load(get_dyn_CONFIGFILE(), False, False, True, True);
-       setup_logging("pdbtest", True);
+       setup_logging("pdbtest", DEBUG_STDOUT);
 
        if (backend == NULL) {
                backend = lp_passdb_backend();
@@ -277,7 +287,7 @@ int main(int argc, char **argv)
                exit(1);
        }
        
-       if ((pwd = getpwnam_alloc(ctx, unix_user)) == NULL) {
+       if ((pwd = Get_Pwnam_alloc(ctx, unix_user)) == NULL) {
                fprintf(stderr, "Error getting user information for %s\n", unix_user);
                exit(1);
        }
@@ -364,6 +374,81 @@ int main(int argc, char **argv)
                                        get_friendly_nt_error_msg(rv));
        }
 
+       /* test trustdom calls */
+       struct pdb_trusted_domain *td;
+       struct pdb_trusted_domain *new_td;
+       struct trustAuthInOutBlob taiob;
+       struct AuthenticationInformation aia;
+       enum ndr_err_code ndr_err;
+
+       td = talloc_zero(ctx ,struct pdb_trusted_domain);
+       if (!td) {
+               fprintf(stderr, "talloc failed\n");
+               exit(1);
+       }
+
+       td->domain_name = talloc_strdup(td, TRUST_DOM);
+       td->netbios_name = talloc_strdup(td, TRUST_DOM);
+       if (!td->domain_name || !td->netbios_name) {
+               fprintf(stderr, "talloc failed\n");
+               exit(1);
+       }
+
+       td->trust_auth_incoming = data_blob_null;
+
+       ZERO_STRUCT(taiob);
+       ZERO_STRUCT(aia);
+       taiob.count = 1;
+       taiob.current.count = 1;
+       taiob.current.array = &aia;
+       unix_to_nt_time(&aia.LastUpdateTime, time(NULL));
+       aia.AuthType = TRUST_AUTH_TYPE_CLEAR;
+       aia.AuthInfo.clear.password = (uint8_t *) talloc_strdup(ctx, TRUST_PWD);
+       aia.AuthInfo.clear.size = strlen(TRUST_PWD);
+
+       taiob.previous.count = 0;
+       taiob.previous.array = NULL;
+
+       ndr_err = ndr_push_struct_blob(&td->trust_auth_outgoing,
+                                       td, &taiob,
+                       (ndr_push_flags_fn_t) ndr_push_trustAuthInOutBlob);
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               fprintf(stderr, "ndr_push_struct_blob failed.\n");
+               exit(1);
+       }
+
+       td->trust_direction = LSA_TRUST_DIRECTION_OUTBOUND;
+       td->trust_type = LSA_TRUST_TYPE_DOWNLEVEL;
+       td->trust_attributes = 0;
+       td->trust_forest_trust_info = data_blob_null;
+
+       rv = pdb->set_trusted_domain(pdb, TRUST_DOM, td);
+       if (!NT_STATUS_IS_OK(rv)) {
+               fprintf(stderr, "Error in set_trusted_domain %s\n",
+                               get_friendly_nt_error_msg(rv));
+               error = True;
+       }
+
+       rv = pdb->get_trusted_domain(pdb, ctx, TRUST_DOM, &new_td);
+       if (!NT_STATUS_IS_OK(rv)) {
+               fprintf(stderr, "Error in set_trusted_domain %s\n",
+                               get_friendly_nt_error_msg(rv));
+               error = True;
+       }
+
+       if (!strequal(td->domain_name, new_td->domain_name) ||
+           !strequal(td->netbios_name, new_td->netbios_name) ||
+           !sid_equal(&td->security_identifier, &new_td->security_identifier) ||
+           td->trust_direction != new_td->trust_direction ||
+           td->trust_type != new_td->trust_type ||
+           td->trust_attributes != new_td->trust_attributes ||
+           td->trust_auth_incoming.length != new_td->trust_auth_incoming.length ||
+           td->trust_forest_trust_info.length != new_td->trust_forest_trust_info.length ||
+           data_blob_cmp(&td->trust_auth_outgoing, &new_td->trust_auth_outgoing) != 0) {
+               fprintf(stderr, "Old and new trusdet domain data do not match\n");
+               error = True;
+       }
+
        TALLOC_FREE(ctx);
 
        if (error) {