s3: libsmbclient: After getting attribute server, ensure main srv pointer is still...
[sfrench/samba-autobuild/.git] / source3 / libsmb / libsmb_xattr.c
index c2ba61f88ea8ac4b469d705ec143629e3ed9a87c..9f7bea8da11b0e6c5d64ad80d6920a57b2e8ec17 100644 (file)
@@ -64,7 +64,7 @@ ace_compare(struct security_ace *ace1,
         bool b2;
 
         /* If the ACEs are equal, we have nothing more to do. */
-        if (sec_ace_equal(ace1, ace2)) {
+        if (security_ace_equal(ace1, ace2)) {
                return 0;
         }
 
@@ -152,7 +152,8 @@ sort_acl(struct security_acl *the_acl)
        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])) {
+               if (security_ace_equal(&the_acl->aces[i-1],
+                                      &the_acl->aces[i])) {
                        int j;
                        for (j=i; j<the_acl->num_aces-1; j++) {
                                the_acl->aces[j] = the_acl->aces[j+1];
@@ -303,7 +304,7 @@ parse_ace(struct cli_state *ipc_cli,
        p++;
        /* Try to parse numeric form */
 
-       if (sscanf(p, "%i/%i/%i", &atype, &aflags, &amask) == 3 &&
+       if (sscanf(p, "%u/%u/%u", &atype, &aflags, &amask) == 3 &&
            convert_string_to_sid(ipc_cli, pol, numeric, &sid, str)) {
                goto done;
        }
@@ -333,7 +334,7 @@ parse_ace(struct cli_state *ipc_cli,
        /* Only numeric form accepted for flags at present */
 
        if (!(next_token_talloc(frame, &cp, &tok, "/") &&
-             sscanf(tok, "%i", &aflags))) {
+             sscanf(tok, "%u", &aflags))) {
                TALLOC_FREE(frame);
                return false;
        }
@@ -344,7 +345,7 @@ parse_ace(struct cli_state *ipc_cli,
        }
 
        if (strncmp(tok, "0x", 2) == 0) {
-               if (sscanf(tok, "%i", &amask) != 1) {
+               if (sscanf(tok, "%u", &amask) != 1) {
                        TALLOC_FREE(frame);
                        return false;
                }
@@ -904,7 +905,7 @@ cacl_get(SMBCCTX *context,
                status = cli_ntcreate(targetcli, targetpath, 0,
                                      CREATE_ACCESS_READ, 0,
                                      FILE_SHARE_READ|FILE_SHARE_WRITE,
-                                     FILE_OPEN, 0x0, 0x0, &fnum);
+                                     FILE_OPEN, 0x0, 0x0, &fnum, NULL);
                if (!NT_STATUS_IS_OK(status)) {
                        DEBUG(5, ("cacl_get failed to open %s: %s\n",
                                  targetpath, nt_errstr(status)));
@@ -1563,7 +1564,7 @@ cacl_set(SMBCCTX *context,
 
        status = cli_ntcreate(targetcli, targetpath, 0, CREATE_ACCESS_READ, 0,
                              FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN,
-                             0x0, 0x0, &fnum);
+                             0x0, 0x0, &fnum, NULL);
        if (!NT_STATUS_IS_OK(status)) {
                 DEBUG(5, ("cacl_set failed to open %s: %s\n",
                           targetpath, nt_errstr(status)));
@@ -1592,8 +1593,8 @@ cacl_set(SMBCCTX *context,
                        bool found = False;
 
                        for (j=0;old->dacl && j<old->dacl->num_aces;j++) {
-                                if (sec_ace_equal(&sd->dacl->aces[i],
-                                                  &old->dacl->aces[j])) {
+                                if (security_ace_equal(&sd->dacl->aces[i],
+                                                      &old->dacl->aces[j])) {
                                        uint32 k;
                                        for (k=j; k<old->dacl->num_aces-1;k++) {
                                                old->dacl->aces[k] =
@@ -1671,7 +1672,7 @@ cacl_set(SMBCCTX *context,
        status = cli_ntcreate(targetcli, targetpath, 0,
                              WRITE_DAC_ACCESS | WRITE_OWNER_ACCESS, 0,
                              FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN,
-                             0x0, 0x0, &fnum);
+                             0x0, 0x0, &fnum, NULL);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(5, ("cacl_set failed to open %s: %s\n",
                           targetpath, nt_errstr(status)));
@@ -1724,6 +1725,7 @@ SMBC_setxattr_ctx(SMBCCTX *context,
                 const char * write_time_attr;
                 const char * change_time_attr;
         } attr_strings;
+       uint16_t port = 0;
         TALLOC_CTX *frame = talloc_stackframe();
 
        if (!context || !context->internal->initialized) {
@@ -1746,6 +1748,7 @@ SMBC_setxattr_ctx(SMBCCTX *context,
                             fname,
                             &workgroup,
                             &server,
+                            &port,
                             &share,
                             &path,
                             &user,
@@ -1766,14 +1769,14 @@ SMBC_setxattr_ctx(SMBCCTX *context,
        }
 
        srv = SMBC_server(frame, context, True,
-                          server, share, &workgroup, &user, &password);
+                          server, port, share, &workgroup, &user, &password);
        if (!srv) {
                TALLOC_FREE(frame);
                return -1;  /* errno set by SMBC_server */
        }
 
         if (! srv->no_nt_session) {
-                ipc_srv = SMBC_attr_server(frame, context, server, share,
+                ipc_srv = SMBC_attr_server(frame, context, server, port, share,
                                            &workgroup, &user, &password);
                 if (! ipc_srv) {
                         srv->no_nt_session = True;
@@ -2018,6 +2021,7 @@ SMBC_getxattr_ctx(SMBCCTX *context,
                 const char * write_time_attr;
                 const char * change_time_attr;
         } attr_strings;
+       uint16_t port = 0;
        TALLOC_CTX *frame = talloc_stackframe();
 
        if (!context || !context->internal->initialized) {
@@ -2039,6 +2043,7 @@ SMBC_getxattr_ctx(SMBCCTX *context,
                             fname,
                             &workgroup,
                             &server,
+                            &port,
                             &share,
                             &path,
                             &user,
@@ -2059,15 +2064,34 @@ SMBC_getxattr_ctx(SMBCCTX *context,
        }
 
         srv = SMBC_server(frame, context, True,
-                          server, share, &workgroup, &user, &password);
+                          server, port, share, &workgroup, &user, &password);
         if (!srv) {
                TALLOC_FREE(frame);
                 return -1;  /* errno set by SMBC_server */
         }
 
         if (! srv->no_nt_session) {
-                ipc_srv = SMBC_attr_server(frame, context, server, share,
+                ipc_srv = SMBC_attr_server(frame, context, server, port, share,
                                            &workgroup, &user, &password);
+               /*
+                * SMBC_attr_server() can cause the original
+                * server to be removed from the cache.
+                * If so we must error out here as the srv
+                * pointer has been freed.
+                */
+               if (smbc_getFunctionGetCachedServer(context)(context,
+                               server,
+                               share,
+                               workgroup,
+                               user) != srv) {
+#if defined(ECONNRESET)
+                       errno = ECONNRESET;
+#else
+                       errno = ETIMEDOUT;
+#endif
+                       TALLOC_FREE(frame);
+                       return -1;
+               }
                 if (! ipc_srv) {
                         srv->no_nt_session = True;
                 }
@@ -2153,6 +2177,7 @@ SMBC_removexattr_ctx(SMBCCTX *context,
        char *password = NULL;
        char *workgroup = NULL;
        char *path = NULL;
+       uint16_t port = 0;
        TALLOC_CTX *frame = talloc_stackframe();
 
        if (!context || !context->internal->initialized) {
@@ -2174,6 +2199,7 @@ SMBC_removexattr_ctx(SMBCCTX *context,
                             fname,
                             &workgroup,
                             &server,
+                            &port,
                             &share,
                             &path,
                             &user,
@@ -2194,16 +2220,38 @@ SMBC_removexattr_ctx(SMBCCTX *context,
        }
 
         srv = SMBC_server(frame, context, True,
-                          server, share, &workgroup, &user, &password);
+                          server, port, share, &workgroup, &user, &password);
         if (!srv) {
                TALLOC_FREE(frame);
                 return -1;  /* errno set by SMBC_server */
         }
 
         if (! srv->no_nt_session) {
-                ipc_srv = SMBC_attr_server(frame, context, server, share,
+               int saved_errno;
+                ipc_srv = SMBC_attr_server(frame, context, server, port, share,
                                            &workgroup, &user, &password);
+               saved_errno = errno;
+               /*
+                * SMBC_attr_server() can cause the original
+                * server to be removed from the cache.
+                * If so we must error out here as the srv
+                * pointer has been freed.
+                */
+               if (smbc_getFunctionGetCachedServer(context)(context,
+                               server,
+                               share,
+                               workgroup,
+                               user) != srv) {
+#if defined(ECONNRESET)
+                       errno = ECONNRESET;
+#else
+                       errno = ETIMEDOUT;
+#endif
+                       TALLOC_FREE(frame);
+                       return -1;
+               }
                 if (! ipc_srv) {
+                       errno = saved_errno;
                         srv->no_nt_session = True;
                 }
         } else {