diff options
author | Gerald Carter <jerry@samba.org> | 2006-11-06 20:10:30 +0000 |
---|---|---|
committer | Gerald Carter <jerry@samba.org> | 2006-11-06 20:10:30 +0000 |
commit | 76cc7dedb3a5434232a29d3d6e33bf84184e2d76 (patch) | |
tree | 6e03d843dc100d65201b1833fff36cafbfcb1cad /source | |
parent | 47dde11977c259e804ae67f1507d0e2f7e8263fc (diff) | |
download | samba-76cc7dedb3a5434232a29d3d6e33bf84184e2d76.tar.gz samba-76cc7dedb3a5434232a29d3d6e33bf84184e2d76.tar.xz samba-76cc7dedb3a5434232a29d3d6e33bf84184e2d76.zip |
r19581: Merge from SAMBA_3_0_23
Diffstat (limited to 'source')
-rw-r--r-- | source/Makefile.in | 14 | ||||
-rw-r--r-- | source/client/client.c | 78 | ||||
-rw-r--r-- | source/lib/gencache.c | 11 | ||||
-rw-r--r-- | source/lib/pidfile.c | 13 | ||||
-rw-r--r-- | source/libads/ldap.c | 5 | ||||
-rw-r--r-- | source/libsmb/libsmbclient.c | 10 | ||||
-rw-r--r-- | source/libsmb/passchange.c | 13 | ||||
-rw-r--r-- | source/nsswitch/winbindd_misc.c | 8 | ||||
-rw-r--r-- | source/passdb/lookup_sid.c | 6 | ||||
-rw-r--r-- | source/smbwrapper/wrapped.c | 68 | ||||
-rw-r--r-- | source/utils/net_ads.c | 44 |
11 files changed, 193 insertions, 77 deletions
diff --git a/source/Makefile.in b/source/Makefile.in index 1c740ed71b4..348893552f8 100644 --- a/source/Makefile.in +++ b/source/Makefile.in @@ -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 $@ diff --git a/source/client/client.c b/source/client/client.c index 3c2d7afe2d6..522048dc74e 100644 --- a/source/client/client.c +++ b/source/client/client.c @@ -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; @@ -2419,6 +2462,25 @@ static int cmd_setcase(void) } /**************************************************************************** + 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; } diff --git a/source/lib/gencache.c b/source/lib/gencache.c index 75a8f2f1e16..013eed8a00d 100644 --- a/source/lib/gencache.c +++ b/source/lib/gencache.c @@ -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; diff --git a/source/lib/pidfile.c b/source/lib/pidfile.c index 08e41083b59..49626acade5 100644 --- a/source/lib/pidfile.c +++ b/source/lib/pidfile.c @@ -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); diff --git a/source/libads/ldap.c b/source/libads/ldap.c index ee60063a88f..fb7c6730a07 100644 --- a/source/libads/ldap.c +++ b/source/libads/ldap.c @@ -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); diff --git a/source/libsmb/libsmbclient.c b/source/libsmb/libsmbclient.c index caa26a70a80..80b09fab1a1 100644 --- a/source/libsmb/libsmbclient.c +++ b/source/libsmb/libsmbclient.c @@ -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); diff --git a/source/libsmb/passchange.c b/source/libsmb/passchange.c index 673671d28db..90eb67aceaa 100644 --- a/source/libsmb/passchange.c +++ b/source/libsmb/passchange.c @@ -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)); diff --git a/source/nsswitch/winbindd_misc.c b/source/nsswitch/winbindd_misc.c index 731d2bb474a..6b44eb9783b 100644 --- a/source/nsswitch/winbindd_misc.c +++ b/source/nsswitch/winbindd_misc.c @@ -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))); diff --git a/source/passdb/lookup_sid.c b/source/passdb/lookup_sid.c index 6f0140386a2..7082cd3abd4 100644 --- a/source/passdb/lookup_sid.c +++ b/source/passdb/lookup_sid.c @@ -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", diff --git a/source/smbwrapper/wrapped.c b/source/smbwrapper/wrapped.c index 338ee0d5b1b..e1bbccd836b 100644 --- a/source/smbwrapper/wrapped.c +++ b/source/smbwrapper/wrapped.c @@ -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); @@ -68,12 +68,12 @@ #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)) { @@ -103,7 +103,7 @@ #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); @@ -113,8 +113,8 @@ } #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); @@ -125,18 +125,18 @@ #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); } @@ -279,7 +279,7 @@ #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); @@ -289,12 +289,12 @@ } #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); } @@ -302,7 +302,7 @@ - int access(char *name, int mode) + int access(const char *name, int mode) { if (smbw_path(name)) { return smbw_access(name, mode); @@ -313,7 +313,7 @@ - int chmod(char *name,mode_t mode) + int chmod(const char *name,mode_t mode) { if (smbw_path(name)) { return smbw_chmod(name, mode); @@ -324,7 +324,7 @@ - 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); @@ -342,7 +342,7 @@ - int mkdir(char *name, mode_t mode) + int mkdir(const char *name, mode_t mode) { if (smbw_path(name)) { return smbw_mkdir(name, mode); @@ -369,7 +369,7 @@ #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; @@ -386,7 +386,7 @@ #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; @@ -402,7 +402,7 @@ #endif - int stat(char *name, void *st) + int stat(const char *name, void *st) { #if HAVE___XSTAT return __xstat(0, name, st); @@ -414,7 +414,7 @@ #endif } - int lstat(char *name, void *st) + int lstat(const char *name, void *st) { #if HAVE___LXSTAT return __lxstat(0, name, st); @@ -439,7 +439,7 @@ } - int unlink(char *name) + int unlink(const char *name) { if (smbw_path(name)) { return smbw_unlink(name); @@ -450,7 +450,7 @@ #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); @@ -471,7 +471,7 @@ } #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); @@ -481,7 +481,7 @@ } - int rename(char *oldname,char *newname) + int rename(const char *oldname,const char *newname) { int p1, p2; p1 = smbw_path(oldname); @@ -498,7 +498,7 @@ return real_rename(oldname, newname); } - int rmdir(char *name) + int rmdir(const char *name) { if (smbw_path(name)) { return smbw_rmdir(name); @@ -508,7 +508,7 @@ } - int symlink(char *topath,char *frompath) + int symlink(const char *topath,const char *frompath) { int p1, p2; p1 = smbw_path(topath); @@ -545,7 +545,7 @@ } #ifdef real_opendir - void *opendir(char *name) + void *opendir(const char *name) { if (smbw_path(name)) { return (void *)smbw_opendir(name); @@ -624,14 +624,14 @@ } #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); @@ -639,7 +639,7 @@ #endif #ifdef HAVE_STAT64 - int stat64(char *name, void *st64) + int stat64(const char *name, void *st64) { if (smbw_path(name)) { double xx[32]; @@ -661,7 +661,7 @@ 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]; diff --git a/source/utils/net_ads.c b/source/utils/net_ads.c index 4f45be5b634..fcf1bf25083 100644 --- a/source/utils/net_ads.c +++ b/source/utils/net_ads.c @@ -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; |