lib: Make sid_parse return the parsed length
[samba.git] / source4 / torture / unix / whoami.c
index 00109eb35a27457a524c2bc28a4a08bc6c001989..f554c9e17114f0097a082fb38d226fd72fef260c 100644 (file)
@@ -91,8 +91,13 @@ static struct smbcli_state *connect_to_server(struct torture_context *tctx,
                                        lpcfg_gensec_settings(tctx, tctx->lp_ctx));
 
        if (!NT_STATUS_IS_OK(status)) {
-               printf("failed to connect to //%s/%s: %s\n",
-                       host, share, nt_errstr(status));
+               torture_comment(tctx,
+                               "FATAL: Failed to connect to //%s/%s "
+                               "with %s - %s\n",
+                               host,
+                               share,
+                               cli_credentials_get_username(creds),
+                               nt_errstr(status));
                return NULL;
        }
 
@@ -298,9 +303,14 @@ static bool test_against_ldap(struct torture_context *torture, struct ldb_contex
                
                for (i = 0; i < el->num_values; i++) {
                        struct dom_sid *sid = talloc(torture, struct dom_sid);
+                       struct sid_parse_ret ret;
                        torture_assert(torture, sid != NULL, "talloc failed");
-                       
-                       torture_assert(torture, sid_blob_parse(el->values[i], sid), "sid parse failed");
+
+                       ret = sid_parse(el->values[i].data,
+                                       el->values[i].length, sid);
+                       torture_assert(torture,
+                                      ret.len != -1,
+                                      "sid parse failed");
                        torture_assert_str_equal(torture, dom_sid_string(sid, sid), dom_sid_string(sid, whoami->sid_list[i]), "SID from LDAP and SID from CIFS does not match!");
                        talloc_free(sid);
                }
@@ -310,14 +320,25 @@ static bool test_against_ldap(struct torture_context *torture, struct ldb_contex
                struct dom_sid *dom_sid = talloc(torture, struct dom_sid);
                struct dom_sid *dc_sids = talloc_array(torture, struct dom_sid, el->num_values);
                struct dom_sid *member_sids = talloc_array(torture, struct dom_sid, whoami->num_sids);
+               struct sid_parse_ret ret;
                torture_assert(torture, user_sid != NULL, "talloc failed");
-               torture_assert(torture, sid_blob_parse(el->values[0], user_sid), "sid parse failed");
+               ret = sid_parse(el->values[0].data,
+                               el->values[0].length,
+                               user_sid);
+               torture_assert(torture,
+                              ret.len != -1,
+                              "sid parse failed");
                torture_assert_ntstatus_equal(torture, dom_sid_split_rid(torture, user_sid, &dom_sid, NULL), NT_STATUS_OK, "failed to split domain SID from user SID");
                for (i = 0; i < el->num_values; i++) {
                        struct dom_sid *sid = talloc(dc_sids, struct dom_sid);
                        torture_assert(torture, sid != NULL, "talloc failed");
-                       
-                       torture_assert(torture, sid_blob_parse(el->values[i], sid), "sid parse failed");
+
+                       ret = sid_parse(el->values[i].data,
+                                       el->values[i].length,
+                                       sid);
+                       torture_assert(torture,
+                                      ret.len != -1,
+                                      "sid parse failed");
                        if (dom_sid_in_domain(dom_sid, sid)) {
                                dc_sids[num_domain_sids_dc] = *sid;
                                num_domain_sids_dc++;
@@ -350,7 +371,7 @@ bool torture_unix_whoami(struct torture_context *torture)
        struct ldb_context *ldb;
        const char *addc, *host;
 
-       cli = connect_to_server(torture, cmdline_credentials);
+       cli = connect_to_server(torture, popt_get_cmdline_credentials());
        torture_assert(torture, cli, "connecting to server with authenticated credentials");
 
        /* Test basic authenticated mapping. */
@@ -365,7 +386,9 @@ bool torture_unix_whoami(struct torture_context *torture)
                bool guest = whoami.mapping_flags & SMB_WHOAMI_GUEST;
                torture_comment(torture, "checking whether we were logged in as guest... %s\n",
                        guest ? "YES" : "NO");
-               torture_assert(torture, cli_credentials_is_anonymous(cmdline_credentials) == guest,
+               torture_assert(torture,
+                       cli_credentials_is_anonymous(
+                               popt_get_cmdline_credentials()) == guest,
                               "login did not credentials map to guest");
        } else {
                torture_comment(torture, "server does not support SMB_WHOAMI_GUEST flag\n");
@@ -376,7 +399,7 @@ bool torture_unix_whoami(struct torture_context *torture)
        
        if (addc) {
                ldb = ldb_wrap_connect(torture, torture->ev, torture->lp_ctx, talloc_asprintf(torture, "ldap://%s", addc),
-                                      NULL, cmdline_credentials, 0);
+                                      NULL, popt_get_cmdline_credentials(), 0);
                torture_assert(torture, ldb, "ldb connect failed");
 
                /* We skip this testing if we could not contact the LDAP server */