diff options
author | Gerald Carter <jerry@samba.org> | 2005-07-28 02:31:38 +0000 |
---|---|---|
committer | Gerald Carter <jerry@samba.org> | 2005-07-28 02:31:38 +0000 |
commit | 0452f23f10a7e25246534ef2ccfeaeea8270c420 (patch) | |
tree | 3fadefb04bf9b6e450424874a6c70ed89c0228fd | |
parent | 2e875bc8747747d5424488bb04a9b33ad0ebd192 (diff) | |
download | samba-0452f23f10a7e25246534ef2ccfeaeea8270c420.tar.gz |
r8814: sync for 3.0.20rc1 (up to r8805 from 3.0 tree)
104 files changed, 2518 insertions, 2922 deletions
diff --git a/examples/VFS/Makefile.in b/examples/VFS/Makefile.in index c368974bd5e..7d04ad9f3a0 100644 --- a/examples/VFS/Makefile.in +++ b/examples/VFS/Makefile.in @@ -7,7 +7,7 @@ INSTALLCMD = @INSTALL@ SAMBA_SOURCE = @SAMBA_SOURCE@ SHLIBEXT = @SHLIBEXT@ OBJEXT = @OBJEXT@ -FLAGS = $(CFLAGS) -Iinclude -I$(SAMBA_SOURCE)/include -I$(SAMBA_SOURCE)/ubiqx -I$(SAMBA_SOURCE)/smbwrapper -I. $(CPPFLAGS) -I$(SAMBA_SOURCE) +FLAGS = $(CFLAGS) -Iinclude -I$(SAMBA_SOURCE)/include -I$(SAMBA_SOURCE)/ubiqx -I$(SAMBA_SOURCE)/smbwrapper -I. $(CPPFLAGS) -I$(SAMBA_SOURCE) -fPIC prefix = @prefix@ diff --git a/source/VERSION b/source/VERSION index 26b90abba74..33cc6f2e01c 100644 --- a/source/VERSION +++ b/source/VERSION @@ -29,7 +29,7 @@ SAMBA_VERSION_RELEASE=20 # e.g. SAMBA_VERSION_PRE_RELEASE=1 # # -> "2.2.9pre1" # ######################################################## -SAMBA_VERSION_PRE_RELEASE=2 +SAMBA_VERSION_PRE_RELEASE= ######################################################## # For 'rc' releases the version will be # @@ -39,7 +39,7 @@ SAMBA_VERSION_PRE_RELEASE=2 # e.g. SAMBA_VERSION_RC_RELEASE=1 # # -> "3.0.0rc1" # ######################################################## -SAMBA_VERSION_RC_RELEASE= +SAMBA_VERSION_RC_RELEASE=1 ######################################################## # To mark SVN snapshots this should be set to 'yes' # diff --git a/source/auth/auth_util.c b/source/auth/auth_util.c index 49df15533a7..6624631b53d 100644 --- a/source/auth/auth_util.c +++ b/source/auth/auth_util.c @@ -1327,6 +1327,9 @@ NTSTATUS make_server_info_info3(TALLOC_CTX *mem_ctx, return nt_status; } + (*server_info)->login_server = unistr2_tdup(mem_ctx, + &(info3->uni_logon_srv)); + (*server_info)->ptok = token; SAFE_FREE(lgroupSIDs); diff --git a/source/client/client.c b/source/client/client.c index 0ada2e3a9a8..d22f1245fac 100644 --- a/source/client/client.c +++ b/source/client/client.c @@ -21,8 +21,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define NO_SYSLOG - #include "includes.h" #include "client/client_proto.h" #ifndef REGISTER @@ -73,8 +71,6 @@ extern BOOL tar_reset; static BOOL prompt = True; -static int printmode = 1; - static BOOL recurse = False; BOOL lowercase = False; @@ -2419,43 +2415,6 @@ static int cmd_translate(void) } /**************************************************************************** - Do a printmode command. -****************************************************************************/ - -static int cmd_printmode(void) -{ - fstring buf; - fstring mode; - - if (next_token_nr(NULL,buf,NULL,sizeof(buf))) { - if (strequal(buf,"text")) { - printmode = 0; - } else { - if (strequal(buf,"graphics")) - printmode = 1; - else - printmode = atoi(buf); - } - } - - switch(printmode) { - case 0: - fstrcpy(mode,"text"); - break; - case 1: - fstrcpy(mode,"graphics"); - break; - default: - slprintf(mode,sizeof(mode)-1,"%d",printmode); - break; - } - - DEBUG(2,("the printmode is now %s\n",mode)); - - return 0; -} - -/**************************************************************************** Do the lcd command. ****************************************************************************/ @@ -2763,7 +2722,6 @@ static struct {"newer",cmd_newer,"<file> only mget files newer than the specified local file",{COMPL_LOCAL,COMPL_NONE}}, {"open",cmd_open,"<mask> open a file",{COMPL_REMOTE,COMPL_NONE}}, {"print",cmd_print,"<file name> print a file",{COMPL_NONE,COMPL_NONE}}, - {"printmode",cmd_printmode,"<graphics or text> set the print mode",{COMPL_NONE,COMPL_NONE}}, {"prompt",cmd_prompt,"toggle prompting for filenames for mget and mput",{COMPL_NONE,COMPL_NONE}}, {"put",cmd_put,"<local name> [remote name] put a file",{COMPL_LOCAL,COMPL_REMOTE}}, {"pwd",cmd_pwd,"show current remote directory (same as 'cd' with no args)",{COMPL_NONE,COMPL_NONE}}, diff --git a/source/client/smbmount.c b/source/client/smbmount.c index 04bb103dae2..4438964b838 100644 --- a/source/client/smbmount.c +++ b/source/client/smbmount.c @@ -18,8 +18,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define NO_SYSLOG - #include "includes.h" #include <mntent.h> diff --git a/source/client/smbspool.c b/source/client/smbspool.c index 04f293a8e63..16b071af193 100644 --- a/source/client/smbspool.c +++ b/source/client/smbspool.c @@ -23,8 +23,6 @@ #include "includes.h" - -#define NO_SYSLOG #define PW_MAX_BUF_SIZE sysconf(_SC_GETPW_R_SIZE_MAX) #define TICKET_CC_DIR "/tmp" #define CC_PREFIX "krb5cc_" /* prefix of the ticket cache */ diff --git a/source/configure.in b/source/configure.in index 8ac3d207056..e343a9f54fd 100644 --- a/source/configure.in +++ b/source/configure.in @@ -752,6 +752,18 @@ CPPFLAGS="$old_CPPFLAGS" # subdirectory of headers. AC_CHECK_HEADERS(valgrind.h valgrind/valgrind.h valgrind/memcheck.h) +/* check for linux on amd64 since valgrind is not quite there yet */ +case "$host_os" in + *linux*) + case "$UNAME_P" in + *x86_64*) + AC_DEFINE(HAVE_64BIT_LINUX,1,[Whether we are running on 64bit linux]) + ;; + esac + ;; +esac + + # # HPUX has a bug in that including shadow.h causes a re-definition of MAXINT. # This causes configure to fail to detect it. Check for shadow separately on HPUX. @@ -1184,6 +1196,57 @@ if test x$ac_cv_func_fstat64 = xno ; then fi fi +################################################# +# Check whether struct stat has timestamps with sub-second resolution. +# At least IRIX and Solaris have these. +# +# We check that +# all of st_mtim, st_atim and st_ctim exist +# all of the members are in fact of type struct timespec +# +# There is some conflicting standards weirdness about whether we should use +# "struct timespec" or "timespec_t". Linux doesn't have timespec_t, so we +# prefer struct timespec. + +AC_CACHE_CHECK([whether struct stat has sub-second timestamps], samba_stat_hires, + [ + AC_TRY_COMPILE( + [ +#if TIME_WITH_SYS_TIME +# include <sys/time.h> +# include <time.h> +#else +# if HAVE_SYS_TIME_H +# include <sys/time.h> +# else +# include <time.h> +# endif +#endif +#ifdef HAVE_SYS_STAT_H +#include <sys/stat.h> +#endif + ], + [ + struct timespec t; + struct stat s = {0}; + t.tv_sec = s.st_mtim.tv_sec; + t.tv_nsec = s.st_mtim.tv_nsec; + t.tv_sec = s.st_ctim.tv_sec; + t.tv_nsec = s.st_ctim.tv_nsec; + t.tv_sec = s.st_atim.tv_sec; + t.tv_nsec = s.st_atim.tv_nsec; + ], + samba_stat_hires=yes, samba_stat_hires=no) + ]) + +if test x"$samba_stat_hires" = x"yes" ; then + AC_DEFINE(HAVE_STAT_ST_MTIM, 1, [whether struct stat contains st_mtim]) + AC_DEFINE(HAVE_STAT_ST_ATIM, 1, [whether struct stat contains st_atim]) + AC_DEFINE(HAVE_STAT_ST_CTIM, 1, [whether struct stat contains st_ctim]) + AC_DEFINE(HAVE_STAT_HIRES_TIMESTAMPS, 1, + [whether struct stat has sub-second timestamps]) +fi + ##################################### # we might need the resolv library on some systems AC_CHECK_LIB(resolv, dn_expand) @@ -4024,7 +4087,7 @@ AC_ARG_WITH(acl-support, AC_DEFINE(HAVE_TRU64_ACLS,1,[Whether Tru64 ACLs are available]) ACL_LIBS="$ACL_LIBS -lpacl" ;; - *freebsd5*|*freebsd6*) + *freebsd[[5-9]]*) AC_MSG_RESULT(Using FreeBSD posix ACLs) AC_DEFINE(HAVE_POSIX_ACLS,1,[Whether FreeBSD POSIX ACLs are available]) AC_DEFINE(HAVE_ACL_GET_PERM_NP,1,[Whether acl_get_perm_np() is available]) @@ -4423,7 +4486,7 @@ case "$host_os" in *linux*) WINBIND_NSS_EXTRA_OBJS="nsswitch/winbind_nss_linux.o" ;; - *freebsd5*|*freebsd6*) + *freebsd[[5-9]]*) # FreeBSD winbind client is implemented as a wrapper around # the Linux version. WINBIND_NSS_EXTRA_OBJS="nsswitch/winbind_nss_freebsd.o \ diff --git a/source/include/auth.h b/source/include/auth.h index 91751e71804..7282f4d38b2 100644 --- a/source/include/auth.h +++ b/source/include/auth.h @@ -69,6 +69,8 @@ typedef struct auth_serversupplied_info DATA_BLOB user_session_key; DATA_BLOB lm_session_key; + + char *login_server; /* which server authorized the login? */ uint32 sam_fill_level; /* How far is this structure filled? */ diff --git a/source/include/debug.h b/source/include/debug.h index f69c213eb70..99c96e6bb18 100644 --- a/source/include/debug.h +++ b/source/include/debug.h @@ -94,9 +94,8 @@ extern int DEBUGLEVEL; #define DBGC_IDMAP 13 #define DBGC_QUOTA 14 #define DBGC_ACLS 15 -#define DBGC_PRINTERDB 16 -#define DBGC_LOCKING 17 -#define DBGC_MSDFS 18 +#define DBGC_LOCKING 16 +#define DBGC_MSDFS 17 /* So you can define DBGC_CLASS before including debug.h */ #ifndef DBGC_CLASS diff --git a/source/include/includes.h b/source/include/includes.h index c091506381f..6cab2525b00 100644 --- a/source/include/includes.h +++ b/source/include/includes.h @@ -507,6 +507,8 @@ #include <aio.h> #endif +/* skip valgrind headers on 64bit AMD boxes */ +#ifndef HAVE_64BIT_LINUX /* Special macros that are no-ops except when run under Valgrind on * x86. They've moved a little bit from valgrind 1.0.4 to 1.9.4 */ #if HAVE_VALGRIND_MEMCHECK_H @@ -515,6 +517,7 @@ #elif HAVE_VALGRIND_H #include <valgrind.h> #endif +#endif /* If we have --enable-developer and the valgrind header is present, * then we're OK to use it. Set a macro so this logic can be done only diff --git a/source/include/rpc_dce.h b/source/include/rpc_dce.h index abc85035ea5..88b8380870e 100644 --- a/source/include/rpc_dce.h +++ b/source/include/rpc_dce.h @@ -66,6 +66,9 @@ enum RPC_PKT_TYPE { #define RPC_AUTH_NETSEC_SIGN_OR_SEAL_CHK_LEN 0x20 #define RPC_AUTH_NETSEC_SIGN_ONLY_CHK_LEN 0x18 +/* SPNEGO auth type. */ +#define SPNEGO_AUTH_TYPE 0x9 + /* The 7 here seems to be required to get Win2k not to downgrade us to NT4. Actually, anything other than 1ff would seem to do... */ #define NETLOGON_NEG_AUTH2_FLAGS 0x000701ff @@ -169,32 +172,25 @@ typedef struct rpc_hdr_bba_info { #define RPC_HDR_BBA_LEN 8 +/* RPC_HDR_AUTH */ +typedef struct rpc_hdr_auth_info { + uint8 auth_type; /* See XXX_AUTH_TYPE above. */ + uint8 auth_level; /* See RPC_PIPE_AUTH_XXX_LEVEL above. */ + uint8 auth_pad_len; + uint8 auth_reserved; + uint32 auth_context_id; +} RPC_HDR_AUTH; + +#define RPC_HDR_AUTH_LEN 8 + /* RPC_HDR_AUTHA */ typedef struct rpc_hdr_autha_info { uint16 max_tsize; /* maximum transmission fragment size (0x1630) */ uint16 max_rsize; /* max receive fragment size (0x1630) */ - - uint8 auth_type; /* 0x0a */ - uint8 auth_level; /* 0x06 */ - uint8 stub_type_len; /* don't know */ - uint8 padding; /* padding */ - - uint32 unknown; /* 0x0014a0c0 */ + RPC_HDR_AUTH auth; } RPC_HDR_AUTHA; -#define RPC_HDR_AUTHA_LEN 12 - -/* RPC_HDR_AUTH */ -typedef struct rpc_hdr_auth_info { - uint8 auth_type; /* 0x0a */ - uint8 auth_level; /* 0x06 */ - uint8 padding; - uint8 reserved; /* padding */ - - uint32 auth_context; /* pointer */ -} RPC_HDR_AUTH; - -#define RPC_HDR_AUTH_LEN 8 +#define RPC_HDR_AUTHA_LEN (RPC_HDR_AUTH_LEN+4) /* this is TEMPORARILY coded up as a specific structure */ /* this structure comes after the bind request */ diff --git a/source/include/rpc_samr.h b/source/include/rpc_samr.h index adf41018809..fb829558d44 100644 --- a/source/include/rpc_samr.h +++ b/source/include/rpc_samr.h @@ -351,8 +351,8 @@ typedef struct sam_user_info_20 } SAM_USER_INFO_20; -/* SAM_USER_INFO_12 */ -typedef struct sam_user_info_12 +/* SAM_USER_INFO_18 */ +typedef struct sam_user_info_18 { uint8 lm_pwd[16]; /* lm user passwords */ uint8 nt_pwd[16]; /* nt user passwords */ @@ -360,10 +360,10 @@ typedef struct sam_user_info_12 uint8 lm_pwd_active; uint8 nt_pwd_active; -} SAM_USER_INFO_12; +} SAM_USER_INFO_18; -/* SAM_USER_INFO_11 */ -typedef struct sam_user_info_11 +/* SAM_USER_INFO_17 */ +typedef struct sam_user_info_17 { uint8 padding_0[16]; /* 0 - padding 16 bytes */ NTTIME expiry; /* expiry time or something? */ @@ -398,15 +398,15 @@ typedef struct sam_user_info_11 uint8 padding_9[48]; /* 0 - padding 48 bytes */ -} SAM_USER_INFO_11; +} SAM_USER_INFO_17; -/* SAM_USER_INFO_10 */ -typedef struct sam_user_info_10 +/* SAM_USER_INFO_16 */ +typedef struct sam_user_info_16 { uint32 acb_info; -} SAM_USER_INFO_10; +} SAM_USER_INFO_16; /* SAM_USER_INFO_7 */ typedef struct sam_user_info_7 @@ -1254,15 +1254,15 @@ typedef struct sam_userinfo_ctr_info union { - SAM_USER_INFO_7 *id7; /* auth-level 0x07 */ - SAM_USER_INFO_10 *id10; /* auth-level 0x10 */ - SAM_USER_INFO_11 *id11; /* auth-level 0x11 */ - SAM_USER_INFO_12 *id12; /* auth-level 0x12 */ - SAM_USER_INFO_20 *id20; /* auth-level 20 */ - SAM_USER_INFO_21 *id21; /* auth-level 21 */ - SAM_USER_INFO_23 *id23; /* auth-level 0x17 */ - SAM_USER_INFO_24 *id24; /* auth-level 0x18 */ - SAM_USER_INFO_25 *id25; /* auth-level 0x19 */ + SAM_USER_INFO_7 *id7; + SAM_USER_INFO_16 *id16; + SAM_USER_INFO_17 *id17; + SAM_USER_INFO_18 *id18; + SAM_USER_INFO_20 *id20; + SAM_USER_INFO_21 *id21; + SAM_USER_INFO_23 *id23; + SAM_USER_INFO_24 *id24; + SAM_USER_INFO_25 *id25; void* id; /* to make typecasting easy */ } info; diff --git a/source/include/smb.h b/source/include/smb.h index 55baf845315..d3374ccafcb 100644 --- a/source/include/smb.h +++ b/source/include/smb.h @@ -150,6 +150,7 @@ typedef union unid_t { /* * SMB UCS2 (16-bit unicode) internal type. + * smb_ucs2_t is *always* in little endian format. */ typedef uint16 smb_ucs2_t; @@ -167,6 +168,10 @@ typedef smb_ucs2_t wfstring[FSTRING_LEN]; /* turn a 7 bit character into a ucs2 character */ #define UCS2_CHAR(c) ((c) << UCS2_SHIFT) +/* Copy into a smb_ucs2_t from a possibly unaligned buffer. Return the copied smb_ucs2_t */ +#define COPY_UCS2_CHAR(dest,src) (((unsigned char *)(dest))[0] = ((unsigned char *)(src))[0],\ + ((unsigned char *)(dest))[1] = ((unsigned char *)(src))[1], (dest)) + /* pipe string names */ #define PIPE_LANMAN "\\PIPE\\LANMAN" #define PIPE_SRVSVC "\\PIPE\\srvsvc" @@ -557,7 +562,7 @@ struct current_user /* Defines for the sent_oplock_break field above. */ #define NO_BREAK_SENT 0 -#define EXCLUSIVE_BREAK_SENT 1 +#define BREAK_TO_NONE_SENT 1 #define LEVEL_II_BREAK_SENT 2 typedef struct { @@ -1644,6 +1649,8 @@ typedef struct user_struct struct auth_serversupplied_info *server_info; + struct auth_ntlmssp_state *auth_ntlmssp_state; + } user_struct; diff --git a/source/lib/debug.c b/source/lib/debug.c index d6785f83adf..f877d540fb4 100644 --- a/source/lib/debug.c +++ b/source/lib/debug.c @@ -164,7 +164,6 @@ static const char *default_classname_table[] = { "idmap", /* DBGC_IDMAP */ "quota", /* DBGC_QUOTA */ "acls", /* DBGC_ACLS */ - "printerdb", /* DBGC_PRINTERDB */ "locking", /* DBGC_LOCKING */ "msdfs", /* DBGC_MSDFS */ NULL diff --git a/source/lib/smbldap.c b/source/lib/smbldap.c index 4a8ef63806f..d1f3f82cb56 100644 --- a/source/lib/smbldap.c +++ b/source/lib/smbldap.c @@ -431,6 +431,7 @@ ATTRIB_MAP_ENTRY sidmap_attr_list[] = { /* Believe it or not, but LDAP will deny a delete and an add at the same time if the values are the same... */ + DEBUG(10,("smbldap_make_mod: attribute |%s| not changed.\n", attribute)); return; } @@ -446,6 +447,7 @@ ATTRIB_MAP_ENTRY sidmap_attr_list[] = { * in Novell NDS. In NDS you have to first remove attribute and then * you could add new value */ + DEBUG(10,("smbldap_make_mod: deleting attribute |%s| values |%s|\n", attribute, oldval)); smbldap_set_mod(mods, LDAP_MOD_DELETE, attribute, oldval); } @@ -454,6 +456,7 @@ ATTRIB_MAP_ENTRY sidmap_attr_list[] = { the old value, should it exist. */ if ((newval != NULL) && (strlen(newval) > 0)) { + DEBUG(10,("smbldap_make_mod: adding attribute |%s| value |%s|\n", attribute)); smbldap_set_mod(mods, LDAP_MOD_ADD, attribute, newval); } } diff --git a/source/lib/socket_wrapper.c b/source/lib/socket_wrapper.c index bb4a4e0a673..808d62601f8 100644 --- a/source/lib/socket_wrapper.c +++ b/source/lib/socket_wrapper.c @@ -56,6 +56,13 @@ #undef malloc #undef calloc #undef strdup +/* we need to use a very terse format here as IRIX 6.4 silently + truncates names to 16 chars, so if we use a longer name then we + can't tell which port a packet came from with recvfrom() + + with this format we have 8 chars left for the directory name +*/ +#define SOCKET_FORMAT "%u_%u" static struct sockaddr *sockaddr_dup(const void *data, socklen_t len) { @@ -102,7 +109,7 @@ static int convert_un_in(const struct sockaddr_un *un, struct sockaddr_in *in, s p = strrchr(un->sun_path, '/'); if (p) p++; else p = un->sun_path; - if (sscanf(p, "sock_ip_%d_%u", &type, &prt) == 2) { + if (sscanf(p, SOCKET_FORMAT, &type, &prt) == 2) { in->sin_port = htons(prt); } in->sin_addr.s_addr = htonl(INADDR_LOOPBACK); @@ -119,12 +126,12 @@ static int convert_in_un(struct socket_info *si, const struct sockaddr_in *in, s /* handle auto-allocation of ephemeral ports */ prt = 5000; do { - snprintf(un->sun_path, sizeof(un->sun_path), "%s/sock_ip_%d_%u", + snprintf(un->sun_path, sizeof(un->sun_path), "%s/"SOCKET_FORMAT, getenv("SOCKET_WRAPPER_DIR"), type, ++prt); } while (stat(un->sun_path, &st) == 0 && prt < 10000); ((struct sockaddr_in *)si->myname)->sin_port = htons(prt); } - snprintf(un->sun_path, sizeof(un->sun_path), "%s/sock_ip_%d_%u", + snprintf(un->sun_path, sizeof(un->sun_path), "%s/"SOCKET_FORMAT, getenv("SOCKET_WRAPPER_DIR"), type, prt); return 0; } @@ -230,6 +237,8 @@ int swrap_accept(int s, struct sockaddr *addr, socklen_t *addrlen) return real_accept(s, addr, addrlen); } + memset(&un_addr, 0, sizeof(un_addr)); + ret = real_accept(s, (struct sockaddr *)&un_addr, &un_addrlen); if (ret == -1) return ret; @@ -270,7 +279,7 @@ static int swrap_auto_bind(struct socket_info *si) for (i=0;i<1000;i++) { snprintf(un_addr.sun_path, sizeof(un_addr.sun_path), - "%s/sock_ip_%u_%u", getenv("SOCKET_WRAPPER_DIR"), + "%s/"SOCKET_FORMAT, getenv("SOCKET_WRAPPER_DIR"), SOCK_DGRAM, i + 10000); if (bind(si->fd, (struct sockaddr *)&un_addr, sizeof(un_addr)) == 0) { @@ -458,6 +467,8 @@ ssize_t swrap_recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr return real_recvfrom(s, buf, len, flags, from, fromlen); } + /* irix 6.4 forgets to null terminate the sun_path string :-( */ + memset(&un_addr, 0, sizeof(un_addr)); ret = real_recvfrom(s, buf, len, flags, (struct sockaddr *)&un_addr, &un_addrlen); if (ret == -1) return ret; diff --git a/source/lib/substitute.c b/source/lib/substitute.c index af30e900ace..15862f7a966 100644 --- a/source/lib/substitute.c +++ b/source/lib/substitute.c @@ -385,15 +385,20 @@ void standard_sub_basic(const char *smb_name, char *str,size_t len) case 'i' : string_sub(p,"%i", client_socket_addr(),l); break; - case 'L' : - if (local_machine_name && *local_machine_name) - string_sub(p,"%L", local_machine_name,l); - else { + case 'L' : + if (!StrnCaseCmp(p, "\%LOGONSERVER\%", 13)) { + p++; + break; + } + + if (local_machine_name && *local_machine_name) { + string_sub_once(p, "%L", local_machine_name, l); + } else { pstring temp_name; pstrcpy(temp_name, global_myname()); strlower_m(temp_name); - string_sub(p,"%L", temp_name,l); + string_sub_once(p, "%L", temp_name, l); } break; case 'M' : diff --git a/source/lib/system.c b/source/lib/system.c index 6ac2cdf2433..2565f92c668 100644 --- a/source/lib/system.c +++ b/source/lib/system.c @@ -1938,7 +1938,7 @@ int sys_aio_fsync(int op, SMB_STRUCT_AIOCB *aiocb) #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_FSYNC64) return aio_fsync64(op, aiocb); #elif defined(HAVE_AIO_FSYNC) - return aio_fsync64(op, aiocb); + return aio_fsync(op, aiocb); #else errno = ENOSYS; return -1; diff --git a/source/lib/username.c b/source/lib/username.c index e691e4c1f18..1973a8c7c60 100644 --- a/source/lib/username.c +++ b/source/lib/username.c @@ -93,7 +93,7 @@ char *get_user_home_dir(const char *user) Returns True if username was changed, false otherwise. ********************************************************************/ -BOOL map_username(char *user) +BOOL map_username(fstring user) { static BOOL initialised=False; static fstring last_from,last_to; @@ -102,18 +102,11 @@ BOOL map_username(char *user) char *s; pstring buf; BOOL mapped_user = False; - + char *cmd = lp_username_map_script(); + if (!*user) return False; - - if (!*mapfile) - return False; - - if (!initialised) { - *last_from = *last_to = 0; - initialised = True; - } - + if (strequal(user,last_to)) return False; @@ -122,6 +115,52 @@ BOOL map_username(char *user) fstrcpy(user,last_to); return True; } + + /* first try the username map script */ + + if ( *cmd ) { + char **qlines; + pstring command; + int numlines, ret, fd; + + pstr_sprintf( command, "%s \"%s\"", cmd, user ); + + DEBUG(10,("Running [%s]\n", command)); + ret = smbrun(command, &fd); + DEBUGADD(10,("returned [%d]\n", ret)); + + if ( ret != 0 ) { + if (fd != -1) + close(fd); + return False; + } + + numlines = 0; + qlines = fd_lines_load(fd, &numlines); + DEBUGADD(10,("Lines returned = [%d]\n", numlines)); + close(fd); + + /* should be either no lines or a single line with the mapped username */ + + if (numlines) { + DEBUG(3,("Mapped user %s to %s\n", user, qlines[0] )); + fstrcpy( user, qlines[0] ); + } + + file_lines_free(qlines); + + return numlines != 0; + } + + /* ok. let's try the mapfile */ + + if (!*mapfile) + return False; + + if (!initialised) { + *last_from = *last_to = 0; + initialised = True; + } f = x_fopen(mapfile,O_RDONLY, 0); if (!f) { @@ -172,10 +211,10 @@ BOOL map_username(char *user) if (strchr_m(dosname,'*') || user_in_list(user, (const char **)dosuserlist, NULL, 0)) { DEBUG(3,("Mapped user %s to %s\n",user,unixname)); mapped_user = True; - fstrcpy(last_from,user); - sscanf(unixname,"%s",user); - fstrcpy(last_to,user); - if(return_if_mapped) { + fstrcpy( last_from,user ); + fstrcpy( user, unixname ); + fstrcpy( last_to,user ); + if ( return_if_mapped ) { str_list_free (&dosuserlist); x_fclose(f); return True; diff --git a/source/lib/util_str.c b/source/lib/util_str.c index 42229f105a1..1401d6d8534 100644 --- a/source/lib/util_str.c +++ b/source/lib/util_str.c @@ -909,14 +909,15 @@ BOOL string_set(char **dest,const char *src) enough room! This routine looks for pattern in s and replaces it with - insert. It may do multiple replacements. + insert. It may do multiple replacements or just one. Any of " ; ' $ or ` in the insert string are replaced with _ if len==0 then the string cannot be extended. This is different from the old use of len==0 which was for no length checks to be done. **/ -void string_sub(char *s,const char *pattern, const char *insert, size_t len) +void string_sub2(char *s,const char *pattern, const char *insert, size_t len, + BOOL remove_unsafe_characters, BOOL replace_once) { char *p; ssize_t ls,lp,li, i; @@ -951,17 +952,34 @@ void string_sub(char *s,const char *pattern, const char *insert, size_t len) case '%': case '\r': case '\n': - p[i] = '_'; - break; + if ( remove_unsafe_characters ) { + p[i] = '_'; + /* yes this break should be here since we want to + fall throw if not replacing unsafe chars */ + break; + } default: p[i] = insert[i]; } } s = p + li; ls += (li-lp); + + if (replace_once) + break; } } +void string_sub_once(char *s, const char *pattern, const char *insert, size_t len) +{ + string_sub2( s, pattern, insert, len, True, True ); +} + +void string_sub(char *s,const char *pattern, const char *insert, size_t len) +{ + string_sub2( s, pattern, insert, len, True, False ); +} + void fstring_sub(char *s,const char *pattern,const char *insert) { string_sub(s, pattern, insert, sizeof(fstring)); diff --git a/source/lib/util_unistr.c b/source/lib/util_unistr.c index 678eb22d2c4..b31e01474a8 100644 --- a/source/lib/util_unistr.c +++ b/source/lib/util_unistr.c @@ -3,6 +3,7 @@ Samba utility functions Copyright (C) Andrew Tridgell 1992-2001 Copyright (C) Simo Sorce 2001 + Copyright (C) Jeremy Allison 2005 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -46,12 +47,15 @@ static uint8 doschar_table[8192]; /* 65536 characters / 8 bits/byte */ * The case tables are defined in UCS2 and don't depend on any * configured parameters, so they never need to be reloaded. **/ + void load_case_tables(void) { static int initialised; int i; - if (initialised) return; + if (initialised) { + return; + } initialised = 1; upcase_table = map_file(lib_path("upcase.dat"), 0x20000); @@ -94,6 +98,7 @@ void load_case_tables(void) see if a ucs2 character can be mapped correctly to a dos character and mapped back to the same character in ucs2 */ + int check_dos_char(smb_ucs2_t c) { lazy_initialize_conv(); @@ -109,10 +114,15 @@ static int check_dos_char_slowly(smb_ucs2_t c) char buf[10]; smb_ucs2_t c2 = 0; int len1, len2; + len1 = convert_string(CH_UCS2, CH_DOS, &c, 2, buf, sizeof(buf),False); - if (len1 == 0) return 0; + if (len1 == 0) { + return 0; + } len2 = convert_string(CH_DOS, CH_UCS2, buf, len1, &c2, 2,False); - if (len2 != 2) return 0; + if (len2 != 2) { + return 0; + } return (c == c2); } @@ -120,6 +130,7 @@ static int check_dos_char_slowly(smb_ucs2_t c) /** * Fill out doschar table the hard way, by examining each character **/ + void init_doschar_table(void) { int i, j, byteval; @@ -133,8 +144,9 @@ void init_doschar_table(void) c = i + j; - if (check_dos_char_slowly(c)) + if (check_dos_char_slowly(c)) { byteval |= 1 << j; + } } doschar_table[i/8] = byteval; } @@ -149,6 +161,7 @@ void init_doschar_table(void) * However, the valid character table is not changed if it's loaded * from a file, because we can't unmap files. **/ + void init_valid_table(void) { static int mapped_file; @@ -176,8 +189,9 @@ void init_valid_table(void) DEBUG(2,("creating default valid table\n")); valid_table = SMB_MALLOC(0x10000); - for (i=0;i<128;i++) + for (i=0;i<128;i++) { valid_table[i] = isalnum(i) || strchr(allowed,i); + } for (;i<0x10000;i++) { smb_ucs2_t c; @@ -186,8 +200,6 @@ void init_valid_table(void) } } - - /******************************************************************* Write a string in (little-endian) unicode format. src is in the current DOS codepage. len is the length in bytes of the @@ -213,27 +225,32 @@ size_t dos_PutUniCode(char *dst,const char *src, ssize_t len, BOOL null_terminat char *skip_unibuf(char *src, size_t len) { - char *srcend = src + len; + char *srcend = src + len; - while (src < srcend && SVAL(src,0)) - src += 2; + while (src < srcend && SVAL(src,0)) { + src += 2; + } - if(!SVAL(src,0)) - src += 2; + if(!SVAL(src,0)) { + src += 2; + } - return src; + return src; } /* Copy a string from little-endian or big-endian unicode source (depending * on flags) to internal samba format destination */ + int rpcstr_pull(char* dest, void *src, int dest_len, int src_len, int flags) { if (!src) { dest[0] = 0; return 0; } - if(dest_len==-1) dest_len=MAXUNI-3; + if(dest_len==-1) { + dest_len=MAXUNI-3; + } return pull_ucs2(NULL, dest, src, dest_len, src_len, flags|STR_UNICODE|STR_NOALIGN); } @@ -249,14 +266,16 @@ int rpcstr_pull_unistr2_fstring(char *dest, UNISTR2 *src) /* Converts a string from internal samba format to unicode */ + int rpcstr_push(void* dest, const char *src, int dest_len, int flags) { return push_ucs2(NULL, dest, src, dest_len, flags|STR_UNICODE|STR_NOALIGN); } /******************************************************************* - Convert a (little-endian) UNISTR2 structure to an ASCII string + Convert a (little-endian) UNISTR2 structure to an ASCII string. ********************************************************************/ + void unistr2_to_ascii(char *dest, const UNISTR2 *str, size_t maxlen) { if (str == NULL) { @@ -267,8 +286,9 @@ void unistr2_to_ascii(char *dest, const UNISTR2 *str, size_t maxlen) } /******************************************************************* - Convert a (little-endian) UNISTR3 structure to an ASCII string + Convert a (little-endian) UNISTR3 structure to an ASCII string. ********************************************************************/ + void unistr3_to_ascii(char *dest, const UNISTR3 *str, size_t maxlen) { if (str == NULL) { @@ -280,8 +300,9 @@ void unistr3_to_ascii(char *dest, const UNISTR3 *str, size_t maxlen) } /******************************************************************* -give a static string for displaying a UNISTR2 + Give a static string for displaying a UNISTR2. ********************************************************************/ + const char *unistr2_static(const UNISTR2 *str) { static pstring ret; @@ -289,24 +310,26 @@ const char *unistr2_static(const UNISTR2 *str) return ret; } - /******************************************************************* - duplicate a UNISTR2 string into a null terminated char* - using a talloc context + Duplicate a UNISTR2 string into a null terminated char* + using a talloc context. ********************************************************************/ + char *unistr2_tdup(TALLOC_CTX *ctx, const UNISTR2 *str) { char *s; int maxlen = (str->uni_str_len+1)*4; - if (!str->buffer) return NULL; + if (!str->buffer) { + return NULL; + } s = (char *)TALLOC(ctx, maxlen); /* convervative */ - if (!s) return NULL; - pull_ucs2(NULL, s, str->buffer, maxlen, str->uni_str_len*2, - STR_NOALIGN); + if (!s) { + return NULL; + } + pull_ucs2(NULL, s, str->buffer, maxlen, str->uni_str_len*2, STR_NOALIGN); return s; } - /******************************************************************* Convert a wchar to upper case. ********************************************************************/ @@ -323,29 +346,30 @@ smb_ucs2_t toupper_w(smb_ucs2_t val) smb_ucs2_t tolower_w( smb_ucs2_t val ) { return lowcase_table[SVAL(&val,0)]; - } /******************************************************************* -determine if a character is lowercase + Determine if a character is lowercase. ********************************************************************/ + BOOL islower_w(smb_ucs2_t c) { return upcase_table[SVAL(&c,0)] != c; } /******************************************************************* -determine if a character is uppercase + Determine if a character is uppercase. ********************************************************************/ + BOOL isupper_w(smb_ucs2_t c) { return lowcase_table[SVAL(&c,0)] != c; } - /******************************************************************* -determine if a character is valid in a 8.3 name + Determine if a character is valid in a 8.3 name. ********************************************************************/ + BOOL isvalid83_w(smb_ucs2_t c) { return valid_table[SVAL(&c,0)] != 0; @@ -354,11 +378,15 @@ BOOL isvalid83_w(smb_ucs2_t c) /******************************************************************* Count the number of characters in a smb_ucs2_t string. ********************************************************************/ + size_t strlen_w(const smb_ucs2_t *src) { size_t len; + smb_ucs2_t c; - for(len = 0; *src++; len++) ; + for(len = 0; *(COPY_UCS2_CHAR(&c,src)); src++, len++) { + ; + } return len; } @@ -366,11 +394,15 @@ size_t strlen_w(const smb_ucs2_t *src) /******************************************************************* Count up to max number of characters in a smb_ucs2_t string. ********************************************************************/ + size_t strnlen_w(const smb_ucs2_t *src, size_t max) { size_t len; + smb_ucs2_t c; - for(len = 0; *src++ && (len < max); len++) ; + for(len = 0; *(COPY_UCS2_CHAR(&c,src)) && (len < max); src++, len++) { + ; + } return len; } @@ -381,11 +413,16 @@ size_t strnlen_w(const smb_ucs2_t *src, size_t max) smb_ucs2_t *strchr_w(const smb_ucs2_t *s, smb_ucs2_t c) { - while (*s != 0) { - if (c == *s) return (smb_ucs2_t *)s; + smb_ucs2_t cp; + while (*(COPY_UCS2_CHAR(&cp,s))) { + if (c == cp) { + return (smb_ucs2_t *)s; + } s++; } - if (c == *s) return (smb_ucs2_t *)s; + if (c == cp) { + return (smb_ucs2_t *)s; + } return NULL; } @@ -401,12 +438,18 @@ smb_ucs2_t *strchr_wa(const smb_ucs2_t *s, char c) smb_ucs2_t *strrchr_w(const smb_ucs2_t *s, smb_ucs2_t c) { + smb_ucs2_t cp; const smb_ucs2_t *p = s; int len = strlen_w(s); - if (len == 0) return NULL; + + if (len == 0) { + return NULL; + } p += (len - 1); do { - if (c == *p) return (smb_ucs2_t *)p; + if (c == *(COPY_UCS2_CHAR(&cp,p))) { + return (smb_ucs2_t *)p; + } } while (p-- != s); return NULL; } @@ -417,17 +460,22 @@ smb_ucs2_t *strrchr_w(const smb_ucs2_t *s, smb_ucs2_t c) smb_ucs2_t *strnrchr_w(const smb_ucs2_t *s, smb_ucs2_t c, unsigned int n) { + smb_ucs2_t cp; const smb_ucs2_t *p = s; int len = strlen_w(s); - if (len == 0 || !n) + + if (len == 0 || !n) { return NULL; + } p += (len - 1); do { - if (c == *p) + if (c == *(COPY_UCS2_CHAR(&cp,p))) { n--; + } - if (!n) + if (!n) { return (smb_ucs2_t *)p; + } } while (p-- != s); return NULL; } @@ -441,15 +489,17 @@ smb_ucs2_t *strstr_w(const smb_ucs2_t *s, const smb_ucs2_t *ins) smb_ucs2_t *r; size_t inslen; - if (!s || !*s || !ins || !*ins) + if (!s || !*s || !ins || !*ins) { return NULL; + } inslen = strlen_w(ins); r = (smb_ucs2_t *)s; while ((r = strchr_w(r, *ins))) { - if (strncmp_w(r, ins, inslen) == 0) + if (strncmp_w(r, ins, inslen) == 0) { return r; + } r++; } @@ -460,13 +510,16 @@ smb_ucs2_t *strstr_w(const smb_ucs2_t *s, const smb_ucs2_t *ins) Convert a string to lower case. return True if any char is converted ********************************************************************/ + BOOL strlower_w(smb_ucs2_t *s) { + smb_ucs2_t cp; BOOL ret = False; - while (*s) { - smb_ucs2_t v = tolower_w(*s); - if (v != *s) { - *s = v; + + while (*(COPY_UCS2_CHAR(&cp,s))) { + smb_ucs2_t v = tolower_w(cp); + if (v != cp) { + COPY_UCS2_CHAR(s,&v); ret = True; } s++; @@ -478,13 +531,15 @@ BOOL strlower_w(smb_ucs2_t *s) Convert a string to upper case. return True if any char is converted ********************************************************************/ + BOOL strupper_w(smb_ucs2_t *s) { + smb_ucs2_t cp; BOOL ret = False; - while (*s) { - smb_ucs2_t v = toupper_w(*s); - if (v != *s) { - *s = v; + while (*(COPY_UCS2_CHAR(&cp,s))) { + smb_ucs2_t v = toupper_w(cp); + if (v != cp) { + COPY_UCS2_CHAR(s,&v); ret = True; } s++; @@ -493,88 +548,127 @@ BOOL strupper_w(smb_ucs2_t *s) } /******************************************************************* - convert a string to "normal" form + Convert a string to "normal" form. ********************************************************************/ void strnorm_w(smb_ucs2_t *s, int case_default) { - if (case_default == CASE_UPPER) + if (case_default == CASE_UPPER) { strupper_w(s); - else + } else { strlower_w(s); + } } int strcmp_w(const smb_ucs2_t *a, const smb_ucs2_t *b) { - while (*b && *a == *b) { a++; b++; } - return (*a - *b); - /* warning: if *a != *b and both are not 0 we retrun a random + smb_ucs2_t cpa, cpb; + + while ((*(COPY_UCS2_CHAR(&cpb,b))) && (*(COPY_UCS2_CHAR(&cpa,a)) == cpb)) { + a++; + b++; + } + return cpa - cpb; + /* warning: if *a != *b and both are not 0 we return a random greater or lesser than 0 number not realted to which string is longer */ } int strncmp_w(const smb_ucs2_t *a, const smb_ucs2_t *b, size_t len) { + smb_ucs2_t cpa, cpb; size_t n = 0; - while ((n < len) && *b && *a == *b) { a++; b++; n++;} - return (len - n)?(*a - *b):0; + + while ((n < len) && (*(COPY_UCS2_CHAR(&cpb,b))) && (*(COPY_UCS2_CHAR(&cpa,a)) == cpb)) { + a++; + b++; + n++; + } + return (len - n)?(cpa - cpb):0; } /******************************************************************* -case insensitive string comparison + Case insensitive string comparison. ********************************************************************/ + int strcasecmp_w(const smb_ucs2_t *a, const smb_ucs2_t *b) { - while (*b && toupper_w(*a) == toupper_w(*b)) { a++; b++; } - return (tolower_w(*a) - tolower_w(*b)); + smb_ucs2_t cpa, cpb; + + while ((*COPY_UCS2_CHAR(&cpb,b)) && toupper_w(*(COPY_UCS2_CHAR(&cpa,a))) == toupper_w(cpb)) { + a++; + b++; + } + return (tolower_w(cpa) - tolower_w(cpb)); } /******************************************************************* -case insensitive string comparison, lenght limited + Case insensitive string comparison, length limited. ********************************************************************/ + int strncasecmp_w(const smb_ucs2_t *a, const smb_ucs2_t *b, size_t len) { + smb_ucs2_t cpa, cpb; size_t n = 0; - while ((n < len) && *b && (toupper_w(*a) == toupper_w(*b))) { a++; b++; n++; } - return (len - n)?(tolower_w(*a) - tolower_w(*b)):0; + + while ((n < len) && *COPY_UCS2_CHAR(&cpb,b) && (toupper_w(*(COPY_UCS2_CHAR(&cpa,a))) == toupper_w(cpb))) { + a++; + b++; + n++; + } + return (len - n)?(tolower_w(cpa) - tolower_w(cpb)):0; } /******************************************************************* - compare 2 strings + Compare 2 strings. ********************************************************************/ + BOOL strequal_w(const smb_ucs2_t *s1, const smb_ucs2_t *s2) { - if (s1 == s2) return(True); - if (!s1 || !s2) return(False); + if (s1 == s2) { + return(True); + } + if (!s1 || !s2) { + return(False); + } return(strcasecmp_w(s1,s2)==0); } /******************************************************************* - compare 2 strings up to and including the nth char. - ******************************************************************/ + Compare 2 strings up to and including the nth char. +******************************************************************/ + BOOL strnequal_w(const smb_ucs2_t *s1,const smb_ucs2_t *s2,size_t n) { - if (s1 == s2) return(True); - if (!s1 || !s2 || !n) return(False); + if (s1 == s2) { + return(True); + } + if (!s1 || !s2 || !n) { + return(False); + } - return(strncasecmp_w(s1,s2,n)==0); + return(strncasecmp_w(s1,s2,n)==0); } /******************************************************************* -duplicate string + Duplicate string. ********************************************************************/ + smb_ucs2_t *strdup_w(const smb_ucs2_t *src) { return strndup_w(src, 0); } /* if len == 0 then duplicate the whole string */ + smb_ucs2_t *strndup_w(const smb_ucs2_t *src, size_t len) { smb_ucs2_t *dest; - if (!len) len = strlen_w(src); + if (!len) { + len = strlen_w(src); + } dest = SMB_MALLOC_ARRAY(smb_ucs2_t, len + 1); if (!dest) { DEBUG(0,("strdup_w: out of memory!\n")); @@ -583,46 +677,53 @@ smb_ucs2_t *strndup_w(const smb_ucs2_t *src, size_t len) memcpy(dest, src, len * sizeof(smb_ucs2_t)); dest[len] = 0; - return dest; } /******************************************************************* -copy a string with max len + Copy a string with max len. ********************************************************************/ smb_ucs2_t *strncpy_w(smb_ucs2_t *dest, const smb_ucs2_t *src, const size_t max) { + smb_ucs2_t cp; size_t len; - if (!dest || !src) return NULL; + if (!dest || !src) { + return NULL; + } - for (len = 0; (src[len] != 0) && (len < max); len++) - dest[len] = src[len]; - while (len < max) - dest[len++] = 0; + for (len = 0; (*COPY_UCS2_CHAR(&cp,(src+len))) && (len < max); len++) { + cp = *COPY_UCS2_CHAR(dest+len,src+len); + } + cp = 0; + for ( /*nothing*/ ; len < max; len++ ) { + cp = *COPY_UCS2_CHAR(dest+len,&cp); + } return dest; } - /******************************************************************* -append a string of len bytes and add a terminator + Append a string of len bytes and add a terminator. ********************************************************************/ smb_ucs2_t *strncat_w(smb_ucs2_t *dest, const smb_ucs2_t *src, const size_t max) { size_t start; size_t len; - - if (!dest || !src) return NULL; + smb_ucs2_t z = 0; + + if (!dest || !src) { + return NULL; + } start = strlen_w(dest); len = strnlen_w(src, max); memcpy(&dest[start], src, len*sizeof(smb_ucs2_t)); - dest[start+len] = 0; - + z = *COPY_UCS2_CHAR(dest+start+len,&z); + return dest; } @@ -630,32 +731,39 @@ smb_ucs2_t *strcat_w(smb_ucs2_t *dest, const smb_ucs2_t *src) { size_t start; size_t len; + smb_ucs2_t z = 0; - if (!dest || !src) return NULL; + if (!dest || !src) { + return NULL; + } start = strlen_w(dest); len = strlen_w(src); memcpy(&dest[start], src, len*sizeof(smb_ucs2_t)); - dest[start+len] = 0; + z = *COPY_UCS2_CHAR(dest+start+len,&z); return dest; } /******************************************************************* -replace any occurence of oldc with newc in unicode string + Replace any occurence of oldc with newc in unicode string. ********************************************************************/ void string_replace_w(smb_ucs2_t *s, smb_ucs2_t oldc, smb_ucs2_t newc) { - for(;*s;s++) { - if(*s==oldc) *s=newc; + smb_ucs2_t cp; + + for(;*(COPY_UCS2_CHAR(&cp,s));s++) { + if(cp==oldc) { + COPY_UCS2_CHAR(s,&newc); + } } } /******************************************************************* -trim unicode string + Trim unicode string. ********************************************************************/ BOOL trim_string_w(smb_ucs2_t *s, const smb_ucs2_t *front, @@ -664,7 +772,9 @@ BOOL trim_string_w(smb_ucs2_t *s, const smb_ucs2_t *front, BOOL ret = False; size_t len, front_len, back_len; - if (!s || !*s) return False; + if (!s) { + return False; + } len = strlen_w(s); @@ -699,24 +809,39 @@ BOOL trim_string_w(smb_ucs2_t *s, const smb_ucs2_t *front, int strcmp_wa(const smb_ucs2_t *a, const char *b) { - while (*b && *a == UCS2_CHAR(*b)) { a++; b++; } - return (*a - UCS2_CHAR(*b)); + smb_ucs2_t cp = 0; + + while (*b && *(COPY_UCS2_CHAR(&cp,a)) == UCS2_CHAR(*b)) { + a++; + b++; + } + return (cp - UCS2_CHAR(*b)); } int strncmp_wa(const smb_ucs2_t *a, const char *b, size_t len) { + smb_ucs2_t cp = 0; size_t n = 0; - while ((n < len) && *b && *a == UCS2_CHAR(*b)) { a++; b++; n++;} - return (len - n)?(*a - UCS2_CHAR(*b)):0; + + while ((n < len) && *b && *(COPY_UCS2_CHAR(&cp,a)) == UCS2_CHAR(*b)) { + a++; + b++; + n++; + } + return (len - n)?(cp - UCS2_CHAR(*b)):0; } smb_ucs2_t *strpbrk_wa(const smb_ucs2_t *s, const char *p) { - while (*s != 0) { + smb_ucs2_t cp; + + while (*(COPY_UCS2_CHAR(&cp,s))) { int i; - for (i=0; p[i] && *s != UCS2_CHAR(p[i]); i++) + for (i=0; p[i] && cp != UCS2_CHAR(p[i]); i++) ; - if (p[i]) return (smb_ucs2_t *)s; + if (p[i]) { + return (smb_ucs2_t *)s; + } s++; } return NULL; @@ -727,8 +852,9 @@ smb_ucs2_t *strstr_wa(const smb_ucs2_t *s, const char *ins) smb_ucs2_t *r; size_t inslen; - if (!s || !*s || !ins || !*ins) + if (!s || !ins) { return NULL; + } inslen = strlen(ins); r = (smb_ucs2_t *)s; @@ -747,37 +873,48 @@ BOOL trim_string_wa(smb_ucs2_t *s, const char *front, { wpstring f, b; - if (front) push_ucs2(NULL, f, front, sizeof(wpstring) - 1, STR_TERMINATE); - else *f = 0; - if (back) push_ucs2(NULL, b, back, sizeof(wpstring) - 1, STR_TERMINATE); - else *b = 0; + if (front) { + push_ucs2(NULL, f, front, sizeof(wpstring) - 1, STR_TERMINATE); + } else { + *f = 0; + } + if (back) { + push_ucs2(NULL, b, back, sizeof(wpstring) - 1, STR_TERMINATE); + } else { + *b = 0; + } return trim_string_w(s, f, b); } /******************************************************************* - returns the length in number of wide characters - ******************************************************************/ + Returns the length in number of wide characters. +******************************************************************/ + int unistrlen(uint16 *s) { int len; - if (!s) + if (!s) { return -1; + } - for (len=0; *s; s++,len++); + for (len=0; SVAL(s,0); s++,len++) { + ; + } return len; } /******************************************************************* - Strcpy for unicode strings. returns length (in num of wide chars) + Strcpy for unicode strings. Returns length (in num of wide chars). + Not odd align safe. ********************************************************************/ int unistrcpy(uint16 *dst, uint16 *src) { int num_wchars = 0; - while (*src) { + while (SVAL(src,0)) { *dst++ = *src++; num_wchars++; } @@ -798,12 +935,15 @@ int unistrcpy(uint16 *dst, uint16 *src) * * @return copied UNISTR2 destination **/ + UNISTR2* ucs2_to_unistr2(TALLOC_CTX *ctx, UNISTR2* dst, smb_ucs2_t* src) { size_t len; - if (!src) + if (!src) { return NULL; + } + len = strlen_w(src); /* allocate UNISTR2 destination if not given */ diff --git a/source/libads/ldap_printer.c b/source/libads/ldap_printer.c index 68e67358910..9773296ae08 100644 --- a/source/libads/ldap_printer.c +++ b/source/libads/ldap_printer.c @@ -55,7 +55,7 @@ ADS_STATUS ads_find_printer_on_server(ADS_STRUCT *ads, void **res, ADS_STATUS ads_find_printers(ADS_STRUCT *ads, void **res) { - char *ldap_expr; + const char *ldap_expr; const char *attrs[] = { "objectClass", "printerName", "location", "driverName", "serverName", "description", NULL }; @@ -267,7 +267,7 @@ WERROR get_remote_printer_publishing_data(struct cli_state *cli, char *printername, *servername; REGVAL_CTR dsdriver_ctr, dsspooler_ctr; BOOL got_dsdriver = False, got_dsspooler = False; - uint32 needed, i; + uint32 i; POLICY_HND pol; asprintf(&servername, "\\\\%s", cli->desthost); @@ -286,14 +286,7 @@ WERROR get_remote_printer_publishing_data(struct cli_state *cli, return result; } - result = cli_spoolss_enumprinterdataex(cli, mem_ctx, 0, &needed, - &pol, SPOOL_DSDRIVER_KEY, NULL); - - if (W_ERROR_V(result) == ERRmoredata) - result = cli_spoolss_enumprinterdataex(cli, mem_ctx, needed, - NULL, &pol, - SPOOL_DSDRIVER_KEY, - &dsdriver_ctr); + result = cli_spoolss_enumprinterdataex(cli, mem_ctx, &pol, SPOOL_DSDRIVER_KEY, NULL); if (!W_ERROR_IS_OK(result)) { DEBUG(3, ("Unable to do enumdataex on %s, error is %s.\n", @@ -307,15 +300,7 @@ WERROR get_remote_printer_publishing_data(struct cli_state *cli, dsdriver_ctr.values[i]); } - result = cli_spoolss_enumprinterdataex(cli, mem_ctx, 0, &needed, - &pol, SPOOL_DSSPOOLER_KEY, - NULL); - - if (W_ERROR_V(result) == ERRmoredata) - result = cli_spoolss_enumprinterdataex(cli, mem_ctx, needed, - NULL, &pol, - SPOOL_DSSPOOLER_KEY, - &dsspooler_ctr); + result = cli_spoolss_enumprinterdataex(cli, mem_ctx, &pol, SPOOL_DSSPOOLER_KEY, NULL); if (!W_ERROR_IS_OK(result)) { DEBUG(3, ("Unable to do enumdataex on %s, error is %s.\n", diff --git a/source/libsmb/cliconnect.c b/source/libsmb/cliconnect.c index 5a9992d4e03..3d8e36c493a 100644 --- a/source/libsmb/cliconnect.c +++ b/source/libsmb/cliconnect.c @@ -19,8 +19,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define NO_SYSLOG - #include "includes.h" extern pstring user_socket_options; diff --git a/source/libsmb/clidfs.c b/source/libsmb/clidfs.c index 7ce4871b4d7..51f21397f7c 100644 --- a/source/libsmb/clidfs.c +++ b/source/libsmb/clidfs.c @@ -19,8 +19,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define NO_SYSLOG - #include "includes.h" diff --git a/source/libsmb/clientgen.c b/source/libsmb/clientgen.c index 2e214735119..f1794ab5dc8 100644 --- a/source/libsmb/clientgen.c +++ b/source/libsmb/clientgen.c @@ -18,8 +18,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define NO_SYSLOG - #include "includes.h" /**************************************************************************** diff --git a/source/libsmb/clierror.c b/source/libsmb/clierror.c index a16c1f52419..355a2adf34d 100644 --- a/source/libsmb/clierror.c +++ b/source/libsmb/clierror.c @@ -19,8 +19,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define NO_SYSLOG - #include "includes.h" /***************************************************** diff --git a/source/libsmb/clifile.c b/source/libsmb/clifile.c index 87c6f2568b1..a7e6fbfe3f1 100644 --- a/source/libsmb/clifile.c +++ b/source/libsmb/clifile.c @@ -19,8 +19,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define NO_SYSLOG - #include "includes.h" /**************************************************************************** diff --git a/source/libsmb/clilist.c b/source/libsmb/clilist.c index d9a6f4709d5..a0be40bdc9f 100644 --- a/source/libsmb/clilist.c +++ b/source/libsmb/clilist.c @@ -18,8 +18,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define NO_SYSLOG - #include "includes.h" extern file_info def_finfo; diff --git a/source/libsmb/climessage.c b/source/libsmb/climessage.c index 8429ca4f413..f646096a4e5 100644 --- a/source/libsmb/climessage.c +++ b/source/libsmb/climessage.c @@ -18,8 +18,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define NO_SYSLOG - #include "includes.h" diff --git a/source/libsmb/clioplock.c b/source/libsmb/clioplock.c index 0ffeb1926b0..037d7147dbb 100644 --- a/source/libsmb/clioplock.c +++ b/source/libsmb/clioplock.c @@ -18,8 +18,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define NO_SYSLOG - #include "includes.h" /**************************************************************************** diff --git a/source/libsmb/cliprint.c b/source/libsmb/cliprint.c index 732241a758f..4a5ee5ae08c 100644 --- a/source/libsmb/cliprint.c +++ b/source/libsmb/cliprint.c @@ -18,8 +18,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define NO_SYSLOG - #include "includes.h" /***************************************************************************** diff --git a/source/libsmb/clirap.c b/source/libsmb/clirap.c index 4766811c8e8..b53e19ef988 100644 --- a/source/libsmb/clirap.c +++ b/source/libsmb/clirap.c @@ -19,8 +19,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define NO_SYSLOG - #include "includes.h" diff --git a/source/libsmb/clirap2.c b/source/libsmb/clirap2.c index b15ee1a63e2..a327bae3174 100644 --- a/source/libsmb/clirap2.c +++ b/source/libsmb/clirap2.c @@ -76,8 +76,6 @@ /* */ /*****************************************************/ -#define NO_SYSLOG - #include "includes.h" #define WORDSIZE 2 diff --git a/source/libsmb/clireadwrite.c b/source/libsmb/clireadwrite.c index 9e52ed35949..1220907629c 100644 --- a/source/libsmb/clireadwrite.c +++ b/source/libsmb/clireadwrite.c @@ -18,8 +18,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define NO_SYSLOG - #include "includes.h" /**************************************************************************** diff --git a/source/libsmb/clitrans.c b/source/libsmb/clitrans.c index 75afe5195ed..c6b1d465ffe 100644 --- a/source/libsmb/clitrans.c +++ b/source/libsmb/clitrans.c @@ -18,8 +18,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define NO_SYSLOG - #include "includes.h" diff --git a/source/libsmb/ntlmssp.c b/source/libsmb/ntlmssp.c index 574b37d4a04..b02c2384a8d 100644 --- a/source/libsmb/ntlmssp.c +++ b/source/libsmb/ntlmssp.c @@ -182,7 +182,7 @@ NTSTATUS ntlmssp_set_domain(NTLMSSP_STATE *ntlmssp_state, const char *domain) NTSTATUS ntlmssp_set_workstation(NTLMSSP_STATE *ntlmssp_state, const char *workstation) { ntlmssp_state->workstation = talloc_strdup(ntlmssp_state->mem_ctx, workstation); - if (!ntlmssp_state->domain) { + if (!ntlmssp_state->workstation) { return NT_STATUS_NO_MEMORY; } return NT_STATUS_OK; diff --git a/source/libsmb/smberr.c b/source/libsmb/smberr.c index b014fb947e3..a21063e52ac 100644 --- a/source/libsmb/smberr.c +++ b/source/libsmb/smberr.c @@ -17,8 +17,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define NO_SYSLOG - #include "includes.h" /* error code stuff - put together by Merik Karman diff --git a/source/nsswitch/winbindd_cm.c b/source/nsswitch/winbindd_cm.c index 6400b23f9ff..8a97b7ae17a 100644 --- a/source/nsswitch/winbindd_cm.c +++ b/source/nsswitch/winbindd_cm.c @@ -64,8 +64,17 @@ #undef DBGC_CLASS #define DBGC_CLASS DBGC_WINBIND -/* Global list of connections. Initially a DLIST but can become a hash - table or whatever later. */ + +/****************************************************************** + Disabling schannl on the LSA pipe for now since + both Win2K-SP4 SR1 & Win2K3-SP1 fail the open_policy() + call (return codes 0xc0020042 and 0xc0020041 respectively). + We really need to fix this soon. Had to disable on the + SAMR pipe as well for now. --jerry +******************************************************************/ + +#define DISABLE_SCHANNEL_WIN2K3_SP1 1 + /* Choose between anonymous or authenticated connections. We need to use an authenticated connection if DCs have the RestrictAnonymous registry @@ -984,6 +993,7 @@ NTSTATUS cm_connect_sam(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx, conn = &domain->conn; if (conn->samr_pipe == NULL) { +#ifndef DISABLE_SCHANNEL_WIN2K3_SP1 unsigned char *session_key; if (cm_get_schannel_key(domain, mem_ctx, &session_key)) @@ -992,6 +1002,7 @@ NTSTATUS cm_connect_sam(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx, session_key, domain->name); else +#endif /* DISABLE_SCHANNEL_WIN2K3_SP1 */ conn->samr_pipe = cli_rpc_open_noauth(conn->cli, PI_SAMR); @@ -1038,6 +1049,7 @@ NTSTATUS cm_connect_lsa(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx, conn = &domain->conn; if (conn->lsa_pipe == NULL) { +#ifndef DISABLE_SCHANNEL_WIN2K3_SP1 unsigned char *session_key; if (cm_get_schannel_key(domain, mem_ctx, &session_key)) @@ -1046,6 +1058,7 @@ NTSTATUS cm_connect_lsa(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx, session_key, domain->name); else +#endif /* DISABLE_SCHANNEL_WIN2K3_SP1 */ conn->lsa_pipe = cli_rpc_open_noauth(conn->cli, PI_LSARPC); diff --git a/source/nsswitch/wins.c b/source/nsswitch/wins.c index 6d4f6cfa264..ac5b0f11572 100644 --- a/source/nsswitch/wins.c +++ b/source/nsswitch/wins.c @@ -19,8 +19,6 @@ */ -#define NO_SYSLOG - #include "includes.h" #ifdef HAVE_NS_API_H #undef VOLATILE diff --git a/source/param/loadparm.c b/source/param/loadparm.c index a1dcf284910..00f191db280 100644 --- a/source/param/loadparm.c +++ b/source/param/loadparm.c @@ -159,6 +159,7 @@ typedef struct char *szAddMachineScript; char *szShutdownScript; char *szAbortShutdownScript; + char *szUsernameMapScript; char *szCheckPasswordScript; char *szWINSHook; char *szWINSPartners; @@ -221,7 +222,6 @@ typedef struct int machine_password_timeout; int change_notify_timeout; int map_to_guest; - int min_passwd_length; int oplock_break_wait_time; int winbind_cache_time; int winbind_max_idle_children; @@ -438,6 +438,7 @@ typedef struct BOOL bEASupport; BOOL bAclCheckPermissions; BOOL bAclMapFullControl; + BOOL bAclGroupControl; int iallocation_roundup_size; int iAioReadSize; int iAioWriteSize; @@ -570,6 +571,7 @@ static service sDefault = { False, /* bEASupport */ True, /* bAclCheckPermissions */ True, /* bAclMapFullControl */ + False, /* bAclGroupControl */ SMB_ROUNDUP_ALLOCATION_SIZE, /* iallocation_roundup_size */ 0, /* iAioReadSize */ 0, /* iAioWriteSize */ @@ -823,8 +825,6 @@ static struct parm_struct parm_table[] = { {"server schannel", P_ENUM, P_GLOBAL, &Globals.serverSchannel, NULL, enum_bool_auto, FLAG_BASIC | FLAG_ADVANCED}, {"allow trusted domains", P_BOOL, P_GLOBAL, &Globals.bAllowTrustedDomains, NULL, NULL, FLAG_ADVANCED}, {"hosts equiv", P_STRING, P_GLOBAL, &Globals.szHostsEquiv, NULL, NULL, FLAG_ADVANCED}, - {"min password length", P_INTEGER, P_GLOBAL, &Globals.min_passwd_length, NULL, NULL, FLAG_DEPRECATED}, - {"min passwd length", P_INTEGER, P_GLOBAL, &Globals.min_passwd_length, NULL, NULL, FLAG_DEPRECATED}, {"map to guest", P_ENUM, P_GLOBAL, &Globals.map_to_guest, NULL, enum_map_to_guest, FLAG_ADVANCED}, {"null passwords", P_BOOL, P_GLOBAL, &Globals.bNullPasswords, NULL, NULL, FLAG_ADVANCED}, {"obey pam restrictions", P_BOOL, P_GLOBAL, &Globals.bObeyPamRestrictions, NULL, NULL, FLAG_ADVANCED}, @@ -876,6 +876,7 @@ static struct parm_struct parm_table[] = { {"writable", P_BOOLREV, P_LOCAL, &sDefault.bRead_only, NULL, NULL, FLAG_HIDE}, {"acl check permissions", P_BOOL, P_LOCAL, &sDefault.bAclCheckPermissions, NULL, NULL, FLAG_ADVANCED | FLAG_GLOBAL | FLAG_SHARE}, + {"acl group control", P_BOOL, P_LOCAL, &sDefault.bAclGroupControl, NULL, NULL, FLAG_ADVANCED | FLAG_GLOBAL | FLAG_SHARE}, {"acl map full control", P_BOOL, P_LOCAL, &sDefault.bAclMapFullControl, NULL, NULL, FLAG_ADVANCED | FLAG_GLOBAL | FLAG_SHARE}, {"create mask", P_OCTAL, P_LOCAL, &sDefault.iCreate_mask, NULL, NULL, FLAG_ADVANCED | FLAG_GLOBAL | FLAG_SHARE}, {"create mode", P_OCTAL, P_LOCAL, &sDefault.iCreate_mask, NULL, NULL, FLAG_HIDE}, @@ -1071,6 +1072,7 @@ static struct parm_struct parm_table[] = { {"add machine script", P_STRING, P_GLOBAL, &Globals.szAddMachineScript, NULL, NULL, FLAG_ADVANCED}, {"shutdown script", P_STRING, P_GLOBAL, &Globals.szShutdownScript, NULL, NULL, FLAG_ADVANCED}, {"abort shutdown script", P_STRING, P_GLOBAL, &Globals.szAbortShutdownScript, NULL, NULL, FLAG_ADVANCED}, + {"username map script", P_STRING, P_GLOBAL, &Globals.szUsernameMapScript, NULL, NULL, FLAG_ADVANCED}, {"logon script", P_STRING, P_GLOBAL, &Globals.szLogonScript, NULL, NULL, FLAG_ADVANCED}, {"logon path", P_STRING, P_GLOBAL, &Globals.szLogonPath, NULL, NULL, FLAG_ADVANCED}, @@ -1491,7 +1493,6 @@ static void init_globals(void) /* Note, that we will use NTLM2 session security (which is different), if it is available */ Globals.map_to_guest = 0; /* By Default, "Never" */ - Globals.min_passwd_length = MINPASSWDLENGTH; /* By Default, 5. */ Globals.oplock_break_wait_time = 0; /* By Default, 0 msecs. */ Globals.enhanced_browsing = True; Globals.iLockSpinCount = 3; /* Try 3 times. */ @@ -1756,6 +1757,7 @@ FN_GLOBAL_STRING(lp_addmachine_script, &Globals.szAddMachineScript) FN_GLOBAL_STRING(lp_shutdown_script, &Globals.szShutdownScript) FN_GLOBAL_STRING(lp_abort_shutdown_script, &Globals.szAbortShutdownScript) +FN_GLOBAL_STRING(lp_username_map_script, &Globals.szUsernameMapScript) FN_GLOBAL_STRING(lp_check_password_script, &Globals.szCheckPasswordScript) @@ -1882,7 +1884,6 @@ FN_GLOBAL_INTEGER(lp_lm_interval, &Globals.lm_interval) FN_GLOBAL_INTEGER(lp_machine_password_timeout, &Globals.machine_password_timeout) FN_GLOBAL_INTEGER(lp_change_notify_timeout, &Globals.change_notify_timeout) FN_GLOBAL_INTEGER(lp_map_to_guest, &Globals.map_to_guest) -FN_GLOBAL_INTEGER(lp_min_passwd_length, &Globals.min_passwd_length) FN_GLOBAL_INTEGER(lp_oplock_break_wait_time, &Globals.oplock_break_wait_time) FN_GLOBAL_INTEGER(lp_lock_spin_count, &Globals.iLockSpinCount) FN_GLOBAL_INTEGER(lp_lock_sleep_time, &Globals.iLockSpinTime) @@ -1984,6 +1985,7 @@ FN_LOCAL_BOOL(lp_profile_acls, bProfileAcls) FN_LOCAL_BOOL(lp_map_acl_inherit, bMap_acl_inherit) FN_LOCAL_BOOL(lp_afs_share, bAfs_Share) FN_LOCAL_BOOL(lp_acl_check_permissions, bAclCheckPermissions) +FN_LOCAL_BOOL(lp_acl_group_control, bAclGroupControl) FN_LOCAL_BOOL(lp_acl_map_full_control, bAclMapFullControl) FN_LOCAL_INTEGER(lp_create_mask, iCreate_mask) FN_LOCAL_INTEGER(lp_force_create_mode, iCreate_force_mode) diff --git a/source/passdb/pdb_ldap.c b/source/passdb/pdb_ldap.c index 002ec70464b..ee7a1f5b4cb 100644 --- a/source/passdb/pdb_ldap.c +++ b/source/passdb/pdb_ldap.c @@ -3370,6 +3370,7 @@ struct ldap_search_state { struct smbldap_state *connection; uint16 acct_flags; + uint16 group_type; const char *base; int scope; @@ -3609,7 +3610,7 @@ static BOOL ldapuser2displayentry(struct ldap_search_state *state, ldap_value_free(vals); if (!sid_peek_check_rid(get_global_sam_sid(), &sid, &result->rid)) { - DEBUG(0, ("%s is not our domain\n", vals[0])); + DEBUG(0, ("sid %s does not belong to our domain\n", sid_string_static(&sid))); return False; } @@ -3635,7 +3636,7 @@ static BOOL ldapsam_search_users(struct pdb_methods *methods, if ((acct_flags != 0) && ((acct_flags & ACB_NORMAL) != 0)) state->base = lp_ldap_user_suffix(); else if ((acct_flags != 0) && - ((acct_flags & (ACB_WSTRUST|ACB_SVRTRUST)) != 0)) + ((acct_flags & (ACB_WSTRUST|ACB_SVRTRUST|ACB_DOMTRUST)) != 0)) state->base = lp_ldap_machine_suffix(); else state->base = lp_ldap_suffix(); @@ -3671,11 +3672,26 @@ static BOOL ldapgroup2displayentry(struct ldap_search_state *state, { char **vals; DOM_SID sid; + uint16 group_type; result->account_name = ""; result->fullname = ""; result->description = ""; + + vals = ldap_get_values(ld, entry, "sambaGroupType"); + if ((vals == NULL) || (vals[0] == NULL)) { + DEBUG(5, ("\"sambaGroupType\" not found\n")); + return False; + } + + group_type = atoi(vals[0]); + + if ((state->group_type != 0) && + ((state->group_type != group_type))) { + return False; + } + vals = ldap_get_values(ld, entry, "cn"); if ((vals == NULL) || (vals[0] == NULL)) { DEBUG(5, ("\"cn\" not found\n")); @@ -3722,12 +3738,32 @@ static BOOL ldapgroup2displayentry(struct ldap_search_state *state, return False; } - if (!sid_peek_check_rid(get_global_sam_sid(), &sid, &result->rid)) { - DEBUG(0, ("%s is not our domain\n", vals[0])); - return False; - } ldap_value_free(vals); + switch (group_type) { + case SID_NAME_DOM_GRP: + case SID_NAME_ALIAS: + + if (!sid_peek_check_rid(get_global_sam_sid(), &sid, &result->rid)) { + DEBUG(0, ("%s is not in our domain\n", sid_string_static(&sid))); + return False; + } + break; + + case SID_NAME_WKN_GRP: + + if (!sid_peek_check_rid(&global_sid_Builtin, &sid, &result->rid)) { + + DEBUG(0, ("%s is not in builtin sid\n", sid_string_static(&sid))); + return False; + } + break; + + default: + DEBUG(0,("unkown group type: %d\n", group_type)); + return False; + } + return True; } @@ -3753,10 +3789,11 @@ static BOOL ldapsam_search_grouptype(struct pdb_methods *methods, "(&(objectclass=sambaGroupMapping)" "(sambaGroupType=%d))", type); state->attrs = talloc_attrs(search->mem_ctx, "cn", "sambaSid", - "displayName", "description", NULL); + "displayName", "description", "sambaGroupType", NULL); state->attrsonly = 0; state->pagedresults_cookie = NULL; state->entries = NULL; + state->group_type = type; state->ldap2displayentry = ldapgroup2displayentry; if ((state->filter == NULL) || (state->attrs == NULL)) { diff --git a/source/printing/nt_printing.c b/source/printing/nt_printing.c index 25083002c31..a7ba46cd511 100644 --- a/source/printing/nt_printing.c +++ b/source/printing/nt_printing.c @@ -3,7 +3,7 @@ * RPC Pipe client / server routines * Copyright (C) Andrew Tridgell 1992-2000, * Copyright (C) Jean François Micouleau 1998-2000. - * Copyright (C) Gerald Carter 2002-2003. + * Copyright (C) Gerald Carter 2002-2005. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -39,8 +39,7 @@ static TDB_CONTEXT *tdb_printers; /* used for printers files */ #define NTDRIVERS_DATABASE_VERSION_2 2 #define NTDRIVERS_DATABASE_VERSION_3 3 /* little endian version of v2 */ #define NTDRIVERS_DATABASE_VERSION_4 4 /* fix generic bits in security descriptors */ - -#define NTDRIVERS_DATABASE_VERSION NTDRIVERS_DATABASE_VERSION_4 +#define NTDRIVERS_DATABASE_VERSION_5 5 /* normalize keys in ntprinters.tdb */ /* Map generic permissions to printer object specific permissions */ @@ -225,6 +224,48 @@ static const struct table_node archi_table[]= { {NULL, "", -1 } }; + +/**************************************************************************** + generate a new TDB_DATA key for storing a printer +****************************************************************************/ + +static TDB_DATA make_printer_tdbkey( const char *sharename ) +{ + fstring share; + static pstring keystr; + TDB_DATA key; + + fstrcpy( share, sharename ); + strlower_m( share ); + + pstr_sprintf( keystr, "%s%s", PRINTERS_PREFIX, share ); + + key.dptr = keystr; + key.dsize = strlen(keystr)+1; + + return key; +} + +/**************************************************************************** + generate a new TDB_DATA key for storing a printer security descriptor +****************************************************************************/ + +static char* make_printers_secdesc_tdbkey( const char* sharename ) +{ + fstring share; + static pstring keystr; + + fstrcpy( share, sharename ); + strlower_m( share ); + + pstr_sprintf( keystr, "%s%s", SECDESC_PREFIX, share ); + + return keystr; +} + +/**************************************************************************** +****************************************************************************/ + static BOOL upgrade_to_version_3(void) { TDB_DATA kbuf, newkey, dbuf; @@ -406,6 +447,73 @@ static BOOL upgrade_to_version_4(void) return ( result != -1 ); } +/******************************************************************* + Fix an issue with security descriptors. Printer sec_desc must + use more than the generic bits that were previously used + in <= 3.0.14a. They must also have a owner and group SID assigned. + Otherwise, any printers than have been migrated to a Windows + host using printmig.exe will not be accessible. +*******************************************************************/ + +static int normalize_printers_fn( TDB_CONTEXT *the_tdb, TDB_DATA key, + TDB_DATA data, void *state ) +{ + TDB_DATA new_key; + + if (!data.dptr || data.dsize == 0) + return 0; + + /* upgrade printer records and security descriptors */ + + if ( strncmp( key.dptr, PRINTERS_PREFIX, strlen(PRINTERS_PREFIX) ) == 0 ) { + new_key = make_printer_tdbkey( key.dptr+strlen(PRINTERS_PREFIX) ); + } + else if ( strncmp( key.dptr, SECDESC_PREFIX, strlen(SECDESC_PREFIX) ) == 0 ) { + new_key.dptr = make_printers_secdesc_tdbkey( key.dptr+strlen(SECDESC_PREFIX) ); + new_key.dsize = strlen( new_key.dptr ) + 1; + } + else { + /* ignore this record */ + return 0; + } + + /* delete the original record and store under the normalized key */ + + if ( tdb_delete( the_tdb, key ) != 0 ) { + DEBUG(0,("normalize_printers_fn: tdb_delete for [%s] failed!\n", + key.dptr)); + return 1; + } + + if ( tdb_store( the_tdb, new_key, data, TDB_REPLACE) != 0 ) { + DEBUG(0,("normalize_printers_fn: failed to store new record for [%s]!\n", + key.dptr)); + return 1; + } + + return 0; +} + +/******************************************************************* +*******************************************************************/ + +static BOOL upgrade_to_version_5(void) +{ + TALLOC_CTX *ctx; + int result; + + DEBUG(0,("upgrade_to_version_5: normalizing printer keys\n")); + + if ( !(ctx = talloc_init( "upgrade_to_version_5" )) ) + return False; + + result = tdb_traverse( tdb_printers, normalize_printers_fn, NULL ); + + talloc_destroy( ctx ); + + return ( result != -1 ); +} + /**************************************************************************** Open the NT printing tdbs. Done once before fork(). ****************************************************************************/ @@ -414,7 +522,7 @@ BOOL nt_printing_init(void) { const char *vstring = "INFO/version"; WERROR win_rc; - uint32 vers_id; + int32 vers_id; if ( tdb_drivers && tdb_printers && tdb_forms ) return True; @@ -447,15 +555,23 @@ BOOL nt_printing_init(void) } /* handle a Samba upgrade */ - tdb_lock_bystring(tdb_drivers, vstring, 0); - - /* ---------------- Start Lock Region ---------------- */ - - /* Cope with byte-reversed older versions of the db. */ + vers_id = tdb_fetch_int32(tdb_drivers, vstring); + if (vers_id == -1) { + DEBUG(10, ("Fresh database\n")); + tdb_store_int32( tdb_drivers, vstring, NTDRIVERS_DATABASE_VERSION_5 ); + vers_id = NTDRIVERS_DATABASE_VERSION_5; + } - if ( vers_id != NTDRIVERS_DATABASE_VERSION ) { + if ( vers_id != NTDRIVERS_DATABASE_VERSION_5 ) { + if ((vers_id == NTDRIVERS_DATABASE_VERSION_1) || (IREV(vers_id) == NTDRIVERS_DATABASE_VERSION_1)) { + if (!upgrade_to_version_3()) + return False; + tdb_store_int32(tdb_drivers, vstring, NTDRIVERS_DATABASE_VERSION_3); + vers_id = NTDRIVERS_DATABASE_VERSION_3; + } + if ((vers_id == NTDRIVERS_DATABASE_VERSION_2) || (IREV(vers_id) == NTDRIVERS_DATABASE_VERSION_2)) { /* Written on a bigendian machine with old fetch_int code. Save as le. */ /* The only upgrade between V2 and V3 is to save the version in little-endian. */ @@ -463,28 +579,27 @@ BOOL nt_printing_init(void) vers_id = NTDRIVERS_DATABASE_VERSION_3; } - if (vers_id != NTDRIVERS_DATABASE_VERSION_3 ) { - - if ((vers_id == NTDRIVERS_DATABASE_VERSION_1) || (IREV(vers_id) == NTDRIVERS_DATABASE_VERSION_1)) { - if (!upgrade_to_version_3()) - return False; - } else - tdb_traverse(tdb_drivers, tdb_traverse_delete_fn, NULL); - - tdb_store_int32(tdb_drivers, vstring, NTDRIVERS_DATABASE_VERSION_3); + if (vers_id == NTDRIVERS_DATABASE_VERSION_3 ) { + if ( !upgrade_to_version_4() ) + return False; + tdb_store_int32(tdb_drivers, vstring, NTDRIVERS_DATABASE_VERSION_4); + vers_id = NTDRIVERS_DATABASE_VERSION_4; } - /* at this point we know that the database is at version 3 so upgrade to v4 */ + if (vers_id == NTDRIVERS_DATABASE_VERSION_4 ) { + if ( !upgrade_to_version_5() ) + return False; + tdb_store_int32(tdb_drivers, vstring, NTDRIVERS_DATABASE_VERSION_5); + vers_id = NTDRIVERS_DATABASE_VERSION_5; + } - if ( !upgrade_to_version_4() ) + + if ( vers_id != NTDRIVERS_DATABASE_VERSION_5 ) { + DEBUG(0,("nt_printing_init: Unknown printer database version [%d]\n", vers_id)); return False; - tdb_store_int32(tdb_drivers, vstring, NTDRIVERS_DATABASE_VERSION); + } } - - /* ---------------- End Lock Region ------------------ */ - - tdb_unlock_bystring(tdb_drivers, vstring); - + update_c_setprinter(True); /* @@ -501,12 +616,14 @@ BOOL nt_printing_init(void) message_register( MSG_PRINTERDATA_INIT_RESET, reset_all_printerdata ); +#ifdef ENABLE_PRINT_HND_OBJECT_CACHE /* * register callback to handle invalidating the printer cache * between smbd processes. */ message_register( MSG_PRINTER_MOD, receive_printer_mod_msg); +#endif /* of course, none of the message callbacks matter if you don't tell messages.c that you interested in receiving PRINT_GENERAL @@ -2220,8 +2337,6 @@ uint32 del_a_printer(const char *sharename) ****************************************************************************/ static WERROR update_a_printer_2(NT_PRINTER_INFO_LEVEL_2 *info) { - pstring key; - fstring norm_sharename; char *buf; int buflen, len; WERROR ret; @@ -2303,15 +2418,8 @@ static WERROR update_a_printer_2(NT_PRINTER_INFO_LEVEL_2 *info) } - /* normalize the key */ - - fstrcpy( norm_sharename, info->sharename ); - strlower_m( norm_sharename ); + kbuf = make_printer_tdbkey( info->sharename ); - slprintf(key, sizeof(key)-1, "%s%s", PRINTERS_PREFIX, info->sharename); - - kbuf.dptr = key; - kbuf.dsize = strlen(key)+1; dbuf.dptr = buf; dbuf.dsize = len; @@ -3595,29 +3703,20 @@ static WERROR get_a_printer_2_default(NT_PRINTER_INFO_LEVEL_2 **info_ptr, const ****************************************************************************/ static WERROR get_a_printer_2(NT_PRINTER_INFO_LEVEL_2 **info_ptr, const char *servername, const char *sharename) { - pstring key; NT_PRINTER_INFO_LEVEL_2 info; int len = 0; int snum = lp_servicenumber(sharename); TDB_DATA kbuf, dbuf; fstring printername; char adevice[MAXDEVICENAME]; - fstring norm_sharename; ZERO_STRUCT(info); - /* normalize case */ - fstrcpy( norm_sharename, sharename ); - strlower_m( norm_sharename ); - - slprintf(key, sizeof(key)-1, "%s%s", PRINTERS_PREFIX, norm_sharename); - - kbuf.dptr = key; - kbuf.dsize = strlen(key)+1; + kbuf = make_printer_tdbkey( sharename ); dbuf = tdb_fetch(tdb_printers, kbuf); if (!dbuf.dptr) - return get_a_printer_2_default(info_ptr, servername, norm_sharename); + return get_a_printer_2_default(info_ptr, servername, sharename); len += tdb_unpack(dbuf.dptr+len, dbuf.dsize-len, "dddddddddddfffffPfffff", &info.attributes, @@ -3651,7 +3750,7 @@ static WERROR get_a_printer_2(NT_PRINTER_INFO_LEVEL_2 **info_ptr, const char *se slprintf(info.servername, sizeof(info.servername)-1, "\\\\%s", servername); if ( lp_force_printername(snum) ) - slprintf(printername, sizeof(printername)-1, "\\\\%s\\%s", servername, norm_sharename ); + slprintf(printername, sizeof(printername)-1, "\\\\%s\\%s", servername, sharename ); else slprintf(printername, sizeof(printername)-1, "\\\\%s\\%s", servername, info.printername); @@ -3781,6 +3880,7 @@ static uint32 rev_changeid(void) #endif } +#ifdef ENABLE_PRINT_HND_OBJECT_CACHE /******************************************************************** Send a message to all smbds about the printer that just changed ********************************************************************/ @@ -3801,6 +3901,8 @@ static BOOL send_printer_mod_msg( char* printername ) return True; } +#endif + /* * The function below are the high level ones. @@ -3818,6 +3920,7 @@ WERROR mod_a_printer(NT_PRINTER_INFO_LEVEL *printer, uint32 level) dump_a_printer(printer, level); +#ifdef ENABLE_PRINT_HND_OBJECT_CACHE /* * invalidate cache for all open handles to this printer. * cache for a given handle will be updated on the next @@ -3825,7 +3928,12 @@ WERROR mod_a_printer(NT_PRINTER_INFO_LEVEL *printer, uint32 level) */ invalidate_printer_hnd_cache( printer->info_2->sharename ); + + /* messages between smbds can only be sent as root */ + become_root(); send_printer_mod_msg( printer->info_2->sharename ); + unbecome_root(); +#endif switch (level) { case 2: @@ -4228,6 +4336,7 @@ WERROR save_driver_init(NT_PRINTER_INFO_LEVEL *printer, uint32 level, uint8 *dat return status; } +#ifdef ENABLE_PRINT_HND_OBJECT_CACHE /**************************************************************************** Deep copy a NT_PRINTER_DATA ****************************************************************************/ @@ -4293,6 +4402,7 @@ NT_PRINTER_INFO_LEVEL_2* dup_printer_2( TALLOC_CTX *ctx, NT_PRINTER_INFO_LEVEL_2 return copy; } +#endif /**************************************************************************** Get a NT_PRINTER_INFO_LEVEL struct. It returns malloced memory. @@ -4333,6 +4443,8 @@ WERROR get_a_printer( Printer_entry *print_hnd, NT_PRINTER_INFO_LEVEL **pp_print fstrcpy( servername, "%L" ); standard_sub_basic( "", servername, sizeof(servername)-1 ); } + +#ifdef ENABLE_PRINT_HND_OBJECT_CACHE /* * check for cache first. A Printer handle cannot changed @@ -4373,12 +4485,17 @@ WERROR get_a_printer( Printer_entry *print_hnd, NT_PRINTER_INFO_LEVEL **pp_print if ( !print_hnd || !W_ERROR_IS_OK(result) ) result = get_a_printer_2(&printer->info_2, servername, sharename ); +#else + result = get_a_printer_2(&printer->info_2, servername, sharename ); +#endif + /* we have a new printer now. Save it with this handle */ if ( W_ERROR_IS_OK(result) ) { dump_a_printer(printer, level); - + +#ifdef ENABLE_PRINT_HND_OBJECT_CACHE /* save a copy in cache */ if ( print_hnd && (print_hnd->printer_type==PRINTER_HANDLE_IS_PRINTER)) { if ( !print_hnd->printer_info ) @@ -4395,6 +4512,7 @@ WERROR get_a_printer( Printer_entry *print_hnd, NT_PRINTER_INFO_LEVEL **pp_print DEBUG(0,("get_a_printer: unable to copy new printer info!\n")); } } +#endif *pp_printer = printer; } else @@ -4990,12 +5108,8 @@ WERROR nt_printing_setsec(const char *sharename, SEC_DESC_BUF *secdesc_ctr) SEC_DESC_BUF *old_secdesc_ctr = NULL; prs_struct ps; TALLOC_CTX *mem_ctx = NULL; - fstring key; + char *key; WERROR status; - fstring norm_sharename; - - fstrcpy( norm_sharename, sharename ); - strlower_m( norm_sharename ); mem_ctx = talloc_init("nt_printing_setsec"); if (mem_ctx == NULL) @@ -5012,7 +5126,7 @@ WERROR nt_printing_setsec(const char *sharename, SEC_DESC_BUF *secdesc_ctr) SEC_DESC *psd = NULL; size_t size; - nt_printing_getsec(mem_ctx, norm_sharename, &old_secdesc_ctr); + nt_printing_getsec(mem_ctx, sharename, &old_secdesc_ctr); /* Pick out correct owner and group sids */ @@ -5058,12 +5172,12 @@ WERROR nt_printing_setsec(const char *sharename, SEC_DESC_BUF *secdesc_ctr) goto out; } - slprintf(key, sizeof(key)-1, "SECDESC/%s", norm_sharename); + key = make_printers_secdesc_tdbkey( sharename ); if (tdb_prs_store(tdb_printers, key, &ps)==0) { status = WERR_OK; } else { - DEBUG(1,("Failed to store secdesc for %s\n", norm_sharename)); + DEBUG(1,("Failed to store secdesc for %s\n", sharename)); status = WERR_BADFUNC; } @@ -5168,9 +5282,8 @@ static SEC_DESC_BUF *construct_default_printer_sdb(TALLOC_CTX *ctx) BOOL nt_printing_getsec(TALLOC_CTX *ctx, const char *sharename, SEC_DESC_BUF **secdesc_ctr) { prs_struct ps; - fstring key; + char *key; char *temp; - fstring norm_sharename; if (strlen(sharename) > 2 && (temp = strchr(sharename + 2, '\\'))) { sharename = temp + 1; @@ -5178,15 +5291,12 @@ BOOL nt_printing_getsec(TALLOC_CTX *ctx, const char *sharename, SEC_DESC_BUF **s /* Fetch security descriptor from tdb */ - fstrcpy( norm_sharename, sharename ); - strlower_m( norm_sharename ); - - slprintf(key, sizeof(key)-1, "SECDESC/%s", norm_sharename); + key = make_printers_secdesc_tdbkey( sharename ); if (tdb_prs_fetch(tdb_printers, key, &ps, ctx)!=0 || !sec_io_desc_buf("nt_printing_getsec", secdesc_ctr, &ps, 1)) { - DEBUG(4,("using default secdesc for %s\n", norm_sharename)); + DEBUG(4,("using default secdesc for %s\n", sharename)); if (!(*secdesc_ctr = construct_default_printer_sdb(ctx))) { return False; @@ -5238,7 +5348,7 @@ BOOL nt_printing_getsec(TALLOC_CTX *ctx, const char *sharename, SEC_DESC_BUF **s /* Set it */ - nt_printing_setsec(norm_sharename, *secdesc_ctr); + nt_printing_setsec(sharename, *secdesc_ctr); } } @@ -5247,7 +5357,7 @@ BOOL nt_printing_getsec(TALLOC_CTX *ctx, const char *sharename, SEC_DESC_BUF **s int i; DEBUG(10, ("secdesc_ctr for %s has %d aces:\n", - norm_sharename, the_acl->num_aces)); + sharename, the_acl->num_aces)); for (i = 0; i < the_acl->num_aces; i++) { fstring sid_str; @@ -5453,7 +5563,10 @@ BOOL print_time_access_check(int snum) /**************************************************************************** Fill in the servername sent in the _spoolss_open_printer_ex() call ****************************************************************************/ + char* get_server_name( Printer_entry *printer ) { return printer->servername; } + + diff --git a/source/printing/printing.c b/source/printing/printing.c index 0737cf00d1d..2a7cd5d3a74 100644 --- a/source/printing/printing.c +++ b/source/printing/printing.c @@ -43,13 +43,6 @@ static BOOL remove_from_jobs_changed(const char* sharename, uint32 jobid); jobids are assigned when a job starts spooling. */ -struct print_queue_update_context { - char* sharename; - int printing_type; - char* lpqcommand; -}; - - static TDB_CONTEXT *rap_tdb; static uint16 next_rap_jobid; struct rap_jobid_key { @@ -1290,14 +1283,14 @@ this is the receive function of the background lpq updater ****************************************************************************/ static void print_queue_receive(int msg_type, pid_t src, void *buf, size_t msglen) { - struct print_queue_update_context ctx; fstring sharename; pstring lpqcommand; + int printing_type; size_t len; len = tdb_unpack( buf, msglen, "fdP", sharename, - &ctx.printing_type, + &printing_type, lpqcommand ); if ( len == -1 ) { @@ -1305,12 +1298,9 @@ static void print_queue_receive(int msg_type, pid_t src, void *buf, size_t msgle return; } - ctx.sharename = sharename; - ctx.lpqcommand = lpqcommand; - - print_queue_update_with_lock(ctx.sharename, - get_printer_fns_from_type(ctx.printing_type), - ctx.lpqcommand ); + print_queue_update_with_lock(sharename, + get_printer_fns_from_type(printing_type), + lpqcommand ); return; } @@ -1390,8 +1380,10 @@ static void print_queue_update(int snum, BOOL force) fstrcpy( sharename, lp_const_servicename(snum)); + /* don't strip out characters like '$' from the printername */ + pstrcpy( lpqcommand, lp_lpqcommand(snum)); - pstring_sub( lpqcommand, "%p", PRINTERNAME(snum) ); + string_sub2( lpqcommand, "%p", PRINTERNAME(snum), sizeof(lpqcommand), False, False ); standard_sub_snum( snum, lpqcommand, sizeof(lpqcommand) ); /* diff --git a/source/python/py_samr.c b/source/python/py_samr.c index 57acd74bedb..77431e24475 100644 --- a/source/python/py_samr.c +++ b/source/python/py_samr.c @@ -146,7 +146,7 @@ static PyObject *samr_set_user_info2(PyObject *self, PyObject *args, NTSTATUS ntstatus; int level; union { - SAM_USER_INFO_10 id10; + SAM_USER_INFO_16 id16; SAM_USER_INFO_21 id21; } pinfo; @@ -164,10 +164,10 @@ static PyObject *samr_set_user_info2(PyObject *self, PyObject *args, ctr.switch_value = level; switch(level) { - case 0x10: - ctr.info.id10 = &pinfo.id10; + case 16: + ctr.info.id16 = &pinfo.id16; - if (!py_to_SAM_USER_INFO_10(ctr.info.id10, info)) { + if (!py_to_SAM_USER_INFO_16(ctr.info.id16, info)) { PyErr_SetString( samr_error, "error converting user info"); goto done; diff --git a/source/python/py_samr.h b/source/python/py_samr.h index 4d2b0675b47..8e91b1671ec 100644 --- a/source/python/py_samr.h +++ b/source/python/py_samr.h @@ -78,8 +78,8 @@ extern PyObject *samr_error; /* The following definitions are from py_samr_conv.c */ BOOL py_from_acct_info(PyObject **array, struct acct_info *info, int num_accts); -BOOL py_from_SAM_USER_INFO_10(PyObject **dict, SAM_USER_INFO_10 *info); -BOOL py_to_SAM_USER_INFO_10(SAM_USER_INFO_10 *info, PyObject *dict); +BOOL py_from_SAM_USER_INFO_16(PyObject **dict, SAM_USER_INFO_16 *info); +BOOL py_to_SAM_USER_INFO_16(SAM_USER_INFO_16 *info, PyObject *dict); BOOL py_from_SAM_USER_INFO_21(PyObject **dict, SAM_USER_INFO_21 *info); BOOL py_to_SAM_USER_INFO_21(SAM_USER_INFO_21 *info, PyObject *dict); diff --git a/source/python/py_samr_conv.c b/source/python/py_samr_conv.c index 7523ee7dfcb..94bedcf779e 100644 --- a/source/python/py_samr_conv.c +++ b/source/python/py_samr_conv.c @@ -22,22 +22,22 @@ #include "python/py_conv.h" /* - * Convert between SAM_USER_INFO_10 and Python + * Convert between SAM_USER_INFO_16 and Python */ -struct pyconv py_SAM_USER_INFO_10[] = { - { "acb_info", PY_UINT32, offsetof(SAM_USER_INFO_10, acb_info) }, +struct pyconv py_SAM_USER_INFO_16[] = { + { "acb_info", PY_UINT32, offsetof(SAM_USER_INFO_16, acb_info) }, { NULL } }; -BOOL py_from_SAM_USER_INFO_10(PyObject **dict, SAM_USER_INFO_10 *info) +BOOL py_from_SAM_USER_INFO_16(PyObject **dict, SAM_USER_INFO_16 *info) { - *dict = from_struct(info, py_SAM_USER_INFO_10); - PyDict_SetItemString(*dict, "level", PyInt_FromLong(0x10)); + *dict = from_struct(info, py_SAM_USER_INFO_16); + PyDict_SetItemString(*dict, "level", PyInt_FromLong(16)); return True; } -BOOL py_to_SAM_USER_INFO_10(SAM_USER_INFO_10 *info, PyObject *dict) +BOOL py_to_SAM_USER_INFO_16(SAM_USER_INFO_16 *info, PyObject *dict) { PyObject *obj, *dict_copy = PyDict_Copy(dict); BOOL result = False; @@ -48,7 +48,7 @@ BOOL py_to_SAM_USER_INFO_10(SAM_USER_INFO_10 *info, PyObject *dict) PyDict_DelItemString(dict_copy, "level"); - if (!to_struct(info, dict_copy, py_SAM_USER_INFO_10)) + if (!to_struct(info, dict_copy, py_SAM_USER_INFO_16)) goto done; result = True; diff --git a/source/python/py_smb.c b/source/python/py_smb.c index d3858d33d8c..679c113f397 100644 --- a/source/python/py_smb.c +++ b/source/python/py_smb.c @@ -154,7 +154,7 @@ static PyObject *py_smb_nt_create_andx(PyObject *self, PyObject *args, char *filename; uint32 desired_access, file_attributes = 0, share_access = FILE_SHARE_READ | FILE_SHARE_WRITE, - create_disposition = FILE_EXISTS_OPEN, create_options = 0; + create_disposition = OPENX_FILE_EXISTS_OPEN, create_options = 0; int result; /* Parse parameters */ diff --git a/source/python/py_spoolss_drivers.c b/source/python/py_spoolss_drivers.c index 310f978188c..abc9a4ba9cb 100644 --- a/source/python/py_spoolss_drivers.c +++ b/source/python/py_spoolss_drivers.c @@ -29,7 +29,7 @@ PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args, PyObject *result = NULL, *creds = NULL; PRINTER_DRIVER_CTR ctr; int level = 1, i; - uint32 needed, num_drivers; + uint32 num_drivers; char *arch = "Windows NT x86", *server, *errstr; static char *kwlist[] = {"server", "level", "creds", "arch", NULL}; struct cli_state *cli = NULL; @@ -70,14 +70,9 @@ PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args, } werror = cli_spoolss_enumprinterdrivers( - cli, mem_ctx, 0, &needed, level, arch, + cli, mem_ctx, level, arch, &num_drivers, &ctr); - if (W_ERROR_V(werror) == ERRinsufficientbuffer) - werror = cli_spoolss_enumprinterdrivers( - cli, mem_ctx, needed, NULL, level, arch, - &num_drivers, &ctr); - if (!W_ERROR_IS_OK(werror)) { PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); goto done; @@ -175,7 +170,6 @@ PyObject *spoolss_hnd_getprinterdriver(PyObject *self, PyObject *args, PyObject *result = Py_None; PRINTER_DRIVER_CTR ctr; int level = 1; - uint32 needed; char *arch = "Windows NT x86"; int version = 2; static char *kwlist[] = {"level", "arch", NULL}; @@ -188,15 +182,9 @@ PyObject *spoolss_hnd_getprinterdriver(PyObject *self, PyObject *args, /* Call rpc function */ - werror = cli_spoolss_getprinterdriver( - hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, level, + werror = cli_spoolss_getprinterdriver(hnd->cli, hnd->mem_ctx, &hnd->pol, level, arch, version, &ctr); - if (W_ERROR_V(werror) == ERRinsufficientbuffer) - werror = cli_spoolss_getprinterdriver( - hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol, - level, arch, version, &ctr); - if (!W_ERROR_IS_OK(werror)) { PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); return NULL; @@ -234,7 +222,7 @@ PyObject *spoolss_getprinterdriverdir(PyObject *self, PyObject *args, WERROR werror; PyObject *result = NULL, *creds = NULL; DRIVER_DIRECTORY_CTR ctr; - uint32 needed, level = 1; + uint32 level = 1; char *arch = "Windows NT x86", *server, *errstr; static char *kwlist[] = {"server", "level", "arch", "creds", NULL}; struct cli_state *cli = NULL; @@ -274,12 +262,7 @@ PyObject *spoolss_getprinterdriverdir(PyObject *self, PyObject *args, goto done; } - werror = cli_spoolss_getprinterdriverdir( - cli, mem_ctx, 0, &needed, level, arch, &ctr); - - if (W_ERROR_V(werror) == ERRinsufficientbuffer) - werror = cli_spoolss_getprinterdriverdir( - cli, mem_ctx, needed, NULL, level, arch, &ctr); + werror = cli_spoolss_getprinterdriverdir(cli, mem_ctx, level, arch, &ctr); if (!W_ERROR_IS_OK(werror)) { PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); diff --git a/source/python/py_spoolss_forms.c b/source/python/py_spoolss_forms.c index 66a6540e074..00c5b18e18d 100644 --- a/source/python/py_spoolss_forms.c +++ b/source/python/py_spoolss_forms.c @@ -101,14 +101,9 @@ PyObject *spoolss_hnd_getform(PyObject *self, PyObject *args, PyObject *kw) /* Call rpc function */ - werror = cli_spoolss_getform(hnd->cli, hnd->mem_ctx, 0, &needed, + werror = cli_spoolss_getform(hnd->cli, hnd->mem_ctx, &hnd->pol, form_name, level, &form); - if (W_ERROR_V(werror) == ERRinsufficientbuffer) - werror = cli_spoolss_getform( - hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol, - form_name, 1, &form); - if (!W_ERROR_IS_OK(werror)) { PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); return NULL; @@ -211,7 +206,7 @@ PyObject *spoolss_hnd_enumforms(PyObject *self, PyObject *args, PyObject *kw) PyObject *result; spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; WERROR werror; - uint32 level = 1, num_forms, needed, i; + uint32 level = 1, num_forms, i; static char *kwlist[] = {"level", NULL}; FORM_1 *forms; @@ -224,14 +219,9 @@ PyObject *spoolss_hnd_enumforms(PyObject *self, PyObject *args, PyObject *kw) /* Call rpc function */ werror = cli_spoolss_enumforms( - hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, level, + hnd->cli, hnd->mem_ctx, &hnd->pol, level, &num_forms, &forms); - if (W_ERROR_V(werror) == ERRinsufficientbuffer) - werror = cli_spoolss_enumforms( - hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol, level, - &num_forms, &forms); - if (!W_ERROR_IS_OK(werror)) { PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); return NULL; diff --git a/source/python/py_spoolss_jobs.c b/source/python/py_spoolss_jobs.c index 59754bd36dd..8ea0ebc073a 100644 --- a/source/python/py_spoolss_jobs.c +++ b/source/python/py_spoolss_jobs.c @@ -28,7 +28,7 @@ PyObject *spoolss_hnd_enumjobs(PyObject *self, PyObject *args, PyObject *kw) WERROR werror; PyObject *result; int level = 1; - uint32 i, needed, num_jobs; + uint32 i, num_jobs; static char *kwlist[] = {"level", NULL}; JOB_INFO_CTR ctr; @@ -40,14 +40,9 @@ PyObject *spoolss_hnd_enumjobs(PyObject *self, PyObject *args, PyObject *kw) /* Call rpc function */ werror = cli_spoolss_enumjobs( - hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, level, 0, + hnd->cli, hnd->mem_ctx, &hnd->pol, level, 0, 1000, &num_jobs, &ctr); - if (W_ERROR_V(werror) == ERRinsufficientbuffer) - werror = cli_spoolss_enumjobs( - hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol, - level, 0, 1000, &num_jobs, &ctr); - /* Return value */ result = Py_None; @@ -123,7 +118,7 @@ PyObject *spoolss_hnd_getjob(PyObject *self, PyObject *args, PyObject *kw) spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; WERROR werror; PyObject *result; - uint32 level = 1, jobid, needed; + uint32 level = 1, jobid; static char *kwlist[] = {"jobid", "level", NULL}; JOB_INFO_CTR ctr; @@ -135,14 +130,9 @@ PyObject *spoolss_hnd_getjob(PyObject *self, PyObject *args, PyObject *kw) /* Call rpc function */ - werror = cli_spoolss_getjob(hnd->cli, hnd->mem_ctx, 0, &needed, + werror = cli_spoolss_getjob(hnd->cli, hnd->mem_ctx, &hnd->pol, jobid, level, &ctr); - if (W_ERROR_V(werror) == ERRinsufficientbuffer) - werror = cli_spoolss_getjob( - hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol, - jobid, level, &ctr); - if (!W_ERROR_IS_OK(werror)) { PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); return NULL; diff --git a/source/python/py_spoolss_ports.c b/source/python/py_spoolss_ports.c index ddc8868f0f5..11a4615bbdb 100644 --- a/source/python/py_spoolss_ports.c +++ b/source/python/py_spoolss_ports.c @@ -67,13 +67,7 @@ PyObject *spoolss_enumports(PyObject *self, PyObject *args, PyObject *kw) /* Call rpc function */ - werror = cli_spoolss_enum_ports( - cli, mem_ctx, 0, &needed, level, &num_ports, &ctr); - - if (W_ERROR_V(werror) == ERRinsufficientbuffer) - werror = cli_spoolss_enum_ports( - cli, mem_ctx, needed, NULL, level, - &num_ports, &ctr); + werror = cli_spoolss_enum_ports( cli, mem_ctx, level, &num_ports, &ctr); if (!W_ERROR_IS_OK(werror)) { PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); diff --git a/source/python/py_spoolss_printerdata.c b/source/python/py_spoolss_printerdata.c index f165475b080..6fc4227ad21 100644 --- a/source/python/py_spoolss_printerdata.c +++ b/source/python/py_spoolss_printerdata.c @@ -112,7 +112,6 @@ PyObject *spoolss_hnd_getprinterdata(PyObject *self, PyObject *args, PyObject *k static char *kwlist[] = { "value", NULL }; char *valuename; WERROR werror; - uint32 needed; PyObject *result; REGISTRY_VALUE value; @@ -124,14 +123,9 @@ PyObject *spoolss_hnd_getprinterdata(PyObject *self, PyObject *args, PyObject *k /* Call rpc function */ werror = cli_spoolss_getprinterdata( - hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, valuename, + hnd->cli, hnd->mem_ctx, &hnd->pol, valuename, &value); - if (W_ERROR_V(werror) == ERRmoredata) - werror = cli_spoolss_getprinterdata( - hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol, - valuename, &value); - if (!W_ERROR_IS_OK(werror)) { PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); return NULL; @@ -255,7 +249,6 @@ PyObject *spoolss_hnd_getprinterdataex(PyObject *self, PyObject *args, PyObject static char *kwlist[] = { "key", "value", NULL }; char *key, *valuename; WERROR werror; - uint32 needed; PyObject *result; REGISTRY_VALUE value; @@ -267,14 +260,9 @@ PyObject *spoolss_hnd_getprinterdataex(PyObject *self, PyObject *args, PyObject /* Call rpc function */ werror = cli_spoolss_getprinterdataex( - hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, key, + hnd->cli, hnd->mem_ctx, &hnd->pol, key, valuename, &value); - if (W_ERROR_V(werror) == ERRmoredata) - werror = cli_spoolss_getprinterdataex( - hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol, key, - valuename, &value); - if (!W_ERROR_IS_OK(werror)) { PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); return NULL; @@ -323,7 +311,7 @@ PyObject *spoolss_hnd_enumprinterdataex(PyObject *self, PyObject *args, PyObject { spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; static char *kwlist[] = { "key", NULL }; - uint32 needed, i; + uint32 i; char *key; WERROR werror; PyObject *result; @@ -334,13 +322,7 @@ PyObject *spoolss_hnd_enumprinterdataex(PyObject *self, PyObject *args, PyObject /* Get max buffer sizes for value and data */ - werror = cli_spoolss_enumprinterdataex( - hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, key, &ctr); - - if (W_ERROR_V(werror) == ERRmoredata) - werror = cli_spoolss_enumprinterdataex( - hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol, key, - &ctr); + werror = cli_spoolss_enumprinterdataex(hnd->cli, hnd->mem_ctx, &hnd->pol, key, &ctr); if (!W_ERROR_IS_OK(werror)) { PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); @@ -400,7 +382,7 @@ PyObject *spoolss_hnd_enumprinterkey(PyObject *self, PyObject *args, static char *kwlist[] = { "key", NULL }; char *keyname; WERROR werror; - uint32 needed, keylist_len; + uint32 keylist_len; uint16 *keylist; PyObject *result; @@ -412,14 +394,9 @@ PyObject *spoolss_hnd_enumprinterkey(PyObject *self, PyObject *args, /* Call rpc function */ werror = cli_spoolss_enumprinterkey( - hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, + hnd->cli, hnd->mem_ctx, &hnd->pol, keyname, &keylist, &keylist_len); - if (W_ERROR_V(werror) == ERRmoredata) - werror = cli_spoolss_enumprinterkey( - hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol, - keyname, &keylist, &keylist_len); - if (!W_ERROR_IS_OK(werror)) { PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); return NULL; diff --git a/source/python/py_spoolss_printers.c b/source/python/py_spoolss_printers.c index 7446e2d2828..aab2d634a34 100644 --- a/source/python/py_spoolss_printers.c +++ b/source/python/py_spoolss_printers.c @@ -127,7 +127,6 @@ PyObject *spoolss_hnd_getprinter(PyObject *self, PyObject *args, PyObject *kw) PyObject *result = NULL; PRINTER_INFO_CTR ctr; int level = 1; - uint32 needed; static char *kwlist[] = {"level", NULL}; /* Parse parameters */ @@ -140,12 +139,7 @@ PyObject *spoolss_hnd_getprinter(PyObject *self, PyObject *args, PyObject *kw) /* Call rpc function */ werror = cli_spoolss_getprinter( - hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, level, &ctr); - - if (W_ERROR_V(werror) == ERRinsufficientbuffer) - werror = cli_spoolss_getprinter( - hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol, - level, &ctr); + hnd->cli, hnd->mem_ctx, &hnd->pol, level, &ctr); /* Return value */ @@ -277,7 +271,7 @@ PyObject *spoolss_enumprinters(PyObject *self, PyObject *args, PyObject *kw) PyObject *result = NULL, *creds = NULL; PRINTER_INFO_CTR ctr; int level = 1, flags = PRINTER_ENUM_LOCAL, i; - uint32 needed, num_printers; + uint32 num_printers; static char *kwlist[] = {"server", "name", "level", "flags", "creds", NULL}; TALLOC_CTX *mem_ctx = NULL; @@ -331,15 +325,9 @@ PyObject *spoolss_enumprinters(PyObject *self, PyObject *args, PyObject *kw) /* Call rpc function */ - werror = cli_spoolss_enum_printers( - cli, mem_ctx, 0, &needed, name, flags, level, + werror = cli_spoolss_enum_printers(cli, mem_ctx, name, flags, level, &num_printers, &ctr); - if (W_ERROR_V(werror) == ERRinsufficientbuffer) - werror = cli_spoolss_enum_printers( - cli, mem_ctx, needed, NULL, name, flags, - level, &num_printers, &ctr); - if (!W_ERROR_IS_OK(werror)) { PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); goto done; diff --git a/source/python/py_spoolss_printers_conv.c b/source/python/py_spoolss_printers_conv.c index e31babb0012..4ab030d9619 100644 --- a/source/python/py_spoolss_printers_conv.c +++ b/source/python/py_spoolss_printers_conv.c @@ -154,7 +154,7 @@ BOOL py_from_DEVICEMODE(PyObject **dict, DEVICEMODE *devmode) PyDict_SetItemString(*dict, "private", PyString_FromStringAndSize( - devmode->private, devmode->driverextra)); + devmode->dev_private, devmode->driverextra)); return True; } @@ -170,7 +170,7 @@ BOOL py_to_DEVICEMODE(DEVICEMODE *devmode, PyObject *dict) if (!PyString_Check(obj)) goto done; - devmode->private = PyString_AsString(obj); + devmode->dev_private = PyString_AsString(obj); devmode->driverextra = PyString_Size(obj); PyDict_DelItemString(dict_copy, "private"); diff --git a/source/python/py_tdb.c b/source/python/py_tdb.c index ccd1e6e1c63..f73aa0ba8be 100644 --- a/source/python/py_tdb.c +++ b/source/python/py_tdb.c @@ -376,49 +376,6 @@ static BOOL make_lock_list(PyObject *py_keys, TDB_DATA **keys, int *num_keys) return True; } -PyObject *py_tdb_hnd_lock(PyObject *self, PyObject *args) -{ - tdb_hnd_object *obj = (tdb_hnd_object *)self; - PyObject *py_keys; - TDB_DATA *keys; - int num_keys, result; - - if (!obj->tdb) { - PyErr_SetString(py_tdb_error, "tdb object has been closed"); - return NULL; - } - - if (!PyArg_ParseTuple(args, "O", &py_keys)) - return NULL; - - if (!make_lock_list(py_keys, &keys, &num_keys)) - return NULL; - - result = tdb_lockkeys(obj->tdb, num_keys, keys); - - free(keys); - - return PyInt_FromLong(result != -1); -} - -PyObject *py_tdb_hnd_unlock(PyObject *self, PyObject *args) -{ - tdb_hnd_object *obj = (tdb_hnd_object *)self; - - if (!obj->tdb) { - PyErr_SetString(py_tdb_error, "tdb object has been closed"); - return NULL; - } - - if (!PyArg_ParseTuple(args, "")) - return NULL; - - tdb_unlockkeys(obj->tdb); - - Py_INCREF(Py_None); - return Py_None; -} - /* * tdb traversal */ @@ -582,8 +539,6 @@ static PyMethodDef tdb_hnd_methods[] = { { "next_key", (PyCFunction)py_tdb_hnd_next_key, METH_VARARGS }, { "lock_all", (PyCFunction)py_tdb_hnd_lock_all, METH_VARARGS }, { "unlock_all", (PyCFunction)py_tdb_hnd_unlock_all, METH_VARARGS }, - { "lock", (PyCFunction)py_tdb_hnd_lock, METH_VARARGS }, - { "unlock", (PyCFunction)py_tdb_hnd_unlock, METH_VARARGS }, { "traverse", (PyCFunction)py_tdb_hnd_traverse, METH_VARARGS | METH_KEYWORDS }, { "chainlock", (PyCFunction)py_tdb_hnd_chainlock, METH_VARARGS | METH_KEYWORDS }, { "chainunlock", (PyCFunction)py_tdb_hnd_chainunlock, METH_VARARGS | METH_KEYWORDS }, diff --git a/source/python/setup.py b/source/python/setup.py index 4a4f6ad3f81..bfc743603bd 100755 --- a/source/python/setup.py +++ b/source/python/setup.py @@ -37,6 +37,8 @@ samba_cflags = os.environ.get("PYTHON_CFLAGS", "") samba_srcdir = os.environ.get("SRCDIR", "") +compiler = os.environ.get("CC", "") + # These variables are filled in by configure samba_libs = os.environ.get("LIBS", "") diff --git a/source/registry/reg_db.c b/source/registry/reg_db.c index bd17303a702..6e3a989972f 100644 --- a/source/registry/reg_db.c +++ b/source/registry/reg_db.c @@ -356,7 +356,7 @@ int regdb_fetch_keys( const char* key, REGSUBKEY_CTR *ctr ) int i; fstring subkeyname; - DEBUG(10,("regdb_fetch_keys: Enter key => [%s]\n", key ? key : "NULL")); + DEBUG(11,("regdb_fetch_keys: Enter key => [%s]\n", key ? key : "NULL")); pstrcpy( path, key ); @@ -383,7 +383,7 @@ int regdb_fetch_keys( const char* key, REGSUBKEY_CTR *ctr ) SAFE_FREE( dbuf.dptr ); - DEBUG(10,("regdb_fetch_keys: Exit [%d] items\n", num_items)); + DEBUG(11,("regdb_fetch_keys: Exit [%d] items\n", num_items)); return num_items; } diff --git a/source/registry/regfio.c b/source/registry/regfio.c index d2035228aef..48683969868 100644 --- a/source/registry/regfio.c +++ b/source/registry/regfio.c @@ -89,7 +89,7 @@ static int read_block( REGF_FILE *file, prs_struct *ps, uint32 file_offset, uint to read some of the header to get the block_size from there */ if ( block_size == 0 ) { - uint8 hdr[0x20]; + char hdr[0x20]; if ( lseek( file->fd, file_offset, SEEK_SET ) == -1 ) { DEBUG(0,("read_block: lseek() failed! (%s)\n", strerror(errno) )); @@ -199,7 +199,7 @@ static BOOL prs_regf_block( const char *desc, prs_struct *ps, int depth, REGF_FI prs_debug(ps, depth, desc, "prs_regf_block"); depth++; - if ( !prs_uint8s( True, "header", ps, depth, file->header, sizeof( file->header )) ) + if ( !prs_uint8s( True, "header", ps, depth, (uint8*)file->header, sizeof( file->header )) ) return False; /* yes, these values are always identical so store them only once */ @@ -261,7 +261,7 @@ static BOOL prs_hbin_block( const char *desc, prs_struct *ps, int depth, REGF_HB prs_debug(ps, depth, desc, "prs_regf_block"); depth++; - if ( !prs_uint8s( True, "header", ps, depth, hbin->header, sizeof( hbin->header )) ) + if ( !prs_uint8s( True, "header", ps, depth, (uint8*)hbin->header, sizeof( hbin->header )) ) return False; if ( !prs_uint32( "first_hbin_off", ps, depth, &hbin->first_hbin_off )) @@ -310,7 +310,7 @@ static BOOL prs_nk_rec( const char *desc, prs_struct *ps, int depth, REGF_NK_REC if ( !prs_uint32( "rec_size", ps, depth, &nk->rec_size )) return False; - if ( !prs_uint8s( True, "header", ps, depth, nk->header, sizeof( nk->header )) ) + if ( !prs_uint8s( True, "header", ps, depth, (uint8*)nk->header, sizeof( nk->header )) ) return False; if ( !prs_uint16( "key_type", ps, depth, &nk->key_type )) @@ -371,7 +371,7 @@ static BOOL prs_nk_rec( const char *desc, prs_struct *ps, int depth, REGF_NK_REC return False; } - if ( !prs_uint8s( True, "name", ps, depth, nk->keyname, name_length) ) + if ( !prs_uint8s( True, "name", ps, depth, (uint8*)nk->keyname, name_length) ) return False; if ( UNMARSHALLING(ps) ) @@ -478,6 +478,7 @@ static REGF_HBIN* read_hbin_block( REGF_FILE *file, off_t offset ) return False; record_size = 0; + header = 0; curr_off = prs_offset( &hbin->ps ); while ( header != 0xffffffff ) { /* not done yet so reset the current offset to the @@ -634,7 +635,7 @@ static BOOL hbin_prs_lf_records( const char *desc, REGF_HBIN *hbin, int depth, R if ( !prs_uint32( "rec_size", &hbin->ps, depth, &lf->rec_size )) return False; - if ( !prs_uint8s( True, "header", &hbin->ps, depth, lf->header, sizeof( lf->header )) ) + if ( !prs_uint8s( True, "header", &hbin->ps, depth, (uint8*)lf->header, sizeof( lf->header )) ) return False; if ( !prs_uint16( "num_keys", &hbin->ps, depth, &lf->num_keys)) @@ -688,7 +689,7 @@ static BOOL hbin_prs_sk_rec( const char *desc, REGF_HBIN *hbin, int depth, REGF_ if ( !prs_uint32( "rec_size", &hbin->ps, depth, &sk->rec_size )) return False; - if ( !prs_uint8s( True, "header", ps, depth, sk->header, sizeof( sk->header )) ) + if ( !prs_uint8s( True, "header", ps, depth, (uint8*)sk->header, sizeof( sk->header )) ) return False; if ( !prs_uint16( "tag", ps, depth, &tag)) return False; @@ -740,7 +741,7 @@ static BOOL hbin_prs_vk_rec( const char *desc, REGF_HBIN *hbin, int depth, REGF_ if ( !prs_uint32( "rec_size", &hbin->ps, depth, &vk->rec_size )) return False; - if ( !prs_uint8s( True, "header", ps, depth, vk->header, sizeof( vk->header )) ) + if ( !prs_uint8s( True, "header", ps, depth, (uint8*)vk->header, sizeof( vk->header )) ) return False; if ( MARSHALLING(&hbin->ps) ) @@ -769,7 +770,7 @@ static BOOL hbin_prs_vk_rec( const char *desc, REGF_HBIN *hbin, int depth, REGF_ if ( !(vk->valuename = PRS_ALLOC_MEM( ps, char, name_length+1 ))) return False; } - if ( !prs_uint8s( True, "name", ps, depth, vk->valuename, name_length ) ) + if ( !prs_uint8s( True, "name", ps, depth, (uint8*)vk->valuename, name_length ) ) return False; } @@ -1019,7 +1020,7 @@ static BOOL hbin_prs_key( REGF_FILE *file, REGF_HBIN *hbin, REGF_NK_REC *nk ) static BOOL next_record( REGF_HBIN *hbin, const char *hdr, BOOL *eob ) { - char header[REC_HDR_SIZE] = ""; + uint8 header[REC_HDR_SIZE]; uint32 record_size; uint32 curr_off, block_size; BOOL found = False; @@ -1036,6 +1037,7 @@ static BOOL next_record( REGF_HBIN *hbin, const char *hdr, BOOL *eob ) block_size = prs_data_size( ps ); record_size = 0; + memset( header, 0x0, sizeof(uint8)*REC_HDR_SIZE ); while ( !found ) { curr_off = curr_off+record_size; diff --git a/source/rpc_client/cli_pipe.c b/source/rpc_client/cli_pipe.c index 5f34fbde5d2..230750817a9 100644 --- a/source/rpc_client/cli_pipe.c +++ b/source/rpc_client/cli_pipe.c @@ -242,7 +242,7 @@ static BOOL rpc_auth_pipe(struct rpc_pipe_client *cli, prs_struct *rdata, } /* Let the caller know how much padding at the end of the data */ - *pauth_padding_len = rhdr_auth.padding; + *pauth_padding_len = rhdr_auth.auth_pad_len; /* Check it's the type of reply we were expecting to decode */ @@ -796,6 +796,7 @@ static NTSTATUS create_rpc_bind_resp(struct rpc_pipe_client *cli, { NTSTATUS nt_status; RPC_HDR hdr; + RPC_HDR_AUTH hdr_auth; RPC_HDR_AUTHA hdr_autha; DATA_BLOB ntlmssp_null_response = data_blob(NULL, 0); DATA_BLOB ntlmssp_reply; @@ -826,8 +827,8 @@ static NTSTATUS create_rpc_bind_resp(struct rpc_pipe_client *cli, get_auth_type_level(cli->pipe_auth_flags, &auth_type, &auth_level); /* Create the request RPC_HDR_AUTHA */ - init_rpc_hdr_autha(&hdr_autha, MAX_PDU_FRAG_LEN, MAX_PDU_FRAG_LEN, - auth_type, auth_level, 0x00); + init_rpc_hdr_auth(&hdr_auth, auth_type, auth_level, 0, 0x0014a0c0); + init_rpc_hdr_autha(&hdr_autha, MAX_PDU_FRAG_LEN, MAX_PDU_FRAG_LEN, &hdr_auth); if(!smb_io_rpc_hdr_autha("hdr_autha", &hdr_autha, rpc_out, 0)) { DEBUG(0,("create_rpc_bind_resp: failed to marshall RPC_HDR_AUTHA.\n")); diff --git a/source/rpc_client/cli_spoolss.c b/source/rpc_client/cli_spoolss.c index 8ed29f50fb9..7ebae0868fa 100644 --- a/source/rpc_client/cli_spoolss.c +++ b/source/rpc_client/cli_spoolss.c @@ -2,7 +2,7 @@ Unix SMB/CIFS implementation. RPC pipe client - Copyright (C) Gerald Carter 2001-2002, + Copyright (C) Gerald Carter 2001-2005, Copyright (C) Tim Potter 2000-2002, Copyright (C) Andrew Tridgell 1994-2000, Copyright (C) Luke Kenneth Casson Leighton 1996-2000, @@ -24,12 +24,7 @@ */ #include "includes.h" - -/** @defgroup spoolss SPOOLSS - NT printing routines - * @ingroup rpc_client - * - * @{ - **/ +#include "rpc_client.h" /********************************************************************* Decode various spoolss rpc's and info levels @@ -37,6 +32,7 @@ /********************************************************************** **********************************************************************/ + static void decode_printer_info_0(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer, uint32 returned, PRINTER_INFO_0 **info) { @@ -257,1613 +253,1102 @@ static void decode_printerdriverdir_1 (TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer, *info=inf; } -/** Return a handle to the specified printer or print server. - * - * @param cli Pointer to client state structure which is open - * on the SPOOLSS pipe. - * - * @param mem_ctx Pointer to an initialised talloc context. - * - * @param printername The name of the printer or print server to be - * opened in UNC format. - * - * @param datatype Specifies the default data type for the printer. - * - * @param access_required The access rights requested on the printer or - * print server. - * - * @param station The UNC name of the requesting workstation. - * - * @param username The name of the user requesting the open. - * - * @param pol Returned policy handle. - */ - -/********************************************************************************* - Win32 API - OpenPrinter() - ********************************************************************************/ +/********************************************************************** +**********************************************************************/ -WERROR cli_spoolss_open_printer_ex(struct cli_state *cli, TALLOC_CTX *mem_ctx, - const char *printername, const char *datatype, uint32 access_required, - const char *station, const char *username, POLICY_HND *pol) +static void decode_jobs_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer, + uint32 num_jobs, JOB_INFO_1 **jobs) { - prs_struct qbuf, rbuf; - SPOOL_Q_OPEN_PRINTER_EX q; - SPOOL_R_OPEN_PRINTER_EX r; - WERROR result = W_ERROR(ERRgeneral); - - ZERO_STRUCT(q); - ZERO_STRUCT(r); - - /* Initialise parse structures */ - - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - /* Initialise input parameters */ + uint32 i; - make_spoolss_q_open_printer_ex(&q, printername, datatype, - access_required, station, username); + *jobs = TALLOC_ARRAY(mem_ctx, JOB_INFO_1, num_jobs); + prs_set_offset(&buffer->prs,0); - /* Marshall data and send request */ + for (i = 0; i < num_jobs; i++) + smb_io_job_info_1("", buffer, &((*jobs)[i]), 0); +} - if (!spoolss_io_q_open_printer_ex("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_OPENPRINTEREX, &qbuf, &rbuf)) - goto done; +/********************************************************************** +**********************************************************************/ - /* Unmarshall response */ +static void decode_jobs_2(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer, + uint32 num_jobs, JOB_INFO_2 **jobs) +{ + uint32 i; - if (!spoolss_io_r_open_printer_ex("", &r, &rbuf, 0)) - goto done; + *jobs = TALLOC_ARRAY(mem_ctx, JOB_INFO_2, num_jobs); + prs_set_offset(&buffer->prs,0); - /* Return output parameters */ + for (i = 0; i < num_jobs; i++) + smb_io_job_info_2("", buffer, &((*jobs)[i]), 0); +} - result = r.status; +/********************************************************************** +**********************************************************************/ - if (W_ERROR_IS_OK(result)) - *pol = r.handle; +static void decode_forms_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer, + uint32 num_forms, FORM_1 **forms) +{ + int i; - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); + *forms = TALLOC_ARRAY(mem_ctx, FORM_1, num_forms); + prs_set_offset(&buffer->prs,0); - return result; + for (i = 0; i < num_forms; i++) + smb_io_form_1("", buffer, &((*forms)[i]), 0); } -/** Close a printer handle - * - * @param cli Pointer to client state structure which is open - * on the SPOOLSS pipe. - * - * @param mem_ctx Pointer to an initialised talloc context. - * - * @param pol Policy handle of printer or print server to close. - */ -/********************************************************************************* - Win32 API - ClosePrinter() - ********************************************************************************/ +/********************************************************************** +**********************************************************************/ -WERROR cli_spoolss_close_printer(struct cli_state *cli, TALLOC_CTX *mem_ctx, - POLICY_HND *pol) +WERROR cli_spoolss_open_printer_ex(struct cli_state *cli, TALLOC_CTX *mem_ctx, + const char *printername, const char *datatype, uint32 access_required, + const char *station, const char *username, POLICY_HND *pol) { prs_struct qbuf, rbuf; - SPOOL_Q_CLOSEPRINTER q; - SPOOL_R_CLOSEPRINTER r; - WERROR result = W_ERROR(ERRgeneral); - - ZERO_STRUCT(q); - ZERO_STRUCT(r); - - /* Initialise parse structures */ - - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - /* Initialise input parameters */ - - make_spoolss_q_closeprinter(&q, pol); + SPOOL_Q_OPEN_PRINTER_EX in; + SPOOL_R_OPEN_PRINTER_EX out; - /* Marshall data and send request */ + ZERO_STRUCT(in); + ZERO_STRUCT(out); - if (!spoolss_io_q_closeprinter("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_CLOSEPRINTER, &qbuf, &rbuf)) - goto done; + make_spoolss_q_open_printer_ex( &in, printername, datatype, + access_required, station, username ); - /* Unmarshall response */ + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_OPENPRINTEREX, + in, out, + qbuf, rbuf, + spoolss_io_q_open_printer_ex, + spoolss_io_r_open_printer_ex, + WERR_GENERAL_FAILURE ); - if (!spoolss_io_r_closeprinter("", &r, &rbuf, 0)) - goto done; - - /* Return output parameters */ - - result = r.status; - - if (W_ERROR_IS_OK(result)) - *pol = r.handle; + memcpy( pol, &out.handle, sizeof(POLICY_HND) ); + + return out.status; +} - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); +/********************************************************************** +**********************************************************************/ - return result; +WERROR cli_spoolss_close_printer(struct cli_state *cli, TALLOC_CTX *mem_ctx, + POLICY_HND *pol) +{ + prs_struct qbuf, rbuf; + SPOOL_Q_CLOSEPRINTER in; + SPOOL_R_CLOSEPRINTER out; + + ZERO_STRUCT(in); + ZERO_STRUCT(out); + + make_spoolss_q_closeprinter( &in, pol ); + + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_CLOSEPRINTER, + in, out, + qbuf, rbuf, + spoolss_io_q_closeprinter, + spoolss_io_r_closeprinter, + WERR_GENERAL_FAILURE ); + + return out.status; } -/** Enumerate printers on a print server. - * - * @param cli Pointer to client state structure which is open - * on the SPOOLSS pipe. - * @param mem_ctx Pointer to an initialised talloc context. - * - * @param offered Buffer size offered in the request. - * @param needed Number of bytes needed to complete the request. - * may be NULL. - * - * @param flags Selected from PRINTER_ENUM_* flags. - * @param level Request information level. - * - * @param num_printers Pointer to number of printers returned. May be - * NULL. - * @param ctr Return structure for printer information. May - * be NULL. - */ -/********************************************************************************* - Win32 API - EnumPrinters() - ********************************************************************************/ +/********************************************************************** +**********************************************************************/ WERROR cli_spoolss_enum_printers(struct cli_state *cli, TALLOC_CTX *mem_ctx, - uint32 offered, uint32 *needed, char *name, uint32 flags, uint32 level, uint32 *num_printers, PRINTER_INFO_CTR *ctr) { prs_struct qbuf, rbuf; - SPOOL_Q_ENUMPRINTERS q; - SPOOL_R_ENUMPRINTERS r; + SPOOL_Q_ENUMPRINTERS in; + SPOOL_R_ENUMPRINTERS out; RPC_BUFFER buffer; - WERROR result = W_ERROR(ERRgeneral); + uint32 offered; - ZERO_STRUCT(q); - ZERO_STRUCT(r); - - /* Initialise input parameters */ + ZERO_STRUCT(in); + ZERO_STRUCT(out); + offered = 0; rpcbuf_init(&buffer, offered, mem_ctx); - - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - make_spoolss_q_enumprinters(&q, flags, name, level, &buffer, - offered); - - /* Marshall data and send request */ - - if (!spoolss_io_q_enumprinters("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_ENUMPRINTERS, &qbuf, &rbuf)) - goto done; - - /* Unmarshall response */ - - if (spoolss_io_r_enumprinters("", &r, &rbuf, 0)) { - if (needed) - *needed = r.needed; + make_spoolss_q_enumprinters( &in, flags, name, level, &buffer, offered ); + + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENUMPRINTERS, + in, out, + qbuf, rbuf, + spoolss_io_q_enumprinters, + spoolss_io_r_enumprinters, + WERR_GENERAL_FAILURE ); + + if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) { + offered = out.needed; + + ZERO_STRUCT(in); + ZERO_STRUCT(out); + + rpcbuf_init(&buffer, offered, mem_ctx); + make_spoolss_q_enumprinters( &in, flags, name, level, &buffer, offered ); + + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENUMPRINTERS, + in, out, + qbuf, rbuf, + spoolss_io_q_enumprinters, + spoolss_io_r_enumprinters, + WERR_GENERAL_FAILURE ); } - - result = r.status; - - /* Return output parameters */ - - if (!W_ERROR_IS_OK(r.status)) - goto done; - - if (num_printers) - *num_printers = r.returned; - if (!ctr) - goto done; + if ( !W_ERROR_IS_OK(out.status) ) + return out.status; switch (level) { case 0: - decode_printer_info_0(mem_ctx, r.buffer, r.returned, - &ctr->printers_0); + decode_printer_info_0(mem_ctx, out.buffer, out.returned, &ctr->printers_0); break; case 1: - decode_printer_info_1(mem_ctx, r.buffer, r.returned, - &ctr->printers_1); + decode_printer_info_1(mem_ctx, out.buffer, out.returned, &ctr->printers_1); break; case 2: - decode_printer_info_2(mem_ctx, r.buffer, r.returned, - &ctr->printers_2); + decode_printer_info_2(mem_ctx, out.buffer, out.returned, &ctr->printers_2); break; case 3: - decode_printer_info_3(mem_ctx, r.buffer, r.returned, - &ctr->printers_3); + decode_printer_info_3(mem_ctx, out.buffer, out.returned, &ctr->printers_3); break; } - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); + *num_printers = out.returned; - return result; + return out.status; } -/********************************************************************************* - Win32 API - EnumPorts() - ********************************************************************************/ -/** Enumerate printer ports on a print server. - * - * @param cli Pointer to client state structure which is open - * on the SPOOLSS pipe. - * @param mem_ctx Pointer to an initialised talloc context. - * - * @param offered Buffer size offered in the request. - * @param needed Number of bytes needed to complete the request. - * May be NULL. - * - * @param level Requested information level. - * - * @param num_ports Pointer to number of ports returned. May be NULL. - * @param ctr Pointer to structure holding port information. - * May be NULL. - */ +/********************************************************************** +**********************************************************************/ WERROR cli_spoolss_enum_ports(struct cli_state *cli, TALLOC_CTX *mem_ctx, - uint32 offered, uint32 *needed, uint32 level, uint32 *num_ports, PORT_INFO_CTR *ctr) { prs_struct qbuf, rbuf; - SPOOL_Q_ENUMPORTS q; - SPOOL_R_ENUMPORTS r; + SPOOL_Q_ENUMPORTS in; + SPOOL_R_ENUMPORTS out; RPC_BUFFER buffer; - WERROR result = W_ERROR(ERRgeneral); fstring server; + uint32 offered; - ZERO_STRUCT(q); - ZERO_STRUCT(r); + ZERO_STRUCT(in); + ZERO_STRUCT(out); slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost); strupper_m(server); - /* Initialise input parameters */ - + offered = 0; rpcbuf_init(&buffer, offered, mem_ctx); + make_spoolss_q_enumports( &in, server, level, &buffer, offered ); - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - make_spoolss_q_enumports(&q, server, level, &buffer, offered); - - /* Marshall data and send request */ - - if (!spoolss_io_q_enumports("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_ENUMPORTS, &qbuf, &rbuf)) - goto done; - - /* Unmarshall response */ - - if (spoolss_io_r_enumports("", &r, &rbuf, 0)) { - if (needed) - *needed = r.needed; - } + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENUMPORTS, + in, out, + qbuf, rbuf, + spoolss_io_q_enumports, + spoolss_io_r_enumports, + WERR_GENERAL_FAILURE ); + + if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) { + offered = out.needed; - result = r.status; - - /* Return output parameters */ - - if (!W_ERROR_IS_OK(result)) - goto done; - - if (num_ports) - *num_ports = r.returned; - - if (!ctr) - goto done; + ZERO_STRUCT(in); + ZERO_STRUCT(out); + + rpcbuf_init(&buffer, offered, mem_ctx); + make_spoolss_q_enumports( &in, server, level, &buffer, offered ); + + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENUMPORTS, + in, out, + qbuf, rbuf, + spoolss_io_q_enumports, + spoolss_io_r_enumports, + WERR_GENERAL_FAILURE ); + } + + if ( !W_ERROR_IS_OK(out.status) ) + return out.status; switch (level) { case 1: - decode_port_info_1(mem_ctx, r.buffer, r.returned, - &ctr->port.info_1); + decode_port_info_1(mem_ctx, out.buffer, out.returned, &ctr->port.info_1); break; case 2: - decode_port_info_2(mem_ctx, r.buffer, r.returned, - &ctr->port.info_2); + decode_port_info_2(mem_ctx, out.buffer, out.returned, &ctr->port.info_2); break; } - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); - - return result; + *num_ports = out.returned; + + return out.status; } -/********************************************************************************* - Win32 API - GetPrinter() - ********************************************************************************/ +/********************************************************************** +**********************************************************************/ WERROR cli_spoolss_getprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx, - uint32 offered, uint32 *needed, POLICY_HND *pol, uint32 level, PRINTER_INFO_CTR *ctr) { prs_struct qbuf, rbuf; - SPOOL_Q_GETPRINTER q; - SPOOL_R_GETPRINTER r; + SPOOL_Q_GETPRINTER in; + SPOOL_R_GETPRINTER out; RPC_BUFFER buffer; - WERROR result = W_ERROR(ERRgeneral); + uint32 offered; - ZERO_STRUCT(q); - ZERO_STRUCT(r); + ZERO_STRUCT(in); + ZERO_STRUCT(out); /* Initialise input parameters */ + offered = 0; rpcbuf_init(&buffer, offered, mem_ctx); + make_spoolss_q_getprinter( mem_ctx, &in, pol, level, &buffer, offered ); - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - make_spoolss_q_getprinter(mem_ctx, &q, pol, level, &buffer, offered); - - /* Marshall data and send request */ - - if (!spoolss_io_q_getprinter("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_GETPRINTER, &qbuf, &rbuf)) - goto done; - - /* Unmarshall response */ - - if (!spoolss_io_r_getprinter("", &r, &rbuf, 0)) - goto done; - - if (needed) - *needed = r.needed; - - /* Return output parameters */ - - result = r.status; - - if (W_ERROR_IS_OK(result)) { - switch (level) { - case 0: - decode_printer_info_0(mem_ctx, r.buffer, 1, &ctr->printers_0); - break; - case 1: - decode_printer_info_1(mem_ctx, r.buffer, 1, &ctr->printers_1); - break; - case 2: - decode_printer_info_2(mem_ctx, r.buffer, 1, &ctr->printers_2); - break; - case 3: - decode_printer_info_3(mem_ctx, r.buffer, 1, &ctr->printers_3); - break; - case 7: - decode_printer_info_7(mem_ctx, r.buffer, 1, &ctr->printers_7); - break; - } + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETPRINTER, + in, out, + qbuf, rbuf, + spoolss_io_q_getprinter, + spoolss_io_r_getprinter, + WERR_GENERAL_FAILURE ); + + if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) { + offered = out.needed; + + ZERO_STRUCT(in); + ZERO_STRUCT(out); + + rpcbuf_init(&buffer, offered, mem_ctx); + make_spoolss_q_getprinter( mem_ctx, &in, pol, level, &buffer, offered ); + + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETPRINTER, + in, out, + qbuf, rbuf, + spoolss_io_q_getprinter, + spoolss_io_r_getprinter, + WERR_GENERAL_FAILURE ); } - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); + if ( !W_ERROR_IS_OK(out.status) ) + return out.status; + + switch (level) { + case 0: + decode_printer_info_0(mem_ctx, out.buffer, 1, &ctr->printers_0); + break; + case 1: + decode_printer_info_1(mem_ctx, out.buffer, 1, &ctr->printers_1); + break; + case 2: + decode_printer_info_2(mem_ctx, out.buffer, 1, &ctr->printers_2); + break; + case 3: + decode_printer_info_3(mem_ctx, out.buffer, 1, &ctr->printers_3); + break; + case 7: + decode_printer_info_7(mem_ctx, out.buffer, 1, &ctr->printers_7); + break; + } - return result; + return out.status; } -/********************************************************************************* - Win32 API - SetPrinter() - ********************************************************************************/ -/** Set printer info - * - * @param cli Pointer to client state structure which is open - * on the SPOOLSS pipe. - * @param mem_ctx Pointer to an initialised talloc context. - * - * @param pol Policy handle on printer to set info. - * @param level Information level to set. - * @param ctr Pointer to structure holding printer information. - * @param command Specifies the action performed. See - * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/prntspol_13ua.asp - * for details. - * - */ +/********************************************************************** +**********************************************************************/ WERROR cli_spoolss_setprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx, POLICY_HND *pol, uint32 level, PRINTER_INFO_CTR *ctr, uint32 command) { prs_struct qbuf, rbuf; - SPOOL_Q_SETPRINTER q; - SPOOL_R_SETPRINTER r; - WERROR result = W_ERROR(ERRgeneral); - - ZERO_STRUCT(q); - ZERO_STRUCT(r); - - /* Initialise input parameters */ - - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - if (!make_spoolss_q_setprinter(mem_ctx, &q, pol, level, ctr, command)) - goto done; - - /* Marshall data and send request */ - - if (!spoolss_io_q_setprinter("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_SETPRINTER, &qbuf, &rbuf)) - goto done; + SPOOL_Q_SETPRINTER in; + SPOOL_R_SETPRINTER out; - /* Unmarshall response */ + ZERO_STRUCT(in); + ZERO_STRUCT(out); - if (!spoolss_io_r_setprinter("", &r, &rbuf, 0)) - goto done; - - result = r.status; + make_spoolss_q_setprinter( mem_ctx, &in, pol, level, ctr, command ); -done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_SETPRINTER, + in, out, + qbuf, rbuf, + spoolss_io_q_setprinter, + spoolss_io_r_setprinter, + WERR_GENERAL_FAILURE ); - return result; + return out.status; } -/********************************************************************************* - Win32 API - GetPrinterDriver() - ********************************************************************************/ -/** Get installed printer drivers for a given printer - * - * @param cli Pointer to client state structure which is open - * on the SPOOLSS pipe. - * - * @param mem_ctx Pointer to an initialised talloc context. - * - * @param offered Buffer size offered in the request. - * @param needed Number of bytes needed to complete the request. - * may be NULL. - * - * @param pol Pointer to an open policy handle for the printer - * opened with cli_spoolss_open_printer_ex(). - * @param level Requested information level. - * @param env The print environment or archictecture. This is - * "Windows NT x86" for NT4. - * @param ctr Returned printer driver information. - */ +/********************************************************************** +**********************************************************************/ WERROR cli_spoolss_getprinterdriver(struct cli_state *cli, TALLOC_CTX *mem_ctx, - uint32 offered, uint32 *needed, POLICY_HND *pol, uint32 level, const char *env, int version, PRINTER_DRIVER_CTR *ctr) { prs_struct qbuf, rbuf; - SPOOL_Q_GETPRINTERDRIVER2 q; - SPOOL_R_GETPRINTERDRIVER2 r; + SPOOL_Q_GETPRINTERDRIVER2 in; + SPOOL_R_GETPRINTERDRIVER2 out; RPC_BUFFER buffer; - WERROR result = W_ERROR(ERRgeneral); fstring server; + uint32 offered; - ZERO_STRUCT(q); - ZERO_STRUCT(r); + ZERO_STRUCT(in); + ZERO_STRUCT(out); fstrcpy(server, cli->desthost); strupper_m(server); - /* Initialise input parameters */ - + offered = 0; rpcbuf_init(&buffer, offered, mem_ctx); - - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - make_spoolss_q_getprinterdriver2(&q, pol, env, level, version, 2, - &buffer, offered); - - /* Marshall data and send request */ - - if (!spoolss_io_q_getprinterdriver2 ("", &q, &qbuf, 0) || - !rpc_api_pipe_req (cli, PI_SPOOLSS, SPOOLSS_GETPRINTERDRIVER2, &qbuf, &rbuf)) - goto done; - - /* Unmarshall response */ - - if (spoolss_io_r_getprinterdriver2 ("", &r, &rbuf, 0)) { - if (needed) - *needed = r.needed; + make_spoolss_q_getprinterdriver2( &in, pol, env, level, + version, 2, &buffer, offered); + + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETPRINTERDRIVER2, + in, out, + qbuf, rbuf, + spoolss_io_q_getprinterdriver2, + spoolss_io_r_getprinterdriver2, + WERR_GENERAL_FAILURE ); + + if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) { + offered = out.needed; + + ZERO_STRUCT(in); + ZERO_STRUCT(out); + + rpcbuf_init(&buffer, offered, mem_ctx); + make_spoolss_q_getprinterdriver2( &in, pol, env, level, + version, 2, &buffer, offered); + + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETPRINTERDRIVER2, + in, out, + qbuf, rbuf, + spoolss_io_q_getprinterdriver2, + spoolss_io_r_getprinterdriver2, + WERR_GENERAL_FAILURE ); } - - result = r.status; - - /* Return output parameters */ - - if (!W_ERROR_IS_OK(result)) - goto done; - - if (!ctr) - goto done; + + if ( !W_ERROR_IS_OK(out.status) ) + return out.status; switch (level) { case 1: - decode_printer_driver_1(mem_ctx, r.buffer, 1, &ctr->info1); + decode_printer_driver_1(mem_ctx, out.buffer, 1, &ctr->info1); break; case 2: - decode_printer_driver_2(mem_ctx, r.buffer, 1, &ctr->info2); + decode_printer_driver_2(mem_ctx, out.buffer, 1, &ctr->info2); break; case 3: - decode_printer_driver_3(mem_ctx, r.buffer, 1, &ctr->info3); + decode_printer_driver_3(mem_ctx, out.buffer, 1, &ctr->info3); break; - default: - DEBUG(10, ("cli_spoolss_getprinterdriver: unknown info level %d", level)); - return WERR_UNKNOWN_LEVEL; } - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); - - return result; + return out.status; } -/********************************************************************************* - Win32 API - EnumPrinterDrivers() - ********************************************************************************/ /********************************************************************** - * Get installed printer drivers for a given printer - */ +**********************************************************************/ + WERROR cli_spoolss_enumprinterdrivers (struct cli_state *cli, TALLOC_CTX *mem_ctx, - uint32 offered, uint32 *needed, uint32 level, const char *env, uint32 *num_drivers, PRINTER_DRIVER_CTR *ctr) { prs_struct qbuf, rbuf; - SPOOL_Q_ENUMPRINTERDRIVERS q; - SPOOL_R_ENUMPRINTERDRIVERS r; + SPOOL_Q_ENUMPRINTERDRIVERS in; + SPOOL_R_ENUMPRINTERDRIVERS out; RPC_BUFFER buffer; - WERROR result = W_ERROR(ERRgeneral); fstring server; + uint32 offered; - ZERO_STRUCT(q); - ZERO_STRUCT(r); + ZERO_STRUCT(in); + ZERO_STRUCT(out); slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost); strupper_m(server); - /* Initialise input parameters */ - + offered = 0; rpcbuf_init(&buffer, offered, mem_ctx); - - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - /* Write the request */ - - make_spoolss_q_enumprinterdrivers(&q, server, env, level, &buffer, - offered); + make_spoolss_q_enumprinterdrivers( &in, server, env, level, + &buffer, offered); + + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENUMPRINTERDRIVERS, + in, out, + qbuf, rbuf, + spoolss_io_q_enumprinterdrivers, + spoolss_io_r_enumprinterdrivers, + WERR_GENERAL_FAILURE ); + + if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) { + offered = out.needed; + + ZERO_STRUCT(in); + ZERO_STRUCT(out); + + rpcbuf_init(&buffer, offered, mem_ctx); + make_spoolss_q_enumprinterdrivers( &in, server, env, level, + &buffer, offered); - /* Marshall data and send request */ + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENUMPRINTERDRIVERS, + in, out, + qbuf, rbuf, + spoolss_io_q_enumprinterdrivers, + spoolss_io_r_enumprinterdrivers, + WERR_GENERAL_FAILURE ); + } - if (!spoolss_io_q_enumprinterdrivers ("", &q, &qbuf, 0) || - !rpc_api_pipe_req (cli, PI_SPOOLSS, SPOOLSS_ENUMPRINTERDRIVERS, &qbuf, &rbuf)) - goto done; - - /* Unmarshall response */ - - if (!spoolss_io_r_enumprinterdrivers ("", &r, &rbuf, 0)) - goto done; - - if (needed) - *needed = r.needed; - - if (num_drivers) - *num_drivers = r.returned; + *num_drivers = out.returned; - result = r.status; - - /* Return output parameters */ - - if (W_ERROR_IS_OK(result) && (r.returned != 0)) { - *num_drivers = r.returned; + if ( !W_ERROR_IS_OK(out.status) ) + return out.status; + + if ( out.returned ) { switch (level) { case 1: - decode_printer_driver_1(mem_ctx, r.buffer, r.returned, &ctr->info1); + decode_printer_driver_1(mem_ctx, out.buffer, out.returned, &ctr->info1); break; case 2: - decode_printer_driver_2(mem_ctx, r.buffer, r.returned, &ctr->info2); + decode_printer_driver_2(mem_ctx, out.buffer, out.returned, &ctr->info2); break; case 3: - decode_printer_driver_3(mem_ctx, r.buffer, r.returned, &ctr->info3); + decode_printer_driver_3(mem_ctx, out.buffer, out.returned, &ctr->info3); break; - default: - DEBUG(10, ("cli_spoolss_enumprinterdrivers: unknown info level %d\n", - level)); - return WERR_UNKNOWN_LEVEL; } } - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); - - return result; + return out.status; } -/********************************************************************************* - Win32 API - GetPrinterDriverDirectory() - ********************************************************************************/ /********************************************************************** - * Get installed printer drivers for a given printer - */ +**********************************************************************/ + WERROR cli_spoolss_getprinterdriverdir (struct cli_state *cli, TALLOC_CTX *mem_ctx, - uint32 offered, uint32 *needed, uint32 level, char *env, DRIVER_DIRECTORY_CTR *ctr) { - prs_struct qbuf, rbuf; - SPOOL_Q_GETPRINTERDRIVERDIR q; - SPOOL_R_GETPRINTERDRIVERDIR r; - RPC_BUFFER buffer; - WERROR result = W_ERROR(ERRgeneral); - fstring server; + prs_struct qbuf, rbuf; + SPOOL_Q_GETPRINTERDRIVERDIR in; + SPOOL_R_GETPRINTERDRIVERDIR out; + RPC_BUFFER buffer; + fstring server; + uint32 offered; - ZERO_STRUCT(q); - ZERO_STRUCT(r); + ZERO_STRUCT(in); + ZERO_STRUCT(out); slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost); strupper_m(server); - /* Initialise input parameters */ - + offered = 0; rpcbuf_init(&buffer, offered, mem_ctx); - - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - /* Write the request */ - - make_spoolss_q_getprinterdriverdir(&q, server, env, level, &buffer, - offered); - - /* Marshall data and send request */ - - if (!spoolss_io_q_getprinterdriverdir ("", &q, &qbuf, 0) || - !rpc_api_pipe_req (cli, PI_SPOOLSS, SPOOLSS_GETPRINTERDRIVERDIRECTORY, - &qbuf, &rbuf)) - goto done; - - /* Unmarshall response */ - - if (spoolss_io_r_getprinterdriverdir ("", &r, &rbuf, 0)) { - if (needed) - *needed = r.needed; - } + make_spoolss_q_getprinterdriverdir( &in, server, env, level, + &buffer, offered ); + + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETPRINTERDRIVERDIRECTORY, + in, out, + qbuf, rbuf, + spoolss_io_q_getprinterdriverdir, + spoolss_io_r_getprinterdriverdir, + WERR_GENERAL_FAILURE ); + + if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) { + offered = out.needed; - /* Return output parameters */ - - result = r.status; - - if (W_ERROR_IS_OK(result)) { - switch (level) { - case 1: - decode_printerdriverdir_1(mem_ctx, r.buffer, 1, - &ctr->info1); - break; - } + ZERO_STRUCT(in); + ZERO_STRUCT(out); + + rpcbuf_init(&buffer, offered, mem_ctx); + make_spoolss_q_getprinterdriverdir( &in, server, env, level, + &buffer, offered ); + + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETPRINTERDRIVERDIRECTORY, + in, out, + qbuf, rbuf, + spoolss_io_q_getprinterdriverdir, + spoolss_io_r_getprinterdriverdir, + WERR_GENERAL_FAILURE ); } + + if (!W_ERROR_IS_OK(out.status)) + return out.status; - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); + decode_printerdriverdir_1(mem_ctx, out.buffer, 1, &ctr->info1); - return result; + return out.status; } -/********************************************************************************* - Win32 API - AddPrinterDriver() - ********************************************************************************/ /********************************************************************** - * Install a printer driver - */ +**********************************************************************/ + WERROR cli_spoolss_addprinterdriver (struct cli_state *cli, TALLOC_CTX *mem_ctx, uint32 level, PRINTER_DRIVER_CTR *ctr) { - prs_struct qbuf, rbuf; - SPOOL_Q_ADDPRINTERDRIVER q; - SPOOL_R_ADDPRINTERDRIVER r; - WERROR result = W_ERROR(ERRgeneral); - fstring server; - - ZERO_STRUCT(q); - ZERO_STRUCT(r); + prs_struct qbuf, rbuf; + SPOOL_Q_ADDPRINTERDRIVER in; + SPOOL_R_ADDPRINTERDRIVER out; + fstring server; + + ZERO_STRUCT(in); + ZERO_STRUCT(out); slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost); strupper_m(server); - /* Initialise input parameters */ - - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - /* Write the request */ - - make_spoolss_q_addprinterdriver (mem_ctx, &q, server, level, ctr); - - /* Marshall data and send request */ - - if (!spoolss_io_q_addprinterdriver ("", &q, &qbuf, 0) || - !rpc_api_pipe_req (cli, PI_SPOOLSS, SPOOLSS_ADDPRINTERDRIVER, &qbuf, &rbuf)) - goto done; + make_spoolss_q_addprinterdriver( mem_ctx, &in, server, level, ctr ); - /* Unmarshall response */ + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ADDPRINTERDRIVER, + in, out, + qbuf, rbuf, + spoolss_io_q_addprinterdriver, + spoolss_io_r_addprinterdriver, + WERR_GENERAL_FAILURE ); - if (!spoolss_io_r_addprinterdriver ("", &r, &rbuf, 0)) - goto done; - - /* Return output parameters */ - - result = r.status; - -done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); - - return result; + return out.status; } -/********************************************************************************* - Win32 API - AddPrinter() - ********************************************************************************/ /********************************************************************** - * Install a printer - */ +**********************************************************************/ + WERROR cli_spoolss_addprinterex (struct cli_state *cli, TALLOC_CTX *mem_ctx, uint32 level, PRINTER_INFO_CTR*ctr) { - prs_struct qbuf, rbuf; - SPOOL_Q_ADDPRINTEREX q; - SPOOL_R_ADDPRINTEREX r; - WERROR result = W_ERROR(ERRgeneral); - fstring server, - client, - user; - - ZERO_STRUCT(q); - ZERO_STRUCT(r); + prs_struct qbuf, rbuf; + SPOOL_Q_ADDPRINTEREX in; + SPOOL_R_ADDPRINTEREX out; + fstring server, client, user; + ZERO_STRUCT(in); + ZERO_STRUCT(out); + slprintf(client, sizeof(fstring)-1, "\\\\%s", cli->desthost); - strupper_m(client); slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost); + + strupper_m(client); strupper_m(server); - fstrcpy (user, cli->user_name); - - /* Initialise input parameters */ - - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - /* Write the request */ - - make_spoolss_q_addprinterex (mem_ctx, &q, server, client, user, - level, ctr); - - /* Marshall data and send request */ - - if (!spoolss_io_q_addprinterex ("", &q, &qbuf, 0) || - !rpc_api_pipe_req (cli, PI_SPOOLSS, SPOOLSS_ADDPRINTEREX, &qbuf, &rbuf)) - goto done; - - /* Unmarshall response */ - if (!spoolss_io_r_addprinterex ("", &r, &rbuf, 0)) - goto done; - - /* Return output parameters */ + fstrcpy (user, cli->user_name); - result = r.status; + make_spoolss_q_addprinterex( mem_ctx, &in, server, client, + user, level, ctr); - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ADDPRINTEREX, + in, out, + qbuf, rbuf, + spoolss_io_q_addprinterex, + spoolss_io_r_addprinterex, + WERR_GENERAL_FAILURE ); - return result; + return out.status; } /********************************************************************** - * Delete a Printer Driver from the server (DOES remove - * the driver files) - */ +**********************************************************************/ + WERROR cli_spoolss_deleteprinterdriverex(struct cli_state *cli, TALLOC_CTX *mem_ctx, const char *arch, const char *driver, int version) { - prs_struct qbuf, rbuf; - SPOOL_Q_DELETEPRINTERDRIVEREX q; - SPOOL_R_DELETEPRINTERDRIVEREX r; - WERROR result = W_ERROR(ERRgeneral); - fstring server; - - ZERO_STRUCT(q); - ZERO_STRUCT(r); + prs_struct qbuf, rbuf; + SPOOL_Q_DELETEPRINTERDRIVEREX in; + SPOOL_R_DELETEPRINTERDRIVEREX out; + fstring server; - - /* Initialise input parameters */ - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); + ZERO_STRUCT(in); + ZERO_STRUCT(out); slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost); strupper_m(server); - /* Write the request */ - make_spoolss_q_deleteprinterdriverex(mem_ctx, &q, server, arch, driver, version); - - /* Marshall data and send request */ + make_spoolss_q_deleteprinterdriverex( mem_ctx, &in, server, arch, driver, version ); - if (!spoolss_io_q_deleteprinterdriverex ("", &q, &qbuf, 0) - || !rpc_api_pipe_req (cli, PI_SPOOLSS, SPOOLSS_DELETEPRINTERDRIVEREX , &qbuf, &rbuf)) - { - goto done; - } - - /* Unmarshall response */ - - if (!spoolss_io_r_deleteprinterdriverex ("", &r, &rbuf, 0)) - goto done; - - /* Return output parameters */ - - result = r.status; - -done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); - - return result; + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_DELETEPRINTERDRIVEREX, + in, out, + qbuf, rbuf, + spoolss_io_q_deleteprinterdriverex, + spoolss_io_r_deleteprinterdriverex, + WERR_GENERAL_FAILURE ); + + return out.status; } -/********************************************************************************* - Win32 API - DeltePrinterDriver() - ********************************************************************************/ /********************************************************************** - * Delete a Printer Driver from the server (does not remove - * the driver files - */ +**********************************************************************/ + WERROR cli_spoolss_deleteprinterdriver (struct cli_state *cli, TALLOC_CTX *mem_ctx, const char *arch, const char *driver) { - prs_struct qbuf, rbuf; - SPOOL_Q_DELETEPRINTERDRIVER q; - SPOOL_R_DELETEPRINTERDRIVER r; - WERROR result = W_ERROR(ERRgeneral); - fstring server; - - ZERO_STRUCT(q); - ZERO_STRUCT(r); - + prs_struct qbuf, rbuf; + SPOOL_Q_DELETEPRINTERDRIVER in; + SPOOL_R_DELETEPRINTERDRIVER out; + fstring server; - /* Initialise input parameters */ - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); + ZERO_STRUCT(in); + ZERO_STRUCT(out); slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost); strupper_m(server); - /* Write the request */ - - make_spoolss_q_deleteprinterdriver(mem_ctx, &q, server, arch, driver); - - /* Marshall data and send request */ - - if (!spoolss_io_q_deleteprinterdriver ("", &q, &qbuf, 0) || - !rpc_api_pipe_req (cli, PI_SPOOLSS, SPOOLSS_DELETEPRINTERDRIVER , &qbuf, &rbuf)) - goto done; - - /* Unmarshall response */ - - if (!spoolss_io_r_deleteprinterdriver ("", &r, &rbuf, 0)) - goto done; - - /* Return output parameters */ - - result = r.status; - - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); + make_spoolss_q_deleteprinterdriver( mem_ctx, &in, server, arch, driver ); - return result; + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_DELETEPRINTERDRIVER, + in, out, + qbuf, rbuf, + spoolss_io_q_deleteprinterdriver, + spoolss_io_r_deleteprinterdriver, + WERR_GENERAL_FAILURE ); + + return out.status; } -/********************************************************************************* - Win32 API - GetPrinterProcessorDirectory() - ********************************************************************************/ +/********************************************************************** +**********************************************************************/ WERROR cli_spoolss_getprintprocessordirectory(struct cli_state *cli, TALLOC_CTX *mem_ctx, - uint32 offered, uint32 *needed, char *name, char *environment, fstring procdir) { prs_struct qbuf, rbuf; - SPOOL_Q_GETPRINTPROCESSORDIRECTORY q; - SPOOL_R_GETPRINTPROCESSORDIRECTORY r; + SPOOL_Q_GETPRINTPROCESSORDIRECTORY in; + SPOOL_R_GETPRINTPROCESSORDIRECTORY out; int level = 1; - WERROR result = W_ERROR(ERRgeneral); RPC_BUFFER buffer; + uint32 offered; - ZERO_STRUCT(q); - ZERO_STRUCT(r); - - /* Initialise parse structures */ - - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - /* Initialise input parameters */ + ZERO_STRUCT(in); + ZERO_STRUCT(out); + offered = 0; rpcbuf_init(&buffer, offered, mem_ctx); - - make_spoolss_q_getprintprocessordirectory( - &q, name, environment, level, &buffer, offered); - - /* Marshall data and send request */ - - if (!spoolss_io_q_getprintprocessordirectory("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_GETPRINTPROCESSORDIRECTORY, - &qbuf, &rbuf)) - goto done; + make_spoolss_q_getprintprocessordirectory( &in, name, + environment, level, &buffer, offered ); + + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETPRINTPROCESSORDIRECTORY, + in, out, + qbuf, rbuf, + spoolss_io_q_getprintprocessordirectory, + spoolss_io_r_getprintprocessordirectory, + WERR_GENERAL_FAILURE ); + + if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) { + offered = out.needed; - /* Unmarshall response */ + ZERO_STRUCT(in); + ZERO_STRUCT(out); - if (!spoolss_io_r_getprintprocessordirectory("", &r, &rbuf, 0)) - goto done; - - /* Return output parameters */ - - result = r.status; - - if (needed) - *needed = r.needed; - - if (W_ERROR_IS_OK(result)) - fstrcpy(procdir, "Not implemented!"); - - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); - - return result; + rpcbuf_init(&buffer, offered, mem_ctx); + make_spoolss_q_getprintprocessordirectory( &in, name, + environment, level, &buffer, offered ); + + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETPRINTPROCESSORDIRECTORY, + in, out, + qbuf, rbuf, + spoolss_io_q_getprintprocessordirectory, + spoolss_io_r_getprintprocessordirectory, + WERR_GENERAL_FAILURE ); + } + + if ( !W_ERROR_IS_OK(out.status) ) + return out.status; + + fstrcpy(procdir, "Not implemented!"); + + return out.status; } -/** Add a form to a printer. - * - * @param cli Pointer to client state structure which is open - * on the SPOOLSS pipe. - * @param mem_ctx Pointer to an initialised talloc context. - * - * @param handle Policy handle opened with cli_spoolss_open_printer_ex - * or cli_spoolss_addprinterex. - * @param level Form info level to add - should always be 1. - * @param form A pointer to the form to be added. - * - */ +/********************************************************************** +**********************************************************************/ WERROR cli_spoolss_addform(struct cli_state *cli, TALLOC_CTX *mem_ctx, POLICY_HND *handle, uint32 level, FORM *form) { prs_struct qbuf, rbuf; - SPOOL_Q_ADDFORM q; - SPOOL_R_ADDFORM r; - WERROR result = W_ERROR(ERRgeneral); + SPOOL_Q_ADDFORM in; + SPOOL_R_ADDFORM out; - ZERO_STRUCT(q); - ZERO_STRUCT(r); + ZERO_STRUCT(in); + ZERO_STRUCT(out); - /* Initialise parse structures */ - - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - /* Initialise input parameters */ - - make_spoolss_q_addform(&q, handle, level, form); + make_spoolss_q_addform( &in, handle, level, form ); - /* Marshall data and send request */ - - if (!spoolss_io_q_addform("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_ADDFORM, &qbuf, &rbuf)) - goto done; - - /* Unmarshall response */ - - if (!spoolss_io_r_addform("", &r, &rbuf, 0)) - goto done; - - /* Return output parameters */ - - result = r.status; - - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); - - return result; + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ADDFORM, + in, out, + qbuf, rbuf, + spoolss_io_q_addform, + spoolss_io_r_addform, + WERR_GENERAL_FAILURE ); + + return out.status; } -/** Set a form on a printer. - * - * @param cli Pointer to client state structure which is open - * on the SPOOLSS pipe. - * @param mem_ctx Pointer to an initialised talloc context. - * - * @param handle Policy handle opened with cli_spoolss_open_printer_ex - * or cli_spoolss_addprinterex. - * @param level Form info level to set - should always be 1. - * @param form A pointer to the form to be set. - * - */ +/********************************************************************** +**********************************************************************/ WERROR cli_spoolss_setform(struct cli_state *cli, TALLOC_CTX *mem_ctx, POLICY_HND *handle, uint32 level, const char *form_name, FORM *form) { prs_struct qbuf, rbuf; - SPOOL_Q_SETFORM q; - SPOOL_R_SETFORM r; - WERROR result = W_ERROR(ERRgeneral); + SPOOL_Q_SETFORM in; + SPOOL_R_SETFORM out; - ZERO_STRUCT(q); - ZERO_STRUCT(r); + ZERO_STRUCT(in); + ZERO_STRUCT(out); - /* Initialise parse structures */ - - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - /* Initialise input parameters */ - - make_spoolss_q_setform(&q, handle, level, form_name, form); + make_spoolss_q_setform( &in, handle, level, form_name, form ); - /* Marshall data and send request */ - - if (!spoolss_io_q_setform("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_SETFORM, &qbuf, &rbuf)) - goto done; - - /* Unmarshall response */ - - if (!spoolss_io_r_setform("", &r, &rbuf, 0)) - goto done; - - /* Return output parameters */ - - result = r.status; - - if (!W_ERROR_IS_OK(result)) - goto done; - - - - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); - - return result; + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_SETFORM, + in, out, + qbuf, rbuf, + spoolss_io_q_setform, + spoolss_io_r_setform, + WERR_GENERAL_FAILURE ); + + return out.status; } -/** Get a form on a printer. - * - * @param cli Pointer to client state structure which is open - * on the SPOOLSS pipe. - * @param mem_ctx Pointer to an initialised talloc context. - * - * @param handle Policy handle opened with cli_spoolss_open_printer_ex - * or cli_spoolss_addprinterex. - * @param formname Name of the form to get - * @param level Form info level to get - should always be 1. - * - */ +/********************************************************************** +**********************************************************************/ WERROR cli_spoolss_getform(struct cli_state *cli, TALLOC_CTX *mem_ctx, - uint32 offered, uint32 *needed, POLICY_HND *handle, const char *formname, uint32 level, FORM_1 *form) { prs_struct qbuf, rbuf; - SPOOL_Q_GETFORM q; - SPOOL_R_GETFORM r; - WERROR result = W_ERROR(ERRgeneral); + SPOOL_Q_GETFORM in; + SPOOL_R_GETFORM out; RPC_BUFFER buffer; + uint32 offered; - ZERO_STRUCT(q); - ZERO_STRUCT(r); - - /* Initialise parse structures */ + ZERO_STRUCT(in); + ZERO_STRUCT(out); + offered = 0; rpcbuf_init(&buffer, offered, mem_ctx); - - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - /* Initialise input parameters */ - - make_spoolss_q_getform(&q, handle, formname, level, &buffer, offered); + make_spoolss_q_getform( &in, handle, formname, level, &buffer, offered ); - /* Marshall data and send request */ - - if (!spoolss_io_q_getform("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_GETFORM, &qbuf, &rbuf)) - goto done; - - /* Unmarshall response */ - - if (!spoolss_io_r_getform("", &r, &rbuf, 0)) - goto done; - - /* Return output parameters */ - - result = r.status; - - if (needed) - *needed = r.needed; - - if (W_ERROR_IS_OK(result)) { - switch(level) { - case 1: - smb_io_form_1("", r.buffer, form, 0); - break; - default: - DEBUG(10, ("cli_spoolss_getform: unknown info level %d", level)); - return WERR_UNKNOWN_LEVEL; - } + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETFORM, + in, out, + qbuf, rbuf, + spoolss_io_q_getform, + spoolss_io_r_getform, + WERR_GENERAL_FAILURE ); + + if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) { + offered = out.needed; + + ZERO_STRUCT(in); + ZERO_STRUCT(out); + + rpcbuf_init(&buffer, offered, mem_ctx); + make_spoolss_q_getform( &in, handle, formname, level, &buffer, offered ); + + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETFORM, + in, out, + qbuf, rbuf, + spoolss_io_q_getform, + spoolss_io_r_getform, + WERR_GENERAL_FAILURE ); } + + if (!W_ERROR_IS_OK(out.status)) + return out.status; - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); + smb_io_form_1("", out.buffer, form, 0); - return result; + return out.status; } -/** Delete a form on a printer. - * - * @param cli Pointer to client state structure which is open - * on the SPOOLSS pipe. - * @param mem_ctx Pointer to an initialised talloc context. - * - * @param handle Policy handle opened with cli_spoolss_open_printer_ex - * or cli_spoolss_addprinterex. - * @param form The name of the form to delete. - * - */ +/********************************************************************** +**********************************************************************/ WERROR cli_spoolss_deleteform(struct cli_state *cli, TALLOC_CTX *mem_ctx, POLICY_HND *handle, const char *form_name) { prs_struct qbuf, rbuf; - SPOOL_Q_DELETEFORM q; - SPOOL_R_DELETEFORM r; - WERROR result = W_ERROR(ERRgeneral); - - ZERO_STRUCT(q); - ZERO_STRUCT(r); - - /* Initialise parse structures */ + SPOOL_Q_DELETEFORM in; + SPOOL_R_DELETEFORM out; - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); + ZERO_STRUCT(in); + ZERO_STRUCT(out); - /* Initialise input parameters */ - - make_spoolss_q_deleteform(&q, handle, form_name); + make_spoolss_q_deleteform( &in, handle, form_name ); - /* Marshall data and send request */ - - if (!spoolss_io_q_deleteform("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_DELETEFORM, &qbuf, &rbuf)) - goto done; - - /* Unmarshall response */ - - if (!spoolss_io_r_deleteform("", &r, &rbuf, 0)) - goto done; - - /* Return output parameters */ - - result = r.status; - - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); - - return result; + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_DELETEFORM, + in, out, + qbuf, rbuf, + spoolss_io_q_deleteform, + spoolss_io_r_deleteform, + WERR_GENERAL_FAILURE ); + + return out.status; } -static void decode_forms_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer, - uint32 num_forms, FORM_1 **forms) -{ - int i; - - *forms = TALLOC_ARRAY(mem_ctx, FORM_1, num_forms); - prs_set_offset(&buffer->prs,0); - - for (i = 0; i < num_forms; i++) - smb_io_form_1("", buffer, &((*forms)[i]), 0); -} - -/** Enumerate forms - * - * @param cli Pointer to client state structure which is open - * on the SPOOLSS pipe. - * @param mem_ctx Pointer to an initialised talloc context. - * - * @param offered Buffer size offered in the request. - * @param needed Number of bytes needed to complete the request. - * may be NULL. - * or cli_spoolss_addprinterex. - * @param level Form info level to get - should always be 1. - * @param handle Open policy handle - * - */ +/********************************************************************** +**********************************************************************/ WERROR cli_spoolss_enumforms(struct cli_state *cli, TALLOC_CTX *mem_ctx, - uint32 offered, uint32 *needed, POLICY_HND *handle, int level, uint32 *num_forms, FORM_1 **forms) { prs_struct qbuf, rbuf; - SPOOL_Q_ENUMFORMS q; - SPOOL_R_ENUMFORMS r; - WERROR result = W_ERROR(ERRgeneral); + SPOOL_Q_ENUMFORMS in; + SPOOL_R_ENUMFORMS out; RPC_BUFFER buffer; + uint32 offered; - ZERO_STRUCT(q); - ZERO_STRUCT(r); - - /* Initialise parse structures */ + ZERO_STRUCT(in); + ZERO_STRUCT(out); + offered = 0; rpcbuf_init(&buffer, offered, mem_ctx); + make_spoolss_q_enumforms( &in, handle, level, &buffer, offered ); - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - /* Initialise input parameters */ - - make_spoolss_q_enumforms(&q, handle, level, &buffer, offered); - - /* Marshall data and send request */ - - if (!spoolss_io_q_enumforms("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_ENUMFORMS, &qbuf, &rbuf)) - goto done; - - /* Unmarshall response */ - - if (!spoolss_io_r_enumforms("", &r, &rbuf, 0)) - goto done; - - /* Return output parameters */ - - result = r.status; - - if (needed) - *needed = r.needed; - - if (num_forms) - *num_forms = r.numofforms; + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENUMFORMS, + in, out, + qbuf, rbuf, + spoolss_io_q_enumforms, + spoolss_io_r_enumforms, + WERR_GENERAL_FAILURE ); - decode_forms_1(mem_ctx, r.buffer, *num_forms, forms); - - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); - - return result; -} - -static void decode_jobs_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer, - uint32 num_jobs, JOB_INFO_1 **jobs) -{ - uint32 i; - - *jobs = TALLOC_ARRAY(mem_ctx, JOB_INFO_1, num_jobs); - prs_set_offset(&buffer->prs,0); - - for (i = 0; i < num_jobs; i++) - smb_io_job_info_1("", buffer, &((*jobs)[i]), 0); -} + if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) { + offered = out.needed; + + ZERO_STRUCT(in); + ZERO_STRUCT(out); + + rpcbuf_init(&buffer, offered, mem_ctx); + make_spoolss_q_enumforms( &in, handle, level, &buffer, offered ); + + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENUMFORMS, + in, out, + qbuf, rbuf, + spoolss_io_q_enumforms, + spoolss_io_r_enumforms, + WERR_GENERAL_FAILURE ); + } -static void decode_jobs_2(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer, - uint32 num_jobs, JOB_INFO_2 **jobs) -{ - uint32 i; + if (!W_ERROR_IS_OK(out.status)) + return out.status; - *jobs = TALLOC_ARRAY(mem_ctx, JOB_INFO_2, num_jobs); - prs_set_offset(&buffer->prs,0); + *num_forms = out.numofforms; + + decode_forms_1(mem_ctx, out.buffer, *num_forms, forms); - for (i = 0; i < num_jobs; i++) - smb_io_job_info_2("", buffer, &((*jobs)[i]), 0); + return out.status; } -/* Enumerate jobs */ +/********************************************************************** +**********************************************************************/ WERROR cli_spoolss_enumjobs(struct cli_state *cli, TALLOC_CTX *mem_ctx, - uint32 offered, uint32 *needed, POLICY_HND *hnd, uint32 level, uint32 firstjob, uint32 num_jobs, uint32 *returned, JOB_INFO_CTR *ctr) { prs_struct qbuf, rbuf; - SPOOL_Q_ENUMJOBS q; - SPOOL_R_ENUMJOBS r; - WERROR result = W_ERROR(ERRgeneral); + SPOOL_Q_ENUMJOBS in; + SPOOL_R_ENUMJOBS out; RPC_BUFFER buffer; + uint32 offered; - ZERO_STRUCT(q); - ZERO_STRUCT(r); - - /* Initialise parse structures */ + ZERO_STRUCT(in); + ZERO_STRUCT(out); + offered = 0; rpcbuf_init(&buffer, offered, mem_ctx); + make_spoolss_q_enumjobs( &in, hnd, firstjob, num_jobs, level, + &buffer, offered ); + + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENUMJOBS, + in, out, + qbuf, rbuf, + spoolss_io_q_enumjobs, + spoolss_io_r_enumjobs, + WERR_GENERAL_FAILURE ); + + if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) { + offered = out.needed; + + ZERO_STRUCT(in); + ZERO_STRUCT(out); + + rpcbuf_init(&buffer, offered, mem_ctx); + make_spoolss_q_enumjobs( &in, hnd, firstjob, num_jobs, level, + &buffer, offered ); + + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENUMJOBS, + in, out, + qbuf, rbuf, + spoolss_io_q_enumjobs, + spoolss_io_r_enumjobs, + WERR_GENERAL_FAILURE ); + } - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - /* Initialise input parameters */ - - make_spoolss_q_enumjobs(&q, hnd, firstjob, num_jobs, level, &buffer, - offered); - - /* Marshall data and send request */ - - if (!spoolss_io_q_enumjobs("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_ENUMJOBS, &qbuf, &rbuf)) - goto done; - - /* Unmarshall response */ - - if (!spoolss_io_r_enumjobs("", &r, &rbuf, 0)) - goto done; - - /* Return output parameters */ - - result = r.status; - - if (needed) - *needed = r.needed; - - if (!W_ERROR_IS_OK(r.status)) - goto done; - - *returned = r.returned; - + if (!W_ERROR_IS_OK(out.status)) + return out.status; + switch(level) { case 1: - decode_jobs_1(mem_ctx, r.buffer, r.returned, - &ctr->job.job_info_1); + decode_jobs_1(mem_ctx, out.buffer, out.returned, &ctr->job.job_info_1); break; case 2: - decode_jobs_2(mem_ctx, r.buffer, r.returned, - &ctr->job.job_info_2); + decode_jobs_2(mem_ctx, out.buffer, out.returned, &ctr->job.job_info_2); break; default: DEBUG(3, ("unsupported info level %d", level)); break; } + + *returned = out.returned; - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); - - return result; + return out.status; } -/* Set job */ +/********************************************************************** +**********************************************************************/ WERROR cli_spoolss_setjob(struct cli_state *cli, TALLOC_CTX *mem_ctx, POLICY_HND *hnd, uint32 jobid, uint32 level, uint32 command) { prs_struct qbuf, rbuf; - SPOOL_Q_SETJOB q; - SPOOL_R_SETJOB r; - WERROR result = W_ERROR(ERRgeneral); - - ZERO_STRUCT(q); - ZERO_STRUCT(r); - - /* Initialise parse structures */ - - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - /* Initialise input parameters */ - - make_spoolss_q_setjob(&q, hnd, jobid, level, command); - - /* Marshall data and send request */ - - if (!spoolss_io_q_setjob("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_SETJOB, &qbuf, &rbuf)) - goto done; - - /* Unmarshall response */ - - if (!spoolss_io_r_setjob("", &r, &rbuf, 0)) - goto done; - - /* Return output parameters */ - - result = r.status; - - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); - - return result; + SPOOL_Q_SETJOB in; + SPOOL_R_SETJOB out; + + ZERO_STRUCT(in); + ZERO_STRUCT(out); + + make_spoolss_q_setjob( &in, hnd, jobid, level, command ); + + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_SETJOB, + in, out, + qbuf, rbuf, + spoolss_io_q_setjob, + spoolss_io_r_setjob, + WERR_GENERAL_FAILURE ); + + return out.status; } -/* Get job */ +/********************************************************************** +**********************************************************************/ WERROR cli_spoolss_getjob(struct cli_state *cli, TALLOC_CTX *mem_ctx, - uint32 offered, uint32 *needed, POLICY_HND *hnd, uint32 jobid, uint32 level, JOB_INFO_CTR *ctr) { prs_struct qbuf, rbuf; - SPOOL_Q_GETJOB q; - SPOOL_R_GETJOB r; - WERROR result = W_ERROR(ERRgeneral); + SPOOL_Q_GETJOB in; + SPOOL_R_GETJOB out; RPC_BUFFER buffer; + uint32 offered; - ZERO_STRUCT(q); - ZERO_STRUCT(r); - - /* Initialise parse structures */ + ZERO_STRUCT(in); + ZERO_STRUCT(out); + offered = 0; rpcbuf_init(&buffer, offered, mem_ctx); + make_spoolss_q_getjob( &in, hnd, jobid, level, &buffer, offered ); - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - /* Initialise input parameters */ - - make_spoolss_q_getjob(&q, hnd, jobid, level, &buffer, offered); - - /* Marshall data and send request */ - - if (!spoolss_io_q_getjob("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_GETJOB, &qbuf, &rbuf)) - goto done; - - /* Unmarshall response */ - - if (!spoolss_io_r_getjob("", &r, &rbuf, 0)) - goto done; + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETJOB, + in, out, + qbuf, rbuf, + spoolss_io_q_getjob, + spoolss_io_r_getjob, + WERR_GENERAL_FAILURE ); - /* Return output parameters */ - - result = r.status; - - if (needed) - *needed = r.needed; + if ( W_ERROR_EQUAL( out.status, WERR_MORE_DATA ) ) { + offered = out.needed; + + ZERO_STRUCT(in); + ZERO_STRUCT(out); + + rpcbuf_init(&buffer, offered, mem_ctx); + make_spoolss_q_getjob( &in, hnd, jobid, level, &buffer, offered ); + + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETJOB, + in, out, + qbuf, rbuf, + spoolss_io_q_getjob, + spoolss_io_r_getjob, + WERR_GENERAL_FAILURE ); + } - if (!W_ERROR_IS_OK(r.status)) - goto done; + if (!W_ERROR_IS_OK(out.status)) + return out.status; switch(level) { case 1: - decode_jobs_1(mem_ctx, r.buffer, 1, &ctr->job.job_info_1); + decode_jobs_1(mem_ctx, out.buffer, 1, &ctr->job.job_info_1); break; case 2: - decode_jobs_2(mem_ctx, r.buffer, 1, &ctr->job.job_info_2); - break; - default: - DEBUG(3, ("unsupported info level %d", level)); + decode_jobs_2(mem_ctx, out.buffer, 1, &ctr->job.job_info_2); break; } - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); - - return result; + return out.status; } -/* Startpageprinter. Sent to notify the spooler when a page is about to be - sent to a printer. */ +/********************************************************************** +**********************************************************************/ WERROR cli_spoolss_startpageprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx, POLICY_HND *hnd) { prs_struct qbuf, rbuf; - SPOOL_Q_STARTPAGEPRINTER q; - SPOOL_R_STARTPAGEPRINTER r; - WERROR result = W_ERROR(ERRgeneral); - - ZERO_STRUCT(q); - ZERO_STRUCT(r); - - /* Initialise parse structures */ - - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - /* Initialise input parameters */ - - make_spoolss_q_startpageprinter(&q, hnd); - - /* Marshall data and send request */ - - if (!spoolss_io_q_startpageprinter("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_STARTPAGEPRINTER, &qbuf, &rbuf)) - goto done; - - /* Unmarshall response */ - - if (!spoolss_io_r_startpageprinter("", &r, &rbuf, 0)) - goto done; - - /* Return output parameters */ - - result = r.status; - - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); - - return result; + SPOOL_Q_STARTPAGEPRINTER in; + SPOOL_R_STARTPAGEPRINTER out; + + ZERO_STRUCT(in); + ZERO_STRUCT(out); + + make_spoolss_q_startpageprinter( &in, hnd ); + + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_STARTPAGEPRINTER, + in, out, + qbuf, rbuf, + spoolss_io_q_startpageprinter, + spoolss_io_r_startpageprinter, + WERR_GENERAL_FAILURE ); + + return out.status; } -/* Endpageprinter. Sent to notify the spooler when a page has finished - being sent to a printer. */ +/********************************************************************** +**********************************************************************/ WERROR cli_spoolss_endpageprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx, POLICY_HND *hnd) { prs_struct qbuf, rbuf; - SPOOL_Q_ENDPAGEPRINTER q; - SPOOL_R_ENDPAGEPRINTER r; - WERROR result = W_ERROR(ERRgeneral); - - ZERO_STRUCT(q); - ZERO_STRUCT(r); - - /* Initialise parse structures */ - - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - /* Initialise input parameters */ - - make_spoolss_q_endpageprinter(&q, hnd); - - /* Marshall data and send request */ - - if (!spoolss_io_q_endpageprinter("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_ENDPAGEPRINTER, &qbuf, &rbuf)) - goto done; - - /* Unmarshall response */ - - if (!spoolss_io_r_endpageprinter("", &r, &rbuf, 0)) - goto done; - - /* Return output parameters */ - - result = r.status; - - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); - - return result; + SPOOL_Q_ENDPAGEPRINTER in; + SPOOL_R_ENDPAGEPRINTER out; + + ZERO_STRUCT(in); + ZERO_STRUCT(out); + + make_spoolss_q_endpageprinter( &in, hnd ); + + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENDPAGEPRINTER, + in, out, + qbuf, rbuf, + spoolss_io_q_endpageprinter, + spoolss_io_r_endpageprinter, + WERR_GENERAL_FAILURE ); + + return out.status; } -/* Startdocprinter. Sent to notify the spooler that a document is about - to be spooled for printing. */ +/********************************************************************** +**********************************************************************/ WERROR cli_spoolss_startdocprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx, POLICY_HND *hnd, char *docname, @@ -1871,298 +1356,214 @@ WERROR cli_spoolss_startdocprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx, uint32 *jobid) { prs_struct qbuf, rbuf; - SPOOL_Q_STARTDOCPRINTER q; - SPOOL_R_STARTDOCPRINTER r; - WERROR result = W_ERROR(ERRgeneral); + SPOOL_Q_STARTDOCPRINTER in; + SPOOL_R_STARTDOCPRINTER out; uint32 level = 1; - ZERO_STRUCT(q); - ZERO_STRUCT(r); - - /* Initialise parse structures */ - - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - /* Initialise input parameters */ - - make_spoolss_q_startdocprinter(&q, hnd, level, docname, outputfile, - datatype); - - /* Marshall data and send request */ - - if (!spoolss_io_q_startdocprinter("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_STARTDOCPRINTER, &qbuf, &rbuf)) - goto done; - - /* Unmarshall response */ - - if (!spoolss_io_r_startdocprinter("", &r, &rbuf, 0)) - goto done; + ZERO_STRUCT(in); + ZERO_STRUCT(out); - /* Return output parameters */ + make_spoolss_q_startdocprinter( &in, hnd, level, docname, + outputfile, datatype ); - result = r.status; - - if (W_ERROR_IS_OK(result)) - *jobid = r.jobid; + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_STARTDOCPRINTER, + in, out, + qbuf, rbuf, + spoolss_io_q_startdocprinter, + spoolss_io_r_startdocprinter, + WERR_GENERAL_FAILURE ); - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); + *jobid = out.jobid; - return result; + return out.status; } -/* Enddocprinter. Sent to notify the spooler that a document has finished - being spooled. */ +/********************************************************************** +**********************************************************************/ WERROR cli_spoolss_enddocprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx, POLICY_HND *hnd) { prs_struct qbuf, rbuf; - SPOOL_Q_ENDDOCPRINTER q; - SPOOL_R_ENDDOCPRINTER r; - WERROR result = W_ERROR(ERRgeneral); - - ZERO_STRUCT(q); - ZERO_STRUCT(r); - - /* Initialise parse structures */ - - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - /* Initialise input parameters */ - - make_spoolss_q_enddocprinter(&q, hnd); - - /* Marshall data and send request */ - - if (!spoolss_io_q_enddocprinter("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_ENDDOCPRINTER, &qbuf, &rbuf)) - goto done; - - /* Unmarshall response */ - - if (!spoolss_io_r_enddocprinter("", &r, &rbuf, 0)) - goto done; - - /* Return output parameters */ - - result = r.status; - - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); - - return result; + SPOOL_Q_ENDDOCPRINTER in; + SPOOL_R_ENDDOCPRINTER out; + + ZERO_STRUCT(in); + ZERO_STRUCT(out); + + make_spoolss_q_enddocprinter( &in, hnd ); + + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENDDOCPRINTER, + in, out, + qbuf, rbuf, + spoolss_io_q_enddocprinter, + spoolss_io_r_enddocprinter, + WERR_GENERAL_FAILURE ); + + return out.status; } -/* Get printer data */ +/********************************************************************** +**********************************************************************/ WERROR cli_spoolss_getprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx, - uint32 offered, uint32 *needed, POLICY_HND *hnd, const char *valuename, REGISTRY_VALUE *value) { prs_struct qbuf, rbuf; - SPOOL_Q_GETPRINTERDATA q; - SPOOL_R_GETPRINTERDATA r; - WERROR result = W_ERROR(ERRgeneral); - - ZERO_STRUCT(q); - ZERO_STRUCT(r); + SPOOL_Q_GETPRINTERDATA in; + SPOOL_R_GETPRINTERDATA out; + uint32 offered; - /* Initialise parse structures */ + ZERO_STRUCT(in); + ZERO_STRUCT(out); - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); + offered = 0; + make_spoolss_q_getprinterdata( &in, hnd, valuename, offered ); - /* Initialise input parameters */ + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETPRINTERDATA, + in, out, + qbuf, rbuf, + spoolss_io_q_getprinterdata, + spoolss_io_r_getprinterdata, + WERR_GENERAL_FAILURE ); - make_spoolss_q_getprinterdata(&q, hnd, valuename, offered); - - /* Marshall data and send request */ - - if (!spoolss_io_q_getprinterdata("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_GETPRINTERDATA, &qbuf, &rbuf)) - goto done; - - /* Unmarshall response */ - - if (!spoolss_io_r_getprinterdata("", &r, &rbuf, 0)) - goto done; - - result = r.status; - - if (needed) - *needed = r.needed; + if ( W_ERROR_EQUAL( out.status, WERR_MORE_DATA ) ) { + offered = out.needed; + + ZERO_STRUCT(in); + ZERO_STRUCT(out); + + make_spoolss_q_getprinterdata( &in, hnd, valuename, offered ); + + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETPRINTERDATA, + in, out, + qbuf, rbuf, + spoolss_io_q_getprinterdata, + spoolss_io_r_getprinterdata, + WERR_GENERAL_FAILURE ); + } - if (!W_ERROR_IS_OK(r.status)) - goto done; + if (!W_ERROR_IS_OK(out.status)) + return out.status; /* Return output parameters */ - value->data_p = TALLOC_MEMDUP(mem_ctx, r.data, r.needed); - value->type = r.type; - value->size = r.size; + value->data_p = TALLOC_MEMDUP(mem_ctx, out.data, out.needed); + value->type = out.type; + value->size = out.size; - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); - - return result; + return out.status; } +/********************************************************************** +**********************************************************************/ + WERROR cli_spoolss_getprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx, - uint32 offered, uint32 *needed, POLICY_HND *hnd, const char *keyname, const char *valuename, REGISTRY_VALUE *value) { prs_struct qbuf, rbuf; - SPOOL_Q_GETPRINTERDATAEX q; - SPOOL_R_GETPRINTERDATAEX r; - WERROR result = W_ERROR(ERRgeneral); - - ZERO_STRUCT(q); - ZERO_STRUCT(r); + SPOOL_Q_GETPRINTERDATAEX in; + SPOOL_R_GETPRINTERDATAEX out; + uint32 offered; - /* Initialise parse structures */ - - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - /* Initialise input parameters */ + ZERO_STRUCT(in); + ZERO_STRUCT(out); - make_spoolss_q_getprinterdataex(&q, hnd, keyname, valuename, offered); + make_spoolss_q_getprinterdataex( &in, hnd, keyname, valuename, offered ); - /* Marshall data and send request */ + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETPRINTERDATAEX, + in, out, + qbuf, rbuf, + spoolss_io_q_getprinterdataex, + spoolss_io_r_getprinterdataex, + WERR_GENERAL_FAILURE ); - if (!spoolss_io_q_getprinterdataex("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_GETPRINTERDATAEX, &qbuf, &rbuf)) - goto done; - - /* Unmarshall response */ - - if (!spoolss_io_r_getprinterdataex("", &r, &rbuf, 0)) - goto done; - - result = r.status; - - if (needed) - *needed = r.needed; + if ( W_ERROR_EQUAL( out.status, WERR_MORE_DATA ) ) { + offered = out.needed; + + ZERO_STRUCT(in); + ZERO_STRUCT(out); + + make_spoolss_q_getprinterdataex( &in, hnd, keyname, valuename, offered ); + + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETPRINTERDATAEX, + in, out, + qbuf, rbuf, + spoolss_io_q_getprinterdataex, + spoolss_io_r_getprinterdataex, + WERR_GENERAL_FAILURE ); + } - if (!W_ERROR_IS_OK(r.status)) - goto done; + if (!W_ERROR_IS_OK(out.status)) + return out.status; /* Return output parameters */ - value->data_p = TALLOC_MEMDUP(mem_ctx, r.data, r.needed); - value->type = r.type; - value->size = r.needed; - - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); - - return result; + value->data_p = TALLOC_MEMDUP(mem_ctx, out.data, out.needed); + value->type = out.type; + value->size = out.needed; + + return out.status; } -/* Set printer data */ +/********************************************************************** +**********************************************************************/ WERROR cli_spoolss_setprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx, POLICY_HND *hnd, REGISTRY_VALUE *value) { prs_struct qbuf, rbuf; - SPOOL_Q_SETPRINTERDATA q; - SPOOL_R_SETPRINTERDATA r; - WERROR result = W_ERROR(ERRgeneral); - - ZERO_STRUCT(q); - ZERO_STRUCT(r); - - /* Initialise parse structures */ - - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - /* Initialise input parameters */ - - make_spoolss_q_setprinterdata( - &q, hnd, value->valuename, value->type, (char *)value->data_p, value->size); - - /* Marshall data and send request */ - - if (!spoolss_io_q_setprinterdata("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_SETPRINTERDATA, &qbuf, &rbuf)) - goto done; - - /* Unmarshall response */ - - if (!spoolss_io_r_setprinterdata("", &r, &rbuf, 0)) - goto done; - - result = r.status; - - if (!W_ERROR_IS_OK(r.status)) - goto done; - - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); - - return result; + SPOOL_Q_SETPRINTERDATA in; + SPOOL_R_SETPRINTERDATA out; + + ZERO_STRUCT(in); + ZERO_STRUCT(out); + + make_spoolss_q_setprinterdata( &in, hnd, value->valuename, + value->type, (char *)value->data_p, value->size); + + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_SETPRINTERDATA, + in, out, + qbuf, rbuf, + spoolss_io_q_setprinterdata, + spoolss_io_r_setprinterdata, + WERR_GENERAL_FAILURE ); + + return out.status; } +/********************************************************************** +**********************************************************************/ + WERROR cli_spoolss_setprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx, POLICY_HND *hnd, char *keyname, REGISTRY_VALUE *value) { prs_struct qbuf, rbuf; - SPOOL_Q_SETPRINTERDATAEX q; - SPOOL_R_SETPRINTERDATAEX r; - WERROR result = W_ERROR(ERRgeneral); - - ZERO_STRUCT(q); - ZERO_STRUCT(r); - - /* Initialise parse structures */ - - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - /* Initialise input parameters */ - - make_spoolss_q_setprinterdataex( - &q, hnd, keyname, value->valuename, value->type, (char *)value->data_p, - value->size); - - /* Marshall data and send request */ - - if (!spoolss_io_q_setprinterdataex("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_SETPRINTERDATAEX, &qbuf, &rbuf)) - goto done; - - /* Unmarshall response */ - - if (!spoolss_io_r_setprinterdataex("", &r, &rbuf, 0)) - goto done; + SPOOL_Q_SETPRINTERDATAEX in; + SPOOL_R_SETPRINTERDATAEX out; - result = r.status; + ZERO_STRUCT(in); + ZERO_STRUCT(out); - if (!W_ERROR_IS_OK(r.status)) - goto done; + make_spoolss_q_setprinterdataex( &in, hnd, keyname, value->valuename, + value->type, (char *)value->data_p, value->size); - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_SETPRINTERDATAEX, + in, out, + qbuf, rbuf, + spoolss_io_q_setprinterdataex, + spoolss_io_r_setprinterdataex, + WERR_GENERAL_FAILURE ); - return result; + return out.status; } -/* Enum printer data */ +/********************************************************************** +**********************************************************************/ WERROR cli_spoolss_enumprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx, POLICY_HND *hnd, uint32 ndx, @@ -2171,109 +1572,87 @@ WERROR cli_spoolss_enumprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx, REGISTRY_VALUE *value) { prs_struct qbuf, rbuf; - SPOOL_Q_ENUMPRINTERDATA q; - SPOOL_R_ENUMPRINTERDATA r; - WERROR result = W_ERROR(ERRgeneral); - - ZERO_STRUCT(q); - ZERO_STRUCT(r); - - /* Initialise parse structures */ - - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - /* Initialise input parameters */ - - make_spoolss_q_enumprinterdata(&q, hnd, ndx, value_offered, data_offered); - - /* Marshall data and send request */ - - if (!spoolss_io_q_enumprinterdata("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_ENUMPRINTERDATA, &qbuf, &rbuf)) - goto done; - - /* Unmarshall response */ - - if (!spoolss_io_r_enumprinterdata("", &r, &rbuf, 0)) - goto done; - - result = r.status; - - if (!W_ERROR_IS_OK(r.status)) - goto done; - - /* Return data */ - - if (value_needed) - *value_needed = r.realvaluesize; - - if (data_needed) - *data_needed = r.realdatasize; + SPOOL_Q_ENUMPRINTERDATA in; + SPOOL_R_ENUMPRINTERDATA out; + + ZERO_STRUCT(in); + ZERO_STRUCT(out); + + make_spoolss_q_enumprinterdata( &in, hnd, ndx, value_offered, data_offered ); + + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENUMPRINTERDATA, + in, out, + qbuf, rbuf, + spoolss_io_q_enumprinterdata, + spoolss_io_r_enumprinterdata, + WERR_GENERAL_FAILURE ); + + *value_needed = out.realvaluesize; + *data_needed = out.realdatasize; + + if (!W_ERROR_IS_OK(out.status)) + return out.status; if (value) { - rpcstr_pull(value->valuename, r.value, sizeof(value->valuename), -1, + rpcstr_pull(value->valuename, out.value, sizeof(value->valuename), -1, STR_TERMINATE); - value->data_p = TALLOC_MEMDUP(mem_ctx, r.data, r.realdatasize); - value->type = r.type; - value->size = r.realdatasize; + value->data_p = TALLOC_MEMDUP(mem_ctx, out.data, out.realdatasize); + value->type = out.type; + value->size = out.realdatasize; } - - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); - - return result; + + return out.status; } +/********************************************************************** +**********************************************************************/ + WERROR cli_spoolss_enumprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx, - uint32 offered, uint32 *needed, POLICY_HND *hnd, const char *keyname, REGVAL_CTR *ctr) { prs_struct qbuf, rbuf; - SPOOL_Q_ENUMPRINTERDATAEX q; - SPOOL_R_ENUMPRINTERDATAEX r; - WERROR result = W_ERROR(ERRgeneral); + SPOOL_Q_ENUMPRINTERDATAEX in; + SPOOL_R_ENUMPRINTERDATAEX out; int i; + uint32 offered; - ZERO_STRUCT(q); - ZERO_STRUCT(r); - - /* Initialise parse structures */ - - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - /* Initialise input parameters */ - - make_spoolss_q_enumprinterdataex(&q, hnd, keyname, offered); - - /* Marshall data and send request */ + ZERO_STRUCT(in); + ZERO_STRUCT(out); - if (!spoolss_io_q_enumprinterdataex("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_ENUMPRINTERDATAEX, &qbuf, &rbuf)) - goto done; + offered = 0; + make_spoolss_q_enumprinterdataex( &in, hnd, keyname, offered ); - /* Unmarshall response */ + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENUMPRINTERDATAEX, + in, out, + qbuf, rbuf, + spoolss_io_q_enumprinterdataex, + spoolss_io_r_enumprinterdataex, + WERR_GENERAL_FAILURE ); - if (!spoolss_io_r_enumprinterdataex("", &r, &rbuf, 0)) - goto done; - - result = r.status; - - if (needed) - *needed = r.needed; + if ( W_ERROR_EQUAL( out.status, WERR_MORE_DATA ) ) { + offered = out.needed; + + ZERO_STRUCT(in); + ZERO_STRUCT(out); + + make_spoolss_q_enumprinterdataex( &in, hnd, keyname, offered ); + + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENUMPRINTERDATAEX, + in, out, + qbuf, rbuf, + spoolss_io_q_enumprinterdataex, + spoolss_io_r_enumprinterdataex, + WERR_GENERAL_FAILURE ); + } - if (!W_ERROR_IS_OK(r.status)) - goto done; - - /* Return data */ + if (!W_ERROR_IS_OK(out.status)) + return out.status; regval_ctr_init(ctr); - for (i = 0; i < r.returned; i++) { - PRINTER_ENUM_VALUES *v = &r.ctr.values[i]; + for (i = 0; i < out.returned; i++) { + PRINTER_ENUM_VALUES *v = &out.ctr.values[i]; fstring name; rpcstr_pull(name, v->valuename.buffer, sizeof(name), -1, @@ -2281,249 +1660,165 @@ WERROR cli_spoolss_enumprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx, regval_ctr_addvalue(ctr, name, v->type, (const char *)v->data, v->data_len); } - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); - - return result; + return out.status; } -/* Write data to printer */ +/********************************************************************** +**********************************************************************/ WERROR cli_spoolss_writeprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx, POLICY_HND *hnd, uint32 data_size, char *data, uint32 *num_written) { prs_struct qbuf, rbuf; - SPOOL_Q_WRITEPRINTER q; - SPOOL_R_WRITEPRINTER r; - WERROR result = W_ERROR(ERRgeneral); - - ZERO_STRUCT(q); - ZERO_STRUCT(r); - - /* Initialise parse structures */ - - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - /* Initialise input parameters */ + SPOOL_Q_WRITEPRINTER in; + SPOOL_R_WRITEPRINTER out; - make_spoolss_q_writeprinter(&q, hnd, data_size, data); + ZERO_STRUCT(in); + ZERO_STRUCT(out); - /* Marshall data and send request */ - - if (!spoolss_io_q_writeprinter("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_WRITEPRINTER, &qbuf, &rbuf)) - goto done; - - /* Unmarshall response */ - - if (!spoolss_io_r_writeprinter("", &r, &rbuf, 0)) - goto done; - - result = r.status; - - if (!W_ERROR_IS_OK(r.status)) - goto done; + make_spoolss_q_writeprinter( &in, hnd, data_size, data ); + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_WRITEPRINTER, + in, out, + qbuf, rbuf, + spoolss_io_q_writeprinter, + spoolss_io_r_writeprinter, + WERR_GENERAL_FAILURE ); + if (num_written) - *num_written = r.buffer_written; - - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); - - return result; + *num_written = out.buffer_written; + + return out.status; } -/* Delete printer data */ +/********************************************************************** +**********************************************************************/ WERROR cli_spoolss_deleteprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx, POLICY_HND *hnd, char *valuename) { prs_struct qbuf, rbuf; - SPOOL_Q_DELETEPRINTERDATA q; - SPOOL_R_DELETEPRINTERDATA r; - WERROR result = W_ERROR(ERRgeneral); - - ZERO_STRUCT(q); - ZERO_STRUCT(r); + SPOOL_Q_DELETEPRINTERDATA in; + SPOOL_R_DELETEPRINTERDATA out; - /* Initialise parse structures */ + ZERO_STRUCT(in); + ZERO_STRUCT(out); - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); + make_spoolss_q_deleteprinterdata( &in, hnd, valuename ); - /* Initialise input parameters */ - - make_spoolss_q_deleteprinterdata(&q, hnd, valuename); - - /* Marshall data and send request */ + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_DELETEPRINTERDATA, + in, out, + qbuf, rbuf, + spoolss_io_q_deleteprinterdata, + spoolss_io_r_deleteprinterdata, + WERR_GENERAL_FAILURE ); - if (!spoolss_io_q_deleteprinterdata("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_DELETEPRINTERDATA, &qbuf, &rbuf)) - goto done; - - /* Unmarshall response */ - - if (!spoolss_io_r_deleteprinterdata("", &r, &rbuf, 0)) - goto done; - - result = r.status; - - if (!W_ERROR_IS_OK(r.status)) - goto done; - - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); - - return result; + return out.status; } +/********************************************************************** +**********************************************************************/ + WERROR cli_spoolss_deleteprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx, POLICY_HND *hnd, char *keyname, char *valuename) { prs_struct qbuf, rbuf; - SPOOL_Q_DELETEPRINTERDATAEX q; - SPOOL_R_DELETEPRINTERDATAEX r; - WERROR result = W_ERROR(ERRgeneral); - - ZERO_STRUCT(q); - ZERO_STRUCT(r); - - /* Initialise parse structures */ - - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - /* Initialise input parameters */ + SPOOL_Q_DELETEPRINTERDATAEX in; + SPOOL_R_DELETEPRINTERDATAEX out; - make_spoolss_q_deleteprinterdataex(&q, hnd, keyname, valuename); - - /* Marshall data and send request */ - - if (!spoolss_io_q_deleteprinterdataex("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_DELETEPRINTERDATAEX, &qbuf, &rbuf)) - goto done; - - /* Unmarshall response */ - - if (!spoolss_io_r_deleteprinterdataex("", &r, &rbuf, 0)) - goto done; - - result = r.status; + ZERO_STRUCT(in); + ZERO_STRUCT(out); - if (!W_ERROR_IS_OK(r.status)) - goto done; + make_spoolss_q_deleteprinterdataex( &in, hnd, keyname, valuename ); - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_DELETEPRINTERDATAEX, + in, out, + qbuf, rbuf, + spoolss_io_q_deleteprinterdataex, + spoolss_io_r_deleteprinterdataex, + WERR_GENERAL_FAILURE ); - return result; + return out.status; } +/********************************************************************** +**********************************************************************/ + WERROR cli_spoolss_enumprinterkey(struct cli_state *cli, TALLOC_CTX *mem_ctx, - uint32 offered, uint32 *needed, POLICY_HND *hnd, const char *keyname, uint16 **keylist, uint32 *len) { prs_struct qbuf, rbuf; - SPOOL_Q_ENUMPRINTERKEY q; - SPOOL_R_ENUMPRINTERKEY r; - WERROR result = W_ERROR(ERRgeneral); - - ZERO_STRUCT(q); - ZERO_STRUCT(r); - - /* Initialise parse structures */ - - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - /* Initialise input parameters */ - - make_spoolss_q_enumprinterkey(&q, hnd, keyname, offered); - - /* Marshall data and send request */ - - if (!spoolss_io_q_enumprinterkey("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_ENUMPRINTERKEY, &qbuf, &rbuf)) - goto done; + SPOOL_Q_ENUMPRINTERKEY in; + SPOOL_R_ENUMPRINTERKEY out; + uint32 offered; - /* Unmarshall response */ + ZERO_STRUCT(in); + ZERO_STRUCT(out); - if (!spoolss_io_r_enumprinterkey("", &r, &rbuf, 0)) - goto done; - - result = r.status; + make_spoolss_q_enumprinterkey( &in, hnd, keyname, offered ); - if (needed) - *needed = r.needed; + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENUMPRINTERKEY, + in, out, + qbuf, rbuf, + spoolss_io_q_enumprinterkey, + spoolss_io_r_enumprinterkey, + WERR_GENERAL_FAILURE ); - if (!W_ERROR_IS_OK(r.status)) - goto done; + if ( W_ERROR_EQUAL( out.status, WERR_MORE_DATA ) ) { + offered = out.needed; + + ZERO_STRUCT(in); + ZERO_STRUCT(out); + + make_spoolss_q_enumprinterkey( &in, hnd, keyname, offered ); + + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENUMPRINTERKEY, + in, out, + qbuf, rbuf, + spoolss_io_q_enumprinterkey, + spoolss_io_r_enumprinterkey, + WERR_GENERAL_FAILURE ); + } - /* Copy results */ + if ( !W_ERROR_IS_OK(out.status) ) + return out.status; if (keylist) { - *keylist = SMB_MALLOC_ARRAY(uint16, r.keys.buf_len); - memcpy(*keylist, r.keys.buffer, r.keys.buf_len * 2); + *keylist = SMB_MALLOC_ARRAY(uint16, out.keys.buf_len); + memcpy(*keylist, out.keys.buffer, out.keys.buf_len * 2); if (len) - *len = r.keys.buf_len * 2; + *len = out.keys.buf_len * 2; } - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); - - return result; + return out.status; } +/********************************************************************** +**********************************************************************/ + WERROR cli_spoolss_deleteprinterkey(struct cli_state *cli, TALLOC_CTX *mem_ctx, POLICY_HND *hnd, char *keyname) { prs_struct qbuf, rbuf; - SPOOL_Q_DELETEPRINTERKEY q; - SPOOL_R_DELETEPRINTERKEY r; - WERROR result = W_ERROR(ERRgeneral); - - ZERO_STRUCT(q); - ZERO_STRUCT(r); - - /* Initialise parse structures */ - - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - - /* Initialise input parameters */ - - make_spoolss_q_deleteprinterkey(&q, hnd, keyname); - - /* Marshall data and send request */ - - if (!spoolss_io_q_deleteprinterkey("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_DELETEPRINTERKEY, &qbuf, &rbuf)) - goto done; - - /* Unmarshall response */ - - if (!spoolss_io_r_deleteprinterkey("", &r, &rbuf, 0)) - goto done; - - result = r.status; - - if (!W_ERROR_IS_OK(r.status)) - goto done; - - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); - - return result; + SPOOL_Q_DELETEPRINTERKEY in; + SPOOL_R_DELETEPRINTERKEY out; + + ZERO_STRUCT(in); + ZERO_STRUCT(out); + + make_spoolss_q_deleteprinterkey( &in, hnd, keyname ); + + CLI_DO_RPC( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_DELETEPRINTERKEY, + in, out, + qbuf, rbuf, + spoolss_io_q_deleteprinterkey, + spoolss_io_r_deleteprinterkey, + WERR_GENERAL_FAILURE ); + + return out.status; } /** @} **/ diff --git a/source/rpc_parse/parse_misc.c b/source/rpc_parse/parse_misc.c index 2fe448f47d1..921e366f11a 100644 --- a/source/rpc_parse/parse_misc.c +++ b/source/rpc_parse/parse_misc.c @@ -1194,7 +1194,7 @@ BOOL init_unistr4_array( UNISTR4_ARRAY *array, uint32 count, const char **string return False; for ( i=0; i<count; i++ ) - init_unistr4( &array->strings[i], strings[i], STR_TERMINATE ); + init_unistr4( &array->strings[i], strings[i], UNI_STR_TERMINATE ); return True; } diff --git a/source/rpc_parse/parse_reg.c b/source/rpc_parse/parse_reg.c index c46eef13003..3d586b3779f 100644 --- a/source/rpc_parse/parse_reg.c +++ b/source/rpc_parse/parse_reg.c @@ -1311,7 +1311,7 @@ void init_reg_r_enum_key(REG_R_ENUM_KEY *r_u, char *subkey ) if ( !r_u ) return; - init_unistr4( &r_u->keyname, subkey, STR_TERMINATE ); + init_unistr4( &r_u->keyname, subkey, UNI_STR_TERMINATE ); r_u->classname = TALLOC_ZERO_P( get_talloc_ctx(), UNISTR4 ); r_u->time = TALLOC_ZERO_P( get_talloc_ctx(), NTTIME ); } diff --git a/source/rpc_parse/parse_rpc.c b/source/rpc_parse/parse_rpc.c index 3c109758766..ce081b92e83 100644 --- a/source/rpc_parse/parse_rpc.c +++ b/source/rpc_parse/parse_rpc.c @@ -650,98 +650,82 @@ BOOL smb_io_rpc_hdr_fault(const char *desc, RPC_HDR_FAULT *rpc, prs_struct *ps, } /******************************************************************* - Init an RPC_HDR_AUTHA structure. + Inits an RPC_HDR_AUTH structure. ********************************************************************/ -void init_rpc_hdr_autha(RPC_HDR_AUTHA *rai, - uint16 max_tsize, uint16 max_rsize, +void init_rpc_hdr_auth(RPC_HDR_AUTH *rai, uint8 auth_type, uint8 auth_level, - uint8 stub_type_len) + uint8 auth_pad_len, + uint32 auth_context_id) { - rai->max_tsize = max_tsize; /* maximum transmission fragment size (0x1630) */ - rai->max_rsize = max_rsize; /* max receive fragment size (0x1630) */ - rai->auth_type = auth_type; /* nt lm ssp 0x0a */ rai->auth_level = auth_level; /* 0x06 */ - rai->stub_type_len = stub_type_len; /* 0x00 */ - rai->padding = 0; /* padding 0x00 */ - - rai->unknown = 0x0014a0c0; /* non-zero pointer to something */ + rai->auth_pad_len = auth_pad_len; + rai->auth_reserved = 0; + rai->auth_context_id = auth_context_id; } /******************************************************************* - Reads or writes an RPC_HDR_AUTHA structure. + Reads or writes an RPC_HDR_AUTH structure. ********************************************************************/ -BOOL smb_io_rpc_hdr_autha(const char *desc, RPC_HDR_AUTHA *rai, prs_struct *ps, int depth) +BOOL smb_io_rpc_hdr_auth(const char *desc, RPC_HDR_AUTH *rai, prs_struct *ps, int depth) { if (rai == NULL) return False; - prs_debug(ps, depth, desc, "smb_io_rpc_hdr_autha"); + prs_debug(ps, depth, desc, "smb_io_rpc_hdr_auth"); depth++; - if(!prs_uint16("max_tsize ", ps, depth, &rai->max_tsize)) - return False; - if(!prs_uint16("max_rsize ", ps, depth, &rai->max_rsize)) + if(!prs_align(ps)) return False; if(!prs_uint8 ("auth_type ", ps, depth, &rai->auth_type)) /* 0x0a nt lm ssp */ return False; if(!prs_uint8 ("auth_level ", ps, depth, &rai->auth_level)) /* 0x06 */ return False; - if(!prs_uint8 ("stub_type_len", ps, depth, &rai->stub_type_len)) + if(!prs_uint8 ("auth_pad_len ", ps, depth, &rai->auth_pad_len)) return False; - if(!prs_uint8 ("padding ", ps, depth, &rai->padding)) + if(!prs_uint8 ("auth_reserved", ps, depth, &rai->auth_reserved)) return False; - - if(!prs_uint32("unknown ", ps, depth, &rai->unknown)) /* 0x0014a0c0 */ + if(!prs_uint32("auth_context_id", ps, depth, &rai->auth_context_id)) return False; return True; } + /******************************************************************* - Inits an RPC_HDR_AUTH structure. + Init an RPC_HDR_AUTHA structure. ********************************************************************/ -void init_rpc_hdr_auth(RPC_HDR_AUTH *rai, - uint8 auth_type, uint8 auth_level, - uint8 padding, - uint32 ptr) +void init_rpc_hdr_autha(RPC_HDR_AUTHA *rai, + uint16 max_tsize, uint16 max_rsize, + RPC_HDR_AUTH *auth) { - rai->auth_type = auth_type; /* nt lm ssp 0x0a */ - rai->auth_level = auth_level; /* 0x06 */ - rai->padding = padding; - rai->reserved = 0; - - rai->auth_context = ptr; /* non-zero pointer to something */ + rai->max_tsize = max_tsize; /* maximum transmission fragment size (0x1630) */ + rai->max_rsize = max_rsize; /* max receive fragment size (0x1630) */ + rai->auth = *auth; } /******************************************************************* - Reads or writes an RPC_HDR_AUTH structure. + Reads or writes an RPC_HDR_AUTHA structure. ********************************************************************/ -BOOL smb_io_rpc_hdr_auth(const char *desc, RPC_HDR_AUTH *rai, prs_struct *ps, int depth) +BOOL smb_io_rpc_hdr_autha(const char *desc, RPC_HDR_AUTHA *rai, prs_struct *ps, int depth) { if (rai == NULL) return False; - prs_debug(ps, depth, desc, "smb_io_rpc_hdr_auth"); + prs_debug(ps, depth, desc, "smb_io_rpc_hdr_autha"); depth++; - if(!prs_align(ps)) - return False; - - if(!prs_uint8 ("auth_type ", ps, depth, &rai->auth_type)) /* 0x0a nt lm ssp */ - return False; - if(!prs_uint8 ("auth_level ", ps, depth, &rai->auth_level)) /* 0x06 */ - return False; - if(!prs_uint8 ("padding ", ps, depth, &rai->padding)) + if(!prs_uint16("max_tsize ", ps, depth, &rai->max_tsize)) return False; - if(!prs_uint8 ("reserved ", ps, depth, &rai->reserved)) + if(!prs_uint16("max_rsize ", ps, depth, &rai->max_rsize)) return False; - if(!prs_uint32("auth_context ", ps, depth, &rai->auth_context)) + + if(!smb_io_rpc_hdr_auth("auth", &rai->auth, ps, depth)) return False; return True; diff --git a/source/rpc_parse/parse_samr.c b/source/rpc_parse/parse_samr.c index ba8b367a425..6b0193c6e46 100644 --- a/source/rpc_parse/parse_samr.c +++ b/source/rpc_parse/parse_samr.c @@ -5103,13 +5103,13 @@ static BOOL sam_io_logon_hrs(const char *desc, LOGON_HRS * hrs, } /******************************************************************* -inits a SAM_USER_INFO_12 structure. +inits a SAM_USER_INFO_18 structure. ********************************************************************/ -void init_sam_user_info12(SAM_USER_INFO_12 * usr, +void init_sam_user_info18(SAM_USER_INFO_18 * usr, const uint8 lm_pwd[16], const uint8 nt_pwd[16]) { - DEBUG(5, ("init_sam_user_info12\n")); + DEBUG(5, ("init_sam_user_info18\n")); usr->lm_pwd_active = memcpy(usr->lm_pwd, lm_pwd, sizeof(usr->lm_pwd)) ? 1 : 0; @@ -5121,13 +5121,13 @@ void init_sam_user_info12(SAM_USER_INFO_12 * usr, reads or writes a structure. ********************************************************************/ -static BOOL sam_io_user_info12(const char *desc, SAM_USER_INFO_12 * u, +static BOOL sam_io_user_info18(const char *desc, SAM_USER_INFO_18 * u, prs_struct *ps, int depth) { if (u == NULL) return False; - prs_debug(ps, depth, desc, "samr_io_r_user_info12"); + prs_debug(ps, depth, desc, "samr_io_r_user_info18"); depth++; if(!prs_align(ps)) @@ -5185,12 +5185,12 @@ static BOOL sam_io_user_info7(const char *desc, SAM_USER_INFO_7 * usr, } /******************************************************************* -inits a SAM_USER_INFO_10 structure. +inits a SAM_USER_INFO_16 structure. ********************************************************************/ -void init_sam_user_info10(SAM_USER_INFO_10 * usr, uint32 acb_info) +void init_sam_user_info16(SAM_USER_INFO_16 * usr, uint32 acb_info) { - DEBUG(5, ("init_sam_user_info10\n")); + DEBUG(5, ("init_sam_user_info16\n")); usr->acb_info = acb_info; } @@ -5199,13 +5199,13 @@ void init_sam_user_info10(SAM_USER_INFO_10 * usr, uint32 acb_info) reads or writes a structure. ********************************************************************/ -static BOOL sam_io_user_info10(const char *desc, SAM_USER_INFO_10 * usr, +static BOOL sam_io_user_info16(const char *desc, SAM_USER_INFO_16 * usr, prs_struct *ps, int depth) { if (usr == NULL) return False; - prs_debug(ps, depth, desc, "samr_io_r_user_info10"); + prs_debug(ps, depth, desc, "samr_io_r_user_info16"); depth++; if(!prs_align(ps)) @@ -5218,15 +5218,15 @@ static BOOL sam_io_user_info10(const char *desc, SAM_USER_INFO_10 * usr, } /******************************************************************* -inits a SAM_USER_INFO_11 structure. +inits a SAM_USER_INFO_17 structure. ********************************************************************/ -void init_sam_user_info11(SAM_USER_INFO_11 * usr, +void init_sam_user_info17(SAM_USER_INFO_17 * usr, NTTIME * expiry, char *mach_acct, uint32 rid_user, uint32 rid_group, uint16 acct_ctrl) { - DEBUG(5, ("init_sam_user_info11\n")); + DEBUG(5, ("init_sam_user_info17\n")); memcpy(&usr->expiry, expiry, sizeof(usr->expiry)); /* expiry time or something? */ ZERO_STRUCT(usr->padding_1); /* 0 - padding 24 bytes */ @@ -5263,13 +5263,13 @@ void init_sam_user_info11(SAM_USER_INFO_11 * usr, reads or writes a structure. ********************************************************************/ -static BOOL sam_io_user_info11(const char *desc, SAM_USER_INFO_11 * usr, +static BOOL sam_io_user_info17(const char *desc, SAM_USER_INFO_17 * usr, prs_struct *ps, int depth) { if (usr == NULL) return False; - prs_debug(ps, depth, desc, "samr_io_r_unknown_11"); + prs_debug(ps, depth, desc, "samr_io_r_unknown_17"); depth++; if(!prs_align(ps)) @@ -6231,16 +6231,16 @@ NTSTATUS make_samr_userinfo_ctr_usr21(TALLOC_CTX *ctx, SAM_USERINFO_CTR * ctr, ctr->info.id = NULL; switch (switch_value) { - case 0x10: - ctr->info.id10 = TALLOC_ZERO_P(ctx,SAM_USER_INFO_10); - if (ctr->info.id10 == NULL) + case 16: + ctr->info.id16 = TALLOC_ZERO_P(ctx,SAM_USER_INFO_16); + if (ctr->info.id16 == NULL) return NT_STATUS_NO_MEMORY; - init_sam_user_info10(ctr->info.id10, usr->acb_info); + init_sam_user_info16(ctr->info.id16, usr->acb_info); break; #if 0 /* whoops - got this wrong. i think. or don't understand what's happening. */ - case 0x11: + case 17: { NTTIME expire; info = (void *)&id11; @@ -6248,8 +6248,8 @@ NTSTATUS make_samr_userinfo_ctr_usr21(TALLOC_CTX *ctx, SAM_USERINFO_CTR * ctr, expire.low = 0xffffffff; expire.high = 0x7fffffff; - ctr->info.id = TALLOC_ZERO_P(ctx,SAM_USER_INFO_11); - init_sam_user_info11(ctr->info.id11, &expire, + ctr->info.id = TALLOC_ZERO_P(ctx,SAM_USER_INFO_17); + init_sam_user_info11(ctr->info.id17, &expire, "BROOKFIELDS$", /* name */ 0x03ef, /* user rid */ 0x201, /* group rid */ @@ -6258,12 +6258,12 @@ NTSTATUS make_samr_userinfo_ctr_usr21(TALLOC_CTX *ctx, SAM_USERINFO_CTR * ctr, break; } #endif - case 0x12: - ctr->info.id12 = TALLOC_ZERO_P(ctx,SAM_USER_INFO_12); - if (ctr->info.id12 == NULL) + case 18: + ctr->info.id18 = TALLOC_ZERO_P(ctx,SAM_USER_INFO_18); + if (ctr->info.id18 == NULL) return NT_STATUS_NO_MEMORY; - init_sam_user_info12(ctr->info.id12, usr->lm_pwd, usr->nt_pwd); + init_sam_user_info18(ctr->info.id18, usr->lm_pwd, usr->nt_pwd); break; case 21: { @@ -6347,7 +6347,7 @@ static BOOL samr_io_userinfo_ctr(const char *desc, SAM_USERINFO_CTR **ppctr, ret = False; switch (ctr->switch_value) { - case 0x07: + case 7: if (UNMARSHALLING(ps)) ctr->info.id7 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_7,1); if (ctr->info.id7 == NULL) { @@ -6356,34 +6356,34 @@ static BOOL samr_io_userinfo_ctr(const char *desc, SAM_USERINFO_CTR **ppctr, } ret = sam_io_user_info7("", ctr->info.id7, ps, depth); break; - case 0x10: + case 16: if (UNMARSHALLING(ps)) - ctr->info.id10 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_10,1); - if (ctr->info.id10 == NULL) { + ctr->info.id16 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_16,1); + if (ctr->info.id16 == NULL) { DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n")); return False; } - ret = sam_io_user_info10("", ctr->info.id10, ps, depth); + ret = sam_io_user_info16("", ctr->info.id16, ps, depth); break; - case 0x11: + case 17: if (UNMARSHALLING(ps)) - ctr->info.id11 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_11,1); + ctr->info.id17 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_17,1); - if (ctr->info.id11 == NULL) { + if (ctr->info.id17 == NULL) { DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n")); return False; } - ret = sam_io_user_info11("", ctr->info.id11, ps, depth); + ret = sam_io_user_info17("", ctr->info.id17, ps, depth); break; - case 0x12: + case 18: if (UNMARSHALLING(ps)) - ctr->info.id12 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_12,1); + ctr->info.id18 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_18,1); - if (ctr->info.id12 == NULL) { + if (ctr->info.id18 == NULL) { DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n")); return False; } - ret = sam_io_user_info12("", ctr->info.id12, ps, depth); + ret = sam_io_user_info18("", ctr->info.id18, ps, depth); break; case 20: if (UNMARSHALLING(ps)) @@ -6588,12 +6588,12 @@ void init_samr_q_set_userinfo2(SAMR_Q_SET_USERINFO2 * q_u, q_u->ctr->switch_value = switch_value; switch (switch_value) { - case 0x12: - SamOEMhashBlob(ctr->info.id12->lm_pwd, 16, sess_key); - SamOEMhashBlob(ctr->info.id12->nt_pwd, 16, sess_key); + case 18: + SamOEMhashBlob(ctr->info.id18->lm_pwd, 16, sess_key); + SamOEMhashBlob(ctr->info.id18->nt_pwd, 16, sess_key); dump_data(100, (char *)sess_key->data, sess_key->length); - dump_data(100, (char *)ctr->info.id12->lm_pwd, 16); - dump_data(100, (char *)ctr->info.id12->nt_pwd, 16); + dump_data(100, (char *)ctr->info.id18->lm_pwd, 16); + dump_data(100, (char *)ctr->info.id18->nt_pwd, 16); break; } } diff --git a/source/rpc_parse/parse_spoolss.c b/source/rpc_parse/parse_spoolss.c index 34e3f8fe355..2663b093812 100644 --- a/source/rpc_parse/parse_spoolss.c +++ b/source/rpc_parse/parse_spoolss.c @@ -945,7 +945,8 @@ BOOL make_spoolss_q_addprinterex( TALLOC_CTX *mem_ctx, SPOOL_Q_ADDPRINTEREX *q_u q_u->user_switch=1; - q_u->user_ctr.level = 1; + q_u->user_ctr.level = 1; + q_u->user_ctr.user.user1 = TALLOC_P( get_talloc_ctx(), SPOOL_USER_1 ); q_u->user_ctr.user.user1->build = 1381; q_u->user_ctr.user.user1->major = 2; q_u->user_ctr.user.user1->minor = 0; @@ -3816,6 +3817,22 @@ BOOL spoolss_io_q_setprinter(const char *desc, SPOOL_Q_SETPRINTER *q_u, prs_stru return False; if(!prs_uint32("level", ps, depth, &q_u->level)) return False; + + /* check for supported levels and structures we know about */ + + switch ( q_u->level ) { + case 0: + case 2: + case 3: + case 7: + /* supported levels */ + break; + default: + DEBUG(0,("spoolss_io_q_setprinter: unsupported printer info level [%d]\n", + q_u->level)); + return True; + } + if(!spool_io_printer_info_level("", &q_u->info, ps, depth)) return False; diff --git a/source/rpc_server/srv_netlog_nt.c b/source/rpc_server/srv_netlog_nt.c index a6fe9ef31af..7880a724b5c 100644 --- a/source/rpc_server/srv_netlog_nt.c +++ b/source/rpc_server/srv_netlog_nt.c @@ -764,8 +764,13 @@ NTSTATUS _net_sam_logon(pipes_struct *p, NET_Q_SAM_LOGON *q_u, NET_R_SAM_LOGON * return NT_STATUS_UNSUCCESSFUL; } - pstrcpy(my_name, global_myname()); - + + if(server_info->login_server) { + pstrcpy(my_name, server_info->login_server); + } else { + pstrcpy(my_name, global_myname()); + } + if (!NT_STATUS_IS_OK(status = nt_token_to_group_list(p->mem_ctx, &domain_sid, diff --git a/source/rpc_server/srv_pipe.c b/source/rpc_server/srv_pipe.c index 30aacdc4c5e..70563d30295 100644 --- a/source/rpc_server/srv_pipe.c +++ b/source/rpc_server/srv_pipe.c @@ -582,9 +582,9 @@ BOOL api_pipe_bind_auth_resp(pipes_struct *p, prs_struct *rpc_in_p) return False; } - if (autha_info.auth_type != NTLMSSP_AUTH_TYPE || autha_info.auth_level != RPC_PIPE_AUTH_SEAL_LEVEL) { + if (autha_info.auth.auth_type != NTLMSSP_AUTH_TYPE || autha_info.auth.auth_level != RPC_PIPE_AUTH_SEAL_LEVEL) { DEBUG(0,("api_pipe_bind_auth_resp: incorrect auth type (%d) or level (%d).\n", - (int)autha_info.auth_type, (int)autha_info.auth_level )); + (int)autha_info.auth.auth_type, (int)autha_info.auth.auth_level )); return False; } @@ -941,67 +941,72 @@ BOOL api_pipe_bind_req(pipes_struct *p, prs_struct *rpc_in_p) return False; } - if(auth_info.auth_type == NTLMSSP_AUTH_TYPE) { - - if(!smb_io_rpc_auth_verifier("", &auth_verifier, rpc_in_p, 0)) { - DEBUG(0,("api_pipe_bind_req: unable to " - "unmarshall RPC_HDR_AUTH struct.\n")); - return False; - } - - if(!strequal(auth_verifier.signature, "NTLMSSP")) { - DEBUG(0,("api_pipe_bind_req: " - "auth_verifier.signature != NTLMSSP\n")); - return False; - } - - if(auth_verifier.msg_type != NTLMSSP_NEGOTIATE) { - DEBUG(0,("api_pipe_bind_req: " - "auth_verifier.msg_type (%d) != NTLMSSP_NEGOTIATE\n", - auth_verifier.msg_type)); - return False; - } - - if(!smb_io_rpc_auth_ntlmssp_neg("", &ntlmssp_neg, rpc_in_p, 0)) { - DEBUG(0,("api_pipe_bind_req: " - "Failed to unmarshall RPC_AUTH_NTLMSSP_NEG.\n")); - return False; - } - - p->ntlmssp_chal_flags = SMBD_NTLMSSP_NEG_FLAGS; - p->ntlmssp_auth_requested = True; - - } else if (auth_info.auth_type == NETSEC_AUTH_TYPE) { - - RPC_AUTH_NETSEC_NEG neg; - struct netsec_auth_struct *a = &(p->netsec_auth); - - if (!server_auth2_negotiated) { - DEBUG(0, ("Attempt to bind using schannel " - "without successful serverauth2\n")); - return False; + switch(auth_info.auth_type) { + case NTLMSSP_AUTH_TYPE: + + if(!smb_io_rpc_auth_verifier("", &auth_verifier, rpc_in_p, 0)) { + DEBUG(0,("api_pipe_bind_req: unable to " + "unmarshall RPC_HDR_AUTH struct.\n")); + return False; + } + + if(!strequal(auth_verifier.signature, "NTLMSSP")) { + DEBUG(0,("api_pipe_bind_req: " + "auth_verifier.signature != NTLMSSP\n")); + return False; + } + + if(auth_verifier.msg_type != NTLMSSP_NEGOTIATE) { + DEBUG(0,("api_pipe_bind_req: " + "auth_verifier.msg_type (%d) != NTLMSSP_NEGOTIATE\n", + auth_verifier.msg_type)); + return False; + } + + if(!smb_io_rpc_auth_ntlmssp_neg("", &ntlmssp_neg, rpc_in_p, 0)) { + DEBUG(0,("api_pipe_bind_req: " + "Failed to unmarshall RPC_AUTH_NTLMSSP_NEG.\n")); + return False; + } + + p->ntlmssp_chal_flags = SMBD_NTLMSSP_NEG_FLAGS; + p->ntlmssp_auth_requested = True; + break; + + case NETSEC_AUTH_TYPE: + { + RPC_AUTH_NETSEC_NEG neg; + struct netsec_auth_struct *a = &(p->netsec_auth); + + if (!server_auth2_negotiated) { + DEBUG(0, ("Attempt to bind using schannel " + "without successful serverauth2\n")); + return False; + } + + if (!smb_io_rpc_auth_netsec_neg("", &neg, rpc_in_p, 0)) { + DEBUG(0,("api_pipe_bind_req: " + "Could not unmarshal SCHANNEL auth neg\n")); + return False; + } + + p->netsec_auth_validated = True; + + memset(a->sess_key, 0, sizeof(a->sess_key)); + memcpy(a->sess_key, last_dcinfo.sess_key, sizeof(last_dcinfo.sess_key)); + + a->seq_num = 0; + + DEBUG(10,("schannel auth: domain [%s] myname [%s]\n", + neg.domain, neg.myname)); + break; } - if (!smb_io_rpc_auth_netsec_neg("", &neg, rpc_in_p, 0)) { - DEBUG(0,("api_pipe_bind_req: " - "Could not unmarshal SCHANNEL auth neg\n")); + case SPNEGO_AUTH_TYPE: + default: + DEBUG(0,("api_pipe_bind_req: unknown auth type %x requested.\n", + auth_info.auth_type )); return False; - } - - p->netsec_auth_validated = True; - - memset(a->sess_key, 0, sizeof(a->sess_key)); - memcpy(a->sess_key, last_dcinfo.sess_key, sizeof(last_dcinfo.sess_key)); - - a->seq_num = 0; - - DEBUG(10,("schannel auth: domain [%s] myname [%s]\n", - neg.domain, neg.myname)); - - } else { - DEBUG(0,("api_pipe_bind_req: unknown auth type %x requested.\n", - auth_info.auth_type )); - return False; } } diff --git a/source/rpc_server/srv_samr_nt.c b/source/rpc_server/srv_samr_nt.c index 9b98d4cb168..2e73db28070 100644 --- a/source/rpc_server/srv_samr_nt.c +++ b/source/rpc_server/srv_samr_nt.c @@ -1411,10 +1411,10 @@ static NTSTATUS get_user_info_7(TALLOC_CTX *mem_ctx, SAM_USER_INFO_7 *id7, DOM_S return NT_STATUS_OK; } /************************************************************************* - get_user_info_10. Safe. Only gives out acb bits. + get_user_info_16. Safe. Only gives out acb bits. *************************************************************************/ -static NTSTATUS get_user_info_10(TALLOC_CTX *mem_ctx, SAM_USER_INFO_10 *id10, DOM_SID *user_sid) +static NTSTATUS get_user_info_16(TALLOC_CTX *mem_ctx, SAM_USER_INFO_16 *id16, DOM_SID *user_sid) { SAM_ACCOUNT *smbpass=NULL; BOOL ret; @@ -1437,8 +1437,8 @@ static NTSTATUS get_user_info_10(TALLOC_CTX *mem_ctx, SAM_USER_INFO_10 *id10, DO DEBUG(3,("User:[%s]\n", pdb_get_username(smbpass) )); - ZERO_STRUCTP(id10); - init_sam_user_info10(id10, pdb_get_acct_ctrl(smbpass) ); + ZERO_STRUCTP(id16); + init_sam_user_info16(id16, pdb_get_acct_ctrl(smbpass) ); pdb_free_sam(&smbpass); @@ -1446,12 +1446,12 @@ static NTSTATUS get_user_info_10(TALLOC_CTX *mem_ctx, SAM_USER_INFO_10 *id10, DO } /************************************************************************* - get_user_info_12. OK - this is the killer as it gives out password info. + get_user_info_18. OK - this is the killer as it gives out password info. Ensure that this is only allowed on an encrypted connection with a root user. JRA. *************************************************************************/ -static NTSTATUS get_user_info_12(pipes_struct *p, TALLOC_CTX *mem_ctx, SAM_USER_INFO_12 * id12, DOM_SID *user_sid) +static NTSTATUS get_user_info_18(pipes_struct *p, TALLOC_CTX *mem_ctx, SAM_USER_INFO_18 * id18, DOM_SID *user_sid) { SAM_ACCOUNT *smbpass=NULL; BOOL ret; @@ -1488,8 +1488,8 @@ static NTSTATUS get_user_info_12(pipes_struct *p, TALLOC_CTX *mem_ctx, SAM_USER_ return NT_STATUS_ACCOUNT_DISABLED; } - ZERO_STRUCTP(id12); - init_sam_user_info12(id12, pdb_get_lanman_passwd(smbpass), pdb_get_nt_passwd(smbpass)); + ZERO_STRUCTP(id18); + init_sam_user_info18(id18, pdb_get_lanman_passwd(smbpass), pdb_get_nt_passwd(smbpass)); pdb_free_sam(&smbpass); @@ -1601,7 +1601,7 @@ NTSTATUS _samr_query_userinfo(pipes_struct *p, SAMR_Q_QUERY_USERINFO *q_u, SAMR_ ctr->switch_value = q_u->switch_value; switch (q_u->switch_value) { - case 0x07: + case 7: ctr->info.id7 = TALLOC_ZERO_P(p->mem_ctx, SAM_USER_INFO_7); if (ctr->info.id7 == NULL) return NT_STATUS_NO_MEMORY; @@ -1609,18 +1609,18 @@ NTSTATUS _samr_query_userinfo(pipes_struct *p, SAMR_Q_QUERY_USERINFO *q_u, SAMR_ if (!NT_STATUS_IS_OK(r_u->status = get_user_info_7(p->mem_ctx, ctr->info.id7, &info->sid))) return r_u->status; break; - case 0x10: - ctr->info.id10 = TALLOC_ZERO_P(p->mem_ctx, SAM_USER_INFO_10); - if (ctr->info.id10 == NULL) + case 16: + ctr->info.id16 = TALLOC_ZERO_P(p->mem_ctx, SAM_USER_INFO_16); + if (ctr->info.id16 == NULL) return NT_STATUS_NO_MEMORY; - if (!NT_STATUS_IS_OK(r_u->status = get_user_info_10(p->mem_ctx, ctr->info.id10, &info->sid))) + if (!NT_STATUS_IS_OK(r_u->status = get_user_info_16(p->mem_ctx, ctr->info.id16, &info->sid))) return r_u->status; break; #if 0 /* whoops - got this wrong. i think. or don't understand what's happening. */ - case 0x11: + case 17: { NTTIME expire; info = (void *)&id11; @@ -1628,9 +1628,9 @@ NTSTATUS _samr_query_userinfo(pipes_struct *p, SAMR_Q_QUERY_USERINFO *q_u, SAMR_ expire.low = 0xffffffff; expire.high = 0x7fffffff; - ctr->info.id = TALLOC_ZERO_P(p->mem_ctx, SAM_USER_INFO_11)); - ZERO_STRUCTP(ctr->info.id11); - init_sam_user_info11(ctr->info.id11, &expire, + ctr->info.id = TALLOC_ZERO_P(p->mem_ctx, SAM_USER_INFO_17)); + ZERO_STRUCTP(ctr->info.id17); + init_sam_user_info17(ctr->info.id17, &expire, "BROOKFIELDS$", /* name */ 0x03ef, /* user rid */ 0x201, /* group rid */ @@ -1640,12 +1640,12 @@ NTSTATUS _samr_query_userinfo(pipes_struct *p, SAMR_Q_QUERY_USERINFO *q_u, SAMR_ } #endif - case 0x12: - ctr->info.id12 = TALLOC_ZERO_P(p->mem_ctx, SAM_USER_INFO_12); - if (ctr->info.id12 == NULL) + case 18: + ctr->info.id18 = TALLOC_ZERO_P(p->mem_ctx, SAM_USER_INFO_18); + if (ctr->info.id18 == NULL) return NT_STATUS_NO_MEMORY; - if (!NT_STATUS_IS_OK(r_u->status = get_user_info_12(p, p->mem_ctx, ctr->info.id12, &info->sid))) + if (!NT_STATUS_IS_OK(r_u->status = get_user_info_18(p, p->mem_ctx, ctr->info.id18, &info->sid))) return r_u->status; break; @@ -2418,19 +2418,19 @@ NTSTATUS _samr_open_alias(pipes_struct *p, SAMR_Q_OPEN_ALIAS *q_u, SAMR_R_OPEN_A } /******************************************************************* - set_user_info_10 + set_user_info_16 ********************************************************************/ -static BOOL set_user_info_10(const SAM_USER_INFO_10 *id10, SAM_ACCOUNT *pwd) +static BOOL set_user_info_16(const SAM_USER_INFO_16 *id16, SAM_ACCOUNT *pwd) { - if (id10 == NULL) { - DEBUG(5, ("set_user_info_10: NULL id10\n")); + if (id16 == NULL) { + DEBUG(5, ("set_user_info_16: NULL id16\n")); pdb_free_sam(&pwd); return False; } /* FIX ME: check if the value is really changed --metze */ - if (!pdb_set_acct_ctrl(pwd, id10->acb_info, PDB_CHANGED)) { + if (!pdb_set_acct_ctrl(pwd, id16->acb_info, PDB_CHANGED)) { pdb_free_sam(&pwd); return False; } @@ -2446,23 +2446,23 @@ static BOOL set_user_info_10(const SAM_USER_INFO_10 *id10, SAM_ACCOUNT *pwd) } /******************************************************************* - set_user_info_12 + set_user_info_18 ********************************************************************/ -static BOOL set_user_info_12(SAM_USER_INFO_12 *id12, SAM_ACCOUNT *pwd) +static BOOL set_user_info_18(SAM_USER_INFO_18 *id18, SAM_ACCOUNT *pwd) { - if (id12 == NULL) { - DEBUG(2, ("set_user_info_12: id12 is NULL\n")); + if (id18 == NULL) { + DEBUG(2, ("set_user_info_18: id18 is NULL\n")); pdb_free_sam(&pwd); return False; } - if (!pdb_set_lanman_passwd (pwd, id12->lm_pwd, PDB_CHANGED)) { + if (!pdb_set_lanman_passwd (pwd, id18->lm_pwd, PDB_CHANGED)) { pdb_free_sam(&pwd); return False; } - if (!pdb_set_nt_passwd (pwd, id12->nt_pwd, PDB_CHANGED)) { + if (!pdb_set_nt_passwd (pwd, id18->nt_pwd, PDB_CHANGED)) { pdb_free_sam(&pwd); return False; } @@ -2779,7 +2779,7 @@ NTSTATUS _samr_set_userinfo(pipes_struct *p, SAMR_Q_SET_USERINFO *q_u, SAMR_R_SE switch (switch_value) { case 18: - if (!set_user_info_12(ctr->info.id12, pwd)) + if (!set_user_info_18(ctr->info.id18, pwd)) r_u->status = NT_STATUS_ACCESS_DENIED; break; @@ -2919,12 +2919,12 @@ NTSTATUS _samr_set_userinfo2(pipes_struct *p, SAMR_Q_SET_USERINFO2 *q_u, SAMR_R_ switch (switch_value) { case 16: - if (!set_user_info_10(ctr->info.id10, pwd)) + if (!set_user_info_16(ctr->info.id16, pwd)) r_u->status = NT_STATUS_ACCESS_DENIED; break; case 18: /* Used by AS/U JRA. */ - if (!set_user_info_12(ctr->info.id12, pwd)) + if (!set_user_info_18(ctr->info.id18, pwd)) r_u->status = NT_STATUS_ACCESS_DENIED; break; case 20: diff --git a/source/rpc_server/srv_spoolss_nt.c b/source/rpc_server/srv_spoolss_nt.c index 5fbb6d91b00..7498a449c3b 100644 --- a/source/rpc_server/srv_spoolss_nt.c +++ b/source/rpc_server/srv_spoolss_nt.c @@ -274,6 +274,7 @@ static Printer_entry *find_printer_index_by_hnd(pipes_struct *p, POLICY_HND *hnd return find_printer; } +#ifdef ENABLE_PRINT_HND_OBJECT_CACHE /**************************************************************************** look for a printer object cached on an open printer handle ****************************************************************************/ @@ -327,6 +328,8 @@ void invalidate_printer_hnd_cache( char *printername ) return; } +#endif + /**************************************************************************** Close printer index by handle. ****************************************************************************/ @@ -1213,6 +1216,7 @@ static void receive_notify2_message_list(int msg_type, pid_t src, void *msg, siz return; } +#ifdef ENABLE_PRINT_HND_OBJECT_CACHE /******************************************************************** callback to MSG_PRINTER_CHANGED. When a printer is changed by one smbd, all of processes must clear their printer cache immediately. @@ -1228,6 +1232,7 @@ void receive_printer_mod_msg(int msg_type, pid_t src, void *buf, size_t len) invalidate_printer_hnd_cache( printername ); } +#endif /******************************************************************** Send a message to ourself about new driver being installed @@ -7487,7 +7492,7 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ /* check to see if the printer already exists */ if ((snum = print_queue_snum(printer->info_2->sharename)) != -1) { - DEBUG(5, ("_spoolss_addprinterex: Attempted to add a printer named [%s] when one already existed!\n", + DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n", printer->info_2->sharename)); free_a_printer(&printer, 2); return WERR_PRINTER_ALREADY_EXISTS; @@ -7500,7 +7505,12 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ if ( !add_printer_hook(p->pipe_user.nt_user_token, printer) ) { free_a_printer(&printer,2); return WERR_ACCESS_DENIED; - } + } + } else { + DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no" + "smb.conf parameter \"addprinter command\" is defined. This" + "parameter must exist for this call to succeed\n", + printer->info_2->sharename )); } /* use our primary netbios name since get_a_printer() will convert diff --git a/source/rpc_server/srv_srvsvc_nt.c b/source/rpc_server/srv_srvsvc_nt.c index c3fd53a3844..b607d32e547 100644 --- a/source/rpc_server/srv_srvsvc_nt.c +++ b/source/rpc_server/srv_srvsvc_nt.c @@ -1355,7 +1355,7 @@ WERROR _srv_net_sess_del(pipes_struct *p, SRV_Q_NET_SESS_DEL *q_u, SRV_R_NET_SES { struct sessionid *session_list; struct current_user user; - int num_sessions, snum, ret; + int num_sessions, snum; fstring username; fstring machine; BOOL not_root = False; @@ -1394,7 +1394,7 @@ WERROR _srv_net_sess_del(pipes_struct *p, SRV_Q_NET_SESS_DEL *q_u, SRV_R_NET_SES become_root(); } - if ((ret = message_send_pid(session_list[snum].pid, MSG_SHUTDOWN, NULL, 0, False))) + if (message_send_pid(session_list[snum].pid, MSG_SHUTDOWN, NULL, 0, False)) r_u->status = WERR_OK; if (not_root) diff --git a/source/rpcclient/cmd_spoolss.c b/source/rpcclient/cmd_spoolss.c index ec9d3048822..f774d408fe6 100644 --- a/source/rpcclient/cmd_spoolss.c +++ b/source/rpcclient/cmd_spoolss.c @@ -2,7 +2,7 @@ Unix SMB/CIFS implementation. RPC pipe client - Copyright (C) Gerald Carter 2001 + Copyright (C) Gerald Carter 2001-2005 Copyright (C) Tim Potter 2000 Copyright (C) Andrew Tridgell 1992-1999 Copyright (C) Luke Kenneth Casson Leighton 1996-1999 @@ -61,9 +61,10 @@ static const struct table_node archi_table[]= { **/ /**************************************************************************** -function to do the mapping between the long architecture name and -the short one. + function to do the mapping between the long architecture name and + the short one. ****************************************************************************/ + static const char *cmd_spoolss_get_short_archi(const char *long_archi) { int i=-1; @@ -89,22 +90,9 @@ static const char *cmd_spoolss_get_short_archi(const char *long_archi) return archi_table[i].short_archi; } -#if 0 -/********************************************************************** - * dummy function -- placeholder - */ -static WERROR cmd_spoolss_not_implemented(struct cli_state *cli, - TALLOC_CTX *mem_ctx, - int argc, const char **argv) -{ - printf ("(*) This command is not currently implemented.\n"); - return WERR_OK; -} -#endif +/**************************************************************************** +****************************************************************************/ -/*********************************************************************** - * Get printer information - */ static WERROR cmd_spoolss_open_printer_ex(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) @@ -148,8 +136,8 @@ static WERROR cmd_spoolss_open_printer_ex(struct cli_state *cli, /**************************************************************************** -printer info level 0 display function ****************************************************************************/ + static void display_print_info_0(PRINTER_INFO_0 *i0) { fstring name = ""; @@ -206,8 +194,8 @@ static void display_print_info_0(PRINTER_INFO_0 *i0) } /**************************************************************************** -printer info level 1 display function ****************************************************************************/ + static void display_print_info_1(PRINTER_INFO_1 *i1) { fstring desc = ""; @@ -229,8 +217,8 @@ static void display_print_info_1(PRINTER_INFO_1 *i1) } /**************************************************************************** -printer info level 2 display function ****************************************************************************/ + static void display_print_info_2(PRINTER_INFO_2 *i2) { fstring servername = ""; @@ -246,25 +234,15 @@ static void display_print_info_2(PRINTER_INFO_2 *i2) fstring parameters = ""; rpcstr_pull(servername, i2->servername.buffer,sizeof(servername), -1, STR_TERMINATE); - rpcstr_pull(printername, i2->printername.buffer,sizeof(printername), -1, STR_TERMINATE); - rpcstr_pull(sharename, i2->sharename.buffer,sizeof(sharename), -1, STR_TERMINATE); - rpcstr_pull(portname, i2->portname.buffer,sizeof(portname), -1, STR_TERMINATE); - rpcstr_pull(drivername, i2->drivername.buffer,sizeof(drivername), -1, STR_TERMINATE); - rpcstr_pull(comment, i2->comment.buffer,sizeof(comment), -1, STR_TERMINATE); - rpcstr_pull(location, i2->location.buffer,sizeof(location), -1, STR_TERMINATE); - rpcstr_pull(sepfile, i2->sepfile.buffer,sizeof(sepfile), -1, STR_TERMINATE); - rpcstr_pull(printprocessor, i2->printprocessor.buffer,sizeof(printprocessor), -1, STR_TERMINATE); - rpcstr_pull(datatype, i2->datatype.buffer,sizeof(datatype), -1, STR_TERMINATE); - rpcstr_pull(parameters, i2->parameters.buffer,sizeof(parameters), -1, STR_TERMINATE); printf("\tservername:[%s]\n", servername); @@ -294,8 +272,8 @@ static void display_print_info_2(PRINTER_INFO_2 *i2) } /**************************************************************************** -printer info level 3 display function ****************************************************************************/ + static void display_print_info_3(PRINTER_INFO_3 *i3) { printf("\tflags:[0x%x]\n", i3->flags); @@ -306,8 +284,8 @@ static void display_print_info_3(PRINTER_INFO_3 *i3) } /**************************************************************************** -printer info level 7 display function ****************************************************************************/ + static void display_print_info_7(PRINTER_INFO_7 *i7) { fstring guid = ""; @@ -317,7 +295,8 @@ static void display_print_info_7(PRINTER_INFO_7 *i7) } -/* Enumerate printers */ +/**************************************************************************** +****************************************************************************/ static WERROR cmd_spoolss_enum_printers(struct cli_state *cli, TALLOC_CTX *mem_ctx, @@ -326,7 +305,7 @@ static WERROR cmd_spoolss_enum_printers(struct cli_state *cli, WERROR result; uint32 info_level = 1; PRINTER_INFO_CTR ctr; - uint32 i = 0, num_printers, needed; + uint32 i = 0, num_printers; fstring name; if (argc > 3) @@ -345,20 +324,11 @@ static WERROR cmd_spoolss_enum_printers(struct cli_state *cli, strupper_m(name); } - /* Enumerate printers -- Should we enumerate types other - than PRINTER_ENUM_LOCAL? Maybe accept as a parameter? --jerry */ - ZERO_STRUCT(ctr); - result = cli_spoolss_enum_printers( - cli, mem_ctx, 0, &needed, name, PRINTER_ENUM_LOCAL, + result = cli_spoolss_enum_printers(cli, mem_ctx, name, PRINTER_ENUM_LOCAL, info_level, &num_printers, &ctr); - if (W_ERROR_V(result) == ERRinsufficientbuffer) - result = cli_spoolss_enum_printers( - cli, mem_ctx, needed, NULL, name, PRINTER_ENUM_LOCAL, - info_level, &num_printers, &ctr); - if (W_ERROR_IS_OK(result)) { if (!num_printers) { @@ -392,8 +362,8 @@ static WERROR cmd_spoolss_enum_printers(struct cli_state *cli, } /**************************************************************************** -port info level 1 display function ****************************************************************************/ + static void display_port_info_1(PORT_INFO_1 *i1) { fstring buffer; @@ -403,8 +373,8 @@ static void display_port_info_1(PORT_INFO_1 *i1) } /**************************************************************************** -port info level 2 display function ****************************************************************************/ + static void display_port_info_2(PORT_INFO_2 *i2) { fstring buffer; @@ -446,14 +416,15 @@ static void display_port_info_2(PORT_INFO_2 *i2) printf("\n"); } -/* Enumerate ports */ +/**************************************************************************** +****************************************************************************/ static WERROR cmd_spoolss_enum_ports(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) { WERROR result; - uint32 needed, info_level = 1; + uint32 info_level = 1; PORT_INFO_CTR ctr; uint32 returned; @@ -469,12 +440,7 @@ static WERROR cmd_spoolss_enum_ports(struct cli_state *cli, ZERO_STRUCT(ctr); - result = cli_spoolss_enum_ports(cli, mem_ctx, 0, &needed, info_level, - &returned, &ctr); - - if (W_ERROR_V(result) == ERRinsufficientbuffer) - result = cli_spoolss_enum_ports(cli, mem_ctx, needed, NULL, - info_level, &returned, &ctr); + result = cli_spoolss_enum_ports(cli, mem_ctx, info_level, &returned, &ctr); if (W_ERROR_IS_OK(result)) { int i; @@ -497,16 +463,15 @@ static WERROR cmd_spoolss_enum_ports(struct cli_state *cli, return result; } -/*********************************************************************** - * Set printer comment - use a level2 set. - */ +/**************************************************************************** +****************************************************************************/ + static WERROR cmd_spoolss_setprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) { POLICY_HND pol; WERROR result; - uint32 needed; uint32 info_level = 2; BOOL opened_hnd = False; PRINTER_INFO_CTR ctr; @@ -542,10 +507,7 @@ static WERROR cmd_spoolss_setprinter(struct cli_state *cli, opened_hnd = True; /* Get printer info */ - result = cli_spoolss_getprinter(cli, mem_ctx, 0, &needed, &pol, info_level, &ctr); - - if (W_ERROR_V(result) == ERRinsufficientbuffer) - result = cli_spoolss_getprinter(cli, mem_ctx, needed, NULL, &pol, info_level, &ctr); + result = cli_spoolss_getprinter(cli, mem_ctx, &pol, info_level, &ctr); if (!W_ERROR_IS_OK(result)) goto done; @@ -567,16 +529,15 @@ static WERROR cmd_spoolss_setprinter(struct cli_state *cli, return result; } -/*********************************************************************** - * Set printer name - use a level2 set. - */ +/**************************************************************************** +****************************************************************************/ + static WERROR cmd_spoolss_setprintername(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) { POLICY_HND pol; WERROR result; - uint32 needed; uint32 info_level = 2; BOOL opened_hnd = False; PRINTER_INFO_CTR ctr; @@ -612,15 +573,11 @@ static WERROR cmd_spoolss_setprintername(struct cli_state *cli, opened_hnd = True; /* Get printer info */ - result = cli_spoolss_getprinter(cli, mem_ctx, 0, &needed, &pol, info_level, &ctr); - - if (W_ERROR_V(result) == ERRinsufficientbuffer) - result = cli_spoolss_getprinter(cli, mem_ctx, needed, NULL, &pol, info_level, &ctr); + result = cli_spoolss_getprinter(cli, mem_ctx, &pol, info_level, &ctr); if (!W_ERROR_IS_OK(result)) goto done; - /* Modify the printername. */ init_unistr(&ctr.printers_2->printername, new_printername); ctr.printers_2->devmode = NULL; @@ -637,9 +594,9 @@ static WERROR cmd_spoolss_setprintername(struct cli_state *cli, return result; } -/*********************************************************************** - * Get printer information - */ +/**************************************************************************** +****************************************************************************/ + static WERROR cmd_spoolss_getprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) @@ -652,7 +609,6 @@ static WERROR cmd_spoolss_getprinter(struct cli_state *cli, fstring printername, servername, user; - uint32 needed; if (argc == 1 || argc > 3) { printf("Usage: %s <printername> [level]\n", argv[0]); @@ -682,12 +638,7 @@ static WERROR cmd_spoolss_getprinter(struct cli_state *cli, /* Get printer info */ - result = cli_spoolss_getprinter(cli, mem_ctx, 0, &needed, - &pol, info_level, &ctr); - - if (W_ERROR_V(result) == ERRinsufficientbuffer) - result = cli_spoolss_getprinter( - cli, mem_ctx, needed, NULL, &pol, info_level, &ctr); + result = cli_spoolss_getprinter(cli, mem_ctx, &pol, info_level, &ctr); if (!W_ERROR_IS_OK(result)) goto done; @@ -722,6 +673,9 @@ static WERROR cmd_spoolss_getprinter(struct cli_state *cli, return result; } +/**************************************************************************** +****************************************************************************/ + static void display_reg_value(REGISTRY_VALUE value) { pstring text; @@ -759,9 +713,9 @@ static void display_reg_value(REGISTRY_VALUE value) } -/*********************************************************************** - * Get printer data - */ +/**************************************************************************** +****************************************************************************/ + static WERROR cmd_spoolss_getprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) @@ -772,7 +726,6 @@ static WERROR cmd_spoolss_getprinterdata(struct cli_state *cli, fstring printername, servername, user; - uint32 needed; const char *valuename; REGISTRY_VALUE value; @@ -807,12 +760,7 @@ static WERROR cmd_spoolss_getprinterdata(struct cli_state *cli, /* Get printer info */ - result = cli_spoolss_getprinterdata(cli, mem_ctx, 0, &needed, - &pol, valuename, &value); - - if (W_ERROR_V(result) == ERRmoredata) - result = cli_spoolss_getprinterdata( - cli, mem_ctx, needed, NULL, &pol, valuename, &value); + result = cli_spoolss_getprinterdata(cli, mem_ctx, &pol, valuename, &value); if (!W_ERROR_IS_OK(result)) goto done; @@ -830,9 +778,9 @@ static WERROR cmd_spoolss_getprinterdata(struct cli_state *cli, return result; } -/*********************************************************************** - * Get printer data - */ +/**************************************************************************** +****************************************************************************/ + static WERROR cmd_spoolss_getprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) @@ -843,7 +791,6 @@ static WERROR cmd_spoolss_getprinterdataex(struct cli_state *cli, fstring printername, servername, user; - uint32 needed; const char *valuename, *keyname; REGISTRY_VALUE value; @@ -880,14 +827,8 @@ static WERROR cmd_spoolss_getprinterdataex(struct cli_state *cli, /* Get printer info */ - result = cli_spoolss_getprinterdataex(cli, mem_ctx, 0, &needed, - &pol, keyname, valuename, - &value); - - if (W_ERROR_V(result) == ERRmoredata) - result = cli_spoolss_getprinterdataex(cli, mem_ctx, needed, - NULL, &pol, keyname, - valuename, &value); + result = cli_spoolss_getprinterdataex(cli, mem_ctx, &pol, keyname, + valuename, &value); if (!W_ERROR_IS_OK(result)) goto done; @@ -906,8 +847,8 @@ static WERROR cmd_spoolss_getprinterdataex(struct cli_state *cli, } /**************************************************************************** -printer info level 0 display function ****************************************************************************/ + static void display_print_driver_1(DRIVER_INFO_1 *i1) { fstring name; @@ -923,8 +864,8 @@ static void display_print_driver_1(DRIVER_INFO_1 *i1) } /**************************************************************************** -printer info level 1 display function ****************************************************************************/ + static void display_print_driver_2(DRIVER_INFO_2 *i1) { fstring name; @@ -953,8 +894,8 @@ static void display_print_driver_2(DRIVER_INFO_2 *i1) } /**************************************************************************** -printer info level 2 display function ****************************************************************************/ + static void display_print_driver_3(DRIVER_INFO_3 *i1) { fstring name = ""; @@ -1015,9 +956,9 @@ static void display_print_driver_3(DRIVER_INFO_3 *i1) return; } -/*********************************************************************** - * Get printer information - */ +/**************************************************************************** +****************************************************************************/ + static WERROR cmd_spoolss_getdriver(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) @@ -1063,20 +1004,11 @@ static WERROR cmd_spoolss_getdriver(struct cli_state *cli, /* loop through and print driver info level for each architecture */ for (i=0; archi_table[i].long_archi!=NULL; i++) { - uint32 needed; - werror = cli_spoolss_getprinterdriver( - cli, mem_ctx, 0, &needed, &pol, info_level, + werror = cli_spoolss_getprinterdriver( cli, mem_ctx, &pol, info_level, archi_table[i].long_archi, archi_table[i].version, &ctr); - if (W_ERROR_V(werror) == ERRinsufficientbuffer) { - werror = cli_spoolss_getprinterdriver( - cli, mem_ctx, needed, NULL, &pol, info_level, - archi_table[i].long_archi, archi_table[i].version, - &ctr); - } - if (!W_ERROR_IS_OK(werror)) continue; @@ -1113,9 +1045,9 @@ static WERROR cmd_spoolss_getdriver(struct cli_state *cli, return werror; } -/*********************************************************************** - * Get printer information - */ +/**************************************************************************** +****************************************************************************/ + static WERROR cmd_spoolss_enum_drivers(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) @@ -1139,22 +1071,15 @@ static WERROR cmd_spoolss_enum_drivers(struct cli_state *cli, /* loop through and print driver info level for each architecture */ for (i=0; archi_table[i].long_archi!=NULL; i++) { - uint32 needed; - /* check to see if we already asked for this architecture string */ if ( i>0 && strequal(archi_table[i].long_archi, archi_table[i-1].long_archi) ) continue; werror = cli_spoolss_enumprinterdrivers( - cli, mem_ctx, 0, &needed, info_level, + cli, mem_ctx, info_level, archi_table[i].long_archi, &returned, &ctr); - if (W_ERROR_V(werror) == ERRinsufficientbuffer) - werror = cli_spoolss_enumprinterdrivers( - cli, mem_ctx, needed, NULL, info_level, - archi_table[i].long_archi, &returned, &ctr); - if (W_ERROR_V(werror) == W_ERROR_V(WERR_INVALID_ENVIRONMENT)) { printf ("Server does not support environment [%s]\n", archi_table[i].long_archi); @@ -1200,8 +1125,8 @@ static WERROR cmd_spoolss_enum_drivers(struct cli_state *cli, } /**************************************************************************** -printer info level 1 display function ****************************************************************************/ + static void display_printdriverdir_1(DRIVER_DIRECTORY_1 *i1) { fstring name; @@ -1213,9 +1138,9 @@ static void display_printdriverdir_1(DRIVER_DIRECTORY_1 *i1) printf ("\tDirectory Name:[%s]\n", name); } -/*********************************************************************** - * Get printer driver directory information - */ +/**************************************************************************** +****************************************************************************/ + static WERROR cmd_spoolss_getdriverdir(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) @@ -1223,7 +1148,6 @@ static WERROR cmd_spoolss_getdriverdir(struct cli_state *cli, WERROR result; fstring env; DRIVER_DIRECTORY_CTR ctr; - uint32 needed; if (argc > 2) { printf("Usage: %s [environment]\n", argv[0]); @@ -1239,12 +1163,7 @@ static WERROR cmd_spoolss_getdriverdir(struct cli_state *cli, /* Get the directory. Only use Info level 1 */ - result = cli_spoolss_getprinterdriverdir( - cli, mem_ctx, 0, &needed, 1, env, &ctr); - - if (W_ERROR_V(result) == ERRinsufficientbuffer) - result = cli_spoolss_getprinterdriverdir( - cli, mem_ctx, needed, NULL, 1, env, &ctr); + result = cli_spoolss_getprinterdriverdir(cli, mem_ctx, 1, env, &ctr); if (W_ERROR_IS_OK(result)) display_printdriverdir_1(ctr.info1); @@ -1252,9 +1171,9 @@ static WERROR cmd_spoolss_getdriverdir(struct cli_state *cli, return result; } -/******************************************************************************* - set the version and environment fields of a DRIVER_INFO_3 struct - ******************************************************************************/ +/**************************************************************************** +****************************************************************************/ + void set_drv_info_3_env (DRIVER_INFO_3 *info, const char *arch) { @@ -1283,6 +1202,7 @@ void set_drv_info_3_env (DRIVER_INFO_3 *info, const char *arch) wrapper for strtok to get the next parameter from a delimited list. Needed to handle the empty parameter string denoted by "NULL" *************************************************************************/ + static char* get_driver_3_param (char* str, const char* delim, UNISTR* dest) { char *ptr; @@ -1357,6 +1277,9 @@ static BOOL init_drv_info_3_members ( TALLOC_CTX *mem_ctx, DRIVER_INFO_3 *info, } +/**************************************************************************** +****************************************************************************/ + static WERROR cmd_spoolss_addprinterdriver(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) @@ -1421,6 +1344,9 @@ static WERROR cmd_spoolss_addprinterdriver(struct cli_state *cli, } +/**************************************************************************** +****************************************************************************/ + static WERROR cmd_spoolss_addprinterex(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) @@ -1443,9 +1369,7 @@ static WERROR cmd_spoolss_addprinterex(struct cli_state *cli, /* Fill in the DRIVER_INFO_2 struct */ ZERO_STRUCT(info2); -#if 0 /* JERRY */ - init_unistr( &info2.servername, servername); -#endif + init_unistr( &info2.printername, argv[1]); init_unistr( &info2.sharename, argv[2]); init_unistr( &info2.drivername, argv[3]); @@ -1478,6 +1402,9 @@ static WERROR cmd_spoolss_addprinterex(struct cli_state *cli, return result; } +/**************************************************************************** +****************************************************************************/ + static WERROR cmd_spoolss_setdriver(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) @@ -1491,7 +1418,6 @@ static WERROR cmd_spoolss_setdriver(struct cli_state *cli, fstring servername, printername, user; - uint32 needed; /* parse the command arguements */ if (argc != 3) @@ -1521,12 +1447,7 @@ static WERROR cmd_spoolss_setdriver(struct cli_state *cli, ZERO_STRUCT (info2); ctr.printers_2 = &info2; - result = cli_spoolss_getprinter(cli, mem_ctx, 0, &needed, - &pol, level, &ctr); - - if (W_ERROR_V(result) == ERRinsufficientbuffer) - result = cli_spoolss_getprinter( - cli, mem_ctx, needed, NULL, &pol, level, &ctr); + result = cli_spoolss_getprinter(cli, mem_ctx, &pol, level, &ctr); if (!W_ERROR_IS_OK(result)) { printf ("Unable to retrieve printer information!\n"); @@ -1556,6 +1477,9 @@ done: } +/**************************************************************************** +****************************************************************************/ + static WERROR cmd_spoolss_deletedriverex(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) @@ -1611,6 +1535,9 @@ static WERROR cmd_spoolss_deletedriverex(struct cli_state *cli, } +/**************************************************************************** +****************************************************************************/ + static WERROR cmd_spoolss_deletedriver(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) @@ -1653,6 +1580,9 @@ static WERROR cmd_spoolss_deletedriver(struct cli_state *cli, return result; } +/**************************************************************************** +****************************************************************************/ + static WERROR cmd_spoolss_getprintprocdir(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) @@ -1660,7 +1590,6 @@ static WERROR cmd_spoolss_getprintprocdir(struct cli_state *cli, WERROR result; char *servername = NULL, *environment = NULL; fstring procdir; - uint32 needed; /* parse the command arguements */ if (argc > 2) { @@ -1679,12 +1608,7 @@ static WERROR cmd_spoolss_getprintprocdir(struct cli_state *cli, } result = cli_spoolss_getprintprocessordirectory( - cli, mem_ctx, 0, &needed, servername, environment, procdir); - - if (W_ERROR_V(result) == ERRinsufficientbuffer) - result = cli_spoolss_getprintprocessordirectory( - cli, mem_ctx, needed, NULL, servername, environment, - procdir); + cli, mem_ctx, servername, environment, procdir); if (W_ERROR_IS_OK(result)) printf("%s\n", procdir); @@ -1695,7 +1619,8 @@ static WERROR cmd_spoolss_getprintprocdir(struct cli_state *cli, return result; } -/* Add a form */ +/**************************************************************************** +****************************************************************************/ static WERROR cmd_spoolss_addform(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) @@ -1754,7 +1679,8 @@ static WERROR cmd_spoolss_addform(struct cli_state *cli, TALLOC_CTX *mem_ctx, return werror; } -/* Set a form */ +/**************************************************************************** +****************************************************************************/ static WERROR cmd_spoolss_setform(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) @@ -1812,6 +1738,9 @@ static WERROR cmd_spoolss_setform(struct cli_state *cli, TALLOC_CTX *mem_ctx, return werror; } +/**************************************************************************** +****************************************************************************/ + static const char *get_form_flag(int form_flag) { switch (form_flag) { @@ -1826,6 +1755,9 @@ static const char *get_form_flag(int form_flag) } } +/**************************************************************************** +****************************************************************************/ + static void display_form(FORM_1 *form) { fstring form_name = ""; @@ -1844,7 +1776,8 @@ static void display_form(FORM_1 *form) form->top, form->bottom); } -/* Get a form */ +/**************************************************************************** +****************************************************************************/ static WERROR cmd_spoolss_getform(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) @@ -1854,7 +1787,6 @@ static WERROR cmd_spoolss_getform(struct cli_state *cli, TALLOC_CTX *mem_ctx, char *servername = NULL, *printername = NULL; FORM_1 form; BOOL got_handle = False; - uint32 needed; /* Parse the command arguements */ @@ -1880,12 +1812,7 @@ static WERROR cmd_spoolss_getform(struct cli_state *cli, TALLOC_CTX *mem_ctx, /* Get the form */ - werror = cli_spoolss_getform(cli, mem_ctx, 0, &needed, - &handle, argv[2], 1, &form); - - if (W_ERROR_V(werror) == ERRinsufficientbuffer) - werror = cli_spoolss_getform(cli, mem_ctx, needed, NULL, - &handle, argv[2], 1, &form); + werror = cli_spoolss_getform(cli, mem_ctx, &handle, argv[2], 1, &form); if (!W_ERROR_IS_OK(werror)) goto done; @@ -1902,7 +1829,8 @@ static WERROR cmd_spoolss_getform(struct cli_state *cli, TALLOC_CTX *mem_ctx, return werror; } -/* Delete a form */ +/**************************************************************************** +****************************************************************************/ static WERROR cmd_spoolss_deleteform(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, @@ -1949,7 +1877,8 @@ static WERROR cmd_spoolss_deleteform(struct cli_state *cli, return werror; } -/* Enumerate forms */ +/**************************************************************************** +****************************************************************************/ static WERROR cmd_spoolss_enum_forms(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, @@ -1959,7 +1888,7 @@ static WERROR cmd_spoolss_enum_forms(struct cli_state *cli, WERROR werror; char *servername = NULL, *printername = NULL; BOOL got_handle = False; - uint32 needed, num_forms, level = 1, i; + uint32 needed, offered, num_forms, level = 1, i; FORM_1 *forms; /* Parse the command arguements */ @@ -1986,13 +1915,8 @@ static WERROR cmd_spoolss_enum_forms(struct cli_state *cli, /* Enumerate forms */ - werror = cli_spoolss_enumforms( - cli, mem_ctx, 0, &needed, &handle, level, &num_forms, &forms); - - if (W_ERROR_V(werror) == ERRinsufficientbuffer) - werror = cli_spoolss_enumforms( - cli, mem_ctx, needed, NULL, &handle, level, - &num_forms, &forms); + offered = needed = 0; + werror = cli_spoolss_enumforms(cli, mem_ctx, &handle, level, &num_forms, &forms); if (!W_ERROR_IS_OK(werror)) goto done; @@ -2015,12 +1939,14 @@ static WERROR cmd_spoolss_enum_forms(struct cli_state *cli, return werror; } +/**************************************************************************** +****************************************************************************/ + static WERROR cmd_spoolss_setprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) { WERROR result; - uint32 needed; fstring servername, printername, user; POLICY_HND pol; BOOL opened_hnd = False; @@ -2033,7 +1959,7 @@ static WERROR cmd_spoolss_setprinterdata(struct cli_state *cli, if (argc != 4) { printf ("Usage: %s <printer> <value> <data>\n", argv[0]); return WERR_OK; - } + } slprintf(servername, sizeof(servername)-1, "\\\\%s", cli->desthost); strupper_m(servername); @@ -2051,11 +1977,7 @@ static WERROR cmd_spoolss_setprinterdata(struct cli_state *cli, ctr.printers_0 = &info; - result = cli_spoolss_getprinter(cli, mem_ctx, 0, &needed, - &pol, 0, &ctr); - - if (W_ERROR_V(result) == ERRinsufficientbuffer) - result = cli_spoolss_getprinter(cli, mem_ctx, needed, NULL, &pol, 0, &ctr); + result = cli_spoolss_getprinter(cli, mem_ctx, &pol, 0, &ctr); if (!W_ERROR_IS_OK(result)) goto done; @@ -2078,11 +2000,8 @@ static WERROR cmd_spoolss_setprinterdata(struct cli_state *cli, goto done; } printf("\tSetPrinterData succeeded [%s: %s]\n", argv[2], argv[3]); - - result = cli_spoolss_getprinter(cli, mem_ctx, 0, &needed, &pol, 0, &ctr); - - if (W_ERROR_V(result) == ERRinsufficientbuffer) - result = cli_spoolss_getprinter(cli, mem_ctx, needed, NULL, &pol, 0, &ctr); + + result = cli_spoolss_getprinter(cli, mem_ctx, &pol, 0, &ctr); if (!W_ERROR_IS_OK(result)) goto done; @@ -2098,6 +2017,9 @@ done: return result; } +/**************************************************************************** +****************************************************************************/ + static void display_job_info_1(JOB_INFO_1 *job) { fstring username = "", document = "", text_status = ""; @@ -2116,6 +2038,9 @@ static void display_job_info_1(JOB_INFO_1 *job) job->totalpages); } +/**************************************************************************** +****************************************************************************/ + static void display_job_info_2(JOB_INFO_2 *job) { fstring username = "", document = "", text_status = ""; @@ -2134,14 +2059,15 @@ static void display_job_info_2(JOB_INFO_2 *job) job->totalpages, job->size); } -/* Enumerate jobs */ +/**************************************************************************** +****************************************************************************/ static WERROR cmd_spoolss_enum_jobs(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) { WERROR result; - uint32 needed, level = 1, num_jobs, i; + uint32 needed, offered, level = 1, num_jobs, i; BOOL got_hnd = False; pstring printername; fstring servername, user; @@ -2176,15 +2102,10 @@ static WERROR cmd_spoolss_enum_jobs(struct cli_state *cli, /* Enumerate ports */ - result = cli_spoolss_enumjobs( - cli, mem_ctx, 0, &needed, &hnd, level, 0, 1000, + offered = needed = 0; + result = cli_spoolss_enumjobs(cli, mem_ctx, &hnd, level, 0, 1000, &num_jobs, &ctr); - if (W_ERROR_V(result) == ERRinsufficientbuffer) - result = cli_spoolss_enumjobs( - cli, mem_ctx, needed, NULL, &hnd, level, 0, - 1000, &num_jobs, &ctr); - if (!W_ERROR_IS_OK(result)) goto done; @@ -2209,7 +2130,8 @@ done: return result; } -/* enumerate data */ +/**************************************************************************** +****************************************************************************/ static WERROR cmd_spoolss_enum_data( struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, @@ -2268,14 +2190,15 @@ done: return result; } -/* enumerate data for a given key */ +/**************************************************************************** +****************************************************************************/ static WERROR cmd_spoolss_enum_data_ex( struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) { WERROR result; - uint32 needed, i; + uint32 i; BOOL got_hnd = False; pstring printername; fstring servername, user; @@ -2311,11 +2234,7 @@ static WERROR cmd_spoolss_enum_data_ex( struct cli_state *cli, /* Enumerate subkeys */ result = cli_spoolss_enumprinterdataex( - cli, mem_ctx, 0, &needed, &hnd, keyname, NULL); - - if (W_ERROR_V(result) == ERRmoredata) - result = cli_spoolss_enumprinterdataex( - cli, mem_ctx, needed, NULL, &hnd, keyname, &ctr); + cli, mem_ctx, &hnd, keyname, NULL); if (!W_ERROR_IS_OK(result)) goto done; @@ -2333,14 +2252,14 @@ done: return result; } -/* enumerate subkeys */ +/**************************************************************************** +****************************************************************************/ static WERROR cmd_spoolss_enum_printerkey( struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) { WERROR result; - uint32 needed, returned; BOOL got_hnd = False; pstring printername; fstring servername, user; @@ -2352,7 +2271,7 @@ static WERROR cmd_spoolss_enum_printerkey( struct cli_state *cli, printf("Usage: %s printername [keyname]\n", argv[0]); return WERR_OK; } - + if (argc == 3) keyname = argv[2]; else @@ -2373,18 +2292,12 @@ static WERROR cmd_spoolss_enum_printerkey( struct cli_state *cli, if (!W_ERROR_IS_OK(result)) goto done; - + got_hnd = True; /* Enumerate subkeys */ - result = cli_spoolss_enumprinterkey( - cli, mem_ctx, 0, &needed, &hnd, keyname, NULL, NULL); - - if (W_ERROR_V(result) == ERRmoredata) - result = cli_spoolss_enumprinterkey( - cli, mem_ctx, needed, NULL, &hnd, keyname, &keylist, - &returned); + result = cli_spoolss_enumprinterkey(cli, mem_ctx, &hnd, keyname, NULL, NULL); if (!W_ERROR_IS_OK(result)) goto done; @@ -2407,6 +2320,9 @@ done: return result; } +/**************************************************************************** +****************************************************************************/ + static WERROR cmd_spoolss_rffpcnex(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) diff --git a/source/smbd/aio.c b/source/smbd/aio.c index 7910ee5a7aa..d19706ff61a 100644 --- a/source/smbd/aio.c +++ b/source/smbd/aio.c @@ -242,7 +242,7 @@ BOOL schedule_aio_read_and_X(connection_struct *conn, /* Now set up the aio record for the read call. */ - a->aio_fildes = fsp->fd; + a->aio_fildes = fsp->fh->fd; a->aio_buf = smb_buf(aio_ex->outbuf); a->aio_nbytes = smb_maxcnt; a->aio_offset = startpos; @@ -321,7 +321,7 @@ BOOL schedule_aio_write_and_X(connection_struct *conn, /* Now set up the aio record for the write call. */ - a->aio_fildes = fsp->fd; + a->aio_fildes = fsp->fh->fd; a->aio_buf = data; /* As we've stolen inbuf this points within inbuf. */ a->aio_nbytes = numtowrite; a->aio_offset = startpos; @@ -677,7 +677,7 @@ void cancel_aio_by_fsp(files_struct *fsp) if (aio_ex->fsp == fsp) { /* Don't delete the aio_extra record as we may have completed and don't yet know it. Just do the aio_cancel call and return. */ - SMB_VFS_AIO_CANCEL(fsp,fsp->fd, &aio_ex->acb); + SMB_VFS_AIO_CANCEL(fsp,fsp->fh->fd, &aio_ex->acb); aio_ex->fsp = NULL; /* fsp will be closed when we return. */ } } diff --git a/source/smbd/chgpasswd.c b/source/smbd/chgpasswd.c index 56e5727b7d9..f445ca3365b 100644 --- a/source/smbd/chgpasswd.c +++ b/source/smbd/chgpasswd.c @@ -1017,7 +1017,6 @@ NTSTATUS change_oem_password(SAM_ACCOUNT *hnd, char *old_passwd, char *new_passw return NT_STATUS_ACCOUNT_RESTRICTION; } - /* FIXME: AP_MIN_PASSWORD_LEN and lp_min_passwd_length() need to be merged - gd */ if (account_policy_get(AP_MIN_PASSWORD_LEN, &min_len) && (str_charnum(new_passwd) < min_len)) { DEBUG(1, ("user %s cannot change password - password too short\n", username)); @@ -1026,16 +1025,6 @@ NTSTATUS change_oem_password(SAM_ACCOUNT *hnd, char *old_passwd, char *new_passw /* return NT_STATUS_PWD_TOO_SHORT; */ } - /* Take the passed information and test it for minimum criteria */ - /* Minimum password length */ - if (str_charnum(new_passwd) < lp_min_passwd_length()) { - /* too short, must be at least MINPASSWDLENGTH */ - DEBUG(1, ("Password Change: user %s, New password is shorter than minimum password length = %d\n", - username, lp_min_passwd_length())); - return NT_STATUS_PASSWORD_RESTRICTION; -/* return NT_STATUS_PWD_TOO_SHORT; */ - } - if (check_passwd_history(hnd,new_passwd)) { return NT_STATUS_PASSWORD_RESTRICTION; } diff --git a/source/smbd/close.c b/source/smbd/close.c index 3fc7fdb0599..afc645ca062 100644 --- a/source/smbd/close.c +++ b/source/smbd/close.c @@ -134,6 +134,7 @@ static void notify_deferred_opens(files_struct *fsp) send_deferred_open_retry_message(entry); } } + SAFE_FREE(de_array); } /**************************************************************************** diff --git a/source/smbd/dir.c b/source/smbd/dir.c index 949e31210f6..a0df924dc7c 100644 --- a/source/smbd/dir.c +++ b/source/smbd/dir.c @@ -26,6 +26,11 @@ extern struct current_user current_user; +/* "Special" directory offsets. */ +#define END_OF_DIRECTORY_OFFSET ((long)-1) +#define START_OF_DIRECTORY_OFFSET ((long)0) +#define DOT_DOT_DIRECTORY_OFFSET ((long)0x80000000) + /* Make directory handle internals available. */ #define NAME_CACHE_SIZE 100 @@ -560,7 +565,7 @@ const char *dptr_ReadDirName(struct dptr_struct *dptr, long *poffset, SMB_STRUCT /* If poffset is -1 then we know we returned this name before and we have no wildcards. We're at the end of the directory. */ - if (*poffset == -1) { + if (*poffset == END_OF_DIRECTORY_OFFSET) { return NULL; } @@ -577,7 +582,7 @@ const char *dptr_ReadDirName(struct dptr_struct *dptr, long *poffset, SMB_STRUCT if (VALID_STAT(*pst)) { /* We need to set the underlying dir_hdn offset to -1 also as this function is usually called with the output from TellDir. */ - dptr->dir_hnd->offset = *poffset = -1; + dptr->dir_hnd->offset = *poffset = END_OF_DIRECTORY_OFFSET; return dptr->wcard; } @@ -588,7 +593,7 @@ const char *dptr_ReadDirName(struct dptr_struct *dptr, long *poffset, SMB_STRUCT if (SMB_VFS_STAT(dptr->conn,pathreal,pst) == 0) { /* We need to set the underlying dir_hdn offset to -1 also as this function is usually called with the output from TellDir. */ - dptr->dir_hnd->offset = *poffset = -1; + dptr->dir_hnd->offset = *poffset = END_OF_DIRECTORY_OFFSET; return dptr->wcard; } else { /* If we get any other error than ENOENT or ENOTDIR @@ -596,7 +601,7 @@ const char *dptr_ReadDirName(struct dptr_struct *dptr, long *poffset, SMB_STRUCT if (errno != ENOENT && errno != ENOTDIR) { /* We need to set the underlying dir_hdn offset to -1 also as this function is usually called with the output from TellDir. */ - dptr->dir_hnd->offset = *poffset = -1; + dptr->dir_hnd->offset = *poffset = END_OF_DIRECTORY_OFFSET; return dptr->wcard; } } @@ -607,7 +612,7 @@ const char *dptr_ReadDirName(struct dptr_struct *dptr, long *poffset, SMB_STRUCT if (dptr->conn->case_sensitive) { /* We need to set the underlying dir_hdn offset to -1 also as this function is usually called with the output from TellDir. */ - dptr->dir_hnd->offset = *poffset = -1; + dptr->dir_hnd->offset = *poffset = END_OF_DIRECTORY_OFFSET; return NULL; } else { dptr->has_wild = True; @@ -623,9 +628,9 @@ BOOL dptr_SearchDir(struct dptr_struct *dptr, const char *name, long *poffset, S { SET_STAT_INVALID(*pst); - if (!dptr->has_wild && (dptr->dir_hnd->offset == -1)) { + if (!dptr->has_wild && (dptr->dir_hnd->offset == END_OF_DIRECTORY_OFFSET)) { /* This is a singleton directory and we're already at the end. */ - *poffset = -1; + *poffset = END_OF_DIRECTORY_OFFSET; return False; } @@ -676,7 +681,7 @@ struct dptr_struct *dptr_fetch(char *buf,int *num) *num = key; offset = IVAL(buf,1); if (offset == (uint32)-1) { - seekoff = -1; + seekoff = END_OF_DIRECTORY_OFFSET; } else { seekoff = (long)offset; } @@ -1083,10 +1088,12 @@ const char *ReadDirName(struct smb_Dir *dirp, long *poffset) connection_struct *conn = dirp->conn; /* Cheat to allow . and .. to be the first entries returned. */ - if ((*poffset == 0) && (dirp->file_number < 2)) { + if (((*poffset == START_OF_DIRECTORY_OFFSET) || (*poffset == DOT_DOT_DIRECTORY_OFFSET)) && (dirp->file_number < 2)) { if (dirp->file_number == 0) { n = "."; + *poffset = dirp->offset = START_OF_DIRECTORY_OFFSET; } else { + *poffset = dirp->offset = DOT_DOT_DIRECTORY_OFFSET; n = ".."; } dirp->file_number++; @@ -1113,7 +1120,7 @@ const char *ReadDirName(struct smb_Dir *dirp, long *poffset) dirp->file_number++; return e->name; } - dirp->offset = -1; + dirp->offset = END_OF_DIRECTORY_OFFSET; return NULL; } @@ -1125,8 +1132,8 @@ void RewindDir(struct smb_Dir *dirp, long *poffset) { SMB_VFS_REWINDDIR(dirp->conn, dirp->dir); dirp->file_number = 0; - dirp->offset = 0; - *poffset = 0; + dirp->offset = START_OF_DIRECTORY_OFFSET; + *poffset = START_OF_DIRECTORY_OFFSET; } /******************************************************************* @@ -1136,7 +1143,7 @@ void RewindDir(struct smb_Dir *dirp, long *poffset) void SeekDir(struct smb_Dir *dirp, long offset) { if (offset != dirp->offset) { - if (offset == 0) { + if (offset == START_OF_DIRECTORY_OFFSET || offset == DOT_DOT_DIRECTORY_OFFSET) { RewindDir(dirp, &offset); } else { SMB_VFS_SEEKDIR(dirp->conn, dirp->dir, offset); @@ -1186,7 +1193,7 @@ BOOL SearchDir(struct smb_Dir *dirp, const char *name, long *poffset) /* Not found in the name cache. Rewind directory and start from scratch. */ SMB_VFS_REWINDDIR(conn, dirp->dir); dirp->file_number = 0; - *poffset = 0; + *poffset = START_OF_DIRECTORY_OFFSET; while ((entry = ReadDirName(dirp, poffset))) { if (conn->case_sensitive ? (strcmp(entry, name) == 0) : strequal(entry, name)) { return True; diff --git a/source/smbd/msdfs.c b/source/smbd/msdfs.c index fffe44ab603..d0438b01af1 100644 --- a/source/smbd/msdfs.c +++ b/source/smbd/msdfs.c @@ -251,8 +251,7 @@ BOOL is_msdfs_link(connection_struct* conn, char * path, if (S_ISLNK(sbufp->st_mode)) { /* open the link and read it */ - referral_len = SMB_VFS_READLINK(conn, path, referral, - sizeof(pstring)); + referral_len = SMB_VFS_READLINK(conn, path, referral, sizeof(pstring)-1); if (referral_len == -1) { DEBUG(0,("is_msdfs_link: Error reading msdfs link %s: %s\n", path, strerror(errno))); return False; diff --git a/source/smbd/notify_hash.c b/source/smbd/notify_hash.c index 08eefab6520..ee7d4314eef 100644 --- a/source/smbd/notify_hash.c +++ b/source/smbd/notify_hash.c @@ -23,14 +23,28 @@ struct change_data { time_t last_check_time; /* time we last checked this entry */ +#ifdef HAVE_STAT_HIRES_TIMESTAMPS + struct timespec modify_time; + struct timespec status_time; +#else time_t modify_time; /* Info from the directory we're monitoring. */ time_t status_time; /* Info from the directory we're monitoring. */ +#endif time_t total_time; /* Total time of all directory entries - don't care if it wraps. */ unsigned int num_entries; /* Zero or the number of files in the directory. */ unsigned int mode_sum; unsigned char name_hash[16]; }; + +#ifdef HAVE_STAT_HIRES_TIMESTAMPS +/* Compare struct timespec. */ +#define TIMESTAMP_NEQ(x, y) (((x).tv_sec != (y).tv_sec) || ((x).tv_nsec != (y).tv_nsec)) +#else +/* Compare time_t . */ +#define TIMESTAMP_NEQ(x, y) ((x) != (y)) +#endif + /**************************************************************************** Create the hash we will use to determine if the contents changed. *****************************************************************************/ @@ -52,20 +66,36 @@ static BOOL notify_hash(connection_struct *conn, char *path, uint32 flags, if(SMB_VFS_STAT(conn,path, &st) == -1) return False; +#ifdef HAVE_STAT_HIRES_TIMESTAMPS + data->modify_time = st.st_mtim; + data->status_time = st.st_ctim; +#else data->modify_time = st.st_mtime; data->status_time = st.st_ctime; +#endif if (old_data) { /* * Shortcut to avoid directory scan if the time * has changed - we always must return true then. */ - if (old_data->modify_time != data->modify_time || - old_data->status_time != data->status_time ) { + if (TIMESTAMP_NEQ(old_data->modify_time, data->modify_time) || + TIMESTAMP_NEQ(old_data->status_time, data->status_time) ) { return True; } } + if (S_ISDIR(st.st_mode) && + (flags & ~(FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME)) == 0) + { + /* This is the case of a client wanting to know only when + * the contents of a directory changes. Since any file + * creation, rename or deletion will update the directory + * timestamps, we don't need to create a hash. + */ + return True; + } + /* * If we are to watch for changes that are only stored * in inodes of files, not in the directory inode, we must @@ -176,8 +206,8 @@ static BOOL hash_check_notify(connection_struct *conn, uint16 vuid, char *path, } if (!notify_hash(conn, path, flags, &data2, data) || - data2.modify_time != data->modify_time || - data2.status_time != data->status_time || + TIMESTAMP_NEQ(data2.modify_time, data->modify_time) || + TIMESTAMP_NEQ(data2.status_time, data->status_time) || data2.total_time != data->total_time || data2.num_entries != data->num_entries || data2.mode_sum != data->mode_sum || diff --git a/source/smbd/open.c b/source/smbd/open.c index 810913c025d..3cd553f55b5 100644 --- a/source/smbd/open.c +++ b/source/smbd/open.c @@ -556,7 +556,6 @@ static int open_mode_check(connection_struct *conn, uint32 access_mask, uint32 share_access, uint32 create_options, - int *p_flags, int *p_oplock_request, BOOL *p_all_current_opens_are_level_II) { @@ -1469,7 +1468,7 @@ files_struct *open_file_ntcreate(connection_struct *conn, num_share_modes = open_mode_check(conn, fname, dev, inode, access_mask, share_access, create_options, - &flags, &oplock_request, + &oplock_request, &all_current_opens_are_level_II); if(num_share_modes == -1) { @@ -1625,7 +1624,7 @@ files_struct *open_file_ntcreate(connection_struct *conn, num_share_modes = open_mode_check(conn, fname, dev, inode, access_mask, share_access, create_options, - &flags, &oplock_request, + &oplock_request, &all_current_opens_are_level_II); if(num_share_modes == -1) { diff --git a/source/smbd/oplock.c b/source/smbd/oplock.c index 3cfce5c7a1f..de120039867 100644 --- a/source/smbd/oplock.c +++ b/source/smbd/oplock.c @@ -276,7 +276,7 @@ BOOL remove_oplock(files_struct *fsp, BOOL break_to_none) return False; } - if (fsp->sent_oplock_break == EXCLUSIVE_BREAK_SENT || break_to_none) { + if (fsp->sent_oplock_break == BREAK_TO_NONE_SENT || break_to_none) { /* * Deal with a reply when a break-to-none was sent. */ @@ -461,12 +461,12 @@ pid %d, port %d, dev = %x, inode = %.0f, file_id = %lu\n", */ DEBUG(3,("process_local_message: oplock break requested with " "no outstanding oplocks. Returning success.\n")); - return True; - } - if (!oplock_break(dev, inode, file_id, False)) { - DEBUG(0,("process_local_message: oplock break failed.\n")); - return False; + } else { + if (!oplock_break(dev, inode, file_id, False)) { + DEBUG(0,("process_local_message: oplock break failed.\n")); + return False; + } } /* @@ -526,24 +526,22 @@ static void prepare_break_message(char *outbuf, files_struct *fsp, BOOL level2) Function to do the waiting before sending a local break. ****************************************************************************/ -static void wait_before_sending_break(BOOL local_request) +static void wait_before_sending_break(void) { - if(local_request) { - struct timeval cur_tv; - long wait_left = (long)lp_oplock_break_wait_time(); + struct timeval cur_tv; + long wait_left = (long)lp_oplock_break_wait_time(); - if (wait_left == 0) - return; + if (wait_left == 0) + return; - GetTimeOfDay(&cur_tv); + GetTimeOfDay(&cur_tv); - wait_left -= ((cur_tv.tv_sec - smb_last_time.tv_sec)*1000) + + wait_left -= ((cur_tv.tv_sec - smb_last_time.tv_sec)*1000) + ((cur_tv.tv_usec - smb_last_time.tv_usec)/1000); - if(wait_left > 0) { - wait_left = MIN(wait_left, 1000); - sys_usleep(wait_left * 1000); - } + if(wait_left > 0) { + wait_left = MIN(wait_left, 1000); + sys_usleep(wait_left * 1000); } } @@ -633,7 +631,9 @@ static BOOL oplock_break_level2(files_struct *fsp, BOOL local_request) * and has reported to cause problems on NT. JRA. */ - wait_before_sending_break(local_request); + if (local_request) { + wait_before_sending_break(); + } /* Prepare the SMBlockingX message. */ prepare_break_message( outbuf, fsp, False); @@ -770,7 +770,9 @@ static BOOL oplock_break(SMB_DEV_T dev, SMB_INO_T inode, unsigned long file_id, * and has reported to cause problems on NT. JRA. */ - wait_before_sending_break(local_request); + if (local_request) { + wait_before_sending_break(); + } /* Prepare the SMBlockingX message. */ @@ -784,7 +786,7 @@ static BOOL oplock_break(SMB_DEV_T dev, SMB_INO_T inode, unsigned long file_id, prepare_break_message( outbuf, fsp, using_levelII); /* Remember if we just sent a break to level II on this file. */ - fsp->sent_oplock_break = using_levelII? LEVEL_II_BREAK_SENT:EXCLUSIVE_BREAK_SENT; + fsp->sent_oplock_break = using_levelII? LEVEL_II_BREAK_SENT:BREAK_TO_NONE_SENT; /* Save the server smb signing state. */ sign_state = srv_oplock_set_signing(False); diff --git a/source/smbd/password.c b/source/smbd/password.c index 2ee8c1232e3..9ee721089c9 100644 --- a/source/smbd/password.c +++ b/source/smbd/password.c @@ -47,7 +47,31 @@ user_struct *get_valid_user_struct(uint16 vuid) return NULL; for (usp=validated_users;usp;usp=usp->next,count++) { - if (vuid == usp->vuid) { + if (vuid == usp->vuid && usp->server_info) { + if (count > 10) { + DLIST_PROMOTE(validated_users, usp); + } + return usp; + } + } + + return NULL; +} + +/**************************************************************************** + Get the user struct of a partial NTLMSSP login +****************************************************************************/ + +user_struct *get_partial_auth_user_struct(uint16 vuid) +{ + user_struct *usp; + int count=0; + + if (vuid == UID_FIELD_INVALID) + return NULL; + + for (usp=validated_users;usp;usp=usp->next,count++) { + if (vuid == usp->vuid && !usp->server_info) { if (count > 10) { DLIST_PROMOTE(validated_users, usp); } @@ -159,6 +183,17 @@ int register_vuid(auth_serversupplied_info *server_info, DATA_BLOB session_key, vuser->vuid = next_vuid; + if (!server_info) { + next_vuid++; + num_validated_vuids++; + + vuser->server_info = NULL; + + DLIST_ADD(validated_users, vuser); + + return vuser->vuid; + } + /* the next functions should be done by a SID mapping system (SMS) as * the new real sam db won't have reference to unix uids or gids */ diff --git a/source/smbd/posix_acls.c b/source/smbd/posix_acls.c index ab14638a24c..a1855b0fa98 100644 --- a/source/smbd/posix_acls.c +++ b/source/smbd/posix_acls.c @@ -1060,7 +1060,6 @@ static BOOL ensure_canon_entry_valid(canon_ace **pp_ace, BOOL got_grp = False; BOOL got_other = False; canon_ace *pace_other = NULL; - canon_ace *pace_group = NULL; for (pace = *pp_ace; pace; pace = pace->next) { if (pace->type == SMB_ACL_USER_OBJ) { @@ -1078,7 +1077,6 @@ static BOOL ensure_canon_entry_valid(canon_ace **pp_ace, if (setting_acl) apply_default_perms(fsp, pace, S_IRGRP); got_grp = True; - pace_group = pace; } else if (pace->type == SMB_ACL_OTHER) { @@ -2239,10 +2237,42 @@ static canon_ace *canonicalise_acl( files_struct *fsp, SMB_ACL_T posix_acl, SMB_ } /**************************************************************************** + Check if the current user group list contains a given group. +****************************************************************************/ + +static BOOL current_user_in_group(gid_t gid) +{ + int i; + + for (i = 0; i < current_user.ngroups; i++) { + if (current_user.groups[i] == gid) { + return True; + } + } + + return False; +} + +/**************************************************************************** + Should we override a deny ? +****************************************************************************/ + +static BOOL acl_group_override(connection_struct *conn, gid_t prim_gid) +{ + if ((errno == EACCES || errno == EPERM) && + lp_acl_group_control(SNUM(conn)) && + current_user_in_group(prim_gid)) { + return True; + } else { + return False; + } +} + +/**************************************************************************** Attempt to apply an ACL to a file or directory. ****************************************************************************/ -static BOOL set_canon_ace_list(files_struct *fsp, canon_ace *the_ace, BOOL default_ace, BOOL *pacl_set_support) +static BOOL set_canon_ace_list(files_struct *fsp, canon_ace *the_ace, BOOL default_ace, gid_t prim_gid, BOOL *pacl_set_support) { connection_struct *conn = fsp->conn; BOOL ret = False; @@ -2307,7 +2337,7 @@ static BOOL set_canon_ace_list(files_struct *fsp, canon_ace *the_ace, BOOL defau if (SMB_VFS_SYS_ACL_CREATE_ENTRY(conn, &the_acl, &the_entry) == -1) { DEBUG(0,("set_canon_ace_list: Failed to create entry %d. (%s)\n", i, strerror(errno) )); - goto done; + goto fail; } if (p_ace->type == SMB_ACL_MASK) { @@ -2333,7 +2363,7 @@ static BOOL set_canon_ace_list(files_struct *fsp, canon_ace *the_ace, BOOL defau if (SMB_VFS_SYS_ACL_SET_TAG_TYPE(conn, the_entry, p_ace->type) == -1) { DEBUG(0,("set_canon_ace_list: Failed to set tag type on entry %d. (%s)\n", i, strerror(errno) )); - goto done; + goto fail; } /* @@ -2345,7 +2375,7 @@ static BOOL set_canon_ace_list(files_struct *fsp, canon_ace *the_ace, BOOL defau if (SMB_VFS_SYS_ACL_SET_QUALIFIER(conn, the_entry,(void *)&p_ace->unix_ug.uid) == -1) { DEBUG(0,("set_canon_ace_list: Failed to set qualifier on entry %d. (%s)\n", i, strerror(errno) )); - goto done; + goto fail; } } @@ -2356,13 +2386,13 @@ static BOOL set_canon_ace_list(files_struct *fsp, canon_ace *the_ace, BOOL defau if (SMB_VFS_SYS_ACL_GET_PERMSET(conn, the_entry, &the_permset) == -1) { DEBUG(0,("set_canon_ace_list: Failed to get permset on entry %d. (%s)\n", i, strerror(errno) )); - goto done; + goto fail; } if (map_acl_perms_to_permset(conn, p_ace->perms, &the_permset) == -1) { DEBUG(0,("set_canon_ace_list: Failed to create permset for mode (%u) on entry %d. (%s)\n", (unsigned int)p_ace->perms, i, strerror(errno) )); - goto done; + goto fail; } /* @@ -2372,7 +2402,7 @@ static BOOL set_canon_ace_list(files_struct *fsp, canon_ace *the_ace, BOOL defau if (SMB_VFS_SYS_ACL_SET_PERMSET(conn, the_entry, the_permset) == -1) { DEBUG(0,("set_canon_ace_list: Failed to add permset on entry %d. (%s)\n", i, strerror(errno) )); - goto done; + goto fail; } if( DEBUGLVL( 10 )) @@ -2383,27 +2413,27 @@ static BOOL set_canon_ace_list(files_struct *fsp, canon_ace *the_ace, BOOL defau if (needs_mask && !got_mask_entry) { if (SMB_VFS_SYS_ACL_CREATE_ENTRY(conn, &the_acl, &mask_entry) == -1) { DEBUG(0,("set_canon_ace_list: Failed to create mask entry. (%s)\n", strerror(errno) )); - goto done; + goto fail; } if (SMB_VFS_SYS_ACL_SET_TAG_TYPE(conn, mask_entry, SMB_ACL_MASK) == -1) { DEBUG(0,("set_canon_ace_list: Failed to set tag type on mask entry. (%s)\n",strerror(errno) )); - goto done; + goto fail; } if (SMB_VFS_SYS_ACL_GET_PERMSET(conn, mask_entry, &mask_permset) == -1) { DEBUG(0,("set_canon_ace_list: Failed to get mask permset. (%s)\n", strerror(errno) )); - goto done; + goto fail; } if (map_acl_perms_to_permset(conn, S_IRUSR|S_IWUSR|S_IXUSR, &mask_permset) == -1) { DEBUG(0,("set_canon_ace_list: Failed to create mask permset. (%s)\n", strerror(errno) )); - goto done; + goto fail; } if (SMB_VFS_SYS_ACL_SET_PERMSET(conn, mask_entry, mask_permset) == -1) { DEBUG(0,("set_canon_ace_list: Failed to add mask permset. (%s)\n", strerror(errno) )); - goto done; + goto fail; } } @@ -2415,7 +2445,7 @@ static BOOL set_canon_ace_list(files_struct *fsp, canon_ace *the_ace, BOOL defau DEBUG(0,("set_canon_ace_list: ACL type (%s) is invalid for set (%s).\n", the_acl_type == SMB_ACL_TYPE_DEFAULT ? "directory default" : "file", strerror(errno) )); - goto done; + goto fail; } /* @@ -2432,10 +2462,26 @@ static BOOL set_canon_ace_list(files_struct *fsp, canon_ace *the_ace, BOOL defau *pacl_set_support = False; } - DEBUG(2,("set_canon_ace_list: sys_acl_set_file type %s failed for file %s (%s).\n", - the_acl_type == SMB_ACL_TYPE_DEFAULT ? "directory default" : "file", - fsp->fsp_name, strerror(errno) )); - goto done; + if (acl_group_override(conn, prim_gid)) { + int sret; + + DEBUG(5,("set_canon_ace_list: acl group control on and current user in file %s primary group.\n", + fsp->fsp_name )); + + become_root(); + sret = SMB_VFS_SYS_ACL_SET_FILE(conn, fsp->fsp_name, the_acl_type, the_acl); + unbecome_root(); + if (sret == 0) { + ret = True; + } + } + + if (ret == False) { + DEBUG(2,("set_canon_ace_list: sys_acl_set_file type %s failed for file %s (%s).\n", + the_acl_type == SMB_ACL_TYPE_DEFAULT ? "directory default" : "file", + fsp->fsp_name, strerror(errno) )); + goto fail; + } } } else { if (SMB_VFS_SYS_ACL_SET_FD(fsp, fsp->fh->fd, the_acl) == -1) { @@ -2447,18 +2493,35 @@ static BOOL set_canon_ace_list(files_struct *fsp, canon_ace *the_ace, BOOL defau *pacl_set_support = False; } - DEBUG(2,("set_canon_ace_list: sys_acl_set_file failed for file %s (%s).\n", - fsp->fsp_name, strerror(errno) )); - goto done; + if (acl_group_override(conn, prim_gid)) { + int sret; + + DEBUG(5,("set_canon_ace_list: acl group control on and current user in file %s primary group.\n", + fsp->fsp_name )); + + become_root(); + sret = SMB_VFS_SYS_ACL_SET_FD(fsp, fsp->fh->fd, the_acl); + unbecome_root(); + if (sret == 0) { + ret = True; + } + } + + if (ret == False) { + DEBUG(2,("set_canon_ace_list: sys_acl_set_file failed for file %s (%s).\n", + fsp->fsp_name, strerror(errno) )); + goto fail; + } } } ret = True; - done: + fail: - if (the_acl != NULL) - SMB_VFS_SYS_ACL_FREE_ACL(conn, the_acl); + if (the_acl != NULL) { + SMB_VFS_SYS_ACL_FREE_ACL(conn, the_acl); + } return ret; } @@ -3129,7 +3192,7 @@ BOOL set_nt_acl(files_struct *fsp, uint32 security_info_sent, SEC_DESC *psd) */ if (acl_perms && file_ace_list) { - ret = set_canon_ace_list(fsp, file_ace_list, False, &acl_set_support); + ret = set_canon_ace_list(fsp, file_ace_list, False, sbuf.st_gid, &acl_set_support); if (acl_set_support && ret == False) { DEBUG(3,("set_nt_acl: failed to set file acl on file %s (%s).\n", fsp->fsp_name, strerror(errno) )); free_canon_ace_list(file_ace_list); @@ -3140,7 +3203,7 @@ BOOL set_nt_acl(files_struct *fsp, uint32 security_info_sent, SEC_DESC *psd) if (acl_perms && acl_set_support && fsp->is_directory) { if (dir_ace_list) { - if (!set_canon_ace_list(fsp, dir_ace_list, True, &acl_set_support)) { + if (!set_canon_ace_list(fsp, dir_ace_list, True, sbuf.st_gid, &acl_set_support)) { DEBUG(3,("set_nt_acl: failed to set default acl on directory %s (%s).\n", fsp->fsp_name, strerror(errno) )); free_canon_ace_list(file_ace_list); free_canon_ace_list(dir_ace_list); @@ -3153,17 +3216,32 @@ BOOL set_nt_acl(files_struct *fsp, uint32 security_info_sent, SEC_DESC *psd) */ if (SMB_VFS_SYS_ACL_DELETE_DEF_FILE(conn, fsp->fsp_name) == -1) { - DEBUG(3,("set_nt_acl: sys_acl_delete_def_file failed (%s)\n", strerror(errno))); - free_canon_ace_list(file_ace_list); - free_canon_ace_list(dir_ace_list); - return False; + int sret = -1; + + if (acl_group_override(conn, sbuf.st_gid)) { + DEBUG(5,("set_nt_acl: acl group control on and " + "current user in file %s primary group. Override delete_def_acl\n", + fsp->fsp_name )); + + become_root(); + sret = SMB_VFS_SYS_ACL_DELETE_DEF_FILE(conn, fsp->fsp_name); + unbecome_root(); + } + + if (sret == -1) { + DEBUG(3,("set_nt_acl: sys_acl_delete_def_file failed (%s)\n", strerror(errno))); + free_canon_ace_list(file_ace_list); + free_canon_ace_list(dir_ace_list); + return False; + } } } } - if (acl_set_support) + if (acl_set_support) { store_inheritance_attributes(fsp, file_ace_list, dir_ace_list, (psd->type & SE_DESC_DACL_PROTECTED) ? True : False); + } /* * If we cannot set using POSIX ACLs we fall back to checking if we need to chmod. @@ -3186,11 +3264,24 @@ BOOL set_nt_acl(files_struct *fsp, uint32 security_info_sent, SEC_DESC *psd) fsp->fsp_name, (unsigned int)posix_perms )); if(SMB_VFS_CHMOD(conn,fsp->fsp_name, posix_perms) == -1) { - DEBUG(3,("set_nt_acl: chmod %s, 0%o failed. Error = %s.\n", + int sret = -1; + if (acl_group_override(conn, sbuf.st_gid)) { + DEBUG(5,("set_nt_acl: acl group control on and " + "current user in file %s primary group. Override chmod\n", + fsp->fsp_name )); + + become_root(); + sret = SMB_VFS_CHMOD(conn,fsp->fsp_name, posix_perms); + unbecome_root(); + } + + if (sret == -1) { + DEBUG(3,("set_nt_acl: chmod %s, 0%o failed. Error = %s.\n", fsp->fsp_name, (unsigned int)posix_perms, strerror(errno) )); - free_canon_ace_list(file_ace_list); - free_canon_ace_list(dir_ace_list); - return False; + free_canon_ace_list(file_ace_list); + free_canon_ace_list(dir_ace_list); + return False; + } } } } diff --git a/source/smbd/process.c b/source/smbd/process.c index 94d4b8d9032..19add7e0951 100644 --- a/source/smbd/process.c +++ b/source/smbd/process.c @@ -29,6 +29,7 @@ struct timeval smb_last_time; static char *InBuffer = NULL; static char *OutBuffer = NULL; +static char *current_inbuf = NULL; /* * Size of data we can send to client. Set @@ -245,12 +246,12 @@ struct pending_message_list *get_open_deferred_message(uint16 mid) /**************************************************************************** Function to push a sharing violation open smb message onto a linked list of local smb messages ready - for processing. + for processing. We must use current_inbuf here not Inbuf in case we're in a chained message set. ****************************************************************************/ BOOL push_sharing_violation_open_smb_message(struct timeval *ptv, char *private_data, size_t priv_len) { - uint16 mid = SVAL(InBuffer,smb_mid); + uint16 mid = SVAL(current_inbuf,smb_mid); struct timeval tv; SMB_BIG_INT tdif; @@ -270,11 +271,11 @@ BOOL push_sharing_violation_open_smb_message(struct timeval *ptv, char *private_ tv.tv_usec = tdif % 1000000; DEBUG(10,("push_sharing_violation_open_smb_message: pushing message len %u mid %u\ - timeout time [%u.%06u]\n", (unsigned int) smb_len(InBuffer)+4, (unsigned int)mid, + timeout time [%u.%06u]\n", (unsigned int) smb_len(current_inbuf)+4, (unsigned int)mid, (unsigned int)tv.tv_sec, (unsigned int)tv.tv_usec)); - return push_queued_message(SHARE_VIOLATION_QUEUE, InBuffer, - smb_len(InBuffer)+4, &tv, private_data, priv_len); + return push_queued_message(SHARE_VIOLATION_QUEUE, current_inbuf, + smb_len(current_inbuf)+4, &tv, private_data, priv_len); } /**************************************************************************** @@ -986,6 +987,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize !check_access(smbd_server_fd(), lp_hostsallow(-1), lp_hostsdeny(-1)))) return(ERROR_DOS(ERRSRV,ERRaccess)); + current_inbuf = inbuf; /* In case we need to defer this message in open... */ outsize = smb_messages[type].fn(conn, inbuf,outbuf,size,bufsize); } @@ -1631,10 +1633,6 @@ void smbd_process(void) lp_talloc_free(); main_loop_talloc_free(); - /* run all registered idle events */ - smb_run_idle_events(time(NULL)); - - /* Did someone ask for immediate checks on things like blocking locks ? */ if (select_timeout == 0) { if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time)) diff --git a/source/smbd/reply.c b/source/smbd/reply.c index 5e8c0ef296d..e96c3dc01ff 100644 --- a/source/smbd/reply.c +++ b/source/smbd/reply.c @@ -1156,7 +1156,9 @@ int reply_search(connection_struct *conn, char *inbuf,char *outbuf, int dum_size memcpy(p,status,21); make_dir_struct(p,mask,fname,size, mode,date, !allow_long_path_components); - dptr_fill(p+12,dptr_num); + if (!dptr_fill(p+12,dptr_num)) { + break; + } numentries++; p += DIR_STRUCT_SIZE; } @@ -1352,7 +1354,7 @@ int reply_open(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, put_dos_date3(outbuf,smb_vwv2,mtime); } SIVAL(outbuf,smb_vwv4,(uint32)size); - SSVAL(outbuf,smb_vwv6,FILE_WAS_OPENED); + SSVAL(outbuf,smb_vwv6,GET_OPENX_MODE(deny_mode)); if (oplock_request && lp_fake_oplocks(SNUM(conn))) { SCVAL(outbuf,smb_flg,CVAL(outbuf,smb_flg)|CORE_OPLOCK_GRANTED); @@ -5308,7 +5310,7 @@ int reply_readbmpx(connection_struct *conn, char *inbuf,char *outbuf,int length, if (nread < (ssize_t)N) tcount = total_read + nread; - set_message(outbuf,8,nread,False); + set_message(outbuf,8,nread+pad,False); SIVAL(outbuf,smb_vwv0,startpos); SSVAL(outbuf,smb_vwv2,tcount); SSVAL(outbuf,smb_vwv6,nread); diff --git a/source/smbd/sesssetup.c b/source/smbd/sesssetup.c index 1ddd6256b31..8586ac1324f 100644 --- a/source/smbd/sesssetup.c +++ b/source/smbd/sesssetup.c @@ -25,8 +25,6 @@ uint32 global_client_caps = 0; -static struct auth_ntlmssp_state *global_ntlmssp_state; - /* on a logon error possibly map the error to success if "map to guest" is set approriately @@ -353,6 +351,7 @@ static int reply_spnego_kerberos(connection_struct *conn, ***************************************************************************/ static BOOL reply_spnego_ntlmssp(connection_struct *conn, char *inbuf, char *outbuf, + uint16 vuid, AUTH_NTLMSSP_STATE **auth_ntlmssp_state, DATA_BLOB *ntlmssp_blob, NTSTATUS nt_status) { @@ -416,6 +415,8 @@ static BOOL reply_spnego_ntlmssp(connection_struct *conn, char *inbuf, char *out if (!ret || !NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { auth_ntlmssp_end(auth_ntlmssp_state); + /* Kill the intermediate vuid */ + invalidate_vuid(vuid); } return ret; @@ -428,8 +429,10 @@ static BOOL reply_spnego_ntlmssp(connection_struct *conn, char *inbuf, char *out static int reply_spnego_negotiate(connection_struct *conn, char *inbuf, char *outbuf, + uint16 vuid, int length, int bufsize, - DATA_BLOB blob1) + DATA_BLOB blob1, + AUTH_NTLMSSP_STATE **auth_ntlmssp_state) { char *OIDs[ASN1_MAX_OIDS]; DATA_BLOB secblob; @@ -442,6 +445,9 @@ static int reply_spnego_negotiate(connection_struct *conn, /* parse out the OIDs and the first sec blob */ if (!parse_negTokenTarg(blob1, OIDs, &secblob)) { + /* Kill the intermediate vuid */ + invalidate_vuid(vuid); + return ERROR_NT(NT_STATUS_LOGON_FAILURE); } @@ -473,25 +479,31 @@ static int reply_spnego_negotiate(connection_struct *conn, int ret = reply_spnego_kerberos(conn, inbuf, outbuf, length, bufsize, &secblob); data_blob_free(&secblob); + /* Kill the intermediate vuid */ + invalidate_vuid(vuid); + return ret; } #endif - if (global_ntlmssp_state) { - auth_ntlmssp_end(&global_ntlmssp_state); + if (*auth_ntlmssp_state) { + auth_ntlmssp_end(auth_ntlmssp_state); } - nt_status = auth_ntlmssp_start(&global_ntlmssp_state); + nt_status = auth_ntlmssp_start(auth_ntlmssp_state); if (!NT_STATUS_IS_OK(nt_status)) { + /* Kill the intermediate vuid */ + invalidate_vuid(vuid); + return ERROR_NT(nt_status); } - nt_status = auth_ntlmssp_update(global_ntlmssp_state, + nt_status = auth_ntlmssp_update(*auth_ntlmssp_state, secblob, &chal); data_blob_free(&secblob); - reply_spnego_ntlmssp(conn, inbuf, outbuf, &global_ntlmssp_state, + reply_spnego_ntlmssp(conn, inbuf, outbuf, vuid, auth_ntlmssp_state, &chal, nt_status); data_blob_free(&chal); @@ -505,8 +517,10 @@ static int reply_spnego_negotiate(connection_struct *conn, ****************************************************************************/ static int reply_spnego_auth(connection_struct *conn, char *inbuf, char *outbuf, + uint16 vuid, int length, int bufsize, - DATA_BLOB blob1) + DATA_BLOB blob1, + AUTH_NTLMSSP_STATE **auth_ntlmssp_state) { DATA_BLOB auth, auth_reply; NTSTATUS nt_status = NT_STATUS_INVALID_PARAMETER; @@ -515,20 +529,27 @@ static int reply_spnego_auth(connection_struct *conn, char *inbuf, char *outbuf, #if 0 file_save("auth.dat", blob1.data, blob1.length); #endif + /* Kill the intermediate vuid */ + invalidate_vuid(vuid); + return ERROR_NT(NT_STATUS_INVALID_PARAMETER); } - if (!global_ntlmssp_state) { + if (!*auth_ntlmssp_state) { + /* Kill the intermediate vuid */ + invalidate_vuid(vuid); + /* auth before negotiatiate? */ return ERROR_NT(NT_STATUS_INVALID_PARAMETER); } - nt_status = auth_ntlmssp_update(global_ntlmssp_state, - auth, &auth_reply); + nt_status = auth_ntlmssp_update(*auth_ntlmssp_state, + auth, &auth_reply); data_blob_free(&auth); - reply_spnego_ntlmssp(conn, inbuf, outbuf, &global_ntlmssp_state, + reply_spnego_ntlmssp(conn, inbuf, outbuf, vuid, + auth_ntlmssp_state, &auth_reply, nt_status); data_blob_free(&auth_reply); @@ -553,6 +574,8 @@ static int reply_sesssetup_and_X_spnego(connection_struct *conn, char *inbuf, char *p2; uint16 data_blob_len = SVAL(inbuf, smb_vwv7); enum remote_arch_types ra_type = get_remote_arch(); + int vuid = SVAL(inbuf,smb_uid); + user_struct *vuser = NULL; DEBUG(3,("Doing spnego session setup\n")); @@ -597,16 +620,34 @@ static int reply_sesssetup_and_X_spnego(connection_struct *conn, char *inbuf, ra_lanman_string( native_lanman ); } + vuser = get_partial_auth_user_struct(vuid); + if (!vuser) { + vuid = register_vuid(NULL, data_blob(NULL, 0), data_blob(NULL, 0), NULL); + if (vuid == -1) { + return ERROR_NT(NT_STATUS_INVALID_PARAMETER); + } + + vuser = get_partial_auth_user_struct(vuid); + } + + if (!vuser) { + return ERROR_NT(NT_STATUS_INVALID_PARAMETER); + } + + SSVAL(outbuf,smb_uid,vuid); + if (blob1.data[0] == ASN1_APPLICATION(0)) { /* its a negTokenTarg packet */ - ret = reply_spnego_negotiate(conn, inbuf, outbuf, length, bufsize, blob1); + ret = reply_spnego_negotiate(conn, inbuf, outbuf, vuid, length, bufsize, blob1, + &vuser->auth_ntlmssp_state); data_blob_free(&blob1); return ret; } if (blob1.data[0] == ASN1_CONTEXT(1)) { /* its a auth packet */ - ret = reply_spnego_auth(conn, inbuf, outbuf, length, bufsize, blob1); + ret = reply_spnego_auth(conn, inbuf, outbuf, vuid, length, bufsize, blob1, + &vuser->auth_ntlmssp_state); data_blob_free(&blob1); return ret; } @@ -682,7 +723,7 @@ int reply_sesssetup_and_X(connection_struct *conn, char *inbuf,char *outbuf, (SVAL(inbuf, smb_flg2) & FLAGS2_EXTENDED_SECURITY)) { if (!global_spnego_negotiated) { DEBUG(0,("reply_sesssetup_and_X: Rejecting attempt at SPNEGO session setup when it was not negoitiated.\n")); - return ERROR_NT(NT_STATUS_UNSUCCESSFUL); + return ERROR_NT(NT_STATUS_LOGON_FAILURE); } if (SVAL(inbuf,smb_vwv4) == 0) { @@ -843,7 +884,7 @@ int reply_sesssetup_and_X(connection_struct *conn, char *inbuf,char *outbuf, /* This has to be here, because this is a perfectly valid behaviour for guest logons :-( */ DEBUG(0,("reply_sesssetup_and_X: Rejecting attempt at 'normal' session setup after negotiating spnego.\n")); - return ERROR_NT(NT_STATUS_UNSUCCESSFUL); + return ERROR_NT(NT_STATUS_LOGON_FAILURE); } fstrcpy(sub_user, user); diff --git a/source/smbd/trans2.c b/source/smbd/trans2.c index 602656080ed..522d3c0f54c 100644 --- a/source/smbd/trans2.c +++ b/source/smbd/trans2.c @@ -472,7 +472,7 @@ struct ea_list *read_ea_list_entry(TALLOC_CTX *ctx, const char *pdata, size_t da } DEBUG(10,("read_ea_list_entry: read ea name %s\n", eal->ea.name)); - dump_data(10, eal->ea.value.data, eal->ea.value.length); + dump_data(10, (const char *)eal->ea.value.data, eal->ea.value.length); return eal; } diff --git a/source/tdb/tdb.h b/source/tdb/tdb.h index 901d470a50a..d1c976cd56b 100644 --- a/source/tdb/tdb.h +++ b/source/tdb/tdb.h @@ -141,8 +141,6 @@ TDB_DATA tdb_firstkey(TDB_CONTEXT *tdb); TDB_DATA tdb_nextkey(TDB_CONTEXT *tdb, TDB_DATA key); int tdb_traverse(TDB_CONTEXT *tdb, tdb_traverse_func fn, void *); int tdb_exists(TDB_CONTEXT *tdb, TDB_DATA key); -int tdb_lockkeys(TDB_CONTEXT *tdb, u32 number, TDB_DATA keys[]); -void tdb_unlockkeys(TDB_CONTEXT *tdb); int tdb_lockall(TDB_CONTEXT *tdb); void tdb_unlockall(TDB_CONTEXT *tdb); diff --git a/source/torture/cmd_vfs.c b/source/torture/cmd_vfs.c index 974d3b8feed..cc683977e8c 100644 --- a/source/torture/cmd_vfs.c +++ b/source/torture/cmd_vfs.c @@ -286,6 +286,7 @@ static NTSTATUS cmd_open(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, c vfs->files[fd] = SMB_MALLOC_P(struct files_struct); vfs->files[fd]->fsp_name = SMB_STRDUP(argv[1]); + vfs->files[fd]->fh = SMB_MALLOC_P(struct fd_handle); vfs->files[fd]->fh->fd = fd; vfs->files[fd]->conn = vfs->conn; printf("open: fd=%d\n", fd); @@ -345,6 +346,7 @@ static NTSTATUS cmd_close(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, printf("close: ok\n"); SAFE_FREE(vfs->files[fd]->fsp_name); + SAFE_FREE(vfs->files[fd]->fh); SAFE_FREE(vfs->files[fd]); vfs->files[fd] = NULL; return NT_STATUS_OK; diff --git a/source/torture/denytest.c b/source/torture/denytest.c index a130b598159..291a4035af7 100644 --- a/source/torture/denytest.c +++ b/source/torture/denytest.c @@ -18,8 +18,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define NO_SYSLOG - #include "includes.h" extern BOOL torture_showall; diff --git a/source/torture/locktest.c b/source/torture/locktest.c index cdeebf2f8ec..a0698162d1c 100644 --- a/source/torture/locktest.c +++ b/source/torture/locktest.c @@ -18,8 +18,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define NO_SYSLOG - #include "includes.h" static fstring password[2]; diff --git a/source/torture/locktest2.c b/source/torture/locktest2.c index 45c0890dc3d..d0b502c74e7 100644 --- a/source/torture/locktest2.c +++ b/source/torture/locktest2.c @@ -18,8 +18,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define NO_SYSLOG - #include "includes.h" static fstring password; diff --git a/source/torture/masktest.c b/source/torture/masktest.c index f3c87e0c72c..07bfe691217 100644 --- a/source/torture/masktest.c +++ b/source/torture/masktest.c @@ -18,8 +18,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define NO_SYSLOG - #include "includes.h" static fstring password; diff --git a/source/torture/msgtest.c b/source/torture/msgtest.c index c40973a75c8..ac55d703276 100644 --- a/source/torture/msgtest.c +++ b/source/torture/msgtest.c @@ -21,8 +21,6 @@ test code for internal messaging */ -#define NO_SYSLOG - #include "includes.h" static int pong_count; diff --git a/source/torture/nbio.c b/source/torture/nbio.c index e00fce02dbc..795392ae5cb 100644 --- a/source/torture/nbio.c +++ b/source/torture/nbio.c @@ -20,8 +20,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define NO_SYSLOG - #include "includes.h" #define MAX_FILES 1000 diff --git a/source/torture/scanner.c b/source/torture/scanner.c index 93f89c105cf..1893be83699 100644 --- a/source/torture/scanner.c +++ b/source/torture/scanner.c @@ -18,8 +18,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define NO_SYSLOG - #include "includes.h" #define VERBOSE 0 diff --git a/source/torture/torture.c b/source/torture/torture.c index f59da14b795..11cea53188f 100644 --- a/source/torture/torture.c +++ b/source/torture/torture.c @@ -18,8 +18,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define NO_SYSLOG - #include "includes.h" extern char *optarg; @@ -715,7 +713,7 @@ static BOOL run_netbench(int client) nb_setup(cli); - slprintf(cname,sizeof(fname), "client%d", client); + slprintf(cname,sizeof(cname)-1, "client%d", client); f = fopen(client_txt, "r"); diff --git a/source/torture/utable.c b/source/torture/utable.c index c9b30f06e1c..1d06194e46d 100644 --- a/source/torture/utable.c +++ b/source/torture/utable.c @@ -18,8 +18,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define NO_SYSLOG - #include "includes.h" BOOL torture_utable(int dummy) diff --git a/source/utils/net_ads.c b/source/utils/net_ads.c index efeb34e53df..6a58fa9fac4 100644 --- a/source/utils/net_ads.c +++ b/source/utils/net_ads.c @@ -81,7 +81,7 @@ static int net_ads_lookup(int argc, const char **argv) d_printf("Didn't find the cldap server!\n"); return -1; } if (!ads->config.realm) { - ads->config.realm = opt_target_workgroup; + ads->config.realm = CONST_DISCARD(char *, opt_target_workgroup); ads->ldap_port = 389; } diff --git a/source/utils/net_rpc_join.c b/source/utils/net_rpc_join.c index 6888076a147..8d19ad888fc 100644 --- a/source/utils/net_rpc_join.c +++ b/source/utils/net_rpc_join.c @@ -117,7 +117,7 @@ int net_rpc_join_newstyle(int argc, const char **argv) uchar pwbuf[516]; SAM_USERINFO_CTR ctr; SAM_USER_INFO_24 p24; - SAM_USER_INFO_10 p10; + SAM_USER_INFO_16 p16; uchar md4_trust_password[16]; /* Misc */ @@ -287,15 +287,15 @@ int net_rpc_join_newstyle(int argc, const char **argv) userinfo2 level 0x10 fails. -tpot */ ZERO_STRUCT(ctr); - ctr.switch_value = 0x10; - ctr.info.id10 = &p10; + ctr.switch_value = 16; + ctr.info.id16 = &p16; - init_sam_user_info10(&p10, acb_info); + init_sam_user_info16(&p16, acb_info); /* Ignoring the return value is necessary for joining a domain as a normal user with "Add workstation to domain" privilege. */ - result = cli_samr_set_userinfo2(cli, mem_ctx, &user_pol, 0x10, + result = cli_samr_set_userinfo2(cli, mem_ctx, &user_pol, 16, &cli->user_session_key, &ctr); /* Now check the whole process from top-to-bottom */ diff --git a/source/utils/net_rpc_printer.c b/source/utils/net_rpc_printer.c index f1f82a5cead..e2080cdc285 100644 --- a/source/utils/net_rpc_printer.c +++ b/source/utils/net_rpc_printer.c @@ -817,19 +817,11 @@ net_spoolss_enum_printers(struct cli_state *cli, TALLOC_CTX *mem_ctx, { WERROR result; - uint32 needed; /* enum printers */ - result = cli_spoolss_enum_printers( - cli, mem_ctx, 0, &needed, name, flags, + result = cli_spoolss_enum_printers(cli, mem_ctx, name, flags, level, num_printers, ctr); - if (W_ERROR_V(result) == W_ERROR_V(WERR_INSUFFICIENT_BUFFER)) - result = cli_spoolss_enum_printers( - cli, mem_ctx, needed, NULL, name, flags, - level, num_printers, ctr); - - if (!W_ERROR_IS_OK(result)) { printf("cannot enum printers: %s\n", dos_errstr(result)); return False; @@ -887,16 +879,10 @@ net_spoolss_getprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx, PRINTER_INFO_CTR *ctr) { WERROR result; - uint32 needed; /* getprinter call */ - result = cli_spoolss_getprinter(cli, - mem_ctx, 0, &needed, hnd, level, ctr); + result = cli_spoolss_getprinter(cli, mem_ctx, hnd, level, ctr); - if (W_ERROR_V(result) == W_ERROR_V(WERR_INSUFFICIENT_BUFFER)) - result = cli_spoolss_getprinter(cli, - mem_ctx, needed, NULL, hnd, level, ctr); - if (!W_ERROR_IS_OK(result)) { printf("cannot get printer-info: %s\n", dos_errstr(result)); return False; @@ -949,17 +935,10 @@ net_spoolss_enumprinterkey(struct cli_state *cli, TALLOC_CTX *mem_ctx, uint16 **keylist) { WERROR result; - uint32 needed, len; /* enumprinterkey call */ - result = cli_spoolss_enumprinterkey( - cli, mem_ctx, 0, &needed, hnd, keyname, NULL, NULL); + result = cli_spoolss_enumprinterkey(cli, mem_ctx, hnd, keyname, NULL, NULL); - if (W_ERROR_V(result) == W_ERROR_V(WERR_MORE_DATA)) - result = cli_spoolss_enumprinterkey( - cli, mem_ctx, needed, NULL, hnd, keyname, keylist, - &len); - if (!W_ERROR_IS_OK(result)) { printf("enumprinterkey failed: %s\n", dos_errstr(result)); return False; @@ -976,16 +955,10 @@ net_spoolss_enumprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx, REGVAL_CTR *ctr) { WERROR result; - uint32 needed; /* enumprinterdataex call */ - result = cli_spoolss_enumprinterdataex( - cli, mem_ctx, 0, &needed, hnd, keyname, ctr); + result = cli_spoolss_enumprinterdataex(cli, mem_ctx, hnd, keyname, ctr); - if (W_ERROR_V(result) == W_ERROR_V(WERR_MORE_DATA)) - result = cli_spoolss_enumprinterdataex( - cli, mem_ctx, needed, NULL, hnd, keyname, ctr); - if (!W_ERROR_IS_OK(result)) { printf("enumprinterdataex failed: %s\n", dos_errstr(result)); return False; @@ -1022,16 +995,9 @@ net_spoolss_enumforms(struct cli_state *cli, TALLOC_CTX *mem_ctx, { WERROR result; - uint32 needed; /* enumforms call */ - result = cli_spoolss_enumforms( - cli, mem_ctx, 0, &needed, hnd, level, num_forms, forms); - - if (W_ERROR_V(result) == W_ERROR_V(WERR_INSUFFICIENT_BUFFER)) - result = cli_spoolss_enumforms( - cli, mem_ctx, needed, NULL, hnd, level, - num_forms, forms); + result = cli_spoolss_enumforms(cli, mem_ctx, hnd, level, num_forms, forms); if (!W_ERROR_IS_OK(result)) { printf("could not enum forms: %s\n", dos_errstr(result)); @@ -1049,18 +1015,12 @@ net_spoolss_enumprinterdrivers (struct cli_state *cli, TALLOC_CTX *mem_ctx, PRINTER_DRIVER_CTR *ctr) { WERROR result; - uint32 needed; /* enumprinterdrivers call */ result = cli_spoolss_enumprinterdrivers( - cli, mem_ctx, 0, &needed, level, + cli, mem_ctx, level, env, num_drivers, ctr); - if (W_ERROR_V(result) == W_ERROR_V(WERR_INSUFFICIENT_BUFFER)) - result = cli_spoolss_enumprinterdrivers( - cli, mem_ctx, needed, NULL, level, - env, num_drivers, ctr); - if (!W_ERROR_IS_OK(result)) { printf("cannot enum drivers: %s\n", dos_errstr(result)); return False; @@ -1078,18 +1038,12 @@ net_spoolss_getprinterdriver(struct cli_state *cli, PRINTER_DRIVER_CTR *ctr) { WERROR result; - uint32 needed; /* getprinterdriver call */ result = cli_spoolss_getprinterdriver( - cli, mem_ctx, 0, &needed, hnd, level, + cli, mem_ctx, hnd, level, env, version, ctr); - if (W_ERROR_V(result) == W_ERROR_V(WERR_INSUFFICIENT_BUFFER)) - result = cli_spoolss_getprinterdriver( - cli, mem_ctx, needed, NULL, hnd, level, - env, version, ctr); - if (!W_ERROR_IS_OK(result)) { DEBUG(1,("cannot get driver (for architecture: %s): %s\n", env, dos_errstr(result))); @@ -1353,7 +1307,7 @@ static NTSTATUS rpc_printer_publish_internals_args(struct cli_state *cli, TALLOC ctr_pub.printers_7->action = action; result = cli_spoolss_setprinter(cli, mem_ctx, &hnd, level, &ctr_pub, 0); - if (!W_ERROR_IS_OK(result) && (W_ERROR_V(result) =! W_ERROR_V(WERR_IO_PENDING))) { + if (!W_ERROR_IS_OK(result) && (W_ERROR_V(result) != W_ERROR_V(WERR_IO_PENDING))) { printf("cannot set printer-info: %s\n", dos_errstr(result)); goto done; } diff --git a/source/utils/net_rpc_samsync.c b/source/utils/net_rpc_samsync.c index dd3364dfcb0..403250675a5 100644 --- a/source/utils/net_rpc_samsync.c +++ b/source/utils/net_rpc_samsync.c @@ -436,7 +436,7 @@ sam_account_from_delta(SAM_ACCOUNT *account, SAM_ACCOUNT_INFO *delta) pdb_sethexhours(oldstr, pdb_get_hours(account)); pdb_sethexhours(newstr, delta->buf_logon_hrs.buffer); if (!strequal(oldstr, newstr)) - pdb_set_hours(account, (const char *)delta->buf_logon_hrs.buffer, PDB_CHANGED); + pdb_set_hours(account, (const uint8 *)delta->buf_logon_hrs.buffer, PDB_CHANGED); } if (pdb_get_bad_password_count(account) != delta->bad_pwd_count) @@ -482,8 +482,7 @@ sam_account_from_delta(SAM_ACCOUNT *account, SAM_ACCOUNT_INFO *delta) /* TODO: account expiry time */ - if (pdb_get_acct_ctrl(account) != delta->acb_info) - pdb_set_acct_ctrl(account, delta->acb_info, PDB_CHANGED); + pdb_set_acct_ctrl(account, delta->acb_info, PDB_CHANGED); pdb_set_domain(account, lp_workgroup(), PDB_CHANGED); @@ -1716,7 +1715,7 @@ fetch_account_info_to_ldif(SAM_DELTA_CTR *delta, GROUPMAP *groupmap, fprintf(add_fd, "sambaLMPassword: %s\n", hex_lm_passwd); if (strcmp(nopasswd, hex_nt_passwd) != 0) fprintf(add_fd, "sambaNTPassword: %s\n", hex_nt_passwd); - fprintf(add_fd, "sambaPwdLastSet: %d\n", unix_time); + fprintf(add_fd, "sambaPwdLastSet: %d\n", (int)unix_time); fprintf(add_fd, "sambaAcctFlags: %s\n", flags); fprintf(add_fd, "\n"); fflush(add_fd); @@ -1871,11 +1870,18 @@ fetch_database_to_ldif(struct cli_state *cli, unsigned db_type, /* Array element is the account rid */ ACCOUNTMAP *accountmap = NULL; + if (!(mem_ctx = talloc_init("fetch_database"))) { + return NT_STATUS_NO_MEMORY; + } + /* Ensure we have an output file */ if (user_file) - ldif_file = user_file; + ldif_file = talloc_strdup(mem_ctx, user_file); else - ldif_file = "/tmp/tmp.ldif"; + ldif_file = talloc_strdup(mem_ctx, "/tmp/tmp.ldif"); + + if (ldif_file == NULL) + return NT_STATUS_NO_MEMORY; /* Open the add and mod ldif files */ add_fd = fopen(add_ldif, "a"); @@ -1892,10 +1898,6 @@ fetch_database_to_ldif(struct cli_state *cli, unsigned db_type, return NT_STATUS_UNSUCCESSFUL; } - if (!(mem_ctx = talloc_init("fetch_database"))) { - return NT_STATUS_NO_MEMORY; - } - /* Get the sid */ sid_to_string(sid, &dom_sid); diff --git a/source/utils/nmblookup.c b/source/utils/nmblookup.c index d1d735f7f9e..09148ad37c3 100644 --- a/source/utils/nmblookup.c +++ b/source/utils/nmblookup.c @@ -20,8 +20,6 @@ */ -#define NO_SYSLOG - #include "includes.h" extern BOOL AllowDebugChange; diff --git a/source/utils/smbget.c b/source/utils/smbget.c index 2aca3001a36..e8069802ca9 100644 --- a/source/utils/smbget.c +++ b/source/utils/smbget.c @@ -101,8 +101,8 @@ void get_auth_data(const char *srv, const char *shr, char *wg, int wglen, char * if(workgroup)strncpy(wg, workgroup, wglen-1); - wgtmp = strndup(wg, wglen); - usertmp = strndup(un, unlen); + wgtmp = SMB_STRNDUP(wg, wglen); + usertmp = SMB_STRNDUP(un, unlen); if(!quiet)printf("Using workgroup %s, %s%s\n", wgtmp, *usertmp?"user ":"guest user", usertmp); free(wgtmp); free(usertmp); } @@ -230,7 +230,7 @@ void print_progress(const char *name, time_t start, time_t now, off_t start_pos, if(columns) { int required = strlen(name), available = columns - len - strlen("[] "); if(required > available) asprintf(&filename, "...%s", name + required - available + 3); - else filename = strndup(name, available); + else filename = SMB_STRNDUP(name, available); } else filename = SMB_STRDUP(name); fprintf(stderr, "\r[%s] %s", filename, status); diff --git a/source/utils/status.c b/source/utils/status.c index f3c88616662..bed9828c228 100644 --- a/source/utils/status.c +++ b/source/utils/status.c @@ -31,8 +31,6 @@ * This program reports current SMB connections */ -#define NO_SYSLOG - #include "includes.h" #define SMB_MAXPIDS 2048 diff --git a/source/web/diagnose.c b/source/web/diagnose.c index c7a7a3598ee..d259717da0b 100644 --- a/source/web/diagnose.c +++ b/source/web/diagnose.c @@ -21,6 +21,8 @@ #include "includes.h" #include "web/swat_proto.h" +extern struct in_addr loopback_ip; + #ifdef WITH_WINBIND /* check to see if winbind is running by pinging it */ @@ -35,7 +37,6 @@ BOOL winbindd_running(void) response */ BOOL nmbd_running(void) { - extern struct in_addr loopback_ip; int fd, count, flags; struct in_addr *ip_list; @@ -60,7 +61,6 @@ BOOL nmbd_running(void) BOOL smbd_running(void) { static struct cli_state cli; - extern struct in_addr loopback_ip; if (!cli_initialise(&cli)) return False; |