The branch, master has been updated
       via  8b7c8eb lib: Fix array size in audit_logging
       via  609ef35 s4:ntvfs: Fix string copy of share_name
       via  fb6cd9c lib:util: Fix size types in debug.c
       via  6f06a01 lib:util: Fix parameter aliasing in tfork test
       via  6b728b8 s3:winbind: Fix uninitialzed variable warning
       via  728297c s3:passdb: Fix size of ascii_p16
       via  ff7568d s3:lib: Use memcpy() in escape_ldap_string()
       via  7a00d90 s4:torture: Use strlcpy() in gen_name()
       via  7cec343 lib:util: Fix string check in mkdir_p()
       via  9b6dc8f s3-utils: fix format-truncation in smbpasswd
       via  5729898 s4-torture: fix format-truncation warning in smb2 session 
tests.
       via  6326b34 s3-printing: fix format-truncation in print_queue_update()
       via  b24d4eb s3-winbindd: remove unused fill_domain_username()
       via  3c6481d s3-winbindd: use fill_domain_username_talloc() in winbind.
       via  e1dad1d s3:winbind: Check if we have an open file descriptor
       via  2a0ad57 s3:winbind: Add sanity check when closing fd
      from  cdd98aa s3:utils: Do not segfault on error in DoDNSUpdate()

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 8b7c8eb3907e2123acee67949e88c26072afc81a
Author: Andreas Schneider <a...@samba.org>
Date:   Wed May 16 13:59:55 2018 +0200

    lib: Fix array size in audit_logging
    
    ../lib/audit_logging/audit_logging.c: In function ‘json_add_timestamp’:
    ../lib/audit_logging/audit_logging.c:603:12: error: ‘%s’ directive
           output may be truncated writing up to 9 bytes into a region of size
           between 0 and 43 [-Werror=format-truncation=]
       "%s.%06ld%s",
                ^~
    ../lib/audit_logging/audit_logging.c:606:3:
       tz);
       ~~
    ../lib/audit_logging/audit_logging.c:600:2: note: ‘snprintf’ output
           between 8 and 70 bytes into a destination of size 50
      snprintf(
      ^~~~~~~~~
       timestamp,
       ~~~~~~~~~~
       sizeof(timestamp),
       ~~~~~~~~~~~~~~~~~~
       "%s.%06ld%s",
       ~~~~~~~~~~~~~
       buffer,
       ~~~~~~~
       tv.tv_usec,
       ~~~~~~~~~~~
       tz);
       ~~~
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13437
    
    Signed-off-by: Andreas Schneider <a...@samba.org>
    Reviewed-by: Guenther Deschner <g...@samba.org>
    
    Autobuild-User(master): Andreas Schneider <a...@cryptomilk.org>
    Autobuild-Date(master): Thu May 17 20:17:35 CEST 2018 on sn-devel-144

commit 609ef35c12900bbd5ecaa557f7b5d71b5784a103
Author: Andreas Schneider <a...@samba.org>
Date:   Tue May 15 17:55:22 2018 +0200

    s4:ntvfs: Fix string copy of share_name
    
    ../source4/ntvfs/ipc/rap_server.c:70:3: error: ‘strncpy’ specified bound 13 
equals destination size [-Werror=stringop-truncation]
       strncpy((char *)r->out.info[j].info1.share_name,
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        snames[i],
        ~~~~~~~~~~
        sizeof(r->out.info[0].info1.share_name));
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    Signed-off-by: Andreas Schneider <a...@samba.org>
    Reviewed-by: Guenther Deschner <g...@samba.org>

commit fb6cd9c44ac6fcc9f6abe3b63fc742aeac42969a
Author: Andreas Schneider <a...@samba.org>
Date:   Tue May 8 09:31:51 2018 +0200

    lib:util: Fix size types in debug.c
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13437
    
    Signed-off-by: Andreas Schneider <a...@samba.org>
    Reviewed-by: Guenther Deschner <g...@samba.org>

commit 6f06a0154f5769cb85f6e189eecd78cd7805090a
Author: Andreas Schneider <a...@samba.org>
Date:   Wed May 9 17:52:19 2018 +0200

    lib:util: Fix parameter aliasing in tfork test
    
    ../lib/util/tests/tfork.c:483:24: error: passing argument 1 to
        restrict-qualified parameter aliases with argument 4 [-Werror=restrict]
       ret = pthread_create(&threads[i],
                            ^~~~~~~~~~~
    ../lib/util/tests/tfork.c:486:10:
              (void *)&threads[i]);
              ~~~~~~~~~~~~~~~~~~~
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13437
    
    Signed-off-by: Andreas Schneider <a...@samba.org>
    Reviewed-by: Guenther Deschner <g...@samba.org>

commit 6b728b87bf5726f14100d76956c3df3fd9bb1058
Author: Andreas Schneider <a...@samba.org>
Date:   Wed May 9 18:07:47 2018 +0200

    s3:winbind: Fix uninitialzed variable warning
    
    Raised by GCC8.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13437
    
    Signed-off-by: Andreas Schneider <a...@samba.org>
    Reviewed-by: Guenther Deschner <g...@samba.org>

commit 728297ca889b39ce2006778bf6a5bf1c3ce82d6d
Author: Andreas Schneider <a...@samba.org>
Date:   Wed May 9 18:05:01 2018 +0200

    s3:passdb: Fix size of ascii_p16
    
    ../source3/passdb/pdb_smbpasswd.c: In function ‘mod_smbfilepwd_entry’:
    ../source3/passdb/pdb_smbpasswd.c:1015:7: error: ‘:LCT-’ directive
        output may be truncated writing 5 bytes into a region of size between 0
        and 255 [-Werror=format-truncat ion=]
        "%s:LCT-%08X:",
           ^~~~~
    ../source3/passdb/pdb_smbpasswd.c:1015:4: note: using the range [0,
        4294967295] for directive argument
        "%s:LCT-%08X:",
        ^~~~~~~~~~~~~~
    In file included from ../source3/include/includes.h:23,
                     from ../source3/passdb/pdb_smbpasswd.c:23:
    ../lib/replace/../replace/replace.h:514:18: note: ‘snprintf’ output
        between 15 and 270 bytes into a destination of size 255
     #define slprintf snprintf
    ../source3/passdb/pdb_smbpasswd.c:1013:3: note: in expansion of macro 
‘slprintf’
       slprintf(&ascii_p16[strlen(ascii_p16)],
       ^~~~~~~~
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13437
    
    Signed-off-by: Andreas Schneider <a...@samba.org>
    Reviewed-by: Guenther Deschner <g...@samba.org>

commit ff7568daaeb19ff30f47f7f600ead247eaf4e826
Author: Andreas Schneider <a...@samba.org>
Date:   Wed May 9 17:29:39 2018 +0200

    s3:lib: Use memcpy() in escape_ldap_string()
    
    ../source3/lib/ldap_escape.c: In function ‘escape_ldap_string’:
    ../source3/lib/ldap_escape.c:79:4: error: ‘strncpy’ output truncated
        before terminating nul copying 3 bytes from a string of the same length
    [-Werror=stringop-truncation]
        strncpy (p, sub, 3);
        ^~~~~~~~~~~~~~~~~~~
    
    We concatenat and do not care about NUL-termination till the loop has
    finished.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13437
    
    Signed-off-by: Andreas Schneider <a...@samba.org>
    Reviewed-by: Guenther Deschner <g...@samba.org>

commit 7a00d90d668f53914ffe035c41a5e79e60b51521
Author: Andreas Schneider <a...@samba.org>
Date:   Wed May 9 17:35:45 2018 +0200

    s4:torture: Use strlcpy() in gen_name()
    
    ../source4/torture/basic/mangle_test.c: In function ‘gen_name’:
    ../source4/torture/basic/mangle_test.c:148:3: error: ‘strncpy’ output
        truncated before terminating nul copying 5 bytes from a string of the
        same length [-Werror=stringop-truncation]
       strncpy(p, "ABCDE", 5);
       ^~~~~~~~~~~~~~~~~~~~~~
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13437
    
    Signed-off-by: Andreas Schneider <a...@samba.org>
    Reviewed-by: Guenther Deschner <g...@samba.org>

commit 7cec343a89a0862c09f5ddd4707eb442157a4af2
Author: Andreas Schneider <a...@samba.org>
Date:   Tue May 8 09:22:00 2018 +0200

    lib:util: Fix string check in mkdir_p()
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13437
    
    Signed-off-by: Andreas Schneider <a...@samba.org>
    Reviewed-by: Guenther Deschner <g...@samba.org>

commit 9b6dc8f504c406ed8a044e5becca7e8f01da6c84
Author: Günther Deschner <g...@samba.org>
Date:   Tue May 8 14:13:56 2018 +0200

    s3-utils: fix format-truncation in smbpasswd
    
    ../source3/utils/smbpasswd.c: In function ‘process_root’:
    ../source3/utils/smbpasswd.c:414:37: error: ‘$’ directive output may be 
truncated writing 1 byte into a region of size between 0 and 255 
[-Werror=format-truncation=]
       slprintf(buf, sizeof(buf) - 1, "%s$", user_name);
                                         ^
    In file included from ../source3/include/includes.h:23,
                     from ../source3/utils/smbpasswd.c:19:
    ../lib/replace/../replace/replace.h:514:18: note: ‘snprintf’ output between 
2 and 257 bytes into a destination of size 255
     #define slprintf snprintf
    ../source3/utils/smbpasswd.c:414:3: note: in expansion of macro ‘slprintf’
       slprintf(buf, sizeof(buf) - 1, "%s$", user_name);
       ^~~~~~~~
    ../source3/utils/smbpasswd.c:397:35: error: ‘$’ directive output may be 
truncated writing 1 byte into a region of size between 0 and 255 
[-Werror=format-truncation=]
       slprintf(buf, sizeof(buf)-1, "%s$", user_name);
                                       ^
    In file included from ../source3/include/includes.h:23,
                     from ../source3/utils/smbpasswd.c:19:
    ../lib/replace/../replace/replace.h:514:18: note: ‘snprintf’ output between 
2 and 257 bytes into a destination of size 255
     #define slprintf snprintf
    ../source3/utils/smbpasswd.c:397:3: note: in expansion of macro ‘slprintf’
       slprintf(buf, sizeof(buf)-1, "%s$", user_name);
       ^~~~~~~~
    cc1: some warnings being treated as errors
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13437
    
    Pair-Programmed-With: Andreas Schneider <a...@samba.org>
    
    Signed-off-by: Guenther Deschner <g...@samba.org>
    Signed-off-by: Andreas Schneider <a...@samba.org>

commit 5729898248041794ffdd0b769332e015baf12cce
Author: Günther Deschner <g...@samba.org>
Date:   Tue May 8 13:54:53 2018 +0200

    s4-torture: fix format-truncation warning in smb2 session tests.
    
    ../source4/torture/smb2/session.c: In function ‘test_session_reauth5’:
    ../source4/torture/smb2/session.c:645:36: error: ‘\file.dat’ directive 
output may be truncated writing 9 bytes into a region of size between 1 and 256 
[-Werror=format-truncation=]
      snprintf(fname, sizeof(fname), "%s\\file.dat", dname);
                                        ^~~~~~~~~~
    ../source4/torture/smb2/session.c:645:2: note: ‘snprintf’ output between 10 
and 265 bytes into a destination of size 256
      snprintf(fname, sizeof(fname), "%s\\file.dat", dname);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ../source4/torture/smb2/session.c:696:38: error: ‘\file2.dat’ directive 
output may be truncated writing 10 bytes into a region of size between 1 and 
256 [-Werror=format-truncation=]
      snprintf(fname2, sizeof(fname2), "%s\\file2.dat", dname);
                                          ^~~~~~~~~~~
    ../source4/torture/smb2/session.c:696:2: note: ‘snprintf’ output between 11 
and 266 bytes into a destination of size 256
      snprintf(fname2, sizeof(fname2), "%s\\file2.dat", dname);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    cc1: some warnings being treated as errors
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13437
    
    Guenther
    
    Signed-off-by: Guenther Deschner <g...@samba.org>
    Reviewed-by: Andreas Schneider <a...@samba.org>

commit 6326b3415f3e225aafd5912d0965c80abcd7b22c
Author: Günther Deschner <g...@samba.org>
Date:   Tue May 8 13:46:11 2018 +0200

    s3-printing: fix format-truncation in print_queue_update()
    
    ../source3/printing/printing.c: In function ‘print_queue_update’:
    ../source3/printing/printing.c:1809:42: error: ‘%s’ directive output may be 
truncated writing up to 255 bytes into a region of size 244 
[-Werror=format-truncation=]
      snprintf(key, sizeof(key), "MSG_PENDING/%s", sharename);
                                              ^~   ~~~~~~~~~
    ../source3/printing/printing.c:1809:2: note: ‘snprintf’ output between 13 
and 268 bytes into a destination of size 256
      snprintf(key, sizeof(key), "MSG_PENDING/%s", sharename);
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13437
    
    Guenther
    
    Signed-off-by: Guenther Deschner <g...@samba.org>
    Reviewed-by: Andreas Schneider <a...@samba.org>

commit b24d4eb7afad82afc3a9bab65e1d799edc4b5172
Author: Günther Deschner <g...@samba.org>
Date:   Tue May 8 11:19:42 2018 +0200

    s3-winbindd: remove unused fill_domain_username()
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13437
    
    Guenther
    
    Signed-off-by: Guenther Deschner <g...@samba.org>
    Reviewed-by: Andreas Schneider <a...@samba.org>

commit 3c6481d75cea175d0a69988577163efb40e2316b
Author: Günther Deschner <g...@samba.org>
Date:   Tue May 8 11:18:56 2018 +0200

    s3-winbindd: use fill_domain_username_talloc() in winbind.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13437
    
    Guenther
    
    Signed-off-by: Guenther Deschner <g...@samba.org>
    Reviewed-by: Andreas Schneider <a...@samba.org>

commit e1dad1d8ddeb9281b267186163dc4109cae3d599
Author: Andreas Schneider <a...@samba.org>
Date:   Wed May 16 14:06:36 2018 +0200

    s3:winbind: Check if we have an open file descriptor
    
    Found by Coverity.
    
    Signed-off-by: Andreas Schneider <a...@samba.org>
    Reviewed-by: Guenther Deschner <g...@samba.org>

commit 2a0ad57b211ad87709e5886f319a450c4f9db3fd
Author: Andreas Schneider <a...@samba.org>
Date:   Wed May 16 11:59:09 2018 +0200

    s3:winbind: Add sanity check when closing fd
    
    Found by Coverity.
    
    Signed-off-by: Andreas Schneider <a...@samba.org>
    Reviewed-by: Guenther Deschner <g...@samba.org>

-----------------------------------------------------------------------

Summary of changes:
 lib/audit_logging/audit_logging.c       |  2 +-
 lib/util/debug.c                        | 14 +++++-----
 lib/util/mkdir_p.c                      |  4 +--
 lib/util/tests/tfork.c                  |  7 ++---
 source3/lib/ldap_escape.c               |  2 +-
 source3/passdb/pdb_smbpasswd.c          |  2 +-
 source3/printing/printing.c             |  2 +-
 source3/utils/smbpasswd.c               | 49 +++++++++++++++++----------------
 source3/winbindd/wb_getpwsid.c          | 15 ++++++++--
 source3/winbindd/wb_query_user_list.c   |  9 ++++--
 source3/winbindd/winbindd_cm.c          | 11 ++++++--
 source3/winbindd/winbindd_group.c       | 12 +++++---
 source3/winbindd/winbindd_list_groups.c | 14 +++++++---
 source3/winbindd/winbindd_pam.c         | 13 +++++++--
 source3/winbindd/winbindd_proto.h       |  1 -
 source3/winbindd/winbindd_util.c        | 20 --------------
 source4/ntvfs/ipc/rap_server.c          |  9 ++++--
 source4/torture/basic/mangle_test.c     |  2 +-
 source4/torture/smb2/session.c          |  2 +-
 19 files changed, 104 insertions(+), 86 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/audit_logging/audit_logging.c 
b/lib/audit_logging/audit_logging.c
index 7da161c..5c16806 100644
--- a/lib/audit_logging/audit_logging.c
+++ b/lib/audit_logging/audit_logging.c
@@ -569,7 +569,7 @@ void json_add_version(struct json_object *object, int 
major, int minor)
 void json_add_timestamp(struct json_object *object)
 {
        char buffer[40];        /* formatted time less usec and timezone */
-       char timestamp[50];     /* the formatted ISO 8601 time stamp     */
+       char timestamp[65];     /* the formatted ISO 8601 time stamp     */
        char tz[10];            /* formatted time zone                   */
        struct tm* tm_info;     /* current local time                    */
        struct timeval tv;      /* current system time                   */
diff --git a/lib/util/debug.c b/lib/util/debug.c
index 2dafd8e..141f3a5 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -480,8 +480,8 @@ static void debug_set_backends(const char *param)
 static void debug_backends_log(const char *msg, int msg_level)
 {
        char msg_no_nl[FORMAT_BUFR_SIZE];
-       unsigned i;
-       int len;
+       size_t i;
+       size_t len;
 
        /*
         * Some backends already add an extra newline, so also provide
@@ -559,7 +559,7 @@ static const char *default_classname_table[] = {
  */
 static const int debug_class_list_initial[ARRAY_SIZE(default_classname_table)];
 
-static int debug_num_classes = 0;
+static size_t debug_num_classes = 0;
 int     *DEBUGLEVEL_CLASS = discard_const_p(int, debug_class_list_initial);
 
 
@@ -638,7 +638,7 @@ utility lists registered debug class names's
 char *debug_list_class_names_and_levels(void)
 {
        char *buf = NULL;
-       int i;
+       size_t i;
        /* prepare strings */
        for (i = 0; i < debug_num_classes; i++) {
                buf = talloc_asprintf_append(buf,
@@ -659,7 +659,7 @@ char *debug_list_class_names_and_levels(void)
 
 static int debug_lookup_classname_int(const char* classname)
 {
-       int i;
+       size_t i;
 
        if (!classname) return -1;
 
@@ -749,7 +749,7 @@ static int debug_lookup_classname(const char *classname)
 
 static void debug_dump_status(int level)
 {
-       int q;
+       size_t q;
 
        DEBUG(level, ("INFO: Current debug levels:\n"));
        for (q = 0; q < debug_num_classes; q++) {
@@ -798,7 +798,7 @@ bool debug_parse_levels(const char *params_str)
        size_t str_len = strlen(params_str);
        char str[str_len+1];
        char *tok, *saveptr;
-       int i;
+       size_t i;
 
        /* Just in case */
        debug_init();
diff --git a/lib/util/mkdir_p.c b/lib/util/mkdir_p.c
index 290a1f3..87a3f79 100644
--- a/lib/util/mkdir_p.c
+++ b/lib/util/mkdir_p.c
@@ -49,11 +49,11 @@ int mkdir_p(const char *dir, int mode)
 
        /* Create ancestors */
        len = strlen(dir);
-       if (len >= PATH_MAX) {
+       ret = snprintf(t, sizeof(t), "%s", dir);
+       if (ret != len) {
                errno = ENAMETOOLONG;
                return -1;
        }
-       strncpy(t, dir, len+1);
 
        ret = mkdir_p(dirname(t), mode);
        if (ret != 0) {
diff --git a/lib/util/tests/tfork.c b/lib/util/tests/tfork.c
index 9bcdc2f..3c73355 100644
--- a/lib/util/tests/tfork.c
+++ b/lib/util/tests/tfork.c
@@ -417,8 +417,7 @@ static void *tfork_thread(void *p)
        struct tfork *t = NULL;
        int status;
        pid_t child;
-       pthread_t *ptid = (pthread_t *)p;
-       uint64_t tid;
+       uint64_t tid = (uint64_t)pthread_self();
        uint64_t *result = NULL;
        int up[2];
        ssize_t nread;
@@ -429,8 +428,6 @@ static void *tfork_thread(void *p)
                pthread_exit(NULL);
        }
 
-       tid = (uint64_t)*ptid;
-
        t = tfork_create();
        if (t == NULL) {
                pthread_exit(NULL);
@@ -480,7 +477,7 @@ static bool test_tfork_threads(struct torture_context *tctx)
 #endif
 
        for (i = 0; i < num_threads; i++) {
-               ret = pthread_create(&threads[i], NULL, tfork_thread, 
&threads[i]);
+               ret = pthread_create(&threads[i], NULL, tfork_thread, NULL);
                torture_assert_goto(tctx, ret == 0, ok, done,
                                    "pthread_create failed\n");
        }
diff --git a/source3/lib/ldap_escape.c b/source3/lib/ldap_escape.c
index fa75dab..0d2b8f5 100644
--- a/source3/lib/ldap_escape.c
+++ b/source3/lib/ldap_escape.c
@@ -76,7 +76,7 @@ char *escape_ldap_string(TALLOC_CTX *mem_ctx, const char *s)
                        output = tmp;
 
                        p = &output[i];
-                       strncpy (p, sub, 3);
+                       memcpy(p, sub, 3);
                        p += 3;
                        i += 3;
 
diff --git a/source3/passdb/pdb_smbpasswd.c b/source3/passdb/pdb_smbpasswd.c
index 8a3d48b..2615cbd 100644
--- a/source3/passdb/pdb_smbpasswd.c
+++ b/source3/passdb/pdb_smbpasswd.c
@@ -741,7 +741,7 @@ static bool mod_smbfilepwd_entry(struct smbpasswd_privates 
*smbpasswd_state, con
        char linebuf[LINEBUF_SIZE + 1];
        char readbuf[1024];
        int c;
-       fstring ascii_p16;
+       char ascii_p16[FSTRING_LEN + 20];
        fstring encode_bits;
        unsigned char *p = NULL;
        size_t linebuf_len = 0;
diff --git a/source3/printing/printing.c b/source3/printing/printing.c
index d812468..0acbb7e 100644
--- a/source3/printing/printing.c
+++ b/source3/printing/printing.c
@@ -1700,7 +1700,7 @@ extern pid_t background_lpq_updater_pid;
 static void print_queue_update(struct messaging_context *msg_ctx,
                               int snum, bool force)
 {
-       fstring key;
+       char key[268];
        fstring sharename;
        char *lpqcommand = NULL;
        char *lprmcommand = NULL;
diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c
index 3136de6..04f34aa 100644
--- a/source3/utils/smbpasswd.c
+++ b/source3/utils/smbpasswd.c
@@ -368,36 +368,44 @@ static int process_root(int local_flags)
 
        if (local_flags & LOCAL_TRUST_ACCOUNT) {
                /* add the $ automatically */
-               static fstring buf;
+               size_t user_name_len = strlen(user_name);
 
-               /*
-                * Remove any trailing '$' before we
-                * generate the initial machine password.
-                */
-
-               if (user_name[strlen(user_name)-1] == '$') {
-                       user_name[strlen(user_name)-1] = 0;
+               if (user_name[user_name_len - 1] == '$') {
+                       user_name_len--;
+               } else {
+                       if (user_name_len + 2 > sizeof(user_name)) {
+                               fprintf(stderr, "machine name too long\n");
+                               exit(1);
+                       }
+                       user_name[user_name_len] = '$';
+                       user_name[user_name_len + 1] = '\0';
                }
 
                if (local_flags & LOCAL_ADD_USER) {
                        SAFE_FREE(new_passwd);
-                       new_passwd = smb_xstrdup(user_name);
+
+                       /*
+                        * Remove any trailing '$' before we
+                        * generate the initial machine password.
+                        */
+                       new_passwd = smb_xstrndup(user_name, user_name_len);
                        if (!strlower_m(new_passwd)) {
                                fprintf(stderr, "strlower_m %s failed\n",
                                        new_passwd);
                                exit(1);
                        }
                }
-
-               /*
-                * Now ensure the username ends in '$' for
-                * the machine add.
-                */
-
-               slprintf(buf, sizeof(buf)-1, "%s$", user_name);
-               strlcpy(user_name, buf, sizeof(user_name));
        } else if (local_flags & LOCAL_INTERDOM_ACCOUNT) {
-               static fstring buf;
+               size_t user_name_len = strlen(user_name);
+
+               if (user_name[user_name_len - 1] != '$') {
+                       if (user_name_len + 2 > sizeof(user_name)) {
+                               fprintf(stderr, "machine name too long\n");
+                               exit(1);
+                       }
+                       user_name[user_name_len] = '$';
+                       user_name[user_name_len + 1] = '\0';
+               }
 
                if ((local_flags & LOCAL_ADD_USER) && (new_passwd == NULL)) {
                        /*
@@ -409,11 +417,6 @@ static int process_root(int local_flags)
                                exit(1);
                        }
                }
-
-               /* prepare uppercased and '$' terminated username */
-               slprintf(buf, sizeof(buf) - 1, "%s$", user_name);
-               strlcpy(user_name, buf, sizeof(user_name));
-
        } else {
 
                if (remote_machine != NULL) {
diff --git a/source3/winbindd/wb_getpwsid.c b/source3/winbindd/wb_getpwsid.c
index 01c2f9c..8e114ab 100644
--- a/source3/winbindd/wb_getpwsid.c
+++ b/source3/winbindd/wb_getpwsid.c
@@ -69,7 +69,8 @@ static void wb_getpwsid_queryuser_done(struct tevent_req 
*subreq)
                req, struct wb_getpwsid_state);
        struct winbindd_pw *pw = state->pw;
        struct wbint_userinfo *info;
-       fstring acct_name, output_username;
+       fstring acct_name;
+       const char *output_username = NULL;
        char *mapped_name = NULL;
        char *tmp;
        NTSTATUS status;
@@ -101,16 +102,24 @@ static void wb_getpwsid_queryuser_done(struct tevent_req 
*subreq)
                                    acct_name,
                                    &mapped_name);
        if (NT_STATUS_IS_OK(status)) {
-               fill_domain_username(output_username,
+               output_username = fill_domain_username_talloc(state,
                                     info->domain_name,
                                     mapped_name, true);
+               if (output_username == NULL) {
+                       tevent_req_nterror(req, NT_STATUS_NO_MEMORY);
+                       return;
+               }
                fstrcpy(acct_name, mapped_name);
        } else if (NT_STATUS_EQUAL(status, NT_STATUS_FILE_RENAMED)) {
                fstrcpy(acct_name, mapped_name);
        } else {
-               fill_domain_username(output_username,
+               output_username = fill_domain_username_talloc(state,
                                     info->domain_name,
                                     acct_name, true);
+               if (output_username == NULL) {
+                       tevent_req_nterror(req, NT_STATUS_NO_MEMORY);
+                       return;
+               }
        }
 
        strlcpy(pw->pw_name, output_username, sizeof(pw->pw_name));
diff --git a/source3/winbindd/wb_query_user_list.c 
b/source3/winbindd/wb_query_user_list.c
index 3c18080..6d69987 100644
--- a/source3/winbindd/wb_query_user_list.c
+++ b/source3/winbindd/wb_query_user_list.c
@@ -104,11 +104,14 @@ static void wb_query_user_list_done(struct tevent_req 
*subreq)
 
        for (i=0; i<state->names.num_principals; i++) {
                struct wbint_Principal *p = &state->names.principals[i];
-               fstring name;
+               const char *name;
                int ret;
 
-               fill_domain_username(name, state->domain_name, p->name, true);
-
+               name = fill_domain_username_talloc(state, state->domain_name, 
p->name, true);
+               if (name == NULL) {
+                       tevent_req_nterror(req, NT_STATUS_NO_MEMORY);
+                       return;
+               }
                ret = strv_add(state, &state->users, name);
                if (ret != 0) {
                        tevent_req_nterror(req, map_nt_error_from_unix(ret));
diff --git a/source3/winbindd/winbindd_cm.c b/source3/winbindd/winbindd_cm.c
index 9c2773d..9561203 100644
--- a/source3/winbindd/winbindd_cm.c
+++ b/source3/winbindd/winbindd_cm.c
@@ -1738,8 +1738,10 @@ static bool find_new_dc(TALLOC_CTX *mem_ctx,
        TALLOC_FREE(addrs);
        num_addrs = 0;
 
-       close(*fd);
-       *fd = -1;
+       if (*fd != -1) {
+               close(*fd);
+               *fd = -1;
+       }
 
        goto again;
 }
@@ -1981,7 +1983,10 @@ static NTSTATUS cm_open_connection(struct 
winbindd_domain *domain,
                        &new_conn->cli, &retry);
                if (!NT_STATUS_IS_OK(result)) {
                        /* Don't leak the smb connection socket */
-                       close(fd);
+                       if (fd != -1) {
+                               close(fd);
+                               fd = -1;
+                       }
                }
 
                if (!retry)
diff --git a/source3/winbindd/winbindd_group.c 
b/source3/winbindd/winbindd_group.c
index 417565e..76ba14a 100644
--- a/source3/winbindd/winbindd_group.c
+++ b/source3/winbindd/winbindd_group.c
@@ -34,7 +34,7 @@
 bool fill_grent(TALLOC_CTX *mem_ctx, struct winbindd_gr *gr,
                const char *dom_name, const char *gr_name, gid_t unix_gid)
 {
-       fstring full_group_name;
+       const char *full_group_name;
        char *mapped_name = NULL;
        NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
 
@@ -43,19 +43,23 @@ bool fill_grent(TALLOC_CTX *mem_ctx, struct winbindd_gr *gr,
 
        /* Basic whitespace replacement */
        if (NT_STATUS_IS_OK(nt_status)) {
-               fill_domain_username(full_group_name, dom_name,
+               full_group_name = fill_domain_username_talloc(mem_ctx, dom_name,
                                     mapped_name, true);
        }
        /* Mapped to an aliase */
        else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_FILE_RENAMED)) {
-               fstrcpy(full_group_name, mapped_name);
+               full_group_name = mapped_name;
        }
        /* no change */
        else {
-               fill_domain_username( full_group_name, dom_name,
+               full_group_name = fill_domain_username_talloc(mem_ctx, dom_name,
                                      gr_name, True );
        }
 
+       if (full_group_name == NULL) {
+               return false;
+       }
+
        gr->gr_gid = unix_gid;
 
        /* Group name and password */
diff --git a/source3/winbindd/winbindd_list_groups.c 
b/source3/winbindd/winbindd_list_groups.c
index f593ba2..36800ae 100644
--- a/source3/winbindd/winbindd_list_groups.c
+++ b/source3/winbindd/winbindd_list_groups.c
@@ -171,10 +171,13 @@ NTSTATUS winbindd_list_groups_recv(struct tevent_req *req,
                struct winbindd_list_groups_domstate *d = &state->domains[i];
 
                for (j=0; j<d->groups.num_principals; j++) {
-                       fstring name;
-                       fill_domain_username(name, d->domain->name,
+                       const char *name;
+                       name = fill_domain_username_talloc(response, 
d->domain->name,
                                             d->groups.principals[j].name,
                                             True);
+                       if (name == NULL) {
+                               return NT_STATUS_NO_MEMORY;
+                       }
                        len += strlen(name)+1;
                }
                response->data.num_entries += d->groups.num_principals;
@@ -190,11 +193,14 @@ NTSTATUS winbindd_list_groups_recv(struct tevent_req *req,
                struct winbindd_list_groups_domstate *d = &state->domains[i];
 
                for (j=0; j<d->groups.num_principals; j++) {
-                       fstring name;
+                       const char *name;
                        size_t this_len;
-                       fill_domain_username(name, d->domain->name,
+                       name = fill_domain_username_talloc(response, 
d->domain->name,
                                             d->groups.principals[j].name,
                                             True);
+                       if (name == NULL) {
+                               return NT_STATUS_NO_MEMORY;
+                       }
                        this_len = strlen(name);
                        memcpy(result+len, name, this_len);
                        len += this_len;
diff --git a/source3/winbindd/winbindd_pam.c b/source3/winbindd/winbindd_pam.c
index 2556427..bed5a94 100644
--- a/source3/winbindd/winbindd_pam.c
+++ b/source3/winbindd/winbindd_pam.c
@@ -194,7 +194,7 @@ static NTSTATUS append_unix_username(TALLOC_CTX *mem_ctx,
        /* We've been asked to return the unix username, per
           'winbind use default domain' settings and the like */
 
-       const char *nt_username, *nt_domain;
+       const char *nt_username, *nt_domain, *unix_username;
 
        nt_domain = talloc_strdup(mem_ctx, info3->base.logon_domain.string);
        if (!nt_domain) {
@@ -210,8 +210,15 @@ static NTSTATUS append_unix_username(TALLOC_CTX *mem_ctx,
                nt_username = name_user;
        }
 
-       fill_domain_username(resp->data.auth.unix_username,
-                            nt_domain, nt_username, true);
+       unix_username = fill_domain_username_talloc(mem_ctx,
+                                                   nt_domain,
+                                                   nt_username,
+                                                   true);
+       if (unix_username == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       fstrcpy(resp->data.auth.unix_username, unix_username);
 
        DEBUG(5, ("Setting unix username to [%s]\n",
                  resp->data.auth.unix_username));
diff --git a/source3/winbindd/winbindd_proto.h 
b/source3/winbindd/winbindd_proto.h
index 1c8cfc3..be3626d 100644
--- a/source3/winbindd/winbindd_proto.h
+++ b/source3/winbindd/winbindd_proto.h
@@ -481,7 +481,6 @@ bool canonicalize_username(fstring username_inout,
                           fstring namespace,
                           fstring domain,
                           fstring user);
-void fill_domain_username(fstring name, const char *domain, const char *user, 
bool can_assume);
 char *fill_domain_username_talloc(TALLOC_CTX *ctx,
                                  const char *domain,
                                  const char *user,
diff --git a/source3/winbindd/winbindd_util.c b/source3/winbindd/winbindd_util.c
index 990c97b..9707574 100644
--- a/source3/winbindd/winbindd_util.c
+++ b/source3/winbindd/winbindd_util.c
@@ -1650,26 +1650,6 @@ bool canonicalize_username(fstring username_inout,
 
     We always canonicalize as UPPERCASE DOMAIN, lowercase username.
 */
-void fill_domain_username(fstring name, const char *domain, const char *user, 
bool can_assume)
-{
-       fstring tmp_user;
-
-       if (lp_server_role() == ROLE_ACTIVE_DIRECTORY_DC) {
-               can_assume = false;
-       }
-
-       fstrcpy(tmp_user, user);
-       (void)strlower_m(tmp_user);
-
-       if (can_assume && assume_domain(domain)) {
-               strlcpy(name, tmp_user, sizeof(fstring));
-       } else {
-               slprintf(name, sizeof(fstring) - 1, "%s%c%s",
-                        domain, *lp_winbind_separator(),
-                        tmp_user);
-       }
-}
-
 /**
  * talloc version of fill_domain_username()
  * return NULL on talloc failure.
diff --git a/source4/ntvfs/ipc/rap_server.c b/source4/ntvfs/ipc/rap_server.c
index 3a133f5..fc2d3aa 100644
--- a/source4/ntvfs/ipc/rap_server.c
+++ b/source4/ntvfs/ipc/rap_server.c
@@ -63,13 +63,18 @@ NTSTATUS rap_netshareenum(TALLOC_CTX *mem_ctx,
                                   union rap_share_info, r->out.available);
 
        for (i = 0, j = 0; i < r->out.available; i++) {
+               size_t sname_len;
+
                if (!NT_STATUS_IS_OK(share_get_config(mem_ctx, sctx, snames[i], 
&scfg))) {
                        DEBUG(3, ("WARNING: Service [%s] disappeared after 
enumeration!\n", snames[i]));
                        continue;
                }
-               strncpy((char *)r->out.info[j].info1.share_name,
+               /* Make sure we have NUL-termination */


-- 
Samba Shared Repository

Reply via email to