r8104: - added support for our client library to not negotiate nt status codes, contr...
authorAndrew Tridgell <tridge@samba.org>
Mon, 4 Jul 2005 01:23:38 +0000 (01:23 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:19:08 +0000 (13:19 -0500)
  with 'nt status support' option.

- make nt_errstr() display nice strings for dos status codes encoded
  using NT_STATUS_DOS()

- no longer map between dos and nt status codes in the client library,
  instead return using NT_STATUS_DOS()

- fixed the RAW-CONTEXT test to look for
  NT_STATUS_DOS(ERRSRV, ERRbaduid) instead of NT_STATUS_INVALID_HANDLE
(This used to be commit ff5549e87ffae9f062394f30d8fd1ae95b614735)

source4/libcli/raw/clitransport.c
source4/libcli/raw/libcliraw.h
source4/libcli/raw/rawnegotiate.c
source4/libcli/util/clierror.c
source4/libcli/util/nterr.c
source4/torture/raw/context.c
source4/torture/torture.c

index 999795b81ee646d0b523165632b24a6aa4c6232d..51a718b10b08599e9cb6e7e2891a33766a729fc5 100644 (file)
@@ -476,15 +476,22 @@ static void smbcli_transport_finish_recv(struct smbcli_transport *transport)
        req->flags2 = SVAL(req->in.hdr, HDR_FLG2);
 
        if (!(req->flags2 & FLAGS2_32_BIT_ERROR_CODES)) {
-               transport->error.etype = ETYPE_DOS;
-               transport->error.e.dos.eclass = CVAL(req->in.hdr,HDR_RCLS);
-               transport->error.e.dos.ecode = SVAL(req->in.hdr,HDR_ERR);
-               req->status = dos_to_ntstatus(transport->error.e.dos.eclass, 
-                                             transport->error.e.dos.ecode);
+               int class = CVAL(req->in.hdr,HDR_RCLS);
+               int code = SVAL(req->in.hdr,HDR_ERR);
+               if (class == 0 && code == 0) {
+                       transport->error.e.nt_status = NT_STATUS_OK;
+               } else {
+                       transport->error.e.nt_status = NT_STATUS_DOS(class, code);
+               }
        } else {
-               transport->error.etype = ETYPE_NT;
                transport->error.e.nt_status = NT_STATUS(IVAL(req->in.hdr, HDR_RCLS));
-               req->status = transport->error.e.nt_status;
+       }
+
+       req->status = transport->error.e.nt_status;
+       if (NT_STATUS_IS_OK(req->status)) {
+               transport->error.etype = ETYPE_NONE;
+       } else {
+               transport->error.etype = ETYPE_SMB;
        }
 
        if (!smbcli_request_check_sign_mac(req)) {
index 2794a22da26c29a28081940ff627c2a8665a9b22..bb13210e747fa8966ba4302f4e7205e55a4301f7 100644 (file)
@@ -124,12 +124,8 @@ struct smbcli_transport {
 
        /* the error fields from the last message */
        struct {
-               enum {ETYPE_NONE, ETYPE_DOS, ETYPE_NT, ETYPE_SOCKET, ETYPE_NBT} etype;
+               enum {ETYPE_NONE, ETYPE_SMB, ETYPE_SOCKET, ETYPE_NBT} etype;
                union {
-                       struct {
-                               uint8_t eclass;
-                               uint16_t ecode;
-                       } dos;
                        NTSTATUS nt_status;
                        enum {SOCKET_READ_TIMEOUT,
                              SOCKET_READ_EOF,
index d2d6b66d5970aca94a5038a3d061e708111c8fba..07b9dd572ab1f5cb062b7ba2fe6adc20f1cafd33 100644 (file)
@@ -174,10 +174,14 @@ NTSTATUS smb_raw_negotiate_recv(struct smbcli_request *req)
        }
 
        /* a way to force ascii SMB */
-       if (!lp_unicode() || getenv("SMBCLI_FORCE_ASCII")) {
+       if (!lp_unicode()) {
                transport->negotiate.capabilities &= ~CAP_UNICODE;
        }
 
+       if (!lp_nt_status_support()) {
+               transport->negotiate.capabilities &= ~CAP_STATUS32;
+       }
+
 failed:
        return smbcli_request_destroy(req);
 }
index 1c82958ce2c4cbd58f86240ca1413d1732999c30..52607b1a47bf68e81a703b12e325fb9fb067f873 100644 (file)
 const char *smbcli_errstr(struct smbcli_tree *tree)
 {   
        switch (tree->session->transport->error.etype) {
-       case ETYPE_DOS:
-               return dos_errstr(
-                       tree->session->transport->error.e.dos.eclass, 
-                       tree->session->transport->error.e.dos.ecode);
-       case ETYPE_NT:
+       case ETYPE_SMB:
                return nt_errstr(tree->session->transport->error.e.nt_status);
 
        case ETYPE_SOCKET:
@@ -53,13 +49,9 @@ const char *smbcli_errstr(struct smbcli_tree *tree)
 NTSTATUS smbcli_nt_error(struct smbcli_tree *tree)
 {
        switch (tree->session->transport->error.etype) {
-       case ETYPE_NT:
+       case ETYPE_SMB:
                return tree->session->transport->error.e.nt_status;
 
-       case ETYPE_DOS:
-               return dos_to_ntstatus(
-                       tree->session->transport->error.e.dos.eclass,
-                       tree->session->transport->error.e.dos.ecode);
        case ETYPE_SOCKET:
                return NT_STATUS_UNSUCCESSFUL;
 
@@ -74,29 +66,8 @@ NTSTATUS smbcli_nt_error(struct smbcli_tree *tree)
 }
 
 
-/* Return the DOS error from the last packet - an error class and an error
-   code. */
-void smbcli_dos_error(struct smbcli_state *cli, uint8_t *eclass, uint32_t *ecode)
-{
-       if (cli->transport->error.etype == ETYPE_DOS) {
-               ntstatus_to_dos(cli->transport->error.e.nt_status, 
-                               eclass, ecode);
-               return;
-       }
-
-       if (eclass) *eclass = cli->transport->error.e.dos.eclass;
-       if (ecode)  *ecode  = cli->transport->error.e.dos.ecode;
-}
-
-
 /* Return true if the last packet was an error */
 BOOL smbcli_is_error(struct smbcli_tree *tree)
 {
        return NT_STATUS_IS_ERR(smbcli_nt_error(tree));
 }
-
-/* Return true if the last error was a DOS error */
-BOOL smbcli_is_dos_error(struct smbcli_tree *tree)
-{
-       return tree->session->transport->error.etype == ETYPE_DOS;
-}
index eca47572e36cce85a6a9b93086600de0d4b78bb0..a5ba1305e4035b7d19731f415e066f328d72c8fe 100644 (file)
@@ -648,9 +648,17 @@ static const nt_err_code_struct nt_err_desc[] =
  *****************************************************************************/
 const char *nt_errstr(NTSTATUS nt_code)
 {
-        static fstring msg;
+        static char msg[40];
         int idx = 0;
 
+       if (NT_STATUS_IS_DOS(nt_code)) {
+               return dos_errstr(NT_STATUS_DOS_CLASS(nt_code), 
+                                 NT_STATUS_DOS_CODE(nt_code));
+       } else if (NT_STATUS_IS_LDAP(nt_code)) {
+               slprintf(msg, sizeof(msg), "LDAP code %u", NT_STATUS_LDAP_CODE(nt_code));
+               return msg;
+       }
+
        while (nt_errs[idx].nt_errstr != NULL) {
                if (NT_STATUS_V(nt_errs[idx].nt_errcode) == 
                     NT_STATUS_V(nt_code)) {
@@ -659,14 +667,7 @@ const char *nt_errstr(NTSTATUS nt_code)
                idx++;
        }
 
-       if (NT_STATUS_IS_DOS(nt_code)) {
-               slprintf(msg, sizeof(msg), "DOS code %u:%u", 
-                        NT_STATUS_DOS_CLASS(nt_code), NT_STATUS_DOS_CODE(nt_code));
-       } else if (NT_STATUS_IS_LDAP(nt_code)) {
-               slprintf(msg, sizeof(msg), "LDAP code %u", NT_STATUS_LDAP_CODE(nt_code));
-       } else {
-               slprintf(msg, sizeof(msg), "NT code 0x%08x", NT_STATUS_V(nt_code));
-       }
+       slprintf(msg, sizeof(msg), "NT code 0x%08x", NT_STATUS_V(nt_code));
 
         return msg;
 }
index f7fe006917a8873e764fa854a4c9a2910193b5f4..830814f69c8a3a7c32874914c38fa861676a1db1 100644 (file)
@@ -202,11 +202,11 @@ static BOOL test_session(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        printf("the new vuid should not now be accessible\n");
        status = smb_raw_write(tree, &wr);
-       CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
+       CHECK_STATUS(status, NT_STATUS_DOS(ERRSRV, ERRbaduid));
 
        printf("second logoff for the new vuid should fail\n");
        status = smb_raw_ulogoff(session);
-       CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
+       CHECK_STATUS(status, NT_STATUS_DOS(ERRSRV, ERRbaduid));
        talloc_free(session);
 
        printf("the fnum should have been auto-closed\n");
index 7e8f8457a49e4cda96e1c39734bc2844ad0e7658..c5ac8735912e2306598dc5e208878056a7303441 100644 (file)
@@ -185,14 +185,13 @@ NTSTATUS torture_rpc_connection_transport(TALLOC_CTX *parent_ctx,
 BOOL check_error(const char *location, struct smbcli_state *c, 
                 uint8_t eclass, uint32_t ecode, NTSTATUS nterr)
 {
-        if (smbcli_is_dos_error(c->tree)) {
-                uint8_t class;
-                uint32_t num;
-
-                /* Check DOS error */
-
-                smbcli_dos_error(c, &class, &num);
-
+       NTSTATUS status;
+       
+       status = smbcli_nt_error(c->tree);
+       if (NT_STATUS_IS_DOS(status)) {
+               int class, num;
+               class = NT_STATUS_DOS_CLASS(status);
+               num = NT_STATUS_DOS_CODE(status);
                 if (eclass != class || ecode != num) {
                         printf("unexpected error code class=%d code=%d\n", 
                                (int)class, (int)num);
@@ -200,15 +199,8 @@ BOOL check_error(const char *location, struct smbcli_state *c,
                                (int)eclass, (int)ecode, nt_errstr(nterr), location);
                         return False;
                 }
-
         } else {
-                NTSTATUS status;
-
-                /* Check NT error */
-
-                status = smbcli_nt_error(c->tree);
-
-                if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
+                if (!NT_STATUS_EQUAL(nterr, status)) {
                         printf("unexpected error code %s\n", nt_errstr(status));
                         printf(" expected %s (at %s)\n", nt_errstr(nterr), location);
                         return False;
@@ -1354,9 +1346,8 @@ static BOOL run_vuidtest(void)
                correct = False;
        }
 
-       if ( (cli->transport->error.etype != ETYPE_DOS) ||
-            (cli->transport->error.e.dos.eclass != ERRSRV) ||
-            (cli->transport->error.e.dos.ecode != ERRbaduid) ) {
+       if (!NT_STATUS_EQUAL(cli->transport->error.e.nt_status, 
+                            NT_STATUS_DOS(ERRSRV, ERRbaduid))) {
                printf("ERROR: qfileinfo should have returned DOS error "
                       "ERRSRV:ERRbaduid\n  but returned %s\n",
                       smbcli_errstr(cli->tree));