smbd: Ensure we grant owner sid in check_parent_access_fsp()
[samba.git] / source3 / utils / net_usershare.c
index 5e630ea5d4a320b7dff35d0b2a7e5c69a9803fb2..745888224348bf422db16c588c88b947f1567e88 100644 (file)
@@ -24,6 +24,7 @@
 #include "utils/net.h"
 #include "../libcli/security/security.h"
 #include "lib/util/string_wrappers.h"
+#include "lib/util/util_file.h"
 
 struct {
        const char *us_errstr;
@@ -891,6 +892,12 @@ static int net_usershare_add(struct net_context *c, int argc, const char **argv)
                        "%s:%c,",
                        dom_sid_str_buf(&sid, &buf),
                        pcolon[1]);
+               if (us_acl == NULL) {
+                       d_fprintf(stderr,
+                                 _("net usershare add: talloc_asprintf_append() failed\n"));
+                       TALLOC_FREE(ctx);
+                       return -1;
+               }
 
                /* Move to the next ACL entry. */
                if (pcolon[2] == ',') {
@@ -955,7 +962,7 @@ static int net_usershare_add(struct net_context *c, int argc, const char **argv)
        if (fchmod(tmpfd, 0644) == -1) {
                d_fprintf(stderr,
                          _("net usershare add: failed to fchmod tmp file %s "
-                           "to 0644n"),
+                           "to 0644\n"),
                          full_path_tmp );
                TALLOC_FREE(ctx);
                close(tmpfd);
@@ -964,6 +971,13 @@ static int net_usershare_add(struct net_context *c, int argc, const char **argv)
 
        /* Create the in-memory image of the file. */
        file_img = talloc_strdup(ctx, "#VERSION 2\npath=");
+       if (file_img == NULL) {
+               d_fprintf(stderr,
+                         _("net usershare add: talloc_strdup() failed\n"));
+               TALLOC_FREE(ctx);
+               close(tmpfd);
+               return -1;
+       }
        file_img = talloc_asprintf_append(file_img,
                        "%s\ncomment=%s\nusershare_acl=%s\n"
                        "guest_ok=%c\nsharename=%s\n",
@@ -972,6 +986,13 @@ static int net_usershare_add(struct net_context *c, int argc, const char **argv)
                        us_acl,
                        guest_ok ? 'y' : 'n',
                        cp_sharename);
+       if (file_img == NULL) {
+               d_fprintf(stderr,
+                         _("net usershare add: talloc_asprintf_append() failed\n"));
+               TALLOC_FREE(ctx);
+               close(tmpfd);
+               return -1;
+       }
 
        to_write = strlen(file_img);