s3: make cli_resolve_path return NTSTATUS
[kai/samba.git] / source3 / libsmb / libsmb_xattr.c
index 93ca0706b2b316f1609c423074c17d1ab804a16a..00f94122bc7b68a7b485bf43af096556484c5279 100644 (file)
@@ -7,25 +7,29 @@
    Copyright (C) Tom Jansen (Ninja ISD) 2002 
    Copyright (C) Derrell Lipman 2003-2008
    Copyright (C) Jeremy Allison 2007, 2008
-   
+
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
-   
+
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
+#include "libsmb/libsmb.h"
 #include "libsmbclient.h"
 #include "libsmb_internal.h"
-
+#include "../librpc/gen_ndr/ndr_lsa.h"
+#include "rpc_client/rpc_client.h"
+#include "rpc_client/cli_lsarpc.h"
+#include "../libcli/security/security.h"
 
 /*
  * Find an lsa pipe handle associated with a cli struct.
@@ -38,12 +42,11 @@ find_lsa_pipe_hnd(struct cli_state *ipc_cli)
        for (pipe_hnd = ipc_cli->pipe_list;
              pipe_hnd;
              pipe_hnd = pipe_hnd->next) {
-            
-               if (pipe_hnd->pipe_idx == PI_LSARPC) {
+               if (ndr_syntax_id_equal(&pipe_hnd->abstract_syntax,
+                                       &ndr_table_lsarpc.syntax_id)) {
                        return pipe_hnd;
                }
        }
-
        return NULL;
 }
 
@@ -54,8 +57,8 @@ find_lsa_pipe_hnd(struct cli_state *ipc_cli)
  */
 
 static int
-ace_compare(SEC_ACE *ace1,
-            SEC_ACE *ace2)
+ace_compare(struct security_ace *ace1,
+            struct security_ace *ace2)
 {
         bool b1;
         bool b2;
@@ -120,8 +123,8 @@ ace_compare(SEC_ACE *ace1,
                return ace2->type - ace1->type;
         }
 
-       if (sid_compare(&ace1->trustee, &ace2->trustee)) {
-               return sid_compare(&ace1->trustee, &ace2->trustee);
+       if (dom_sid_compare(&ace1->trustee, &ace2->trustee)) {
+               return dom_sid_compare(&ace1->trustee, &ace2->trustee);
         }
 
        if (ace1->flags != ace2->flags) {
@@ -136,18 +139,17 @@ ace_compare(SEC_ACE *ace1,
                return ace1->size - ace2->size;
         }
 
-       return memcmp(ace1, ace2, sizeof(SEC_ACE));
+       return memcmp(ace1, ace2, sizeof(struct security_ace));
 }
 
 
 static void
-sort_acl(SEC_ACL *the_acl)
+sort_acl(struct security_acl *the_acl)
 {
        uint32 i;
        if (!the_acl) return;
 
-       qsort(the_acl->aces, the_acl->num_aces, sizeof(the_acl->aces[0]),
-              QSORT_CAST ace_compare);
+       TYPESAFE_QSORT(the_acl->aces, the_acl->num_aces, ace_compare);
 
        for (i=1;i<the_acl->num_aces;) {
                if (sec_ace_equal(&the_acl->aces[i-1], &the_acl->aces[i])) {
@@ -165,10 +167,10 @@ sort_acl(SEC_ACL *the_acl)
 /* convert a SID to a string, either numeric or username/group */
 static void
 convert_sid_to_string(struct cli_state *ipc_cli,
-                      POLICY_HND *pol,
+                      struct policy_handle *pol,
                       fstring str,
                       bool numeric,
-                      DOM_SID *sid)
+                      struct dom_sid *sid)
 {
        char **domains = NULL;
        char **names = NULL;
@@ -191,31 +193,32 @@ convert_sid_to_string(struct cli_state *ipc_cli,
        ctx = talloc_stackframe();
 
        if (!NT_STATUS_IS_OK(rpccli_lsa_lookup_sids(pipe_hnd, ctx,
-                                                pol, 1, sid, &domains,
-                                                &names, &types)) ||
+                                                    pol, 1, sid, &domains,
+                                                    &names, &types)) ||
            !domains || !domains[0] || !names || !names[0]) {
                TALLOC_FREE(ctx);
                return;
        }
 
-       TALLOC_FREE(ctx);
        /* Converted OK */
 
        slprintf(str, sizeof(fstring) - 1, "%s%s%s",
                 domains[0], lp_winbind_separator(),
                 names[0]);
+
+       TALLOC_FREE(ctx);
 }
 
 /* convert a string to a SID, either numeric or username/group */
 static bool
 convert_string_to_sid(struct cli_state *ipc_cli,
-                      POLICY_HND *pol,
+                      struct policy_handle *pol,
                       bool numeric,
-                      DOM_SID *sid,
+                      struct dom_sid *sid,
                       const char *str)
 {
        enum lsa_SidType *types = NULL;
-       DOM_SID *sids = NULL;
+       struct dom_sid *sids = NULL;
        bool result = True;
        TALLOC_CTX *ctx = NULL;
        struct rpc_pipe_client *pipe_hnd = find_lsa_pipe_hnd(ipc_cli);
@@ -235,25 +238,25 @@ convert_string_to_sid(struct cli_state *ipc_cli,
 
        ctx = talloc_stackframe();
        if (!NT_STATUS_IS_OK(rpccli_lsa_lookup_names(pipe_hnd, ctx,
-                                         pol, 1, &str, NULL, 1, &sids,
-                                         &types))) {
+                                                     pol, 1, &str,
+                                                     NULL, 1, &sids,
+                                                     &types))) {
                result = False;
                goto done;
        }
 
        sid_copy(sid, &sids[0]);
- done:
-
+done:
        TALLOC_FREE(ctx);
        return result;
 }
 
 
-/* parse an ACE in the same format as print_ace() */
+/* parse an struct security_ace in the same format as print_ace() */
 static bool
 parse_ace(struct cli_state *ipc_cli,
-          POLICY_HND *pol,
-          SEC_ACE *ace,
+          struct policy_handle *pol,
+          struct security_ace *ace,
           bool numeric,
           char *str)
 {
@@ -263,11 +266,11 @@ parse_ace(struct cli_state *ipc_cli,
        unsigned int atype;
         unsigned int aflags;
         unsigned int amask;
-       DOM_SID sid;
-       SEC_ACCESS mask;
+       struct dom_sid sid;
+       uint32_t mask;
        const struct perm_value *v;
         struct perm_value {
-                const char *perm;
+                const char perm[7];
                 uint32 mask;
         };
        TALLOC_CTX *frame = talloc_stackframe();
@@ -280,17 +283,16 @@ parse_ace(struct cli_state *ipc_cli,
                 { "D", 0x00010000 },
                 { "P", 0x00040000 },
                 { "O", 0x00080000 },
-                { NULL, 0 },
+                { "", 0 },
         };
 
         static const struct perm_value standard_values[] = {
                 { "READ",   0x001200a9 },
                 { "CHANGE", 0x001301bf },
                 { "FULL",   0x001f01ff },
-                { NULL, 0 },
+                { "", 0 },
         };
 
-
        ZERO_STRUCTP(ace);
        p = strchr_m(str,':');
        if (!p) {
@@ -319,9 +321,9 @@ parse_ace(struct cli_state *ipc_cli,
                return false;
        }
 
-       if (StrnCaseCmp(tok, "ALLOWED", strlen("ALLOWED")) == 0) {
+       if (strncasecmp_m(tok, "ALLOWED", strlen("ALLOWED")) == 0) {
                atype = SEC_ACE_TYPE_ACCESS_ALLOWED;
-       } else if (StrnCaseCmp(tok, "DENIED", strlen("DENIED")) == 0) {
+       } else if (strncasecmp_m(tok, "DENIED", strlen("DENIED")) == 0) {
                atype = SEC_ACE_TYPE_ACCESS_DENIED;
        } else {
                TALLOC_FREE(frame);
@@ -380,32 +382,33 @@ parse_ace(struct cli_state *ipc_cli,
                return false;
        }
 
- done:
+done:
        mask = amask;
        init_sec_ace(ace, &sid, atype, mask, aflags);
        TALLOC_FREE(frame);
        return true;
 }
 
-/* add an ACE to a list of ACEs in a SEC_ACL */
+/* add an struct security_ace to a list of struct security_aces in a struct security_acl */
 static bool
-add_ace(SEC_ACL **the_acl,
-        SEC_ACE *ace,
+add_ace(struct security_acl **the_acl,
+        struct security_ace *ace,
         TALLOC_CTX *ctx)
 {
-       SEC_ACL *newacl;
-       SEC_ACE *aces;
+       struct security_acl *newacl;
+       struct security_ace *aces;
 
        if (! *the_acl) {
                (*the_acl) = make_sec_acl(ctx, 3, 1, ace);
                return True;
        }
 
-       if ((aces = SMB_CALLOC_ARRAY(SEC_ACE, 1+(*the_acl)->num_aces)) == NULL) {
+       if ((aces = SMB_CALLOC_ARRAY(struct security_ace,
+                                     1+(*the_acl)->num_aces)) == NULL) {
                return False;
        }
-       memcpy(aces, (*the_acl)->aces, (*the_acl)->num_aces * sizeof(SEC_ACE));
-       memcpy(aces+(*the_acl)->num_aces, ace, sizeof(SEC_ACE));
+       memcpy(aces, (*the_acl)->aces, (*the_acl)->num_aces * sizeof(struct security_ace));
+       memcpy(aces+(*the_acl)->num_aces, ace, sizeof(struct security_ace));
        newacl = make_sec_acl(ctx, (*the_acl)->revision,
                               1+(*the_acl)->num_aces, aces);
        SAFE_FREE(aces);
@@ -415,35 +418,35 @@ add_ace(SEC_ACL **the_acl,
 
 
 /* parse a ascii version of a security descriptor */
-static SEC_DESC *
+static struct security_descriptor *
 sec_desc_parse(TALLOC_CTX *ctx,
                struct cli_state *ipc_cli,
-               POLICY_HND *pol,
+               struct policy_handle *pol,
                bool numeric,
-               char *str)
+               const char *str)
 {
        const char *p = str;
        char *tok;
-       SEC_DESC *ret = NULL;
+       struct security_descriptor *ret = NULL;
        size_t sd_size;
-       DOM_SID *group_sid=NULL;
-        DOM_SID *owner_sid=NULL;
-       SEC_ACL *dacl=NULL;
+       struct dom_sid *group_sid=NULL;
+        struct dom_sid *owner_sid=NULL;
+       struct security_acl *dacl=NULL;
        int revision=1;
 
        while (next_token_talloc(ctx, &p, &tok, "\t,\r\n")) {
 
-               if (StrnCaseCmp(tok,"REVISION:", 9) == 0) {
+               if (strncasecmp_m(tok,"REVISION:", 9) == 0) {
                        revision = strtol(tok+9, NULL, 16);
                        continue;
                }
 
-               if (StrnCaseCmp(tok,"OWNER:", 6) == 0) {
+               if (strncasecmp_m(tok,"OWNER:", 6) == 0) {
                        if (owner_sid) {
-                               DEBUG(5, ("OWNER specified more than once!\n"));
+                               DEBUG(5,("OWNER specified more than once!\n"));
                                goto done;
                        }
-                       owner_sid = SMB_CALLOC_ARRAY(DOM_SID, 1);
+                       owner_sid = SMB_CALLOC_ARRAY(struct dom_sid, 1);
                        if (!owner_sid ||
                            !convert_string_to_sid(ipc_cli, pol,
                                                    numeric,
@@ -454,12 +457,12 @@ sec_desc_parse(TALLOC_CTX *ctx,
                        continue;
                }
 
-               if (StrnCaseCmp(tok,"OWNER+:", 7) == 0) {
+               if (strncasecmp_m(tok,"OWNER+:", 7) == 0) {
                        if (owner_sid) {
-                               DEBUG(5, ("OWNER specified more than once!\n"));
+                               DEBUG(5,("OWNER specified more than once!\n"));
                                goto done;
                        }
-                       owner_sid = SMB_CALLOC_ARRAY(DOM_SID, 1);
+                       owner_sid = SMB_CALLOC_ARRAY(struct dom_sid, 1);
                        if (!owner_sid ||
                            !convert_string_to_sid(ipc_cli, pol,
                                                    False,
@@ -470,12 +473,12 @@ sec_desc_parse(TALLOC_CTX *ctx,
                        continue;
                }
 
-               if (StrnCaseCmp(tok,"GROUP:", 6) == 0) {
+               if (strncasecmp_m(tok,"GROUP:", 6) == 0) {
                        if (group_sid) {
-                               DEBUG(5, ("GROUP specified more than once!\n"));
+                               DEBUG(5,("GROUP specified more than once!\n"));
                                goto done;
                        }
-                       group_sid = SMB_CALLOC_ARRAY(DOM_SID, 1);
+                       group_sid = SMB_CALLOC_ARRAY(struct dom_sid, 1);
                        if (!group_sid ||
                            !convert_string_to_sid(ipc_cli, pol,
                                                    numeric,
@@ -486,12 +489,12 @@ sec_desc_parse(TALLOC_CTX *ctx,
                        continue;
                }
 
-               if (StrnCaseCmp(tok,"GROUP+:", 7) == 0) {
+               if (strncasecmp_m(tok,"GROUP+:", 7) == 0) {
                        if (group_sid) {
-                               DEBUG(5, ("GROUP specified more than once!\n"));
+                               DEBUG(5,("GROUP specified more than once!\n"));
                                goto done;
                        }
-                       group_sid = SMB_CALLOC_ARRAY(DOM_SID, 1);
+                       group_sid = SMB_CALLOC_ARRAY(struct dom_sid, 1);
                        if (!group_sid ||
                            !convert_string_to_sid(ipc_cli, pol,
                                                    False,
@@ -502,8 +505,8 @@ sec_desc_parse(TALLOC_CTX *ctx,
                        continue;
                }
 
-               if (StrnCaseCmp(tok,"ACL:", 4) == 0) {
-                       SEC_ACE ace;
+               if (strncasecmp_m(tok,"ACL:", 4) == 0) {
+                       struct security_ace ace;
                        if (!parse_ace(ipc_cli, pol, &ace, numeric, tok+4)) {
                                DEBUG(5, ("Failed to parse ACL %s\n", tok));
                                goto done;
@@ -515,8 +518,8 @@ sec_desc_parse(TALLOC_CTX *ctx,
                        continue;
                }
 
-               if (StrnCaseCmp(tok,"ACL+:", 5) == 0) {
-                       SEC_ACE ace;
+               if (strncasecmp_m(tok,"ACL+:", 5) == 0) {
+                       struct security_ace ace;
                        if (!parse_ace(ipc_cli, pol, &ace, False, tok+5)) {
                                DEBUG(5, ("Failed to parse ACL %s\n", tok));
                                goto done;
@@ -535,10 +538,9 @@ sec_desc_parse(TALLOC_CTX *ctx,
        ret = make_sec_desc(ctx, revision, SEC_DESC_SELF_RELATIVE, 
                            owner_sid, group_sid, NULL, dacl, &sd_size);
 
-  done:
+done:
        SAFE_FREE(group_sid);
        SAFE_FREE(owner_sid);
-
        return ret;
 }
 
@@ -559,14 +561,14 @@ dos_attr_query(SMBCCTX *context,
        SMB_INO_T inode = 0;
         DOS_ATTR_DESC *ret;
 
-        ret = TALLOC_P(ctx, DOS_ATTR_DESC);
+        ret = talloc(ctx, DOS_ATTR_DESC);
         if (!ret) {
                 errno = ENOMEM;
                 return NULL;
         }
 
         /* Obtain the DOS attributes */
-        if (!SMBC_getatr(context, srv, CONST_DISCARD(char *, filename),
+        if (!SMBC_getatr(context, srv, filename,
                          &mode, &size,
                          &create_time_ts,
                          &access_time_ts,
@@ -609,7 +611,7 @@ dos_attr_parse(SMBCCTX *context,
         } attr_strings;
 
         /* Determine whether to use old-style or new-style attribute names */
-        if (context->full_time_names) {
+        if (context->internal->full_time_names) {
                 /* new-style names */
                 attr_strings.create_time_attr = "CREATE_TIME";
                 attr_strings.access_time_attr = "ACCESS_TIME";
@@ -635,7 +637,7 @@ dos_attr_parse(SMBCCTX *context,
 
        frame = talloc_stackframe();
        while (next_token_talloc(frame, &p, &tok, "\t,\r\n")) {
-               if (StrnCaseCmp(tok, "MODE:", 5) == 0) {
+               if (strncasecmp_m(tok, "MODE:", 5) == 0) {
                         long request = strtol(tok+5, NULL, 16);
                         if (request == 0) {
                                 dad->mode = (request |
@@ -648,32 +650,32 @@ dos_attr_parse(SMBCCTX *context,
                        continue;
                }
 
-               if (StrnCaseCmp(tok, "SIZE:", 5) == 0) {
+               if (strncasecmp_m(tok, "SIZE:", 5) == 0) {
                         dad->size = (SMB_OFF_T)atof(tok+5);
                        continue;
                }
 
                 n = strlen(attr_strings.access_time_attr);
-                if (StrnCaseCmp(tok, attr_strings.access_time_attr, n) == 0) {
+                if (strncasecmp_m(tok, attr_strings.access_time_attr, n) == 0) {
                         dad->access_time = (time_t)strtol(tok+n+1, NULL, 10);
                        continue;
                }
 
                 n = strlen(attr_strings.change_time_attr);
-                if (StrnCaseCmp(tok, attr_strings.change_time_attr, n) == 0) {
+                if (strncasecmp_m(tok, attr_strings.change_time_attr, n) == 0) {
                         dad->change_time = (time_t)strtol(tok+n+1, NULL, 10);
                        continue;
                }
 
                 n = strlen(attr_strings.write_time_attr);
-                if (StrnCaseCmp(tok, attr_strings.write_time_attr, n) == 0) {
+                if (strncasecmp_m(tok, attr_strings.write_time_attr, n) == 0) {
                         dad->write_time = (time_t)strtol(tok+n+1, NULL, 10);
                        continue;
                }
 
                if (attr_strings.create_time_attr != NULL) {
                        n = strlen(attr_strings.create_time_attr);
-                       if (StrnCaseCmp(tok, attr_strings.create_time_attr,
+                       if (strncasecmp_m(tok, attr_strings.create_time_attr,
                                        n) == 0) {
                                dad->create_time = (time_t)strtol(tok+n+1,
                                                                  NULL, 10);
@@ -681,7 +683,7 @@ dos_attr_parse(SMBCCTX *context,
                        }
                }
 
-               if (StrnCaseCmp(tok, "INODE:", 6) == 0) {
+               if (strncasecmp_m(tok, "INODE:", 6) == 0) {
                         dad->inode = (SMB_INO_T)atof(tok+6);
                        continue;
                }
@@ -698,9 +700,9 @@ cacl_get(SMBCCTX *context,
          TALLOC_CTX *ctx,
          SMBCSRV *srv,
          struct cli_state *ipc_cli,
-         POLICY_HND *pol,
-         char *filename,
-         char *attr_name,
+         struct policy_handle *pol,
+         const char *filename,
+         const char *attr_name,
          char *buf,
          int bufsize)
 {
@@ -726,8 +728,8 @@ cacl_get(SMBCCTX *context,
         bool exclude_dos_inode = False;
         bool numeric = True;
         bool determine_size = (bufsize == 0);
-       int fnum = -1;
-       SEC_DESC *sd;
+       uint16_t fnum;
+       struct security_descriptor *sd;
        fstring sidstr;
         fstring name_sandbox;
         char *name;
@@ -744,7 +746,7 @@ cacl_get(SMBCCTX *context,
        SMB_OFF_T size = 0;
        uint16 mode = 0;
        SMB_INO_T ino = 0;
-        struct cli_state *cli = srv->cli;
+       struct cli_state *cli = srv->cli;
         struct {
                 const char * create_time_attr;
                 const char * access_time_attr;
@@ -759,7 +761,7 @@ cacl_get(SMBCCTX *context,
         } excl_attr_strings;
 
         /* Determine whether to use old-style or new-style attribute names */
-        if (context->full_time_names) {
+        if (context->internal->full_time_names) {
                 /* new-style names */
                 attr_strings.create_time_attr = "CREATE_TIME";
                 attr_strings.access_time_attr = "ACCESS_TIME";
@@ -798,74 +800,79 @@ cacl_get(SMBCCTX *context,
                 *pExclude++ = '\0';
         }
 
-        all = (StrnCaseCmp(name, "system.*", 8) == 0);
-        all_nt = (StrnCaseCmp(name, "system.nt_sec_desc.*", 20) == 0);
-        all_nt_acls = (StrnCaseCmp(name, "system.nt_sec_desc.acl.*", 24) == 0);
-        all_dos = (StrnCaseCmp(name, "system.dos_attr.*", 17) == 0);
-        some_nt = (StrnCaseCmp(name, "system.nt_sec_desc.", 19) == 0);
-        some_dos = (StrnCaseCmp(name, "system.dos_attr.", 16) == 0);
+        all = (strncasecmp_m(name, "system.*", 8) == 0);
+        all_nt = (strncasecmp_m(name, "system.nt_sec_desc.*", 20) == 0);
+        all_nt_acls = (strncasecmp_m(name, "system.nt_sec_desc.acl.*", 24) == 0);
+        all_dos = (strncasecmp_m(name, "system.dos_attr.*", 17) == 0);
+        some_nt = (strncasecmp_m(name, "system.nt_sec_desc.", 19) == 0);
+        some_dos = (strncasecmp_m(name, "system.dos_attr.", 16) == 0);
         numeric = (* (name + strlen(name) - 1) != '+');
 
         /* Look for exclusions from "all" requests */
         if (all || all_nt || all_dos) {
-
                 /* Exclusions are delimited by '!' */
                 for (;
                      pExclude != NULL;
                      pExclude = (p == NULL ? NULL : p + 1)) {
 
-                /* Find end of this exclusion name */
-                if ((p = strchr(pExclude, '!')) != NULL)
-                {
-                    *p = '\0';
-                }
+                        /* Find end of this exclusion name */
+                        if ((p = strchr(pExclude, '!')) != NULL)
+                        {
+                                *p = '\0';
+                        }
 
-                /* Which exclusion name is this? */
-                if (StrCaseCmp(pExclude, "nt_sec_desc.revision") == 0) {
-                    exclude_nt_revision = True;
-                }
-                else if (StrCaseCmp(pExclude, "nt_sec_desc.owner") == 0) {
-                    exclude_nt_owner = True;
-                }
-                else if (StrCaseCmp(pExclude, "nt_sec_desc.group") == 0) {
-                    exclude_nt_group = True;
-                }
-                else if (StrCaseCmp(pExclude, "nt_sec_desc.acl") == 0) {
-                    exclude_nt_acl = True;
-                }
-                else if (StrCaseCmp(pExclude, "dos_attr.mode") == 0) {
-                    exclude_dos_mode = True;
-                }
-                else if (StrCaseCmp(pExclude, "dos_attr.size") == 0) {
-                    exclude_dos_size = True;
-                }
-                else if (excl_attr_strings.create_time_attr != NULL &&
-                         StrCaseCmp(pExclude,
-                                    excl_attr_strings.change_time_attr) == 0) {
-                    exclude_dos_create_time = True;
-                }
-                else if (StrCaseCmp(pExclude,
-                                    excl_attr_strings.access_time_attr) == 0) {
-                    exclude_dos_access_time = True;
-                }
-                else if (StrCaseCmp(pExclude,
-                                    excl_attr_strings.write_time_attr) == 0) {
-                    exclude_dos_write_time = True;
-                }
-                else if (StrCaseCmp(pExclude,
-                                    excl_attr_strings.change_time_attr) == 0) {
-                    exclude_dos_change_time = True;
-                }
-                else if (StrCaseCmp(pExclude, "dos_attr.inode") == 0) {
-                    exclude_dos_inode = True;
-                }
-                else {
-                    DEBUG(5, ("cacl_get received unknown exclusion: %s\n",
-                              pExclude));
-                    errno = ENOATTR;
-                    return -1;
+                        /* Which exclusion name is this? */
+                        if (strcasecmp_m(pExclude,
+                                       "nt_sec_desc.revision") == 0) {
+                                exclude_nt_revision = True;
+                        }
+                        else if (strcasecmp_m(pExclude,
+                                            "nt_sec_desc.owner") == 0) {
+                                exclude_nt_owner = True;
+                        }
+                        else if (strcasecmp_m(pExclude,
+                                            "nt_sec_desc.group") == 0) {
+                                exclude_nt_group = True;
+                        }
+                        else if (strcasecmp_m(pExclude,
+                                            "nt_sec_desc.acl") == 0) {
+                                exclude_nt_acl = True;
+                        }
+                        else if (strcasecmp_m(pExclude,
+                                            "dos_attr.mode") == 0) {
+                                exclude_dos_mode = True;
+                        }
+                        else if (strcasecmp_m(pExclude,
+                                            "dos_attr.size") == 0) {
+                                exclude_dos_size = True;
+                        }
+                        else if (excl_attr_strings.create_time_attr != NULL &&
+                                 strcasecmp_m(pExclude,
+                                            excl_attr_strings.change_time_attr) == 0) {
+                                exclude_dos_create_time = True;
+                        }
+                        else if (strcasecmp_m(pExclude,
+                                            excl_attr_strings.access_time_attr) == 0) {
+                                exclude_dos_access_time = True;
+                        }
+                        else if (strcasecmp_m(pExclude,
+                                            excl_attr_strings.write_time_attr) == 0) {
+                                exclude_dos_write_time = True;
+                        }
+                        else if (strcasecmp_m(pExclude,
+                                            excl_attr_strings.change_time_attr) == 0) {
+                                exclude_dos_change_time = True;
+                        }
+                        else if (strcasecmp_m(pExclude, "dos_attr.inode") == 0) {
+                                exclude_dos_inode = True;
+                        }
+                        else {
+                                DEBUG(5, ("cacl_get received unknown exclusion: %s\n",
+                                          pExclude));
+                                errno = ENOATTR;
+                                return -1;
+                        }
                 }
-            }
         }
 
         n_used = 0;
@@ -875,20 +882,36 @@ cacl_get(SMBCCTX *context,
          * attributes have been requested...
          */
         if (ipc_cli && (all || some_nt || all_nt_acls)) {
+               char *targetpath = NULL;
+               struct cli_state *targetcli = NULL;
+               NTSTATUS status;
+
                 /* Point to the portion after "system.nt_sec_desc." */
                 name += 19;     /* if (all) this will be invalid but unused */
 
-                /* ... then obtain any NT attributes which were requested */
-                fnum = cli_nt_create(cli, filename, CREATE_ACCESS_READ);
-
-                if (fnum == -1) {
-                        DEBUG(5, ("cacl_get failed to open %s: %s\n",
-                                  filename, cli_errstr(cli)));
-                        errno = 0;
+               status = cli_resolve_path(
+                       ctx, "", context->internal->auth_info,
+                       cli, filename, &targetcli, &targetpath);
+               if (!NT_STATUS_IS_OK(status)) {
+                       DEBUG(5, ("cacl_get Could not resolve %s\n",
+                               filename));
+                        errno = ENOENT;
                         return -1;
-                }
+               }
 
-                sd = cli_query_secdesc(cli, fnum, ctx);
+                /* ... then obtain any NT attributes which were requested */
+               status = cli_ntcreate(targetcli, targetpath, 0,
+                                     CREATE_ACCESS_READ, 0,
+                                     FILE_SHARE_READ|FILE_SHARE_WRITE,
+                                     FILE_OPEN, 0x0, 0x0, &fnum);
+               if (!NT_STATUS_IS_OK(status)) {
+                       DEBUG(5, ("cacl_get failed to open %s: %s\n",
+                                 targetpath, nt_errstr(status)));
+                       errno = 0;
+                       return -1;
+               }
+
+               sd = cli_query_secdesc(targetcli, fnum, ctx);
 
                 if (!sd) {
                         DEBUG(5,
@@ -897,7 +920,7 @@ cacl_get(SMBCCTX *context,
                         return -1;
                 }
 
-                cli_close(cli, fnum);
+                cli_close(targetcli, fnum);
 
                 if (! exclude_nt_revision) {
                         if (all || all_nt) {
@@ -915,7 +938,7 @@ cacl_get(SMBCCTX *context,
                                                      "REVISION:%d",
                                                      sd->revision);
                                 }
-                        } else if (StrCaseCmp(name, "revision") == 0) {
+                        } else if (strcasecmp_m(name, "revision") == 0) {
                                 if (determine_size) {
                                         p = talloc_asprintf(ctx, "%d",
                                                             sd->revision);
@@ -964,7 +987,7 @@ cacl_get(SMBCCTX *context,
                                         n = snprintf(buf, bufsize,
                                                      ",OWNER:%s", sidstr);
                                 }
-                        } else if (StrnCaseCmp(name, "owner", 5) == 0) {
+                        } else if (strncasecmp_m(name, "owner", 5) == 0) {
                                 if (determine_size) {
                                         p = talloc_asprintf(ctx, "%s", sidstr);
                                         if (!p) {
@@ -1010,7 +1033,7 @@ cacl_get(SMBCCTX *context,
                                         n = snprintf(buf, bufsize,
                                                      ",GROUP:%s", sidstr);
                                 }
-                        } else if (StrnCaseCmp(name, "group", 5) == 0) {
+                        } else if (strncasecmp_m(name, "group", 5) == 0) {
                                 if (determine_size) {
                                         p = talloc_asprintf(ctx, "%s", sidstr);
                                         if (!p) {
@@ -1038,7 +1061,7 @@ cacl_get(SMBCCTX *context,
                         /* Add aces to value buffer  */
                         for (i = 0; sd->dacl && i < sd->dacl->num_aces; i++) {
 
-                                SEC_ACE *ace = &sd->dacl->aces[i];
+                                struct security_ace *ace = &sd->dacl->aces[i];
                                 convert_sid_to_string(ipc_cli, pol,
                                                       sidstr, numeric,
                                                       &ace->trustee);
@@ -1067,10 +1090,10 @@ cacl_get(SMBCCTX *context,
                                                         ace->flags,
                                                         ace->access_mask);
                                         }
-                                } else if ((StrnCaseCmp(name, "acl", 3) == 0 &&
-                                            StrCaseCmp(name+3, sidstr) == 0) ||
-                                           (StrnCaseCmp(name, "acl+", 4) == 0 &&
-                                            StrCaseCmp(name+4, sidstr) == 0)) {
+                                } else if ((strncasecmp_m(name, "acl", 3) == 0 &&
+                                            strcasecmp_m(name+3, sidstr) == 0) ||
+                                           (strncasecmp_m(name, "acl+", 4) == 0 &&
+                                            strcasecmp_m(name+4, sidstr) == 0)) {
                                         if (determine_size) {
                                                 p = talloc_asprintf(
                                                         ctx, 
@@ -1144,7 +1167,6 @@ cacl_get(SMBCCTX *context,
 
                         errno = SMBC_errno(context, srv->cli);
                         return -1;
-
                 }
 
                 create_time = convert_timespec_to_time_t(create_time_ts);
@@ -1176,7 +1198,7 @@ cacl_get(SMBCCTX *context,
                                                       : ""),
                                                      mode);
                                 }
-                        } else if (StrCaseCmp(name, "mode") == 0) {
+                        } else if (strcasecmp_m(name, "mode") == 0) {
                                 if (determine_size) {
                                         p = talloc_asprintf(ctx, "0x%x", mode);
                                         if (!p) {
@@ -1217,7 +1239,7 @@ cacl_get(SMBCCTX *context,
                                                      ",SIZE:%.0f",
                                                      (double)size);
                                 }
-                        } else if (StrCaseCmp(name, "size") == 0) {
+                        } else if (strcasecmp_m(name, "size") == 0) {
                                 if (determine_size) {
                                         p = talloc_asprintf(
                                                 ctx,
@@ -1252,7 +1274,7 @@ cacl_get(SMBCCTX *context,
                                         p = talloc_asprintf(ctx,
                                                             ",%s:%lu",
                                                             attr_strings.create_time_attr,
-                                                            create_time);
+                                                            (unsigned long) create_time);
                                         if (!p) {
                                                 errno = ENOMEM;
                                                 return -1;
@@ -1262,11 +1284,11 @@ cacl_get(SMBCCTX *context,
                                         n = snprintf(buf, bufsize,
                                                      ",%s:%lu",
                                                      attr_strings.create_time_attr,
-                                                     create_time);
+                                                     (unsigned long) create_time);
                                 }
-                        } else if (StrCaseCmp(name, attr_strings.create_time_attr) == 0) {
+                        } else if (strcasecmp_m(name, attr_strings.create_time_attr) == 0) {
                                 if (determine_size) {
-                                        p = talloc_asprintf(ctx, "%lu", create_time);
+                                        p = talloc_asprintf(ctx, "%lu", (unsigned long) create_time);
                                         if (!p) {
                                                 errno = ENOMEM;
                                                 return -1;
@@ -1274,7 +1296,7 @@ cacl_get(SMBCCTX *context,
                                         n = strlen(p);
                                 } else {
                                         n = snprintf(buf, bufsize,
-                                                     "%lu", create_time);
+                                                     "%lu", (unsigned long) create_time);
                                 }
                         }
 
@@ -1294,7 +1316,7 @@ cacl_get(SMBCCTX *context,
                                         p = talloc_asprintf(ctx,
                                                             ",%s:%lu",
                                                             attr_strings.access_time_attr,
-                                                            access_time);
+                                                            (unsigned long) access_time);
                                         if (!p) {
                                                 errno = ENOMEM;
                                                 return -1;
@@ -1304,11 +1326,11 @@ cacl_get(SMBCCTX *context,
                                         n = snprintf(buf, bufsize,
                                                      ",%s:%lu",
                                                      attr_strings.access_time_attr,
-                                                     access_time);
+                                                     (unsigned long) access_time);
                                 }
-                        } else if (StrCaseCmp(name, attr_strings.access_time_attr) == 0) {
+                        } else if (strcasecmp_m(name, attr_strings.access_time_attr) == 0) {
                                 if (determine_size) {
-                                        p = talloc_asprintf(ctx, "%lu", access_time);
+                                        p = talloc_asprintf(ctx, "%lu", (unsigned long) access_time);
                                         if (!p) {
                                                 errno = ENOMEM;
                                                 return -1;
@@ -1316,7 +1338,7 @@ cacl_get(SMBCCTX *context,
                                         n = strlen(p);
                                 } else {
                                         n = snprintf(buf, bufsize,
-                                                     "%lu", access_time);
+                                                     "%lu", (unsigned long) access_time);
                                 }
                         }
 
@@ -1336,7 +1358,7 @@ cacl_get(SMBCCTX *context,
                                         p = talloc_asprintf(ctx,
                                                             ",%s:%lu",
                                                             attr_strings.write_time_attr,
-                                                            write_time);
+                                                            (unsigned long) write_time);
                                         if (!p) {
                                                 errno = ENOMEM;
                                                 return -1;
@@ -1346,11 +1368,11 @@ cacl_get(SMBCCTX *context,
                                         n = snprintf(buf, bufsize,
                                                      ",%s:%lu",
                                                      attr_strings.write_time_attr,
-                                                     write_time);
+                                                     (unsigned long) write_time);
                                 }
-                        } else if (StrCaseCmp(name, attr_strings.write_time_attr) == 0) {
+                        } else if (strcasecmp_m(name, attr_strings.write_time_attr) == 0) {
                                 if (determine_size) {
-                                        p = talloc_asprintf(ctx, "%lu", write_time);
+                                        p = talloc_asprintf(ctx, "%lu", (unsigned long) write_time);
                                         if (!p) {
                                                 errno = ENOMEM;
                                                 return -1;
@@ -1358,7 +1380,7 @@ cacl_get(SMBCCTX *context,
                                         n = strlen(p);
                                 } else {
                                         n = snprintf(buf, bufsize,
-                                                     "%lu", write_time);
+                                                     "%lu", (unsigned long) write_time);
                                 }
                         }
 
@@ -1378,7 +1400,7 @@ cacl_get(SMBCCTX *context,
                                         p = talloc_asprintf(ctx,
                                                             ",%s:%lu",
                                                             attr_strings.change_time_attr,
-                                                            change_time);
+                                                            (unsigned long) change_time);
                                         if (!p) {
                                                 errno = ENOMEM;
                                                 return -1;
@@ -1388,11 +1410,11 @@ cacl_get(SMBCCTX *context,
                                         n = snprintf(buf, bufsize,
                                                      ",%s:%lu",
                                                      attr_strings.change_time_attr,
-                                                     change_time);
+                                                     (unsigned long) change_time);
                                 }
-                        } else if (StrCaseCmp(name, attr_strings.change_time_attr) == 0) {
+                        } else if (strcasecmp_m(name, attr_strings.change_time_attr) == 0) {
                                 if (determine_size) {
-                                        p = talloc_asprintf(ctx, "%lu", change_time);
+                                        p = talloc_asprintf(ctx, "%lu", (unsigned long) change_time);
                                         if (!p) {
                                                 errno = ENOMEM;
                                                 return -1;
@@ -1400,7 +1422,7 @@ cacl_get(SMBCCTX *context,
                                         n = strlen(p);
                                 } else {
                                         n = snprintf(buf, bufsize,
-                                                     "%lu", change_time);
+                                                     "%lu", (unsigned long) change_time);
                                 }
                         }
 
@@ -1431,7 +1453,7 @@ cacl_get(SMBCCTX *context,
                                                      ",INODE:%.0f",
                                                      (double) ino);
                                 }
-                        } else if (StrCaseCmp(name, "inode") == 0) {
+                        } else if (strcasecmp_m(name, "inode") == 0) {
                                 if (determine_size) {
                                         p = talloc_asprintf(
                                                 ctx,
@@ -1475,26 +1497,30 @@ cacl_get(SMBCCTX *context,
 set the ACLs on a file given an ascii description
 *******************************************************/
 static int
-cacl_set(TALLOC_CTX *ctx,
-         struct cli_state *cli,
-         struct cli_state *ipc_cli,
-         POLICY_HND *pol,
-         const char *filename,
-         const char *the_acl,
-         int mode,
-         int flags)
+cacl_set(SMBCCTX *context,
+       TALLOC_CTX *ctx,
+       struct cli_state *cli,
+       struct cli_state *ipc_cli,
+       struct policy_handle *pol,
+       const char *filename,
+       char *the_acl,
+       int mode,
+       int flags)
 {
-       int fnum;
+       uint16_t fnum = (uint16_t)-1;
         int err = 0;
-       SEC_DESC *sd = NULL, *old;
-        SEC_ACL *dacl = NULL;
-       DOM_SID *owner_sid = NULL;
-       DOM_SID *group_sid = NULL;
+       struct security_descriptor *sd = NULL, *old;
+        struct security_acl *dacl = NULL;
+       struct dom_sid *owner_sid = NULL;
+       struct dom_sid *group_sid = NULL;
        uint32 i, j;
        size_t sd_size;
        int ret = 0;
         char *p;
         bool numeric = True;
+       char *targetpath = NULL;
+       struct cli_state *targetcli = NULL;
+       NTSTATUS status;
 
         /* the_acl will be null for REMOVE_ALL operations */
         if (the_acl) {
@@ -1508,9 +1534,7 @@ cacl_set(TALLOC_CTX *ctx,
                         the_acl = p + 1;
                 }
 
-                sd = sec_desc_parse(ctx, ipc_cli, pol, numeric,
-                                    CONST_DISCARD(char *, the_acl));
-
+                sd = sec_desc_parse(ctx, ipc_cli, pol, numeric, the_acl);
                 if (!sd) {
                        errno = EINVAL;
                        return -1;
@@ -1525,19 +1549,28 @@ cacl_set(TALLOC_CTX *ctx,
                return -1;
        }
 
+       status = cli_resolve_path(ctx, "", context->internal->auth_info,
+                                 cli, filename, &targetcli, &targetpath);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(5,("cacl_set: Could not resolve %s\n", filename));
+               errno = ENOENT;
+               return -1;
+       }
+
        /* The desired access below is the only one I could find that works
           with NT4, W2KP and Samba */
 
-       fnum = cli_nt_create(cli, filename, CREATE_ACCESS_READ);
-
-       if (fnum == -1) {
+       status = cli_ntcreate(targetcli, targetpath, 0, CREATE_ACCESS_READ, 0,
+                             FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN,
+                             0x0, 0x0, &fnum);
+       if (!NT_STATUS_IS_OK(status)) {
                 DEBUG(5, ("cacl_set failed to open %s: %s\n",
-                          filename, cli_errstr(cli)));
+                          targetpath, nt_errstr(status)));
                 errno = 0;
                return -1;
        }
 
-       old = cli_query_secdesc(cli, fnum, ctx);
+       old = cli_query_secdesc(targetcli, fnum, ctx);
 
        if (!old) {
                 DEBUG(5, ("cacl_set Failed to query old descriptor\n"));
@@ -1545,7 +1578,7 @@ cacl_set(TALLOC_CTX *ctx,
                return -1;
        }
 
-       cli_close(cli, fnum);
+       cli_close(targetcli, fnum);
 
        switch (mode) {
        case SMBC_XATTR_MODE_REMOVE_ALL:
@@ -1585,7 +1618,7 @@ cacl_set(TALLOC_CTX *ctx,
                        bool found = False;
 
                        for (j=0;old->dacl && j<old->dacl->num_aces;j++) {
-                               if (sid_equal(&sd->dacl->aces[i].trustee,
+                               if (dom_sid_equal(&sd->dacl->aces[i].trustee,
                                              &old->dacl->aces[j].trustee)) {
                                         if (!(flags & SMBC_XATTR_FLAG_CREATE)) {
                                                 err = EEXIST;
@@ -1634,25 +1667,28 @@ cacl_set(TALLOC_CTX *ctx,
        sd = make_sec_desc(ctx, old->revision, SEC_DESC_SELF_RELATIVE,
                           owner_sid, group_sid, NULL, dacl, &sd_size);
 
-       fnum = cli_nt_create(cli, filename,
-                             WRITE_DAC_ACCESS | WRITE_OWNER_ACCESS);
-
-       if (fnum == -1) {
+       status = cli_ntcreate(targetcli, targetpath, 0,
+                             WRITE_DAC_ACCESS | WRITE_OWNER_ACCESS, 0,
+                             FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN,
+                             0x0, 0x0, &fnum);
+       if (!NT_STATUS_IS_OK(status)) {
                DEBUG(5, ("cacl_set failed to open %s: %s\n",
-                          filename, cli_errstr(cli)));
+                          targetpath, nt_errstr(status)));
                 errno = 0;
                return -1;
        }
 
-       if (!cli_set_secdesc(cli, fnum, sd)) {
-               DEBUG(5, ("ERROR: secdesc set failed: %s\n", cli_errstr(cli)));
+       status = cli_set_secdesc(targetcli, fnum, sd);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(5, ("ERROR: secdesc set failed: %s\n",
+                         nt_errstr(status)));
                ret = -1;
        }
 
        /* Clean up */
 
- failed:
-       cli_close(cli, fnum);
+failed:
+       cli_close(targetcli, fnum);
 
         if (err != 0) {
                 errno = err;
@@ -1689,8 +1725,7 @@ SMBC_setxattr_ctx(SMBCCTX *context,
         } attr_strings;
         TALLOC_CTX *frame = talloc_stackframe();
 
-       if (!context || !context->initialized) {
-
+       if (!context || !context->internal->initialized) {
                errno = EINVAL;  /* Best I can think of ... */
                TALLOC_FREE(frame);
                return -1;
@@ -1706,22 +1741,22 @@ SMBC_setxattr_ctx(SMBCCTX *context,
                   fname, name, (int) size, (const char*)value));
 
        if (SMBC_parse_path(frame,
-                               context,
-                               fname,
-                               &workgroup,
-                               &server,
-                               &share,
-                               &path,
-                               &user,
-                               &password,
-                               NULL)) {
+                            context,
+                            fname,
+                            &workgroup,
+                            &server,
+                            &share,
+                            &path,
+                            &user,
+                            &password,
+                            NULL)) {
                errno = EINVAL;
                TALLOC_FREE(frame);
                return -1;
         }
 
        if (!user || user[0] == (char)0) {
-               user = talloc_strdup(frame, context->user);
+               user = talloc_strdup(frame, smbc_getUser(context));
                if (!user) {
                        errno = ENOMEM;
                        TALLOC_FREE(frame);
@@ -1749,8 +1784,8 @@ SMBC_setxattr_ctx(SMBCCTX *context,
         /*
          * Are they asking to set the entire set of known attributes?
          */
-        if (StrCaseCmp(name, "system.*") == 0 ||
-            StrCaseCmp(name, "system.*+") == 0) {
+        if (strcasecmp_m(name, "system.*") == 0 ||
+            strcasecmp_m(name, "system.*+") == 0) {
                 /* Yup. */
                 char *namevalue =
                         talloc_asprintf(talloc_tos(), "%s:%s",
@@ -1763,7 +1798,7 @@ SMBC_setxattr_ctx(SMBCCTX *context,
                 }
 
                 if (ipc_srv) {
-                        ret = cacl_set(talloc_tos(), srv->cli,
+                        ret = cacl_set(context, talloc_tos(), srv->cli,
                                        ipc_srv->cli, &ipc_srv->pol, path,
                                        namevalue,
                                        (*namevalue == '*'
@@ -1809,11 +1844,11 @@ SMBC_setxattr_ctx(SMBCCTX *context,
          * Are they asking to set an access control element or to set
          * the entire access control list?
          */
-        if (StrCaseCmp(name, "system.nt_sec_desc.*") == 0 ||
-            StrCaseCmp(name, "system.nt_sec_desc.*+") == 0 ||
-            StrCaseCmp(name, "system.nt_sec_desc.revision") == 0 ||
-            StrnCaseCmp(name, "system.nt_sec_desc.acl", 22) == 0 ||
-            StrnCaseCmp(name, "system.nt_sec_desc.acl+", 23) == 0) {
+        if (strcasecmp_m(name, "system.nt_sec_desc.*") == 0 ||
+            strcasecmp_m(name, "system.nt_sec_desc.*+") == 0 ||
+            strcasecmp_m(name, "system.nt_sec_desc.revision") == 0 ||
+            strncasecmp_m(name, "system.nt_sec_desc.acl", 22) == 0 ||
+            strncasecmp_m(name, "system.nt_sec_desc.acl+", 23) == 0) {
 
                 /* Yup. */
                 char *namevalue =
@@ -1827,7 +1862,7 @@ SMBC_setxattr_ctx(SMBCCTX *context,
                         errno = ENOMEM;
                         ret = -1;
                 } else {
-                        ret = cacl_set(talloc_tos(), srv->cli,
+                        ret = cacl_set(context, talloc_tos(), srv->cli,
                                        ipc_srv->cli, &ipc_srv->pol, path,
                                        namevalue,
                                        (*namevalue == '*'
@@ -1842,8 +1877,8 @@ SMBC_setxattr_ctx(SMBCCTX *context,
         /*
          * Are they asking to set the owner?
          */
-        if (StrCaseCmp(name, "system.nt_sec_desc.owner") == 0 ||
-            StrCaseCmp(name, "system.nt_sec_desc.owner+") == 0) {
+        if (strcasecmp_m(name, "system.nt_sec_desc.owner") == 0 ||
+            strcasecmp_m(name, "system.nt_sec_desc.owner+") == 0) {
 
                 /* Yup. */
                 char *namevalue =
@@ -1857,7 +1892,7 @@ SMBC_setxattr_ctx(SMBCCTX *context,
                         errno = ENOMEM;
                         ret = -1;
                 } else {
-                        ret = cacl_set(talloc_tos(), srv->cli,
+                        ret = cacl_set(context, talloc_tos(), srv->cli,
                                        ipc_srv->cli, &ipc_srv->pol, path,
                                        namevalue, SMBC_XATTR_MODE_CHOWN, 0);
                 }
@@ -1868,8 +1903,8 @@ SMBC_setxattr_ctx(SMBCCTX *context,
         /*
          * Are they asking to set the group?
          */
-        if (StrCaseCmp(name, "system.nt_sec_desc.group") == 0 ||
-            StrCaseCmp(name, "system.nt_sec_desc.group+") == 0) {
+        if (strcasecmp_m(name, "system.nt_sec_desc.group") == 0 ||
+            strcasecmp_m(name, "system.nt_sec_desc.group+") == 0) {
 
                 /* Yup. */
                 char *namevalue =
@@ -1884,7 +1919,7 @@ SMBC_setxattr_ctx(SMBCCTX *context,
                         errno = ENOMEM;
                         ret = -1;
                 } else {
-                        ret = cacl_set(talloc_tos(), srv->cli,
+                        ret = cacl_set(context, talloc_tos(), srv->cli,
                                        ipc_srv->cli, &ipc_srv->pol, path,
                                        namevalue, SMBC_XATTR_MODE_CHGRP, 0);
                 }
@@ -1893,7 +1928,7 @@ SMBC_setxattr_ctx(SMBCCTX *context,
         }
 
         /* Determine whether to use old-style or new-style attribute names */
-        if (context->full_time_names) {
+        if (context->internal->full_time_names) {
                 /* new-style names */
                 attr_strings.create_time_attr = "system.dos_attr.CREATE_TIME";
                 attr_strings.access_time_attr = "system.dos_attr.ACCESS_TIME";
@@ -1910,13 +1945,13 @@ SMBC_setxattr_ctx(SMBCCTX *context,
         /*
          * Are they asking to set a DOS attribute?
          */
-        if (StrCaseCmp(name, "system.dos_attr.*") == 0 ||
-            StrCaseCmp(name, "system.dos_attr.mode") == 0 ||
+        if (strcasecmp_m(name, "system.dos_attr.*") == 0 ||
+            strcasecmp_m(name, "system.dos_attr.mode") == 0 ||
             (attr_strings.create_time_attr != NULL &&
-             StrCaseCmp(name, attr_strings.create_time_attr) == 0) ||
-            StrCaseCmp(name, attr_strings.access_time_attr) == 0 ||
-            StrCaseCmp(name, attr_strings.write_time_attr) == 0 ||
-            StrCaseCmp(name, attr_strings.change_time_attr) == 0) {
+             strcasecmp_m(name, attr_strings.create_time_attr) == 0) ||
+            strcasecmp_m(name, attr_strings.access_time_attr) == 0 ||
+            strcasecmp_m(name, attr_strings.write_time_attr) == 0 ||
+            strcasecmp_m(name, attr_strings.change_time_attr) == 0) {
 
                 /* get a DOS Attribute Descriptor with current attributes */
                 dad = dos_attr_query(context, talloc_tos(), path, srv);
@@ -1984,8 +2019,7 @@ SMBC_getxattr_ctx(SMBCCTX *context,
         } attr_strings;
        TALLOC_CTX *frame = talloc_stackframe();
 
-       if (!context || !context->initialized) {
-
+       if (!context || !context->internal->initialized) {
                 errno = EINVAL;  /* Best I can think of ... */
                TALLOC_FREE(frame);
                 return -1;
@@ -2000,22 +2034,22 @@ SMBC_getxattr_ctx(SMBCCTX *context,
         DEBUG(4, ("smbc_getxattr(%s, %s)\n", fname, name));
 
         if (SMBC_parse_path(frame,
-                               context,
-                               fname,
-                               &workgroup,
-                               &server,
-                               &share,
-                               &path,
-                               &user,
-                               &password,
-                               NULL)) {
+                            context,
+                            fname,
+                            &workgroup,
+                            &server,
+                            &share,
+                            &path,
+                            &user,
+                            &password,
+                            NULL)) {
                errno = EINVAL;
                TALLOC_FREE(frame);
                return -1;
         }
 
         if (!user || user[0] == (char)0) {
-               user = talloc_strdup(frame, context->user);
+               user = talloc_strdup(frame, smbc_getUser(context));
                if (!user) {
                        errno = ENOMEM;
                        TALLOC_FREE(frame);
@@ -2041,7 +2075,7 @@ SMBC_getxattr_ctx(SMBCCTX *context,
         }
 
         /* Determine whether to use old-style or new-style attribute names */
-        if (context->full_time_names) {
+        if (context->internal->full_time_names) {
                 /* new-style names */
                 attr_strings.create_time_attr = "system.dos_attr.CREATE_TIME";
                 attr_strings.access_time_attr = "system.dos_attr.ACCESS_TIME";
@@ -2056,38 +2090,40 @@ SMBC_getxattr_ctx(SMBCCTX *context,
         }
 
         /* Are they requesting a supported attribute? */
-        if (StrCaseCmp(name, "system.*") == 0 ||
-            StrnCaseCmp(name, "system.*!", 9) == 0 ||
-            StrCaseCmp(name, "system.*+") == 0 ||
-            StrnCaseCmp(name, "system.*+!", 10) == 0 ||
-            StrCaseCmp(name, "system.nt_sec_desc.*") == 0 ||
-            StrnCaseCmp(name, "system.nt_sec_desc.*!", 21) == 0 ||
-            StrCaseCmp(name, "system.nt_sec_desc.*+") == 0 ||
-            StrnCaseCmp(name, "system.nt_sec_desc.*+!", 22) == 0 ||
-            StrCaseCmp(name, "system.nt_sec_desc.revision") == 0 ||
-            StrCaseCmp(name, "system.nt_sec_desc.owner") == 0 ||
-            StrCaseCmp(name, "system.nt_sec_desc.owner+") == 0 ||
-            StrCaseCmp(name, "system.nt_sec_desc.group") == 0 ||
-            StrCaseCmp(name, "system.nt_sec_desc.group+") == 0 ||
-            StrnCaseCmp(name, "system.nt_sec_desc.acl", 22) == 0 ||
-            StrnCaseCmp(name, "system.nt_sec_desc.acl+", 23) == 0 ||
-            StrCaseCmp(name, "system.dos_attr.*") == 0 ||
-            StrnCaseCmp(name, "system.dos_attr.*!", 18) == 0 ||
-            StrCaseCmp(name, "system.dos_attr.mode") == 0 ||
-            StrCaseCmp(name, "system.dos_attr.size") == 0 ||
+        if (strcasecmp_m(name, "system.*") == 0 ||
+            strncasecmp_m(name, "system.*!", 9) == 0 ||
+            strcasecmp_m(name, "system.*+") == 0 ||
+            strncasecmp_m(name, "system.*+!", 10) == 0 ||
+            strcasecmp_m(name, "system.nt_sec_desc.*") == 0 ||
+            strncasecmp_m(name, "system.nt_sec_desc.*!", 21) == 0 ||
+            strcasecmp_m(name, "system.nt_sec_desc.*+") == 0 ||
+            strncasecmp_m(name, "system.nt_sec_desc.*+!", 22) == 0 ||
+            strcasecmp_m(name, "system.nt_sec_desc.revision") == 0 ||
+            strcasecmp_m(name, "system.nt_sec_desc.owner") == 0 ||
+            strcasecmp_m(name, "system.nt_sec_desc.owner+") == 0 ||
+            strcasecmp_m(name, "system.nt_sec_desc.group") == 0 ||
+            strcasecmp_m(name, "system.nt_sec_desc.group+") == 0 ||
+            strncasecmp_m(name, "system.nt_sec_desc.acl", 22) == 0 ||
+            strncasecmp_m(name, "system.nt_sec_desc.acl+", 23) == 0 ||
+            strcasecmp_m(name, "system.dos_attr.*") == 0 ||
+            strncasecmp_m(name, "system.dos_attr.*!", 18) == 0 ||
+            strcasecmp_m(name, "system.dos_attr.mode") == 0 ||
+            strcasecmp_m(name, "system.dos_attr.size") == 0 ||
             (attr_strings.create_time_attr != NULL &&
-             StrCaseCmp(name, attr_strings.create_time_attr) == 0) ||
-            StrCaseCmp(name, attr_strings.access_time_attr) == 0 ||
-            StrCaseCmp(name, attr_strings.write_time_attr) == 0 ||
-            StrCaseCmp(name, attr_strings.change_time_attr) == 0 ||
-            StrCaseCmp(name, "system.dos_attr.inode") == 0) {
+             strcasecmp_m(name, attr_strings.create_time_attr) == 0) ||
+            strcasecmp_m(name, attr_strings.access_time_attr) == 0 ||
+            strcasecmp_m(name, attr_strings.write_time_attr) == 0 ||
+            strcasecmp_m(name, attr_strings.change_time_attr) == 0 ||
+            strcasecmp_m(name, "system.dos_attr.inode") == 0) {
 
                 /* Yup. */
+                const char *filename = name;
                 ret = cacl_get(context, talloc_tos(), srv,
                                ipc_srv == NULL ? NULL : ipc_srv->cli, 
                                &ipc_srv->pol, path,
-                               CONST_DISCARD(char *, name),
-                               CONST_DISCARD(char *, value), size);
+                               filename,
+                               discard_const_p(char, value),
+                               size);
                 if (ret < 0 && errno == 0) {
                         errno = SMBC_errno(context, srv->cli);
                 }
@@ -2118,8 +2154,7 @@ SMBC_removexattr_ctx(SMBCCTX *context,
        char *path = NULL;
        TALLOC_CTX *frame = talloc_stackframe();
 
-       if (!context || !context->initialized) {
-
+       if (!context || !context->internal->initialized) {
                 errno = EINVAL;  /* Best I can think of ... */
                TALLOC_FREE(frame);
                 return -1;
@@ -2134,22 +2169,22 @@ SMBC_removexattr_ctx(SMBCCTX *context,
         DEBUG(4, ("smbc_removexattr(%s, %s)\n", fname, name));
 
        if (SMBC_parse_path(frame,
-                               context,
-                               fname,
-                               &workgroup,
-                               &server,
-                               &share,
-                               &path,
-                               &user,
-                               &password,
-                               NULL)) {
+                            context,
+                            fname,
+                            &workgroup,
+                            &server,
+                            &share,
+                            &path,
+                            &user,
+                            &password,
+                            NULL)) {
                errno = EINVAL;
                TALLOC_FREE(frame);
                return -1;
         }
 
         if (!user || user[0] == (char)0) {
-               user = talloc_strdup(frame, context->user);
+               user = talloc_strdup(frame, smbc_getUser(context));
                if (!user) {
                        errno = ENOMEM;
                        TALLOC_FREE(frame);
@@ -2180,11 +2215,11 @@ SMBC_removexattr_ctx(SMBCCTX *context,
         }
 
         /* Are they asking to set the entire ACL? */
-        if (StrCaseCmp(name, "system.nt_sec_desc.*") == 0 ||
-            StrCaseCmp(name, "system.nt_sec_desc.*+") == 0) {
+        if (strcasecmp_m(name, "system.nt_sec_desc.*") == 0 ||
+            strcasecmp_m(name, "system.nt_sec_desc.*+") == 0) {
 
                 /* Yup. */
-                ret = cacl_set(talloc_tos(), srv->cli,
+                ret = cacl_set(context, talloc_tos(), srv->cli,
                                ipc_srv->cli, &ipc_srv->pol, path,
                                NULL, SMBC_XATTR_MODE_REMOVE_ALL, 0);
                TALLOC_FREE(frame);
@@ -2195,18 +2230,19 @@ SMBC_removexattr_ctx(SMBCCTX *context,
          * Are they asking to remove one or more spceific security descriptor
          * attributes?
          */
-        if (StrCaseCmp(name, "system.nt_sec_desc.revision") == 0 ||
-            StrCaseCmp(name, "system.nt_sec_desc.owner") == 0 ||
-            StrCaseCmp(name, "system.nt_sec_desc.owner+") == 0 ||
-            StrCaseCmp(name, "system.nt_sec_desc.group") == 0 ||
-            StrCaseCmp(name, "system.nt_sec_desc.group+") == 0 ||
-            StrnCaseCmp(name, "system.nt_sec_desc.acl", 22) == 0 ||
-            StrnCaseCmp(name, "system.nt_sec_desc.acl+", 23) == 0) {
+        if (strcasecmp_m(name, "system.nt_sec_desc.revision") == 0 ||
+            strcasecmp_m(name, "system.nt_sec_desc.owner") == 0 ||
+            strcasecmp_m(name, "system.nt_sec_desc.owner+") == 0 ||
+            strcasecmp_m(name, "system.nt_sec_desc.group") == 0 ||
+            strcasecmp_m(name, "system.nt_sec_desc.group+") == 0 ||
+            strncasecmp_m(name, "system.nt_sec_desc.acl", 22) == 0 ||
+            strncasecmp_m(name, "system.nt_sec_desc.acl+", 23) == 0) {
 
                 /* Yup. */
-                ret = cacl_set(talloc_tos(), srv->cli,
+                ret = cacl_set(context, talloc_tos(), srv->cli,
                                ipc_srv->cli, &ipc_srv->pol, path,
-                               name + 19, SMBC_XATTR_MODE_REMOVE, 0);
+                               discard_const_p(char, name) + 19,
+                               SMBC_XATTR_MODE_REMOVE, 0);
                TALLOC_FREE(frame);
                 return ret;
         }
@@ -2270,7 +2306,7 @@ SMBC_listxattr_ctx(SMBCCTX *context,
                 ;
         const char * supported;
 
-        if (context->full_time_names) {
+        if (context->internal->full_time_names) {
                 supported = supported_new;
                 retsize = sizeof(supported_new);
         } else {