X-Git-Url: http://git.samba.org/?a=blobdiff_plain;f=source4%2Ftorture%2Funix%2Fwhoami.c;h=f554c9e17114f0097a082fb38d226fd72fef260c;hb=e18610a197aab80a32cae8c1e09b96496679bbad;hp=968af6b4a25b05ef363127f577faf870374ce702;hpb=624f11e4b46884c13056709ba6abc8dc2a659bc3;p=samba.git diff --git a/source4/torture/unix/whoami.c b/source4/torture/unix/whoami.c index 968af6b4a25..f554c9e1711 100644 --- a/source4/torture/unix/whoami.c +++ b/source4/torture/unix/whoami.c @@ -21,6 +21,7 @@ #include "libcli/libcli.h" #include "libcli/raw/raw_proto.h" #include "torture/torture.h" +#include "torture/unix/proto.h" #include "lib/cmdline/popt_common.h" #include "auth/credentials/credentials.h" #include "param/param.h" @@ -90,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; } @@ -297,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); } @@ -309,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++; @@ -345,11 +367,11 @@ bool torture_unix_whoami(struct torture_context *torture) { struct smbcli_state *cli; struct smb_whoami whoami; - bool ret; + bool ret = false; 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. */ @@ -357,12 +379,27 @@ bool torture_unix_whoami(struct torture_context *torture) cli, &whoami, 0xFFFF), ret, fail, "calling SMB_QFS_POSIX_WHOAMI on an authenticated connection"); + /* Check that our anonymous login mapped us to guest on the server, but + * only if the server supports this. + */ + if (whoami.mapping_mask & SMB_WHOAMI_GUEST) { + 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( + 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"); + } + addc = torture_setting_string(torture, "addc", NULL); host = torture_setting_string(torture, "host", NULL); 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 */ @@ -385,19 +422,6 @@ bool torture_unix_whoami(struct torture_context *torture) smbcli_tdis(cli); - /* Check that our anonymous login mapped us to guest on the server, but - * only if the server supports this. - */ - if (whoami.mapping_mask & SMB_WHOAMI_GUEST) { - bool guest = whoami.mapping_flags & SMB_WHOAMI_GUEST; - printf("checking whether we were logged in as guest... %s\n", - guest ? "YES" : "NO"); - torture_assert(torture, cli_credentials_is_anonymous(cmdline_credentials) == guest, - "login did not credentials map to guest"); - } else { - printf("server does not support SMB_WHOAMI_GUEST flag\n"); - } - return true; fail: