{
ret = smbc_read(fd, buffer, sizeof(buffer));
savedErrno = errno;
+ if (ret > 0) fwrite(buffer, 1, ret, stdout);
} while (ret > 0);
smbc_close(fd);
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) \
@$(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 $@
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)
static BOOL prompt = True;
static BOOL recurse = False;
+static BOOL showacls = False;
BOOL lowercase = False;
static struct in_addr dest_ip;
{
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);
+ }
+ }
+ }
}
}
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 = '\\';
}
static int cmd_quit(void)
{
cli_cm_shutdown();
+ talloc_destroy( ctx);
exit(0);
/* NOTREACHED */
return 0;
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.
****************************************************************************/
{"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}},
return 1;
}
+ talloc_destroy( ctx);
return rc;
}
/* 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);
}
}
- SAFE_FREE(cache_fname);
if (!cache) {
DEBUG(5, ("Attempt to open gencache.tdb has failed.\n"));
return False;
}
/* 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);
}
ret = ldap_delete_s(ads->ld, utf8_dn);
+ SAFE_FREE(utf8_dn);
return ADS_ERROR(ret);
}
SAFE_FREE(base);
if (ads_count_replies(ads, res) != 1) {
+ ads_msgfree(ads, res);
return NULL;
}
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;
free(s);
}
+ ads_msgfree(ads, res);
ads_memfree(ads, wkn_dn);
ldap_value_free(wkn_dn_exp);
ldap_value_free(bind_dn_exp);
}
- 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);
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));
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';
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)));
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",
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",
# 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);
}
#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);
}
#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);
}
}
#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];
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) {
char *upn, *userdn;
void *res=NULL;
int rc = -1;
+ char *ou_str = NULL;
if (argc < 1) return net_ads_user_usage(argc, 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],
if (res)
ads_msgfree(ads, res);
ads_destroy(&ads);
+ SAFE_FREE(ou_str);
return rc;
}
{
ADS_STRUCT *ads;
ADS_STATUS rc;
- void *res;
+ void *res = NULL;
char *userdn;
if (argc < 1) {
}
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;
}
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;
ADS_STATUS status;
void *res=NULL;
int rc = -1;
+ char *ou_str = NULL;
if (argc < 1) {
return net_ads_group_usage(argc, 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]);
if (res)
ads_msgfree(ads, res);
ads_destroy(&ads);
+ SAFE_FREE(ou_str);
return rc;
}
{
ADS_STRUCT *ads;
ADS_STATUS rc;
- void *res;
+ void *res = NULL;
char *groupdn;
if (argc < 1) {
}
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;
}
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;
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);
}
}
+ SAFE_FREE( ou_str );
SAFE_FREE( dn );
return rc;