Merge from SAMBA_3_0_23
authorjerry <jerry@0c0555d6-39d7-0310-84fc-f1cc0bd64818>
Mon, 6 Nov 2006 20:10:30 +0000 (20:10 +0000)
committerjerry <jerry@0c0555d6-39d7-0310-84fc-f1cc0bd64818>
Mon, 6 Nov 2006 20:10:30 +0000 (20:10 +0000)
git-svn-id: svn+ssh://svn.samba.org/data/svn/samba/branches/SAMBA_3_0_RELEASE@19581 0c0555d6-39d7-0310-84fc-f1cc0bd64818

12 files changed:
examples/libsmbclient/testread.c
source/Makefile.in
source/client/client.c
source/lib/gencache.c
source/lib/pidfile.c
source/libads/ldap.c
source/libsmb/libsmbclient.c
source/libsmb/passchange.c
source/nsswitch/winbindd_misc.c
source/passdb/lookup_sid.c
source/smbwrapper/wrapped.c
source/utils/net_ads.c

index 1f1219ca8498067147a592bc4e6e262a382d6a8c..d59fc70ec11fcc7683ed71cf0c991e6c291a46b8 100644 (file)
@@ -55,6 +55,7 @@ int main(int argc, char * argv[])
     {
         ret = smbc_read(fd, buffer, sizeof(buffer));
         savedErrno = errno;
+        if (ret > 0) fwrite(buffer, 1, ret, stdout);
     } while (ret > 0);
 
     smbc_close(fd);
index 1c740ed71b43248cb335bc82b7a752d15a6b2099..348893552f876fea618b63a7d50927601327aa89 100644 (file)
@@ -562,7 +562,8 @@ CLIENT_OBJ1 = client/client.o client/clitar.o rpc_client/cli_srvsvc.o \
 
 CLIENT_OBJ = $(CLIENT_OBJ1) $(PARAM_OBJ) $(LIBSMB_OBJ) \
             $(LIB_NONSMBD_OBJ) $(KRBCLIENT_OBJ) \
-             $(READLINE_OBJ) $(POPT_LIB_OBJ) $(SECRETS_OBJ)
+             $(READLINE_OBJ) $(POPT_LIB_OBJ) $(SECRETS_OBJ) \
+            lib/display_sec.o
 
 TOOL_OBJ = client/smbctool.o client/clitar.o $(PARAM_OBJ) $(LIBSMB_OBJ) \
             $(LIB_NONSMBD_OBJ) $(KRBCLIENT_OBJ) \
@@ -871,6 +872,17 @@ dynconfig.@PICSUFFIX@: dynconfig.c Makefile
        @$(CC) -I. -I$(srcdir) $(FLAGS) $(PATH_FLAGS) @PICFLAGS@ -c $(srcdir)/dynconfig.c -o $@
 @BROKEN_CC@    -mv `echo $@ | sed -e 's%^.*/%%g' -e 's%\.@PICSUFFIX@$$%.o%'` $@
 
+lib/pidfile.o: lib/pidfile.c
+       @echo Compiling $*.c
+       @$(CC) -I. -I$(srcdir) $(FLAGS) $(PATH_FLAGS) @PIE_CFLAGS@ -c $(srcdir)/lib/pidfile.c -o $@ 
+
+lib/pidfile.@PICSUFFIX@: lib/pidfile.c
+       @if (: >> $@ || : > $@) >/dev/null 2>&1; then rm -f $@; else \
+         dir=`echo $@ | sed 's,/[^/]*$$,,;s,^$$,.,'` $(MAKEDIR); fi
+       @echo Compiling $*.c with @PICFLAGS@
+       @$(CC) -I. -I$(srcdir) $(FLAGS) $(PATH_FLAGS) @PICFLAGS@ -c $(srcdir)/lib/pidfile.c -o $@
+@BROKEN_CC@    -mv `echo $@ | sed -e 's%^.*/%%g' -e 's%\.@PICSUFFIX@$$%.o%'` $@
+
 lib/version.o: lib/version.c include/version.h
        @echo Compiling $*.c
        @$(CC) -I. -I$(srcdir) $(FLAGS) $(PATH_FLAGS) @PIE_CFLAGS@ -c $(srcdir)/lib/version.c -o $@ 
index 3c2d7afe2d65d1804402b8dd6e9100f645ba6098..522048dc74e02fbd72952a0a23b1f3576d2e0bdf 100644 (file)
@@ -49,6 +49,10 @@ extern int max_protocol;
 static int process_tok(pstring tok);
 static int cmd_help(void);
 
+static TALLOC_CTX *ctx;
+#define CREATE_ACCESS_READ READ_CONTROL_ACCESS
+static pstring cwd;
+
 /* 30 second timeout on most commands */
 #define CLIENT_TIMEOUT (30*1000)
 #define SHORT_TIMEOUT (5*1000)
@@ -72,6 +76,7 @@ extern BOOL tar_reset;
 static BOOL prompt = True;
 
 static BOOL recurse = False;
+static BOOL showacls = False;
 BOOL lowercase = False;
 
 static struct in_addr dest_ip;
@@ -375,12 +380,46 @@ static void display_finfo(file_info *finfo)
 {
        if (do_this_one(finfo)) {
                time_t t = finfo->mtime; /* the time is assumed to be passed as GMT */
-               d_printf("  %-30s%7.7s %8.0f  %s",
-                        finfo->name,
-                        attrib_string(finfo->mode),
-                        (double)finfo->size,
-                        time_to_asc(&t));
-               dir_total += finfo->size;
+               if (!showacls) {
+                       d_printf("  %-30s%7.7s %8.0f  %s",
+                                finfo->name,
+                                attrib_string(finfo->mode),
+                                (double)finfo->size,
+                                time_to_asc(&t));
+                       dir_total += finfo->size;
+               } else { /* showacls */
+                       static pstring afname;
+                       int fnum;
+
+                       /* skip if this is . or .. */
+                       if ( strequal(finfo->name,"..") || strequal(finfo->name,".") )
+                               return;
+                       /* create absolute filename for cli_nt_create() FIXME */
+                       pstrcpy( afname, cwd);
+                       pstrcat( afname, "\\");
+                       pstrcat( afname, finfo->name);
+                       /* print file meta date header */
+                       d_printf( "FILENAME:%s\n", afname);
+                       d_printf( "MODE:%s\n", attrib_string(finfo->mode));
+                       d_printf( "SIZE:%.0f\n", (double)finfo->size);
+                       d_printf( "MTIME:%s", time_to_asc(&t));
+                       fnum = cli_nt_create(cli, afname, CREATE_ACCESS_READ);
+                       if (fnum == -1) {
+                               DEBUG( 0, ("display_finfo() Failed to open %s: %s\n",
+                                                       afname,
+                                                       cli_errstr( cli)));
+                       } else {
+                               SEC_DESC *sd = NULL;
+                               sd = cli_query_secdesc(cli, fnum, ctx);
+                               if (!sd) {
+                                       DEBUG( 0, ("display_finfo() failed to "
+                                               "get security descriptor: %s",
+                                               cli_errstr( cli)));
+                               } else {
+                                       display_sec_desc(sd);
+                               }
+                       }
+               }
        }
 }
 
@@ -616,8 +655,11 @@ void do_list(const char *mask,uint16 attribute,void (*fn)(file_info *),BOOL rec,
                                        save_ch = next_file +
                                                strlen(next_file) - 2;
                                        *save_ch = '\0';
+                                       if (showacls) /* cwd is only used if showacls is on */
+                                               pstrcpy( cwd, next_file);
                                }
-                               d_printf("\n%s\n",next_file);
+                               if (!showacls) /* don't disturbe the showacls output */
+                                       d_printf("\n%s\n",next_file);
                                if (save_ch) {
                                        *save_ch = '\\';
                                }
@@ -1083,6 +1125,7 @@ static BOOL do_altname(char *name)
 static int cmd_quit(void)
 {
        cli_cm_shutdown();
+       talloc_destroy( ctx);
        exit(0);
        /* NOTREACHED */
        return 0;
@@ -2418,6 +2461,25 @@ static int cmd_setcase(void)
        return 0;
 }
 
+/****************************************************************************
+ Toggle the showacls flag.
+****************************************************************************/
+
+static int cmd_showacls(void)
+{
+       showacls = !showacls;
+       DEBUG(2,("showacls is now %s\n",showacls?"on":"off"));
+
+       if (!ctx && showacls)
+               ctx = talloc_init("smbclient:showacls");
+               if (!ctx) {
+                       DEBUG( 0, ("cmd_showacls() out of memory.  talloc_init() failed.\n"));
+       }
+
+       return 0;
+}
+
+
 /****************************************************************************
  Toggle the recurse flag.
 ****************************************************************************/
@@ -2819,6 +2881,7 @@ static struct
   {"reput",cmd_reput,"<local name> [remote name] put a file restarting at end of remote file",{COMPL_LOCAL,COMPL_REMOTE}},
   {"rm",cmd_del,"<mask> delete all matching files",{COMPL_REMOTE,COMPL_NONE}},
   {"rmdir",cmd_rmdir,"<directory> remove a directory",{COMPL_NONE,COMPL_NONE}},
+  {"showacls",cmd_showacls,"toggle if ACLs are shown or not",{COMPL_NONE,COMPL_NONE}},  
   {"setmode",cmd_setmode,"filename <setmode string> change modes of file",{COMPL_REMOTE,COMPL_NONE}},
   {"stat",cmd_stat,"filename Do a UNIX extensions stat call on a file",{COMPL_REMOTE,COMPL_REMOTE}},
   {"symlink",cmd_symlink,"<oldname> <newname> create a UNIX symlink",{COMPL_REMOTE,COMPL_REMOTE}},
@@ -3623,5 +3686,6 @@ static int do_message_op(void)
                return 1;
        }
 
+       talloc_destroy( ctx);
        return rc;
 }
index 75a8f2f1e161e0486a55af5afa24d16aad3ea2c7..013eed8a00db8017caaf533e94f3f8785608a3ae 100644 (file)
@@ -56,13 +56,9 @@ BOOL gencache_init(void)
        /* skip file open if it's already opened */
        if (cache) return True;
 
-       asprintf(&cache_fname, "%s/%s", lp_lockdir(), "gencache.tdb");
-       if (cache_fname)
-               DEBUG(5, ("Opening cache file at %s\n", cache_fname));
-       else {
-               DEBUG(0, ("Filename allocation failed.\n"));
-               return False;
-       }
+       cache_fname = lock_path("gencache.tdb");
+
+       DEBUG(5, ("Opening cache file at %s\n", cache_fname));
 
        cache = tdb_open_log(cache_fname, 0, TDB_DEFAULT,
                             O_RDWR|O_CREAT, 0644);
@@ -75,7 +71,6 @@ BOOL gencache_init(void)
                }
        }
 
-       SAFE_FREE(cache_fname);
        if (!cache) {
                DEBUG(5, ("Attempt to open gencache.tdb has failed.\n"));
                return False;
index 08e41083b59946f0ef1ac29e33b61544961c997a..49626acade570fcd9bef80bf8a5ea7be6eb58f6f 100644 (file)
@@ -78,13 +78,24 @@ pid_t pidfile_pid(const char *name)
 }
 
 /* create a pid file in the pid directory. open it and leave it locked */
-void pidfile_create(const char *name)
+void pidfile_create(const char *program_name)
 {
        int     fd;
        char    buf[20];
+       char    *short_configfile;
+       pstring name;
        pstring pidFile;
        pid_t pid;
 
+       /* Add a suffix to the program name if this is a process with a
+        * none default configuration file name. */
+       if (strcmp( CONFIGFILE, dyn_CONFIGFILE) == 0) {
+               strncpy( name, program_name, sizeof( name)-1);
+       } else {
+               short_configfile = strrchr( dyn_CONFIGFILE, '/');
+               slprintf( name, sizeof( name)-1, "%s-%s", program_name, short_configfile+1);
+       }
+
        slprintf(pidFile, sizeof(pidFile)-1, "%s/%s.pid", lp_piddir(), name);
 
        pid = pidfile_pid(name);
index ee60063a88f983204ab39a26a7a0624f6fe32d47..fb7c6730a07e65755fd5a6f12d5955f2da0cc48b 100644 (file)
@@ -1156,6 +1156,7 @@ ADS_STATUS ads_del_dn(ADS_STRUCT *ads, char *del_dn)
        }
        
        ret = ldap_delete_s(ads->ld, utf8_dn);
+       SAFE_FREE(utf8_dn);
        return ADS_ERROR(ret);
 }
 
@@ -1222,6 +1223,7 @@ char *ads_default_ou_string(ADS_STRUCT *ads, const char *wknguid)
        SAFE_FREE(base);
 
        if (ads_count_replies(ads, res) != 1) {
+               ads_msgfree(ads, res);
                return NULL;
        }
 
@@ -1237,7 +1239,7 @@ char *ads_default_ou_string(ADS_STRUCT *ads, const char *wknguid)
 
        new_ln = wkn_ln - bind_ln;
 
-       ret = wkn_dn_exp[0];
+       ret = SMB_STRDUP(wkn_dn_exp[0]);
 
        for (i=1; i < new_ln; i++) {
                char *s;
@@ -1246,6 +1248,7 @@ char *ads_default_ou_string(ADS_STRUCT *ads, const char *wknguid)
                free(s);
        }
 
+       ads_msgfree(ads, res);
        ads_memfree(ads, wkn_dn);
        ldap_value_free(wkn_dn_exp);
        ldap_value_free(bind_dn_exp);
index caa26a70a808aa514aa039df002fdbd56b994cdb..80b09fab1a1ed0bed6121409bea3e4372323f533 100644 (file)
@@ -413,7 +413,15 @@ smbc_parse_path(SMBCCTX *context,
 
        }
 
-        safe_strcpy(path, p, path_len - 1);
+        /*
+         * Prepend a leading slash if there's a file path, as required by
+         * NetApp filers.
+         */
+        *path = '\0';
+        if (*p != '\0') {
+                *path = '/';
+                safe_strcpy(path + 1, p, path_len - 2);
+        }
 
        all_string_sub(path, "/", "\\", 0);
 
index 673671d28db05ba02621562f54e38205d61d50c7..90eb67aceaad0ef345aab37ae629ad95ea901272 100644 (file)
@@ -80,13 +80,14 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
 
                if (!NT_STATUS_IS_OK(result)) {
 
-                       /* Password must change is the only valid error
-                        * condition here from where we can proceed, the rest
-                        * like account locked out or logon failure will lead
-                        * to errors later anyway */
+                       /* Password must change or Password expired are the only valid
+                        * error conditions here from where we can proceed, the rest like
+                        * account locked out or logon failure will lead to errors later
+                        * anyway */
+
+                       if (!NT_STATUS_EQUAL(result, NT_STATUS_PASSWORD_MUST_CHANGE) &&
+                           !NT_STATUS_EQUAL(result, NT_STATUS_PASSWORD_EXPIRED)) {
 
-                       if (!NT_STATUS_EQUAL(result,
-                                            NT_STATUS_PASSWORD_MUST_CHANGE)) {
                                slprintf(err_str, err_str_len-1, "Could not "
                                         "connect to machine %s: %s\n",
                                         remote_machine, cli_errstr(&cli));
index 731d2bb474a61b1c1a5009e6bc1b145381666e85..6b44eb9783b6335d0f7cb620a2de9b4aecb7465f 100644 (file)
@@ -190,6 +190,7 @@ enum winbindd_result winbindd_dual_getdcname(struct winbindd_domain *domain,
        struct rpc_pipe_client *netlogon_pipe;
        NTSTATUS result;
        WERROR werr;
+       unsigned int orig_timeout;
 
        state->request.domain_name
                [sizeof(state->request.domain_name)-1] = '\0';
@@ -204,9 +205,16 @@ enum winbindd_result winbindd_dual_getdcname(struct winbindd_domain *domain,
                return WINBINDD_ERROR;
        }
 
+       /* This call can take a long time - allow the server to time out.
+          35 seconds should do it. */
+
+       orig_timeout = cli_set_timeout(netlogon_pipe->cli, 35000);
+
        werr = rpccli_netlogon_getdcname(netlogon_pipe, state->mem_ctx, domain->dcname,
                                           state->request.domain_name,
                                           dcname_slash);
+       /* And restore our original timeout. */
+       cli_set_timeout(netlogon_pipe->cli, orig_timeout);
 
        if (!W_ERROR_IS_OK(werr)) {
                DEBUG(5, ("Error requesting DCname: %s\n", dos_errstr(werr)));
index 6f0140386a24e1e9dccf2184f6cfda5eb9303228..7082cd3abd40ba2c9bef7c541964e00766eb6fec 100644 (file)
@@ -1076,7 +1076,8 @@ void uid_to_sid(DOM_SID *psid, uid_t uid)
        if (fetch_sid_from_uid_cache(psid, uid))
                return;
 
-       if (lp_idmap_uid(&low, &high) && (uid >= low) && (uid <= high) &&
+       if ((lp_winbind_trusted_domains_only() ||
+            (lp_idmap_uid(&low, &high) && (uid >= low) && (uid <= high))) &&
            winbind_uid_to_sid(psid, uid)) {
 
                DEBUG(10,("uid_to_sid: winbindd %u -> %s\n",
@@ -1121,7 +1122,8 @@ void gid_to_sid(DOM_SID *psid, gid_t gid)
        if (fetch_sid_from_gid_cache(psid, gid))
                return;
 
-       if (lp_idmap_gid(&low, &high) && (gid >= low) && (gid <= high) &&
+       if ((lp_winbind_trusted_domains_only() ||
+            (lp_idmap_gid(&low, &high) && (gid >= low) && (gid <= high))) &&
            winbind_gid_to_sid(psid, gid)) {
 
                DEBUG(10,("gid_to_sid: winbindd %u -> %s\n",
index 338ee0d5b1b8887087bb5c3c4eb731e41024f34e..e1bbccd836bb8487a6b8cec1e2013d9c4826f451 100644 (file)
@@ -33,7 +33,7 @@
 # define NULL ((void *)0)
 #endif
 
- int open(char *name, int flags, mode_t mode)
+ int open(const char *name, int flags, mode_t mode)
 {
        if (smbw_path(name)) {
                return smbw_open(name, flags, mode);
@@ -43,7 +43,7 @@
 }
 
 #ifdef HAVE__OPEN
- int _open(char *name, int flags, mode_t mode) 
+ int _open(const char *name, int flags, mode_t mode) 
 {
        return open(name, flags, mode);
 }
@@ -56,7 +56,7 @@
 
 
 #ifdef HAVE_OPEN64
- int open64(char *name, int flags, mode_t mode)
+ int open64(const char *name, int flags, mode_t mode)
 {
        if (smbw_path(name)) {
                return smbw_open(name, flags, mode);
 
 #ifndef NO_OPEN64_ALIAS
 #ifdef HAVE__OPEN64
- int _open64(char *name, int flags, mode_t mode) 
+ int _open64(const char *name, int flags, mode_t mode) 
 {
        return open64(name, flags, mode);
 }
 #elif HAVE___OPEN64
- int __open64(char *name, int flags, mode_t mode) 
+ int __open64(const char *name, int flags, mode_t mode) 
 {
        return open64(name, flags, mode);
 }
@@ -91,7 +91,7 @@
 }
 #endif
 
-#if defined(HAVE_PREAD64) && defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT)
+#if 0 && defined(HAVE_PREAD64) && defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT)
  ssize_t pread64(int fd, void *buf, size_t size, off64_t ofs)
 {
        if (smbw_fd(fd)) {
 #endif
 
 #ifdef HAVE_PWRITE
- ssize_t pwrite(int fd, void *buf, size_t size, off_t ofs)
+ ssize_t pwrite(int fd, const void *buf, size_t size, off_t ofs)
 {
        if (smbw_fd(fd)) {
                return smbw_pwrite(fd, buf, size, ofs);
 }
 #endif
 
-#if defined(HAVE_PWRITE64) && defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT)
- ssize_t pwrite64(int fd, void *buf, size_t size, off64_t ofs)
+#if 0 && defined(HAVE_PWRITE64) && defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT)
+ ssize_t pwrite64(int fd, const void *buf, size_t size, off64_t ofs)
 {
        if (smbw_fd(fd)) {
                return smbw_pwrite(fd, buf, size, ofs);
 #endif
 
 
- int chdir(char *name)
+ int chdir(const char *name)
 {
        return smbw_chdir(name);
 }
 
 #ifdef HAVE___CHDIR
- int __chdir(char *name)
+ int __chdir(const char *name)
 {
        return chdir(name);
 }
 #elif HAVE__CHDIR
- int _chdir(char *name)
+ int _chdir(const char *name)
 {
        return chdir(name);
 }
 #endif
 
 
- ssize_t write(int fd, void *buf, size_t count)
+ ssize_t write(int fd, const void *buf, size_t count)
 {
        if (smbw_fd(fd)) {
                return smbw_write(fd, buf, count);
 }
 
 #ifdef HAVE___WRITE
- ssize_t __write(int fd, void *buf, size_t count)
+ ssize_t __write(int fd, const void *buf, size_t count)
 {
        return write(fd, buf, count);
 }
 #elif HAVE__WRITE
- ssize_t _write(int fd, void *buf, size_t count)
+ ssize_t _write(int fd, const void *buf, size_t count)
 {
        return write(fd, buf, count);
 }
 
 
 
- int access(char *name, int mode)
+ int access(const char *name, int mode)
 {
        if (smbw_path(name)) {
                return smbw_access(name, mode);
 
 
 
- int chmod(char *name,mode_t mode)
+ int chmod(const char *name,mode_t mode)
 {
        if (smbw_path(name)) {
                return smbw_chmod(name, mode);
 
 
 
- int chown(char *name,uid_t owner, gid_t group)
+ int chown(const char *name,uid_t owner, gid_t group)
 {
        if (smbw_path(name)) {
                return smbw_chown(name, owner, group);
 
 
 
- int mkdir(char *name, mode_t mode)
+ int mkdir(const char *name, mode_t mode)
 {
        if (smbw_path(name)) {
                return smbw_mkdir(name, mode);
 #endif
 
 #if HAVE___XSTAT
- int __xstat(int vers, char *name, void *st)
+ int __xstat(int vers, const char *name, void *st)
 {
        double xx[32];
        int ret;
 
 
 #if HAVE___LXSTAT
- int __lxstat(int vers, char *name, void *st)
+ int __lxstat(int vers, const char *name, void *st)
 {
        double xx[32];
        int ret;
 #endif
 
 
- int stat(char *name, void *st)
+ int stat(const char *name, void *st)
 {
 #if HAVE___XSTAT
        return __xstat(0, name, st);
 #endif
 }
 
- int lstat(char *name, void *st)
+ int lstat(const char *name, void *st)
 {
 #if HAVE___LXSTAT
        return __lxstat(0, name, st);
 }
 
 
- int unlink(char *name)
+ int unlink(const char *name)
 {
        if (smbw_path(name)) {
                return smbw_unlink(name);
 
 
 #ifdef HAVE_UTIME
- int utime(char *name,void *tvp)
+ int utime(const char *name,void *tvp)
 {
        if (smbw_path(name)) {
                return smbw_utime(name, tvp);
 }
 #endif
 
- int readlink(char *path, char *buf, size_t bufsize)
+ int readlink(const char *path, char *buf, size_t bufsize)
 {
        if (smbw_path(path)) {
                return smbw_readlink(path, buf, bufsize);
 }
 
 
- int rename(char *oldname,char *newname)
+ int rename(const char *oldname,const char *newname)
 {
        int p1, p2;
        p1 = smbw_path(oldname); 
        return real_rename(oldname, newname);
 }
 
- int rmdir(char *name)
+ int rmdir(const char *name)
 {
        if (smbw_path(name)) {
                return smbw_rmdir(name);
 }
 
 
- int symlink(char *topath,char *frompath)
+ int symlink(const char *topath,const char *frompath)
 {
        int p1, p2;
        p1 = smbw_path(topath); 
 }
 
 #ifdef real_opendir
- void *opendir(char *name)
+ void *opendir(const char *name)
 {
        if (smbw_path(name)) {
                return (void *)smbw_opendir(name);
 }
 #endif
 
- int creat(char *path, mode_t mode)
+ int creat(const char *path, mode_t mode)
 {
        extern int creat_bits;
        return open(path, creat_bits, mode);
 }
 
 #ifdef HAVE_CREAT64
- int creat64(char *path, mode_t mode)
+ int creat64(const char *path, mode_t mode)
 {
        extern int creat_bits;
        return open64(path, creat_bits, mode);
 #endif
 
 #ifdef HAVE_STAT64
-  int stat64(char *name, void *st64)
+  int stat64(const char *name, void *st64)
 {
        if (smbw_path(name)) {
                double xx[32];
        return real_fstat64(fd, st64);
 }
 
-  int lstat64(char *name, void *st64)
+  int lstat64(const char *name, void *st64)
 {
        if (smbw_path(name)) {
                double xx[32];
index 4f45be5b6346c7d2a6410a9d62733e6eecc928b3..fcf1bf25083c16fd25ed9307905a797f33bd92fb 100644 (file)
@@ -278,7 +278,7 @@ retry:
                                    NT_STATUS_NO_LOGON_SERVERS)) {
                        DEBUG(0,("ads_connect: %s\n", ads_errstr(status)));
                        ads_destroy(&ads);
-                       return status;
+                       return NULL;
                }
        
                if (!need_password && !second_time) {
@@ -409,6 +409,7 @@ static int ads_user_add(int argc, const char **argv)
        char *upn, *userdn;
        void *res=NULL;
        int rc = -1;
+       char *ou_str = NULL;
 
        if (argc < 1) return net_ads_user_usage(argc, argv);
        
@@ -428,11 +429,13 @@ static int ads_user_add(int argc, const char **argv)
                goto done;
        }
 
-       if (opt_container == NULL) {
-               opt_container = ads_default_ou_string(ads, WELL_KNOWN_GUID_USERS);
+       if (opt_container) {
+               ou_str = SMB_STRDUP(opt_container);
+       } else {
+               ou_str = ads_default_ou_string(ads, WELL_KNOWN_GUID_USERS);
        }
 
-       status = ads_add_user_acct(ads, argv[0], opt_container, opt_comment);
+       status = ads_add_user_acct(ads, argv[0], ou_str, opt_comment);
 
        if (!ADS_ERR_OK(status)) {
                d_fprintf(stderr, "Could not add user %s: %s\n", argv[0],
@@ -473,6 +476,7 @@ static int ads_user_add(int argc, const char **argv)
        if (res)
                ads_msgfree(ads, res);
        ads_destroy(&ads);
+       SAFE_FREE(ou_str);
        return rc;
 }
 
@@ -537,7 +541,7 @@ static int ads_user_delete(int argc, const char **argv)
 {
        ADS_STRUCT *ads;
        ADS_STATUS rc;
-       void *res;
+       void *res = NULL;
        char *userdn;
 
        if (argc < 1) {
@@ -549,8 +553,9 @@ static int ads_user_delete(int argc, const char **argv)
        }
 
        rc = ads_find_user_acct(ads, &res, argv[0]);
-       if (!ADS_ERR_OK(rc)) {
+       if (!ADS_ERR_OK(rc) || ads_count_replies(ads, res) != 1) {
                DEBUG(0, ("User %s does not exist\n", argv[0]));
+               ads_msgfree(ads, res);
                ads_destroy(&ads);
                return -1;
        }
@@ -558,7 +563,7 @@ static int ads_user_delete(int argc, const char **argv)
        ads_msgfree(ads, res);
        rc = ads_del_dn(ads, userdn);
        ads_memfree(ads, userdn);
-       if (!ADS_ERR_OK(rc)) {
+       if (ADS_ERR_OK(rc)) {
                d_printf("User %s deleted\n", argv[0]);
                ads_destroy(&ads);
                return 0;
@@ -616,6 +621,7 @@ static int ads_group_add(int argc, const char **argv)
        ADS_STATUS status;
        void *res=NULL;
        int rc = -1;
+       char *ou_str = NULL;
 
        if (argc < 1) {
                return net_ads_group_usage(argc, argv);
@@ -634,15 +640,16 @@ static int ads_group_add(int argc, const char **argv)
        
        if (ads_count_replies(ads, res)) {
                d_fprintf(stderr, "ads_group_add: Group %s already exists\n", argv[0]);
-               ads_msgfree(ads, res);
                goto done;
        }
 
-       if (opt_container == NULL) {
-               opt_container = ads_default_ou_string(ads, WELL_KNOWN_GUID_USERS);
+       if (opt_container) {
+               ou_str = SMB_STRDUP(opt_container);
+       } else {
+               ou_str = ads_default_ou_string(ads, WELL_KNOWN_GUID_USERS);
        }
 
-       status = ads_add_group_acct(ads, argv[0], opt_container, opt_comment);
+       status = ads_add_group_acct(ads, argv[0], ou_str, opt_comment);
 
        if (ADS_ERR_OK(status)) {
                d_printf("Group %s added\n", argv[0]);
@@ -656,6 +663,7 @@ static int ads_group_add(int argc, const char **argv)
        if (res)
                ads_msgfree(ads, res);
        ads_destroy(&ads);
+       SAFE_FREE(ou_str);
        return rc;
 }
 
@@ -663,7 +671,7 @@ static int ads_group_delete(int argc, const char **argv)
 {
        ADS_STRUCT *ads;
        ADS_STATUS rc;
-       void *res;
+       void *res = NULL;
        char *groupdn;
 
        if (argc < 1) {
@@ -675,8 +683,9 @@ static int ads_group_delete(int argc, const char **argv)
        }
 
        rc = ads_find_user_acct(ads, &res, argv[0]);
-       if (!ADS_ERR_OK(rc)) {
+       if (!ADS_ERR_OK(rc) || ads_count_replies(ads, res) != 1) {
                DEBUG(0, ("Group %s does not exist\n", argv[0]));
+               ads_msgfree(ads, res);
                ads_destroy(&ads);
                return -1;
        }
@@ -684,7 +693,7 @@ static int ads_group_delete(int argc, const char **argv)
        ads_msgfree(ads, res);
        rc = ads_del_dn(ads, groupdn);
        ads_memfree(ads, groupdn);
-       if (!ADS_ERR_OK(rc)) {
+       if (ADS_ERR_OK(rc)) {
                d_printf("Group %s deleted\n", argv[0]);
                ads_destroy(&ads);
                return 0;
@@ -1066,8 +1075,10 @@ static ADS_STATUS net_precreate_machine_acct( ADS_STRUCT *ads, const char *ou )
        LDAPMessage *res = NULL;
 
        ou_str = ads_ou_string(ads, ou);
-       asprintf(&dn, "%s,%s", ou_str, ads->config.bind_path);
-       free(ou_str);
+       if ((asprintf(&dn, "%s,%s", ou_str, ads->config.bind_path)) == -1) {
+               SAFE_FREE(ou_str);
+               return ADS_ERROR(LDAP_NO_MEMORY);
+       }
 
        rc = ads_search_dn(ads, (void**)&res, dn, NULL);
        ads_msgfree(ads, res);
@@ -1082,6 +1093,7 @@ static ADS_STATUS net_precreate_machine_acct( ADS_STRUCT *ads, const char *ou )
                }
        }
 
+       SAFE_FREE( ou_str );
        SAFE_FREE( dn );
 
        return rc;