diff options
author | Andrew Tridgell <tridge@samba.org> | 1998-08-14 17:38:29 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 1998-08-14 17:38:29 +0000 |
commit | b9623ab59e813131b1ed3f51616a46e719d59c21 (patch) | |
tree | a1ba04e55e67ca102b05dd22b024bab9e9d51d57 /source3 | |
parent | 58fb3c31c03601042fdba71501068fcaea8a821c (diff) | |
download | samba-b9623ab59e813131b1ed3f51616a46e719d59c21.tar.gz samba-b9623ab59e813131b1ed3f51616a46e719d59c21.tar.bz2 samba-b9623ab59e813131b1ed3f51616a46e719d59c21.zip |
this is the bug change to using connection_struct* instead of cnum.
Connections[] is now a local array in server.c
I might have broken something with this change. In particular the
oplock code is suspect and some .dll files aren't being oplocked when
I expected them to be. I'll look at it after I've got some sleep.
(This used to be commit c7ee025ead4a85b6fa44a832047b878451845fb6)
Diffstat (limited to 'source3')
49 files changed, 3885 insertions, 3823 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in index fc3f93f2f3..70af6f9b59 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -88,12 +88,12 @@ LIB_OBJ = lib/charcnv.o lib/charset.o lib/debug.o lib/fault.o \ lib/getsmbpass.o lib/interface.o lib/kanji.o lib/md4.o \ lib/membuffer.o lib/netmask.o lib/pidfile.o lib/replace.o \ lib/signal.o lib/slprintf.o lib/system.o lib/time.o lib/ufc.o \ - lib/util.o lib/genrand.o lib/username.o lib/access.o + lib/util.o lib/genrand.o lib/username.o lib/access.o lib/smbrun.o UBIQX_OBJ = ubiqx/ubi_BinTree.o ubiqx/ubi_Cache.o ubiqx/ubi_SplayTree.o \ ubiqx/ubi_dLinkList.o ubiqx/ubi_sLinkList.o -PARAM_OBJ = param/loadparm.o param/params.o param/pcap.o smbd/print_svid.o +PARAM_OBJ = param/loadparm.o param/params.o LIBSMB_OBJ = libsmb/clientgen.o libsmb/namequery.o libsmb/nmblib.o \ libsmb/nterr.o libsmb/smbdes.o libsmb/smbencrypt.o \ @@ -118,18 +118,19 @@ LOCKING_OBJ = locking/locking.o locking/locking_shm.o locking/locking_slow.o \ locking/shmem.o locking/shmem_sysv.o PASSDB_OBJ = passdb/passdb.o passdb/smbpassfile.o passdb/smbpass.o \ - passdb/pass_check.o + passdb/pass_check.o passdb/ldap.o passdb/nispass.o SMBD_OBJ1 = smbd/server.o smbd/chgpasswd.o smbd/connection.o \ smbd/dfree.o smbd/dir.o smbd/password.o \ - smbd/groupname.o smbd/ipc.o passdb/ldap.o smbd/mangle.o \ - smbd/message.o passdb/nispass.o smbd/nttrans.o \ - smbd/pipes.o smbd/predict.o smbd/printing.o \ + smbd/groupname.o smbd/ipc.o smbd/mangle.o \ + smbd/message.o smbd/nttrans.o smbd/pipes.o smbd/predict.o \ smbd/quotas.o smbd/reply.o smbd/ssl.o smbd/trans2.o smbd/uid.o +PRINTING_OBJ = param/pcap.o smbd/print_svid.o smbd/printing.o + SMBD_OBJ = $(SMBD_OBJ1) $(PARAM_OBJ) $(LIBSMB_OBJ) $(UBIQX_OBJ) \ $(RPC_SERVER_OBJ) $(RPC_CLIENT_OBJ) $(RPC_PARSE_OBJ) \ - $(LOCKING_OBJ) $(PASSDB_OBJ) $(LIB_OBJ) + $(LOCKING_OBJ) $(PASSDB_OBJ) $(PRINTING_OBJ) $(LIB_OBJ) NMBD_OBJ1 = nmbd/asyncdns.o nmbd/nmbd.o nmbd/nmbd_become_dmb.o \ @@ -167,7 +168,7 @@ STATUS_OBJ = utils/status.o $(LOCKING_OBJ) $(PARAM_OBJ) \ TESTPARM_OBJ = utils/testparm.o \ $(PARAM_OBJ) $(UBIQX_OBJ) $(LIB_OBJ) -TESTPRNS_OBJ = utils/testprns.o $(PARAM_OBJ) $(UBIQX_OBJ) \ +TESTPRNS_OBJ = utils/testprns.o $(PARAM_OBJ) $(PRINTING_OBJ) $(UBIQX_OBJ) \ $(LIB_OBJ) SMBPASSWD_OBJ = utils/smbpasswd.o $(PARAM_OBJ) $(LIBSMB_OBJ) $(PASSDB_OBJ) \ diff --git a/source3/acconfig.h b/source3/acconfig.h index 24712e3b7f..78ae60be1b 100644 --- a/source3/acconfig.h +++ b/source3/acconfig.h @@ -52,3 +52,5 @@ #undef REPLACE_INET_NTOA #undef HAVE_FILE_MACRO #undef HAVE_FUNCTION_MACRO +#undef HAVE_SETRESUID_DECL +#undef WITH_NETATALK diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 1f453da492..035e4f7607 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -297,12 +297,12 @@ static long readtarheader(union hblock *hb, file_info2 *finfo, char *prefix) fchk=unoct(hb->dbuf.chksum, sizeof(hb->dbuf.chksum)); - DEBUG(5, ("checksum totals chk=%d fchk=%d chksum=%s\n", + DEBUG(5, ("checksum totals chk=%ld fchk=%ld chksum=%s\n", chk, fchk, hb->dbuf.chksum)); if (fchk != chk) { - DEBUG(0, ("checksums don't match %d %d\n", fchk, chk)); + DEBUG(0, ("checksums don't match %ld %ld\n", fchk, chk)); /* for (i = 0; i < sizeof(hb -> dummy); i++) { fprintf(stdout, "%2X ", hb -> dummy[i]); } @@ -840,7 +840,7 @@ static BOOL smbshut(file_info2 finfo, int fnum, char *inbuf, char *outbuf) SSVAL(outbuf,smb_vwv0,fnum); put_dos_date3(outbuf,smb_vwv1,finfo.mtime); - DEBUG(3,("Setting date to %s (0x%X)", + DEBUG(3,("Setting date to %s (0x%lX)", asctime(LocalTime(&finfo.mtime)), finfo.mtime)); @@ -1517,7 +1517,7 @@ static void unfixtarname(char *tptr, char *fp, int l, BOOL first) * dos \'s in path. Kill any absolute path names. But only if first! */ - DEBUG(5, ("firstb=%X, secondb=%X, len=%i\n", tptr, fp, l)); + DEBUG(5, ("firstb=%lX, secondb=%lX, len=%i\n", tptr, fp, l)); if (first) { if (*fp == '.') { @@ -1829,7 +1829,8 @@ static void do_tarput() finfo.name = NULL; } - DEBUG(5, ("Tarbuf=%X, buffer=%X, endofbuf=%X\n", tarbuf, buffer_p, endofbuffer)); + DEBUG(5, ("Tarbuf=%X, buffer=%X, endofbuf=%X\n", + (int)tarbuf, (int)buffer_p, (int)endofbuffer)); switch (readtarheader((union hblock *) buffer_p, &finfo, cur_dir)) { case -2: /* something dodgy but not fatal about this */ @@ -1899,7 +1900,8 @@ static void do_tarput() cp = longname + strlen(cur_dir); file_len = finfo.size; - DEBUG(5, ("longname=%0X, cp=%0X, file_len=%i\n", longname, cp, file_len)); + DEBUG(5, ("longname=%0X, cp=%0X, file_len=%i\n", + (int)longname, (int)cp, file_len)); while (file_len > 0) { @@ -1917,7 +1919,7 @@ static void do_tarput() cp = cp + strlen(cp); /* Move to end of string */ buffer_p += TBLOCK; file_len -= TBLOCK; - DEBUG(5, ("cp=%0X, file_len=%i\n", cp, file_len)); + DEBUG(5, ("cp=%0X, file_len=%i\n", (int)cp, file_len)); next_header = 1; /* Force read of next header */ } @@ -2045,7 +2047,7 @@ static void do_tarput() } if (fsize % TBLOCK) buffer_p+=TBLOCK - (fsize % TBLOCK); DEBUG(5, ("buffer_p is now %d (psn=%d)\n", - (long) buffer_p, (long)(buffer_p - tarbuf))); + (int) buffer_p, (int)(buffer_p - tarbuf))); ntarf++; fsize=0; diff --git a/source3/configure b/source3/configure index 3298e9a82f..11e36f6562 100755 --- a/source3/configure +++ b/source3/configure @@ -38,6 +38,9 @@ ac_help="$ac_help ac_help="$ac_help --with-syslog Include experimental SYSLOG support --without-syslog Don't include SYSLOG support (default)" +ac_help="$ac_help + --with-netatalk Include experimental Netatalk support + --without-netatalk Don't include experimental Netatalk support (default)" # Initialize some variables set by options. # The variables have the same names as the options, with @@ -550,7 +553,7 @@ fi # Extract the first word of "gcc", so it can be a program name with args. set dummy gcc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:554: checking for $ac_word" >&5 +echo "configure:557: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -579,7 +582,7 @@ if test -z "$CC"; then # Extract the first word of "cc", so it can be a program name with args. set dummy cc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:583: checking for $ac_word" >&5 +echo "configure:586: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -627,7 +630,7 @@ fi fi echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6 -echo "configure:631: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 +echo "configure:634: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 ac_ext=c # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. @@ -637,11 +640,11 @@ ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS cross_compiling=$ac_cv_prog_cc_cross cat > conftest.$ac_ext <<EOF -#line 641 "configure" +#line 644 "configure" #include "confdefs.h" main(){return(0);} EOF -if { (eval echo configure:645: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:648: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then ac_cv_prog_cc_works=yes # If we can't run a trivial program, we are probably using a cross compiler. if (./conftest; exit) 2>/dev/null; then @@ -661,12 +664,12 @@ if test $ac_cv_prog_cc_works = no; then { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; } fi echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6 -echo "configure:665: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 +echo "configure:668: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6 cross_compiling=$ac_cv_prog_cc_cross echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6 -echo "configure:670: checking whether we are using GNU C" >&5 +echo "configure:673: checking whether we are using GNU C" >&5 if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -675,7 +678,7 @@ else yes; #endif EOF -if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:679: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then +if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:682: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then ac_cv_prog_gcc=yes else ac_cv_prog_gcc=no @@ -690,7 +693,7 @@ if test $ac_cv_prog_gcc = yes; then ac_save_CFLAGS="$CFLAGS" CFLAGS= echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6 -echo "configure:694: checking whether ${CC-cc} accepts -g" >&5 +echo "configure:697: checking whether ${CC-cc} accepts -g" >&5 if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -747,7 +750,7 @@ ac_configure=$ac_aux_dir/configure # This should be Cygnus configure. # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" # ./install, which can be erroneously created by make from ./install.sh. echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6 -echo "configure:751: checking for a BSD compatible install" >&5 +echo "configure:754: checking for a BSD compatible install" >&5 if test -z "$INSTALL"; then if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -802,7 +805,7 @@ do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:806: checking for $ac_word" >&5 +echo "configure:809: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_AWK'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -859,7 +862,7 @@ else { echo "configure: error: can not run $ac_config_sub" 1>&2; exit 1; } fi echo $ac_n "checking host system type""... $ac_c" 1>&6 -echo "configure:863: checking host system type" >&5 +echo "configure:866: checking host system type" >&5 host_alias=$host case "$host_alias" in @@ -880,7 +883,7 @@ host_os=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'` echo "$ac_t""$host" 1>&6 echo $ac_n "checking target system type""... $ac_c" 1>&6 -echo "configure:884: checking target system type" >&5 +echo "configure:887: checking target system type" >&5 target_alias=$target case "$target_alias" in @@ -898,7 +901,7 @@ target_os=`echo $target | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'` echo "$ac_t""$target" 1>&6 echo $ac_n "checking build system type""... $ac_c" 1>&6 -echo "configure:902: checking build system type" >&5 +echo "configure:905: checking build system type" >&5 build_alias=$build case "$build_alias" in @@ -964,21 +967,21 @@ EOF esac echo $ac_n "checking for inline""... $ac_c" 1>&6 -echo "configure:968: checking for inline" >&5 +echo "configure:971: checking for inline" >&5 if eval "test \"`echo '$''{'ac_cv_c_inline'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else ac_cv_c_inline=no for ac_kw in inline __inline__ __inline; do cat > conftest.$ac_ext <<EOF -#line 975 "configure" +#line 978 "configure" #include "confdefs.h" int main() { } $ac_kw foo() { ; return 0; } EOF -if { (eval echo configure:982: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:985: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_c_inline=$ac_kw; break else @@ -1004,7 +1007,7 @@ EOF esac echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6 -echo "configure:1008: checking how to run the C preprocessor" >&5 +echo "configure:1011: checking how to run the C preprocessor" >&5 # On Suns, sometimes $CPP names a directory. if test -n "$CPP" && test -d "$CPP"; then CPP= @@ -1019,13 +1022,13 @@ else # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. cat > conftest.$ac_ext <<EOF -#line 1023 "configure" +#line 1026 "configure" #include "confdefs.h" #include <assert.h> Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1029: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1032: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then : @@ -1036,13 +1039,13 @@ else rm -rf conftest* CPP="${CC-cc} -E -traditional-cpp" cat > conftest.$ac_ext <<EOF -#line 1040 "configure" +#line 1043 "configure" #include "confdefs.h" #include <assert.h> Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1046: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1049: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then : @@ -1065,12 +1068,12 @@ fi echo "$ac_t""$CPP" 1>&6 echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6 -echo "configure:1069: checking for ANSI C header files" >&5 +echo "configure:1072: checking for ANSI C header files" >&5 if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1074 "configure" +#line 1077 "configure" #include "confdefs.h" #include <stdlib.h> #include <stdarg.h> @@ -1078,7 +1081,7 @@ else #include <float.h> EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1082: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1085: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then rm -rf conftest* @@ -1095,7 +1098,7 @@ rm -f conftest* if test $ac_cv_header_stdc = yes; then # SunOS 4.x string.h does not declare mem*, contrary to ANSI. cat > conftest.$ac_ext <<EOF -#line 1099 "configure" +#line 1102 "configure" #include "confdefs.h" #include <string.h> EOF @@ -1113,7 +1116,7 @@ fi if test $ac_cv_header_stdc = yes; then # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. cat > conftest.$ac_ext <<EOF -#line 1117 "configure" +#line 1120 "configure" #include "confdefs.h" #include <stdlib.h> EOF @@ -1134,7 +1137,7 @@ if test "$cross_compiling" = yes; then : else cat > conftest.$ac_ext <<EOF -#line 1138 "configure" +#line 1141 "configure" #include "confdefs.h" #include <ctype.h> #define ISLOWER(c) ('a' <= (c) && (c) <= 'z') @@ -1145,7 +1148,7 @@ if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2); exit (0); } EOF -if { (eval echo configure:1149: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:1152: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then : else @@ -1173,12 +1176,12 @@ for ac_hdr in dirent.h sys/ndir.h sys/dir.h ndir.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr that defines DIR""... $ac_c" 1>&6 -echo "configure:1177: checking for $ac_hdr that defines DIR" >&5 +echo "configure:1180: checking for $ac_hdr that defines DIR" >&5 if eval "test \"`echo '$''{'ac_cv_header_dirent_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1182 "configure" +#line 1185 "configure" #include "confdefs.h" #include <sys/types.h> #include <$ac_hdr> @@ -1186,7 +1189,7 @@ int main() { DIR *dirp = 0; ; return 0; } EOF -if { (eval echo configure:1190: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1193: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* eval "ac_cv_header_dirent_$ac_safe=yes" else @@ -1211,7 +1214,7 @@ done # Two versions of opendir et al. are in -ldir and -lx on SCO Xenix. if test $ac_header_dirent = dirent.h; then echo $ac_n "checking for opendir in -ldir""... $ac_c" 1>&6 -echo "configure:1215: checking for opendir in -ldir" >&5 +echo "configure:1218: checking for opendir in -ldir" >&5 ac_lib_var=`echo dir'_'opendir | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -1219,7 +1222,7 @@ else ac_save_LIBS="$LIBS" LIBS="-ldir $LIBS" cat > conftest.$ac_ext <<EOF -#line 1223 "configure" +#line 1226 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -1230,7 +1233,7 @@ int main() { opendir() ; return 0; } EOF -if { (eval echo configure:1234: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:1237: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -1252,7 +1255,7 @@ fi else echo $ac_n "checking for opendir in -lx""... $ac_c" 1>&6 -echo "configure:1256: checking for opendir in -lx" >&5 +echo "configure:1259: checking for opendir in -lx" >&5 ac_lib_var=`echo x'_'opendir | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -1260,7 +1263,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lx $LIBS" cat > conftest.$ac_ext <<EOF -#line 1264 "configure" +#line 1267 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -1271,7 +1274,7 @@ int main() { opendir() ; return 0; } EOF -if { (eval echo configure:1275: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:1278: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -1294,12 +1297,12 @@ fi fi echo $ac_n "checking whether time.h and sys/time.h may both be included""... $ac_c" 1>&6 -echo "configure:1298: checking whether time.h and sys/time.h may both be included" >&5 +echo "configure:1301: checking whether time.h and sys/time.h may both be included" >&5 if eval "test \"`echo '$''{'ac_cv_header_time'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1303 "configure" +#line 1306 "configure" #include "confdefs.h" #include <sys/types.h> #include <sys/time.h> @@ -1308,7 +1311,7 @@ int main() { struct tm *tp; ; return 0; } EOF -if { (eval echo configure:1312: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1315: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_header_time=yes else @@ -1329,12 +1332,12 @@ EOF fi echo $ac_n "checking for sys/wait.h that is POSIX.1 compatible""... $ac_c" 1>&6 -echo "configure:1333: checking for sys/wait.h that is POSIX.1 compatible" >&5 +echo "configure:1336: checking for sys/wait.h that is POSIX.1 compatible" >&5 if eval "test \"`echo '$''{'ac_cv_header_sys_wait_h'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1338 "configure" +#line 1341 "configure" #include "confdefs.h" #include <sys/types.h> #include <sys/wait.h> @@ -1350,7 +1353,7 @@ wait (&s); s = WIFEXITED (s) ? WEXITSTATUS (s) : 1; ; return 0; } EOF -if { (eval echo configure:1354: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1357: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_header_sys_wait_h=yes else @@ -1374,17 +1377,17 @@ for ac_hdr in sys/fcntl.h sys/select.h fcntl.h sys/time.h sys/unistd.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:1378: checking for $ac_hdr" >&5 +echo "configure:1381: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1383 "configure" +#line 1386 "configure" #include "confdefs.h" #include <$ac_hdr> EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1388: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1391: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then rm -rf conftest* @@ -1414,17 +1417,17 @@ for ac_hdr in unistd.h utime.h grp.h sys/id.h limits.h net/if.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:1418: checking for $ac_hdr" >&5 +echo "configure:1421: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1423 "configure" +#line 1426 "configure" #include "confdefs.h" #include <$ac_hdr> EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1428: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1431: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then rm -rf conftest* @@ -1454,17 +1457,17 @@ for ac_hdr in compat.h sys/param.h ctype.h sys/wait.h sys/ioctl.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:1458: checking for $ac_hdr" >&5 +echo "configure:1461: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1463 "configure" +#line 1466 "configure" #include "confdefs.h" #include <$ac_hdr> EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1468: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1471: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then rm -rf conftest* @@ -1494,17 +1497,17 @@ for ac_hdr in sys/filio.h string.h stdlib.h sys/socket.h sys/mode.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:1498: checking for $ac_hdr" >&5 +echo "configure:1501: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1503 "configure" +#line 1506 "configure" #include "confdefs.h" #include <$ac_hdr> EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1508: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1511: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then rm -rf conftest* @@ -1534,17 +1537,17 @@ for ac_hdr in sys/mount.h sys/vfs.h sys/fs/s5param.h sys/filsys.h termios.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:1538: checking for $ac_hdr" >&5 +echo "configure:1541: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1543 "configure" +#line 1546 "configure" #include "confdefs.h" #include <$ac_hdr> EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1548: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1551: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then rm -rf conftest* @@ -1574,17 +1577,17 @@ for ac_hdr in sys/statfs.h sys/dustat.h sys/statvfs.h stdarg.h sys/sockio.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:1578: checking for $ac_hdr" >&5 +echo "configure:1581: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1583 "configure" +#line 1586 "configure" #include "confdefs.h" #include <$ac_hdr> EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1588: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1591: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then rm -rf conftest* @@ -1614,17 +1617,17 @@ for ac_hdr in shadow.h netinet/tcp.h sys/security.h security/pam_appl.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:1618: checking for $ac_hdr" >&5 +echo "configure:1621: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1623 "configure" +#line 1626 "configure" #include "confdefs.h" #include <$ac_hdr> EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1628: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1631: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then rm -rf conftest* @@ -1652,7 +1655,7 @@ done echo $ac_n "checking size of int""... $ac_c" 1>&6 -echo "configure:1656: checking size of int" >&5 +echo "configure:1659: checking size of int" >&5 if eval "test \"`echo '$''{'ac_cv_sizeof_int'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1660,7 +1663,7 @@ else { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext <<EOF -#line 1664 "configure" +#line 1667 "configure" #include "confdefs.h" #include <stdio.h> main() @@ -1671,7 +1674,7 @@ main() exit(0); } EOF -if { (eval echo configure:1675: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:1678: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then ac_cv_sizeof_int=`cat conftestval` else @@ -1691,7 +1694,7 @@ EOF echo $ac_n "checking size of long""... $ac_c" 1>&6 -echo "configure:1695: checking size of long" >&5 +echo "configure:1698: checking size of long" >&5 if eval "test \"`echo '$''{'ac_cv_sizeof_long'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1699,7 +1702,7 @@ else { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext <<EOF -#line 1703 "configure" +#line 1706 "configure" #include "confdefs.h" #include <stdio.h> main() @@ -1710,7 +1713,7 @@ main() exit(0); } EOF -if { (eval echo configure:1714: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:1717: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then ac_cv_sizeof_long=`cat conftestval` else @@ -1730,7 +1733,7 @@ EOF echo $ac_n "checking size of short""... $ac_c" 1>&6 -echo "configure:1734: checking size of short" >&5 +echo "configure:1737: checking size of short" >&5 if eval "test \"`echo '$''{'ac_cv_sizeof_short'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1738,7 +1741,7 @@ else { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext <<EOF -#line 1742 "configure" +#line 1745 "configure" #include "confdefs.h" #include <stdio.h> main() @@ -1749,7 +1752,7 @@ main() exit(0); } EOF -if { (eval echo configure:1753: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:1756: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then ac_cv_sizeof_short=`cat conftestval` else @@ -1770,12 +1773,12 @@ EOF echo $ac_n "checking for working const""... $ac_c" 1>&6 -echo "configure:1774: checking for working const" >&5 +echo "configure:1777: checking for working const" >&5 if eval "test \"`echo '$''{'ac_cv_c_const'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1779 "configure" +#line 1782 "configure" #include "confdefs.h" int main() { @@ -1824,7 +1827,7 @@ ccp = (char const *const *) p; ; return 0; } EOF -if { (eval echo configure:1828: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1831: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_c_const=yes else @@ -1845,21 +1848,21 @@ EOF fi echo $ac_n "checking for inline""... $ac_c" 1>&6 -echo "configure:1849: checking for inline" >&5 +echo "configure:1852: checking for inline" >&5 if eval "test \"`echo '$''{'ac_cv_c_inline'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else ac_cv_c_inline=no for ac_kw in inline __inline__ __inline; do cat > conftest.$ac_ext <<EOF -#line 1856 "configure" +#line 1859 "configure" #include "confdefs.h" int main() { } $ac_kw foo() { ; return 0; } EOF -if { (eval echo configure:1863: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1866: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_c_inline=$ac_kw; break else @@ -1885,14 +1888,14 @@ EOF esac echo $ac_n "checking whether byte ordering is bigendian""... $ac_c" 1>&6 -echo "configure:1889: checking whether byte ordering is bigendian" >&5 +echo "configure:1892: checking whether byte ordering is bigendian" >&5 if eval "test \"`echo '$''{'ac_cv_c_bigendian'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else ac_cv_c_bigendian=unknown # See if sys/param.h defines the BYTE_ORDER macro. cat > conftest.$ac_ext <<EOF -#line 1896 "configure" +#line 1899 "configure" #include "confdefs.h" #include <sys/types.h> #include <sys/param.h> @@ -1903,11 +1906,11 @@ int main() { #endif ; return 0; } EOF -if { (eval echo configure:1907: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1910: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* # It does; now see whether it defined to BIG_ENDIAN or not. cat > conftest.$ac_ext <<EOF -#line 1911 "configure" +#line 1914 "configure" #include "confdefs.h" #include <sys/types.h> #include <sys/param.h> @@ -1918,7 +1921,7 @@ int main() { #endif ; return 0; } EOF -if { (eval echo configure:1922: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1925: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_c_bigendian=yes else @@ -1938,7 +1941,7 @@ if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext <<EOF -#line 1942 "configure" +#line 1945 "configure" #include "confdefs.h" main () { /* Are we little or big endian? From Harbison&Steele. */ @@ -1951,7 +1954,7 @@ main () { exit (u.c[sizeof (long) - 1] == 1); } EOF -if { (eval echo configure:1955: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:1958: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then ac_cv_c_bigendian=no else @@ -1975,14 +1978,14 @@ EOF fi echo $ac_n "checking whether char is unsigned""... $ac_c" 1>&6 -echo "configure:1979: checking whether char is unsigned" >&5 +echo "configure:1982: checking whether char is unsigned" >&5 if eval "test \"`echo '$''{'ac_cv_c_char_unsigned'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test "$GCC" = yes; then # GCC predefines this symbol on systems where it applies. cat > conftest.$ac_ext <<EOF -#line 1986 "configure" +#line 1989 "configure" #include "confdefs.h" #ifdef __CHAR_UNSIGNED__ yes @@ -2004,7 +2007,7 @@ if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext <<EOF -#line 2008 "configure" +#line 2011 "configure" #include "confdefs.h" /* volatile prevents gcc2 from optimizing the test away on sparcs. */ #if !defined(__STDC__) || __STDC__ != 1 @@ -2014,7 +2017,7 @@ main() { volatile char c = 255; exit(c < 0); } EOF -if { (eval echo configure:2018: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:2021: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then ac_cv_c_char_unsigned=yes else @@ -2039,12 +2042,12 @@ fi echo $ac_n "checking return type of signal handlers""... $ac_c" 1>&6 -echo "configure:2043: checking return type of signal handlers" >&5 +echo "configure:2046: checking return type of signal handlers" >&5 if eval "test \"`echo '$''{'ac_cv_type_signal'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2048 "configure" +#line 2051 "configure" #include "confdefs.h" #include <sys/types.h> #include <signal.h> @@ -2061,7 +2064,7 @@ int main() { int i; ; return 0; } EOF -if { (eval echo configure:2065: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:2068: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_type_signal=void else @@ -2080,12 +2083,12 @@ EOF echo $ac_n "checking for uid_t in sys/types.h""... $ac_c" 1>&6 -echo "configure:2084: checking for uid_t in sys/types.h" >&5 +echo "configure:2087: checking for uid_t in sys/types.h" >&5 if eval "test \"`echo '$''{'ac_cv_type_uid_t'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2089 "configure" +#line 2092 "configure" #include "confdefs.h" #include <sys/types.h> EOF @@ -2114,12 +2117,12 @@ EOF fi echo $ac_n "checking for mode_t""... $ac_c" 1>&6 -echo "configure:2118: checking for mode_t" >&5 +echo "configure:2121: checking for mode_t" >&5 if eval "test \"`echo '$''{'ac_cv_type_mode_t'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2123 "configure" +#line 2126 "configure" #include "confdefs.h" #include <sys/types.h> #if STDC_HEADERS @@ -2147,12 +2150,12 @@ EOF fi echo $ac_n "checking for off_t""... $ac_c" 1>&6 -echo "configure:2151: checking for off_t" >&5 +echo "configure:2154: checking for off_t" >&5 if eval "test \"`echo '$''{'ac_cv_type_off_t'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2156 "configure" +#line 2159 "configure" #include "confdefs.h" #include <sys/types.h> #if STDC_HEADERS @@ -2180,12 +2183,12 @@ EOF fi echo $ac_n "checking for size_t""... $ac_c" 1>&6 -echo "configure:2184: checking for size_t" >&5 +echo "configure:2187: checking for size_t" >&5 if eval "test \"`echo '$''{'ac_cv_type_size_t'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2189 "configure" +#line 2192 "configure" #include "confdefs.h" #include <sys/types.h> #if STDC_HEADERS @@ -2213,12 +2216,12 @@ EOF fi echo $ac_n "checking for pid_t""... $ac_c" 1>&6 -echo "configure:2217: checking for pid_t" >&5 +echo "configure:2220: checking for pid_t" >&5 if eval "test \"`echo '$''{'ac_cv_type_pid_t'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2222 "configure" +#line 2225 "configure" #include "confdefs.h" #include <sys/types.h> #if STDC_HEADERS @@ -2246,12 +2249,12 @@ EOF fi echo $ac_n "checking for st_rdev in struct stat""... $ac_c" 1>&6 -echo "configure:2250: checking for st_rdev in struct stat" >&5 +echo "configure:2253: checking for st_rdev in struct stat" >&5 if eval "test \"`echo '$''{'ac_cv_struct_st_rdev'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2255 "configure" +#line 2258 "configure" #include "confdefs.h" #include <sys/types.h> #include <sys/stat.h> @@ -2259,7 +2262,7 @@ int main() { struct stat s; s.st_rdev; ; return 0; } EOF -if { (eval echo configure:2263: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:2266: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_struct_st_rdev=yes else @@ -2280,12 +2283,12 @@ EOF fi echo $ac_n "checking for ino_t""... $ac_c" 1>&6 -echo "configure:2284: checking for ino_t" >&5 +echo "configure:2287: checking for ino_t" >&5 if eval "test \"`echo '$''{'ac_cv_type_ino_t'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2289 "configure" +#line 2292 "configure" #include "confdefs.h" #include <sys/types.h> #if STDC_HEADERS @@ -2315,14 +2318,14 @@ fi echo $ac_n "checking for errno in errno.h... $ac_c" cat > conftest.$ac_ext <<EOF -#line 2319 "configure" +#line 2322 "configure" #include "confdefs.h" #include <errno.h> int main() { int i = errno ; return 0; } EOF -if { (eval echo configure:2326: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:2329: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* echo yes; cat >> confdefs.h <<\EOF #define HAVE_ERRNO_DECL 1 @@ -2336,8 +2339,32 @@ else fi rm -f conftest* +# stupid glibc has the functions but no declaration. grrrr. +echo $ac_n "checking for setresuid declaration $ac_c" +cat > conftest.$ac_ext <<EOF +#line 2346 "configure" +#include "confdefs.h" +#include <unistd.h> +int main() { +int i = setresuid +; return 0; } +EOF +if { (eval echo configure:2353: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then + rm -rf conftest* + echo yes; cat >> confdefs.h <<\EOF +#define HAVE_SETRESUID_DECL 1 +EOF + +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + echo no +fi +rm -f conftest* + echo $ac_n "checking for 8-bit clean memcmp""... $ac_c" 1>&6 -echo "configure:2341: checking for 8-bit clean memcmp" >&5 +echo "configure:2368: checking for 8-bit clean memcmp" >&5 if eval "test \"`echo '$''{'ac_cv_func_memcmp_clean'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -2345,7 +2372,7 @@ else ac_cv_func_memcmp_clean=no else cat > conftest.$ac_ext <<EOF -#line 2349 "configure" +#line 2376 "configure" #include "confdefs.h" main() @@ -2355,7 +2382,7 @@ main() } EOF -if { (eval echo configure:2359: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:2386: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then ac_cv_func_memcmp_clean=yes else @@ -2377,7 +2404,7 @@ test $ac_cv_func_memcmp_clean = no && LIBOBJS="$LIBOBJS memcmp.o" # test for where we get crypt() from if test "$ac_cv_lib_crypt_crypt" = "yes"; then echo $ac_n "checking for crypt in -lcrypt""... $ac_c" 1>&6 -echo "configure:2381: checking for crypt in -lcrypt" >&5 +echo "configure:2408: checking for crypt in -lcrypt" >&5 ac_lib_var=`echo crypt'_'crypt | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -2385,7 +2412,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lcrypt $LIBS" cat > conftest.$ac_ext <<EOF -#line 2389 "configure" +#line 2416 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -2396,7 +2423,7 @@ int main() { crypt() ; return 0; } EOF -if { (eval echo configure:2400: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:2427: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -2432,12 +2459,12 @@ if test "$ac_cv_lib_crypt_crypt" = "no" || test "$ac_cv_lib_crypt_crypt" = ""; then # look for crypt echo $ac_n "checking for crypt""... $ac_c" 1>&6 -echo "configure:2436: checking for crypt" >&5 +echo "configure:2463: checking for crypt" >&5 if eval "test \"`echo '$''{'ac_cv_func_crypt'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2441 "configure" +#line 2468 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char crypt(); below. */ @@ -2460,7 +2487,7 @@ crypt(); ; return 0; } EOF -if { (eval echo configure:2464: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:2491: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_func_crypt=yes" else @@ -2483,7 +2510,7 @@ else case "$LIBS" in *-lcrypt*) ;; *) echo $ac_n "checking for crypt in -lcrypt""... $ac_c" 1>&6 -echo "configure:2487: checking for crypt in -lcrypt" >&5 +echo "configure:2514: checking for crypt in -lcrypt" >&5 ac_lib_var=`echo crypt'_'crypt | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -2491,7 +2518,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lcrypt $LIBS" cat > conftest.$ac_ext <<EOF -#line 2495 "configure" +#line 2522 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -2502,7 +2529,7 @@ int main() { crypt() ; return 0; } EOF -if { (eval echo configure:2506: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:2533: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -2547,21 +2574,21 @@ fi # might need libdl for this to work if test "$ac_cv_header_security_pam_appl_h" = "yes"; then echo $ac_n "checking for -ldl""... $ac_c" 1>&6 -echo "configure:2551: checking for -ldl" >&5 +echo "configure:2578: checking for -ldl" >&5 if eval "test \"`echo '$''{'ac_cv_lib_dl'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else ac_save_LIBS="$LIBS" LIBS="-ldl $LIBS" cat > conftest.$ac_ext <<EOF -#line 2558 "configure" +#line 2585 "configure" #include "confdefs.h" int main() { main() ; return 0; } EOF -if { (eval echo configure:2565: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:2592: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* ac_cv_lib_dl=yes else @@ -2587,7 +2614,7 @@ fi fi if test "$ac_cv_lib_pam_pam_authenticate" = "yes"; then echo $ac_n "checking for pam_authenticate in -lpam""... $ac_c" 1>&6 -echo "configure:2591: checking for pam_authenticate in -lpam" >&5 +echo "configure:2618: checking for pam_authenticate in -lpam" >&5 ac_lib_var=`echo pam'_'pam_authenticate | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -2595,7 +2622,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lpam $LIBS" cat > conftest.$ac_ext <<EOF -#line 2599 "configure" +#line 2626 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -2606,7 +2633,7 @@ int main() { pam_authenticate() ; return 0; } EOF -if { (eval echo configure:2610: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:2637: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -2642,12 +2669,12 @@ if test "$ac_cv_lib_pam_pam_authenticate" = "no" || test "$ac_cv_lib_pam_pam_authenticate" = ""; then # look for pam_authenticate echo $ac_n "checking for pam_authenticate""... $ac_c" 1>&6 -echo "configure:2646: checking for pam_authenticate" >&5 +echo "configure:2673: checking for pam_authenticate" >&5 if eval "test \"`echo '$''{'ac_cv_func_pam_authenticate'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2651 "configure" +#line 2678 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char pam_authenticate(); below. */ @@ -2670,7 +2697,7 @@ pam_authenticate(); ; return 0; } EOF -if { (eval echo configure:2674: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:2701: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_func_pam_authenticate=yes" else @@ -2693,7 +2720,7 @@ else case "$LIBS" in *-lpam*) ;; *) echo $ac_n "checking for pam_authenticate in -lpam""... $ac_c" 1>&6 -echo "configure:2697: checking for pam_authenticate in -lpam" >&5 +echo "configure:2724: checking for pam_authenticate in -lpam" >&5 ac_lib_var=`echo pam'_'pam_authenticate | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -2701,7 +2728,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lpam $LIBS" cat > conftest.$ac_ext <<EOF -#line 2705 "configure" +#line 2732 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -2712,7 +2739,7 @@ int main() { pam_authenticate() ; return 0; } EOF -if { (eval echo configure:2716: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:2743: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -2758,12 +2785,12 @@ fi # only looks in /etc/hosts), so we only look for -lsocket if we need # it. echo $ac_n "checking for connect""... $ac_c" 1>&6 -echo "configure:2762: checking for connect" >&5 +echo "configure:2789: checking for connect" >&5 if eval "test \"`echo '$''{'ac_cv_func_connect'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2767 "configure" +#line 2794 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char connect(); below. */ @@ -2786,7 +2813,7 @@ connect(); ; return 0; } EOF -if { (eval echo configure:2790: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:2817: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_func_connect=yes" else @@ -2806,7 +2833,7 @@ else case "$LIBS" in *-lnsl*) ;; *) echo $ac_n "checking for printf in -lnsl_s""... $ac_c" 1>&6 -echo "configure:2810: checking for printf in -lnsl_s" >&5 +echo "configure:2837: checking for printf in -lnsl_s" >&5 ac_lib_var=`echo nsl_s'_'printf | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -2814,7 +2841,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lnsl_s $LIBS" cat > conftest.$ac_ext <<EOF -#line 2818 "configure" +#line 2845 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -2825,7 +2852,7 @@ int main() { printf() ; return 0; } EOF -if { (eval echo configure:2829: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:2856: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -2856,7 +2883,7 @@ esac case "$LIBS" in *-lnsl*) ;; *) echo $ac_n "checking for printf in -lnsl""... $ac_c" 1>&6 -echo "configure:2860: checking for printf in -lnsl" >&5 +echo "configure:2887: checking for printf in -lnsl" >&5 ac_lib_var=`echo nsl'_'printf | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -2864,7 +2891,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lnsl $LIBS" cat > conftest.$ac_ext <<EOF -#line 2868 "configure" +#line 2895 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -2875,7 +2902,7 @@ int main() { printf() ; return 0; } EOF -if { (eval echo configure:2879: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:2906: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -2906,7 +2933,7 @@ esac case "$LIBS" in *-lsocket*) ;; *) echo $ac_n "checking for connect in -lsocket""... $ac_c" 1>&6 -echo "configure:2910: checking for connect in -lsocket" >&5 +echo "configure:2937: checking for connect in -lsocket" >&5 ac_lib_var=`echo socket'_'connect | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -2914,7 +2941,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lsocket $LIBS" cat > conftest.$ac_ext <<EOF -#line 2918 "configure" +#line 2945 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -2925,7 +2952,7 @@ int main() { connect() ; return 0; } EOF -if { (eval echo configure:2929: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:2956: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -2956,7 +2983,7 @@ esac case "$LIBS" in *-linet*) ;; *) echo $ac_n "checking for connect in -linet""... $ac_c" 1>&6 -echo "configure:2960: checking for connect in -linet" >&5 +echo "configure:2987: checking for connect in -linet" >&5 ac_lib_var=`echo inet'_'connect | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -2964,7 +2991,7 @@ else ac_save_LIBS="$LIBS" LIBS="-linet $LIBS" cat > conftest.$ac_ext <<EOF -#line 2968 "configure" +#line 2995 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -2975,7 +3002,7 @@ int main() { connect() ; return 0; } EOF -if { (eval echo configure:2979: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:3006: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -3018,12 +3045,12 @@ fi for ac_func in waitpid getcwd strdup strerror chown chmod chroot do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:3022: checking for $ac_func" >&5 +echo "configure:3049: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 3027 "configure" +#line 3054 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -3046,7 +3073,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:3050: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:3077: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -3073,12 +3100,12 @@ done for ac_func in fstat strchr utime utimes getrlimit fsync execl do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:3077: checking for $ac_func" >&5 +echo "configure:3104: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 3082 "configure" +#line 3109 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -3101,7 +3128,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:3105: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:3132: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -3128,12 +3155,12 @@ done for ac_func in memmove vsnprintf setsid glob strpbrk pipe crypt16 getauthuid do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:3132: checking for $ac_func" >&5 +echo "configure:3159: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 3137 "configure" +#line 3164 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -3156,7 +3183,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:3160: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:3187: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -3183,12 +3210,12 @@ done for ac_func in strftime sigprocmask sigblock sigaction innetgr do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:3187: checking for $ac_func" >&5 +echo "configure:3214: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 3192 "configure" +#line 3219 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -3211,7 +3238,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:3215: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:3242: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -3238,12 +3265,12 @@ done for ac_func in initgroups select rdchk getgrnam pathconf putprpwnam do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:3242: checking for $ac_func" >&5 +echo "configure:3269: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 3247 "configure" +#line 3274 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -3266,7 +3293,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:3270: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:3297: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -3293,12 +3320,12 @@ done for ac_func in setresuid setuidx setgroups mktime rename ftruncate do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:3297: checking for $ac_func" >&5 +echo "configure:3324: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 3302 "configure" +#line 3329 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -3321,7 +3348,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:3325: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:3352: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -3348,12 +3375,12 @@ done for ac_func in set_auth_parameters atexit grantpt getspnam dup2 do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:3352: checking for $ac_func" >&5 +echo "configure:3379: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 3357 "configure" +#line 3384 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -3376,7 +3403,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:3380: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:3407: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -3403,12 +3430,12 @@ done for ac_func in bigcrypt getprpwnam setluid yp_get_default_domain getpwanam do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:3407: checking for $ac_func" >&5 +echo "configure:3434: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 3412 "configure" +#line 3439 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -3431,7 +3458,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:3435: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:3462: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -3461,12 +3488,12 @@ if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext <<EOF -#line 3465 "configure" +#line 3492 "configure" #include "confdefs.h" #include <stdio.h> main() { long long x = 1000000; x *= x; exit(((x/1000000) == 1000000)? 0: 1); } EOF -if { (eval echo configure:3470: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:3497: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then echo yes;cat >> confdefs.h <<\EOF #define HAVE_LONGLONG 1 @@ -3487,13 +3514,13 @@ if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext <<EOF -#line 3491 "configure" +#line 3518 "configure" #include "confdefs.h" #include <stdio.h> #include <sys/stat.h> main() { struct stat64 st; off64_t s; if (sizeof(off_t) == sizeof(off64_t)) exit(1); exit((lstat64("/dev/null", &st)==0)?0:1); } EOF -if { (eval echo configure:3497: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:3524: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then echo yes;cat >> confdefs.h <<\EOF #define HAVE_OFF64_T 1 @@ -3514,7 +3541,7 @@ if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext <<EOF -#line 3518 "configure" +#line 3545 "configure" #include "confdefs.h" #include <sys/types.h> @@ -3522,7 +3549,7 @@ else #include <sys/sem.h> main() { union semun ss; exit(0); } EOF -if { (eval echo configure:3526: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:3553: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then echo yes;cat >> confdefs.h <<\EOF #define HAVE_UNION_SEMUN 1 @@ -3543,12 +3570,12 @@ if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext <<EOF -#line 3547 "configure" +#line 3574 "configure" #include "confdefs.h" #include <stdio.h> main() { char c; c=250; exit((c > 0)?0:1); } EOF -if { (eval echo configure:3552: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:3579: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then echo yes;cat >> confdefs.h <<\EOF #define HAVE_UNSIGNED_CHAR 1 @@ -3566,7 +3593,7 @@ fi echo $ac_n "checking for sin_len in sock ... $ac_c" cat > conftest.$ac_ext <<EOF -#line 3570 "configure" +#line 3597 "configure" #include "confdefs.h" #include <sys/types.h> #include <sys/socket.h> @@ -3575,7 +3602,7 @@ int main() { struct sockaddr_in sock; sock.sin_len = sizeof(sock); ; return 0; } EOF -if { (eval echo configure:3579: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:3606: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* echo yes;cat >> confdefs.h <<\EOF #define HAVE_SOCK_SIN_LEN 1 @@ -3591,14 +3618,14 @@ rm -f conftest* echo $ac_n "checking for __FILE__ macro ... $ac_c" cat > conftest.$ac_ext <<EOF -#line 3595 "configure" +#line 3622 "configure" #include "confdefs.h" #include <stdio.h> int main() { printf("%s\n", __FILE__); ; return 0; } EOF -if { (eval echo configure:3602: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:3629: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* echo yes;cat >> confdefs.h <<\EOF #define HAVE_FILE_MACRO 1 @@ -3614,14 +3641,14 @@ rm -f conftest* echo $ac_n "checking for __FUNCTION__ macro ... $ac_c" cat > conftest.$ac_ext <<EOF -#line 3618 "configure" +#line 3645 "configure" #include "confdefs.h" #include <stdio.h> int main() { printf("%s\n", __FUNCTION__); ; return 0; } EOF -if { (eval echo configure:3625: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:3652: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* echo yes;cat >> confdefs.h <<\EOF #define HAVE_FUNCTION_MACRO 1 @@ -3640,14 +3667,14 @@ if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext <<EOF -#line 3644 "configure" +#line 3671 "configure" #include "confdefs.h" #include <sys/time.h> #include <unistd.h> main() { struct timeval tv; exit(gettimeofday(&tv, NULL));} EOF -if { (eval echo configure:3651: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:3678: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then echo yes;cat >> confdefs.h <<\EOF #define HAVE_GETTIMEOFDAY_TZ 1 @@ -3669,7 +3696,7 @@ if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext <<EOF -#line 3673 "configure" +#line 3700 "configure" #include "confdefs.h" #include <sys/types.h> #include <dirent.h> @@ -3677,7 +3704,7 @@ main() { struct dirent *di; DIR *d = opendir("."); di = readdir(d); if (di && di->d_name[-2] == '.' && di->d_name[-1] == 0 && di->d_name[0] == 0) exit(0); exit(1);} EOF -if { (eval echo configure:3681: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:3708: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then echo yes - you are using the broken /usr/ucb/cc;cat >> confdefs.h <<\EOF #define HAVE_BROKEN_READDIR 1 @@ -3695,7 +3722,7 @@ fi echo $ac_n "checking for utimbuf ... $ac_c" cat > conftest.$ac_ext <<EOF -#line 3699 "configure" +#line 3726 "configure" #include "confdefs.h" #include <sys/types.h> #include <utime.h> @@ -3703,7 +3730,7 @@ int main() { struct utimbuf tbuf; tbuf.actime = 0; tbuf.modtime = 1; exit(utime("foo.c",&tbuf)); ; return 0; } EOF -if { (eval echo configure:3707: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:3734: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* echo yes;cat >> confdefs.h <<\EOF #define HAVE_UTIMBUF 1 @@ -3722,11 +3749,11 @@ if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext <<EOF -#line 3726 "configure" +#line 3753 "configure" #include "confdefs.h" #include "tests/ftruncate.c" EOF -if { (eval echo configure:3730: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:3757: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then echo yes;cat >> confdefs.h <<\EOF #define HAVE_FTRUNCATE_EXTEND 1 @@ -3747,11 +3774,11 @@ if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext <<EOF -#line 3751 "configure" +#line 3778 "configure" #include "confdefs.h" #include "tests/getgroups.c" EOF -if { (eval echo configure:3755: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:3782: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then echo yes;cat >> confdefs.h <<\EOF #define HAVE_BROKEN_GETGROUPS 1 @@ -3773,7 +3800,7 @@ if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext <<EOF -#line 3777 "configure" +#line 3804 "configure" #include "confdefs.h" #include <stdio.h> @@ -3785,7 +3812,7 @@ if (strcmp(inet_ntoa(ip),"18.52.86.120") && strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); } exit(1);} EOF -if { (eval echo configure:3789: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:3816: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then echo yes;cat >> confdefs.h <<\EOF #define REPLACE_INET_NTOA 1 @@ -3806,11 +3833,11 @@ if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext <<EOF -#line 3810 "configure" +#line 3837 "configure" #include "confdefs.h" main() { exit(getuid() != 0); } EOF -if { (eval echo configure:3814: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:3841: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then echo yes;cat >> confdefs.h <<\EOF #define HAVE_ROOT 1 @@ -3832,14 +3859,14 @@ if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext <<EOF -#line 3836 "configure" +#line 3863 "configure" #include "confdefs.h" #define HAVE_NETMASK_IFCONF 1 #define AUTOCONF 1 #include "lib/netmask.c" EOF -if { (eval echo configure:3843: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:3870: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then echo yes;netmask=yes;cat >> confdefs.h <<\EOF #define HAVE_NETMASK_IFCONF 1 @@ -3861,14 +3888,14 @@ if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext <<EOF -#line 3865 "configure" +#line 3892 "configure" #include "confdefs.h" #define HAVE_NETMASK_IFREQ 1 #define AUTOCONF 1 #include "lib/netmask.c" EOF -if { (eval echo configure:3872: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:3899: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then echo yes;netmask=yes;cat >> confdefs.h <<\EOF #define HAVE_NETMASK_IFREQ 1 @@ -3891,14 +3918,14 @@ if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext <<EOF -#line 3895 "configure" +#line 3922 "configure" #include "confdefs.h" #define HAVE_NETMASK_AIX 1 #define AUTOCONF 1 #include "lib/netmask.c" EOF -if { (eval echo configure:3902: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:3929: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then echo yes;netmask=yes;cat >> confdefs.h <<\EOF #define HAVE_NETMASK_AIX 1 @@ -3920,11 +3947,11 @@ if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext <<EOF -#line 3924 "configure" +#line 3951 "configure" #include "confdefs.h" #include "tests/trapdoor.c" EOF -if { (eval echo configure:3928: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:3955: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then echo no else @@ -3945,11 +3972,11 @@ if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext <<EOF -#line 3949 "configure" +#line 3976 "configure" #include "confdefs.h" #include "tests/shared_mmap.c" EOF -if { (eval echo configure:3953: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:3980: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then echo yes;cat >> confdefs.h <<\EOF #define HAVE_SHARED_MMAP 1 @@ -3970,11 +3997,11 @@ if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext <<EOF -#line 3974 "configure" +#line 4001 "configure" #include "confdefs.h" #include "tests/fcntl_lock.c" EOF -if { (eval echo configure:3978: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:4005: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then echo yes;cat >> confdefs.h <<\EOF #define HAVE_FCNTL_LOCK 1 @@ -3995,11 +4022,11 @@ if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext <<EOF -#line 3999 "configure" +#line 4026 "configure" #include "confdefs.h" #include "tests/sysv_ipc.c" EOF -if { (eval echo configure:4003: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:4030: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then echo yes;cat >> confdefs.h <<\EOF #define HAVE_SYSV_IPC 1 @@ -4018,7 +4045,7 @@ fi ################################################# # check for the AFS filesystem echo $ac_n "checking whether to use AFS""... $ac_c" 1>&6 -echo "configure:4022: checking whether to use AFS" >&5 +echo "configure:4049: checking whether to use AFS" >&5 # Check whether --with-afs or --without-afs was given. if test "${with_afs+set}" = set; then withval="$with_afs" @@ -4044,7 +4071,7 @@ fi ################################################# # check for the DFS auth system echo $ac_n "checking whether to use DFS auth""... $ac_c" 1>&6 -echo "configure:4048: checking whether to use DFS auth" >&5 +echo "configure:4075: checking whether to use DFS auth" >&5 # Check whether --with-dfs or --without-dfs was given. if test "${with_dfs+set}" = set; then withval="$with_dfs" @@ -4069,7 +4096,7 @@ fi ################################################# # check for automount support echo $ac_n "checking whether to use AUTOMOUNT""... $ac_c" 1>&6 -echo "configure:4073: checking whether to use AUTOMOUNT" >&5 +echo "configure:4100: checking whether to use AUTOMOUNT" >&5 # Check whether --with-automount or --without-automount was given. if test "${with_automount+set}" = set; then withval="$with_automount" @@ -4094,7 +4121,7 @@ fi ################################################# # check for a LDAP password database echo $ac_n "checking whether to use LDAP password database""... $ac_c" 1>&6 -echo "configure:4098: checking whether to use LDAP password database" >&5 +echo "configure:4125: checking whether to use LDAP password database" >&5 # Check whether --with-ldap or --without-ldap was given. if test "${with_ldap+set}" = set; then withval="$with_ldap" @@ -4119,7 +4146,7 @@ fi ################################################# # check for a NISPLUS password database echo $ac_n "checking whether to use NISPLUS password database""... $ac_c" 1>&6 -echo "configure:4123: checking whether to use NISPLUS password database" >&5 +echo "configure:4150: checking whether to use NISPLUS password database" >&5 # Check whether --with-nisplus or --without-nisplus was given. if test "${with_nisplus+set}" = set; then withval="$with_nisplus" @@ -4144,7 +4171,7 @@ fi ################################################# # check for a NISPLUS_HOME support echo $ac_n "checking whether to use NISPLUS_HOME""... $ac_c" 1>&6 -echo "configure:4148: checking whether to use NISPLUS_HOME" >&5 +echo "configure:4175: checking whether to use NISPLUS_HOME" >&5 # Check whether --with-nisplus-home or --without-nisplus-home was given. if test "${with_nisplus_home+set}" = set; then withval="$with_nisplus_home" @@ -4169,7 +4196,7 @@ fi ################################################# # check for the secure socket layer echo $ac_n "checking whether to use SSL""... $ac_c" 1>&6 -echo "configure:4173: checking whether to use SSL" >&5 +echo "configure:4200: checking whether to use SSL" >&5 # Check whether --with-ssl or --without-ssl was given. if test "${with_ssl+set}" = set; then withval="$with_ssl" @@ -4194,7 +4221,7 @@ fi ################################################# # check for experimental mmap support echo $ac_n "checking whether to use MMAP""... $ac_c" 1>&6 -echo "configure:4198: checking whether to use MMAP" >&5 +echo "configure:4225: checking whether to use MMAP" >&5 # Check whether --with-mmap or --without-mmap was given. if test "${with_mmap+set}" = set; then withval="$with_mmap" @@ -4219,7 +4246,7 @@ fi ################################################# # check for syslog logging echo $ac_n "checking whether to use syslog logging""... $ac_c" 1>&6 -echo "configure:4223: checking whether to use syslog logging" >&5 +echo "configure:4250: checking whether to use syslog logging" >&5 # Check whether --with-syslog or --without-syslog was given. if test "${with_syslog+set}" = set; then withval="$with_syslog" @@ -4241,11 +4268,36 @@ else fi +################################################# +# check for experimental netatalk resource fork support +echo $ac_n "checking whether to support netatalk""... $ac_c" 1>&6 +echo "configure:4275: checking whether to support netatalk" >&5 +# Check whether --with-netatalk or --without-netatalk was given. +if test "${with_netatalk+set}" = set; then + withval="$with_netatalk" + case "$withval" in + yes) + echo "$ac_t""yes" 1>&6 + cat >> confdefs.h <<\EOF +#define WITH_NETATALK 1 +EOF + + ;; + *) + echo "$ac_t""no" 1>&6 + ;; + esac +else + echo "$ac_t""no" 1>&6 + +fi + + ################################################# # these tests are taken from the GNU fileutils package echo "checking how to get filesystem space usage" 1>&6 -echo "configure:4249: checking how to get filesystem space usage" >&5 +echo "configure:4301: checking how to get filesystem space usage" >&5 space=no # Perform only the link test since it seems there are no variants of the @@ -4257,12 +4309,12 @@ space=no if test $space = no; then # SVR4 echo $ac_n "checking statvfs function (SVR4)""... $ac_c" 1>&6 -echo "configure:4261: checking statvfs function (SVR4)" >&5 +echo "configure:4313: checking statvfs function (SVR4)" >&5 if eval "test \"`echo '$''{'fu_cv_sys_stat_statvfs'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 4266 "configure" +#line 4318 "configure" #include "confdefs.h" #include <sys/types.h> #include <sys/statvfs.h> @@ -4270,7 +4322,7 @@ int main() { struct statvfs fsd; statvfs (0, &fsd); ; return 0; } EOF -if { (eval echo configure:4274: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:4326: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* fu_cv_sys_stat_statvfs=yes else @@ -4295,7 +4347,7 @@ fi if test $space = no; then # DEC Alpha running OSF/1 echo $ac_n "checking for 3-argument statfs function (DEC OSF/1)""... $ac_c" 1>&6 -echo "configure:4299: checking for 3-argument statfs function (DEC OSF/1)" >&5 +echo "configure:4351: checking for 3-argument statfs function (DEC OSF/1)" >&5 if eval "test \"`echo '$''{'fu_cv_sys_stat_statfs3_osf1'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -4303,7 +4355,7 @@ else fu_cv_sys_stat_statfs3_osf1=no else cat > conftest.$ac_ext <<EOF -#line 4307 "configure" +#line 4359 "configure" #include "confdefs.h" #include <sys/param.h> @@ -4316,7 +4368,7 @@ else exit (statfs (".", &fsd, sizeof (struct statfs))); } EOF -if { (eval echo configure:4320: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:4372: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then fu_cv_sys_stat_statfs3_osf1=yes else @@ -4343,7 +4395,7 @@ fi if test $space = no; then # AIX echo $ac_n "checking for two-argument statfs with statfs.bsize member (AIX, 4.3BSD)""... $ac_c" 1>&6 -echo "configure:4347: checking for two-argument statfs with statfs.bsize member (AIX, 4.3BSD)" >&5 +echo "configure:4399: checking for two-argument statfs with statfs.bsize member (AIX, 4.3BSD)" >&5 if eval "test \"`echo '$''{'fu_cv_sys_stat_statfs2_bsize'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -4351,7 +4403,7 @@ else fu_cv_sys_stat_statfs2_bsize=no else cat > conftest.$ac_ext <<EOF -#line 4355 "configure" +#line 4407 "configure" #include "confdefs.h" #ifdef HAVE_SYS_PARAM_H @@ -4370,7 +4422,7 @@ else exit (statfs (".", &fsd)); } EOF -if { (eval echo configure:4374: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:4426: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then fu_cv_sys_stat_statfs2_bsize=yes else @@ -4397,7 +4449,7 @@ fi if test $space = no; then # SVR3 echo $ac_n "checking for four-argument statfs (AIX-3.2.5, SVR3)""... $ac_c" 1>&6 -echo "configure:4401: checking for four-argument statfs (AIX-3.2.5, SVR3)" >&5 +echo "configure:4453: checking for four-argument statfs (AIX-3.2.5, SVR3)" >&5 if eval "test \"`echo '$''{'fu_cv_sys_stat_statfs4'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -4405,7 +4457,7 @@ else fu_cv_sys_stat_statfs4=no else cat > conftest.$ac_ext <<EOF -#line 4409 "configure" +#line 4461 "configure" #include "confdefs.h" #include <sys/types.h> #include <sys/statfs.h> @@ -4415,7 +4467,7 @@ else exit (statfs (".", &fsd, sizeof fsd, 0)); } EOF -if { (eval echo configure:4419: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:4471: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then fu_cv_sys_stat_statfs4=yes else @@ -4442,7 +4494,7 @@ fi if test $space = no; then # 4.4BSD and NetBSD echo $ac_n "checking for two-argument statfs with statfs.fsize member (4.4BSD and NetBSD)""... $ac_c" 1>&6 -echo "configure:4446: checking for two-argument statfs with statfs.fsize member (4.4BSD and NetBSD)" >&5 +echo "configure:4498: checking for two-argument statfs with statfs.fsize member (4.4BSD and NetBSD)" >&5 if eval "test \"`echo '$''{'fu_cv_sys_stat_statfs2_fsize'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -4450,7 +4502,7 @@ else fu_cv_sys_stat_statfs2_fsize=no else cat > conftest.$ac_ext <<EOF -#line 4454 "configure" +#line 4506 "configure" #include "confdefs.h" #include <sys/types.h> #ifdef HAVE_SYS_PARAM_H @@ -4466,7 +4518,7 @@ else exit (statfs (".", &fsd)); } EOF -if { (eval echo configure:4470: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:4522: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then fu_cv_sys_stat_statfs2_fsize=yes else @@ -4493,7 +4545,7 @@ fi if test $space = no; then # Ultrix echo $ac_n "checking for two-argument statfs with struct fs_data (Ultrix)""... $ac_c" 1>&6 -echo "configure:4497: checking for two-argument statfs with struct fs_data (Ultrix)" >&5 +echo "configure:4549: checking for two-argument statfs with struct fs_data (Ultrix)" >&5 if eval "test \"`echo '$''{'fu_cv_sys_stat_fs_data'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -4501,7 +4553,7 @@ else fu_cv_sys_stat_fs_data=no else cat > conftest.$ac_ext <<EOF -#line 4505 "configure" +#line 4557 "configure" #include "confdefs.h" #include <sys/types.h> #ifdef HAVE_SYS_PARAM_H @@ -4521,7 +4573,7 @@ else exit (statfs (".", &fsd) != 1); } EOF -if { (eval echo configure:4525: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:4577: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then fu_cv_sys_stat_fs_data=yes else @@ -4650,7 +4702,7 @@ ac_given_INSTALL="$INSTALL" trap 'rm -fr `echo "Makefile tests/dummy client/dummy lib/dummy ubiqx/dummy web/dummy param/dummy nmbd/dummy smbd/dummy rpc_server/dummy rpc_parse/dummy script/dummy include/dummy codepages/dummy -libsmb/dummy include/config.h" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15 +libsmb/dummy bin/dummy include/config.h" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15 EOF cat >> $CONFIG_STATUS <<EOF @@ -4746,7 +4798,7 @@ cat >> $CONFIG_STATUS <<EOF CONFIG_FILES=\${CONFIG_FILES-"Makefile tests/dummy client/dummy lib/dummy ubiqx/dummy web/dummy param/dummy nmbd/dummy smbd/dummy rpc_server/dummy rpc_parse/dummy script/dummy include/dummy codepages/dummy -libsmb/dummy"} +libsmb/dummy bin/dummy"} EOF cat >> $CONFIG_STATUS <<\EOF for ac_file in .. $CONFIG_FILES; do if test "x$ac_file" != x..; then diff --git a/source3/configure.in b/source3/configure.in index 14698e401f..af5d9200c9 100644 --- a/source3/configure.in +++ b/source3/configure.in @@ -58,6 +58,12 @@ AC_TRY_COMPILE([#include <errno.h>],[int i = errno], echo yes; AC_DEFINE(HAVE_ERRNO_DECL), echo no) +# stupid glibc has the functions but no declaration. grrrr. +echo $ac_n "checking for setresuid declaration $ac_c" +AC_TRY_COMPILE([#include <unistd.h>],[int i = setresuid], +echo yes; AC_DEFINE(HAVE_SETRESUID_DECL), +echo no) + AC_FUNC_MEMCMP ############################################### diff --git a/source3/include/config.h.in b/source3/include/config.h.in index b73ee04e77..ced68aa762 100644 --- a/source3/include/config.h.in +++ b/source3/include/config.h.in @@ -109,6 +109,8 @@ #undef REPLACE_INET_NTOA #undef HAVE_FILE_MACRO #undef HAVE_FUNCTION_MACRO +#undef HAVE_SETRESUID_DECL +#undef WITH_NETATALK /* The number of bytes in a int. */ #undef SIZEOF_INT diff --git a/source3/include/includes.h b/source3/include/includes.h index a65114f3de..237251209a 100644 --- a/source3/include/includes.h +++ b/source3/include/includes.h @@ -464,4 +464,10 @@ time_t mktime(struct tm *t); int ftruncate(int f,long l); #endif +#if (defined(HAVE_SETRESUID) && !defined(HAVE_SETRESUID_DECL)) +/* stupid glibc */ +int setresuid(uid_t ruid, uid_t euid, uid_t suid); +int setresgid(gid_t rgid, gid_t egid, gid_t sgid); +#endif + #endif /* _INCLUDES_H */ diff --git a/source3/include/ntdomain.h b/source3/include/ntdomain.h index 50f9397012..0b2648372b 100644 --- a/source3/include/ntdomain.h +++ b/source3/include/ntdomain.h @@ -55,7 +55,7 @@ typedef struct typedef struct { - int cnum; + connection_struct *conn; int uid; BOOL open; /* open connection */ uint16 device_state; @@ -79,7 +79,6 @@ typedef struct uint32 hdr_offsets; uint32 frag_len_left; uint32 next_frag_start; - } pipes_struct; struct acct_info diff --git a/source3/include/proto.h b/source3/include/proto.h index e310246a87..1cab9c5e9d 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -148,6 +148,10 @@ void CatchChild(void); int vslprintf(char *str, int n, char *format, va_list ap); +/*The following definitions come from lib/smbrun.c */ + +int smbrun(char *cmd,char *outfile,BOOL shared); + /*The following definitions come from lib/system.c */ int sys_select(fd_set *fds,struct timeval *tval); @@ -308,6 +312,7 @@ char *client_addr(int fd); char *automount_server(char *user_name); char *automount_path(char *user_name); void standard_sub_basic(char *str); +void standard_sub(connection_struct *conn,char *str); BOOL same_net(struct in_addr ip1,struct in_addr ip2,struct in_addr mask); int PutUniCode(char *dst,char *src); struct hostent *Get_Hostbyname(char *name); @@ -342,6 +347,7 @@ void dump_data(int level,char *buf1,int len); char *tab_depth(int depth); char *sid_to_string(pstring sidstr_out, DOM_SID *sid); BOOL string_to_sid(DOM_SID *sidout, char *sidstr); +int str_checksum(char *s); /*The following definitions come from libsmb/clientgen.c */ @@ -468,15 +474,21 @@ char *smb_errstr(char *inbuf); BOOL push_blocking_lock_request( char *inbuf, int length, int lock_timeout, int lock_num); void process_blocking_lock_queue(time_t t); -BOOL is_locked(int fnum,int cnum,uint32 count,uint32 offset, int lock_type); -BOOL do_lock(int fnum,int cnum,uint32 count,uint32 offset,int lock_type, +BOOL is_locked(int fnum,connection_struct *conn, + uint32 count,uint32 offset, int lock_type); +BOOL do_lock(int fnum,connection_struct *conn, + uint32 count,uint32 offset,int lock_type, int *eclass,uint32 *ecode); -BOOL do_unlock(int fnum,int cnum,uint32 count,uint32 offset,int *eclass,uint32 *ecode); +BOOL do_unlock(int fnum,connection_struct *conn, + uint32 count,uint32 offset,int *eclass,uint32 *ecode); BOOL locking_init(int read_only); BOOL locking_end(void); -BOOL lock_share_entry(int cnum, uint32 dev, uint32 inode, int *ptok); -BOOL unlock_share_entry(int cnum, uint32 dev, uint32 inode, int token); -int get_share_modes(int cnum, int token, uint32 dev, uint32 inode, +BOOL lock_share_entry(connection_struct *conn, + uint32 dev, uint32 inode, int *ptok); +BOOL unlock_share_entry(connection_struct *conn, + uint32 dev, uint32 inode, int token); +int get_share_modes(connection_struct *conn, + int token, uint32 dev, uint32 inode, share_mode_entry **shares); void del_share_mode(int token, int fnum); BOOL set_share_mode(int token, int fnum, uint16 port, uint16 op_type); @@ -1057,6 +1069,7 @@ BOOL lp_do_parameter(int snum, char *pszParmName, char *pszParmValue); BOOL lp_is_default(int snum, struct parm_struct *parm); struct parm_struct *lp_next_parameter(int snum, int *i, int allparameters); BOOL lp_snum_ok(int iService); +void lp_add_one_printer(char *name,char *comment); BOOL lp_loaded(void); void lp_killunused(BOOL (*snumused)(int )); BOOL lp_load(char *pszFname,BOOL global_only, BOOL save_defaults, BOOL add_ipc); @@ -1819,12 +1832,12 @@ BOOL api_netlog_rpc(pipes_struct *p, prs_struct *data); void reset_chain_pnum(void); void set_chain_pnum(int new_pnum); void init_rpc_pipe_hnd(void); -int open_rpc_pipe_hnd(char *pipe_name, int cnum, uint16 vuid); +int open_rpc_pipe_hnd(char *pipe_name, connection_struct *conn, uint16 vuid); int read_pipe(uint16 pnum, char *data, uint32 pos, int n); BOOL get_rpc_pipe(int pnum, pipes_struct **p); char *get_rpc_pipe_hnd_name(int pnum); BOOL set_rpc_pipe_hnd_state(pipes_struct *p, uint16 device_state); -BOOL close_rpc_pipe_hnd(int pnum, int cnum); +BOOL close_rpc_pipe_hnd(int pnum, connection_struct *conn); int get_rpc_pipe_num(char *buf, int where); /*The following definitions come from rpc_server/srv_reg.c */ @@ -1874,8 +1887,8 @@ BOOL change_oem_password(struct smb_passwd *smbpw, char *new_passwd, BOOL overri /*The following definitions come from smbd/connection.c */ -BOOL yield_connection(int cnum,char *name,int max_connections); -BOOL claim_connection(int cnum,char *name,int max_connections,BOOL Clear); +BOOL yield_connection(connection_struct *conn,char *name,int max_connections); +BOOL claim_connection(connection_struct *conn,char *name,int max_connections,BOOL Clear); /*The following definitions come from smbd/dfree.c */ @@ -1890,17 +1903,17 @@ BOOL dptr_set_wcard(int key, char *wcard); BOOL dptr_set_attr(int key, uint16 attr); uint16 dptr_attr(int key); void dptr_close(int key); -void dptr_closecnum(int cnum); -void dptr_idlecnum(int cnum); +void dptr_closecnum(connection_struct *conn); +void dptr_idlecnum(connection_struct *conn); void dptr_closepath(char *path,int pid); -int dptr_create(int cnum,char *path, BOOL expect_close,int pid); +int dptr_create(connection_struct *conn,char *path, BOOL expect_close,int pid); BOOL dptr_fill(char *buf1,unsigned int key); BOOL dptr_zero(char *buf); void *dptr_fetch(char *buf,int *num); void *dptr_fetch_lanman2(int dptr_num); -BOOL dir_check_ftype(int cnum,int mode,struct stat *st,int dirtype); -BOOL get_dir_entry(int cnum,char *mask,int dirtype,char *fname,int *size,int *mode,time_t *date,BOOL check_descend); -void *OpenDir(int cnum, char *name, BOOL use_veto); +BOOL dir_check_ftype(connection_struct *conn,int mode,struct stat *st,int dirtype); +BOOL get_dir_entry(connection_struct *conn,char *mask,int dirtype,char *fname,int *size,int *mode,time_t *date,BOOL check_descend); +void *OpenDir(connection_struct *conn, char *name, BOOL use_veto); void CloseDir(void *p); char *ReadDirName(void *p); BOOL SeekDir(void *p,int pos); @@ -1917,13 +1930,12 @@ void map_gid_to_sid( gid_t gid, DOM_SID *psid); /*The following definitions come from smbd/ipc.c */ int get_printerdrivernumber(int snum); -int reply_trans(char *inbuf,char *outbuf, int size, int bufsize); +int reply_trans(connection_struct *conn, char *inbuf,char *outbuf, int size, int bufsize); /*The following definitions come from smbd/mangle.c */ BOOL is_mangled( char *s ); BOOL is_8_3( char *fname, BOOL check_case ); -int str_checksum( char *s ); void reset_mangled_cache( void ); BOOL check_mangled_cache( char *s ); void mangle_name_83( char *s, int s_len ); @@ -1931,20 +1943,28 @@ BOOL name_map_mangle( char *OutName, BOOL need83, int snum ); /*The following definitions come from smbd/message.c */ -int reply_sends(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_sendstrt(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_sendtxt(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_sendend(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_sends(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_sendstrt(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_sendtxt(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_sendend(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, int dum_buffsize); /*The following definitions come from smbd/nttrans.c */ -int reply_ntcreate_and_X(char *inbuf,char *outbuf,int length,int bufsize); -int reply_ntcancel(char *inbuf,char *outbuf,int length,int bufsize); -int reply_nttranss(char *inbuf,char *outbuf,int length,int bufsize); +int reply_ntcreate_and_X(connection_struct *conn, + char *inbuf,char *outbuf,int length,int bufsize); +int reply_ntcancel(connection_struct *conn, + char *inbuf,char *outbuf,int length,int bufsize); +int reply_nttranss(connection_struct *conn, + char *inbuf,char *outbuf,int length,int bufsize); void remove_pending_change_notify_requests_by_fid(int fnum); void remove_pending_change_notify_requests_by_mid(int mid); void process_pending_change_notify_queue(time_t t); -int reply_nttrans(char *inbuf,char *outbuf,int length,int bufsize); +int reply_nttrans(connection_struct *conn, + char *inbuf,char *outbuf,int length,int bufsize); /*The following definitions come from smbd/password.c */ @@ -1977,9 +1997,10 @@ BOOL domain_client_validate( char *user, char *domain, /*The following definitions come from smbd/pipes.c */ -int reply_open_pipe_and_X(char *inbuf,char *outbuf,int length,int bufsize); +int reply_open_pipe_and_X(connection_struct *conn, + char *inbuf,char *outbuf,int length,int bufsize); int reply_pipe_read_and_X(char *inbuf,char *outbuf,int length,int bufsize); -int reply_pipe_close(char *inbuf,char *outbuf); +int reply_pipe_close(connection_struct *conn, char *inbuf,char *outbuf); /*The following definitions come from smbd/predict.c */ @@ -1995,14 +2016,16 @@ int sysv_printername_ok(char *name); /*The following definitions come from smbd/printing.c */ void lpq_reset(int snum); -void print_file(int fnum); -int get_printqueue(int snum,int cnum,print_queue_struct **queue, +void print_file(connection_struct *conn, files_struct *file); +int get_printqueue(int snum, + connection_struct *conn,print_queue_struct **queue, print_status_struct *status); -void del_printqueue(int cnum,int snum,int jobid); -void status_printjob(int cnum,int snum,int jobid,int status); +void del_printqueue(connection_struct *conn,int snum,int jobid); +void status_printjob(connection_struct *conn,int snum,int jobid,int status); int printjob_encode(int snum, int job); void printjob_decode(int jobid, int *snum, int *job); -void status_printqueue(int cnum,int snum,int status); +void status_printqueue(connection_struct *conn,int snum,int status); +void load_printers(void); /*The following definitions come from smbd/quotas.c */ @@ -2016,81 +2039,95 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize); /*The following definitions come from smbd/reply.c */ int reply_special(char *inbuf,char *outbuf); -int reply_tcon(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_tcon_and_X(char *inbuf,char *outbuf,int length,int bufsize); +int reply_tcon(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_tcon_and_X(connection_struct *conn, char *inbuf,char *outbuf,int length,int bufsize); int reply_unknown(char *inbuf,char *outbuf); -int reply_ioctl(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_sesssetup_and_X(char *inbuf,char *outbuf,int length,int bufsize); -int reply_chkpth(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_getatr(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_setatr(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_dskattr(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_search(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_fclose(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_open(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_open_and_X(char *inbuf,char *outbuf,int length,int bufsize); -int reply_ulogoffX(char *inbuf,char *outbuf,int length,int bufsize); -int reply_mknew(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_ctemp(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_unlink(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_readbraw(char *inbuf, char *outbuf, int dum_size, int dum_buffsize); -int reply_lockread(char *inbuf,char *outbuf, int dum_size, int dum_buffsiz); -int reply_read(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_read_and_X(char *inbuf,char *outbuf,int length,int bufsize); -int reply_writebraw(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_writeunlock(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_write(char *inbuf,char *outbuf,int dum_size,int dum_buffsize); -int reply_write_and_X(char *inbuf,char *outbuf,int length,int bufsize); -int reply_lseek(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_flush(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_exit(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_close(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_writeclose(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_lock(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_unlock(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_tdis(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_echo(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_printopen(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_printclose(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_printqueue(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_printwrite(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_mkdir(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_rmdir(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int rename_internals(char *inbuf, char *outbuf, char *name, char *newname, BOOL replace_if_exists); -int reply_mv(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_copy(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_setdir(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_lockingX(char *inbuf,char *outbuf,int length,int bufsize); -int reply_readbmpx(char *inbuf,char *outbuf,int length,int bufsize); -int reply_writebmpx(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_writebs(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_setattrE(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); -int reply_getattrE(char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_ioctl(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_sesssetup_and_X(connection_struct *conn, char *inbuf,char *outbuf,int length,int bufsize); +int reply_chkpth(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_getatr(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_setatr(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_dskattr(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_search(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_fclose(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_open(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_open_and_X(connection_struct *conn, char *inbuf,char *outbuf,int length,int bufsize); +int reply_ulogoffX(connection_struct *conn, char *inbuf,char *outbuf,int length,int bufsize); +int reply_mknew(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_ctemp(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_unlink(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_readbraw(connection_struct *conn, char *inbuf, char *outbuf, int dum_size, int dum_buffsize); +int reply_lockread(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsiz); +int reply_read(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_read_and_X(connection_struct *conn, char *inbuf,char *outbuf,int length,int bufsize); +int reply_writebraw(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_writeunlock(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_write(connection_struct *conn, char *inbuf,char *outbuf,int dum_size,int dum_buffsize); +int reply_write_and_X(connection_struct *conn, char *inbuf,char *outbuf,int length,int bufsize); +int reply_lseek(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_flush(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_exit(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_close(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_writeclose(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_lock(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_unlock(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_tdis(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_echo(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_printopen(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_printclose(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_printqueue(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_printwrite(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_mkdir(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_rmdir(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int rename_internals(connection_struct *conn, + char *inbuf, char *outbuf, char *name, + char *newname, BOOL replace_if_exists); +int reply_mv(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_copy(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_setdir(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_lockingX(connection_struct *conn, char *inbuf,char *outbuf,int length,int bufsize); +int reply_readbmpx(connection_struct *conn, char *inbuf,char *outbuf,int length,int bufsize); +int reply_writebmpx(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_writebs(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_setattrE(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize); +int reply_getattrE(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize); /*The following definitions come from smbd/server.c */ void *dflt_sig(void); void killkids(void); -mode_t unix_mode(int cnum,int dosmode); -int dos_mode(int cnum,char *path,struct stat *sbuf); -int dos_chmod(int cnum,char *fname,int dosmode,struct stat *st); -int file_utime(int cnum, char *fname, struct utimbuf *times); -BOOL set_filetime(int cnum, char *fname, time_t mtime); -BOOL unix_convert(char *name,int cnum,pstring saved_last_component, BOOL *bad_path); -BOOL check_name(char *name,int cnum); -void sync_file(int cnum, int fnum); +mode_t unix_mode(connection_struct *conn,int dosmode); +int dos_mode(connection_struct *conn,char *path,struct stat *sbuf); +int dos_chmod(connection_struct *conn,char *fname,int dosmode,struct stat *st); +int file_utime(connection_struct *conn, char *fname, struct utimbuf *times); +BOOL set_filetime(connection_struct *conn, char *fname, time_t mtime); +BOOL unix_convert(char *name,connection_struct *conn,char *saved_last_component, BOOL *bad_path); +BOOL check_name(char *name,connection_struct *conn); +void sync_file(connection_struct *conn, int fnum); void close_file(int fnum, BOOL normal_close); void close_directory(int fnum); -int open_directory(int fnum,int cnum,char *fname, int smb_ofun, int unixmode, int *action); -BOOL check_file_sharing(int cnum,char *fname, BOOL rename_op); +int open_directory(int fnum,connection_struct *conn, + char *fname, int smb_ofun, int unixmode, int *action); +BOOL check_file_sharing(connection_struct *conn,char *fname, BOOL rename_op); int check_share_mode( share_mode_entry *share, int deny_mode, char *fname, BOOL fcbopen, int *flags); -void open_file_shared(int fnum,int cnum,char *fname,int share_mode,int ofun, +void open_file_shared(int fnum,connection_struct *conn,char *fname,int share_mode,int ofun, int mode,int oplock_request, int *Access,int *action); int seek_file(int fnum,uint32 pos); int read_file(int fnum,char *data,uint32 pos,int n); int write_file(int fnum,char *data,int n); -BOOL become_service(int cnum,BOOL do_chdir); +BOOL become_service(connection_struct *conn,BOOL do_chdir); int find_service(char *service); int cached_error_packet(char *inbuf,char *outbuf,int fnum,int line); int unix_error_packet(char *inbuf,char *outbuf,int def_class,uint32 def_code,int line); @@ -2101,16 +2138,15 @@ BOOL request_oplock_break(share_mode_entry *share_entry, BOOL receive_next_smb(int smbfd, int oplockfd, char *inbuf, int bufsize, int timeout); BOOL snum_used(int snum); BOOL reload_services(BOOL test); -int make_connection(char *service,char *user,char *password, int pwlen, char *dev,uint16 vuid); +connection_struct *make_connection(char *service,char *user,char *password, int pwlen, char *dev,uint16 vuid, int *ecode); int find_free_file(void ); int reply_corep(char *outbuf); int reply_coreplus(char *outbuf); int reply_lanman1(char *outbuf); int reply_lanman2(char *outbuf); int reply_nt1(char *outbuf); -void close_cnum(int cnum, uint16 vuid); +void close_cnum(connection_struct *conn, uint16 vuid); void exit_server(char *reason); -void standard_sub(int cnum,char *str); char *smb_fn_name(int type); int chain_reply(char *inbuf,char *outbuf,int size,int bufsize); void construct_reply_common(char *inbuf,char *outbuf); @@ -2128,18 +2164,21 @@ int sslutil_negotiate_ssl(int fd, int msg_type); /*The following definitions come from smbd/trans2.c */ void mask_convert( char *mask); -int reply_findclose(char *inbuf,char *outbuf,int length,int bufsize); -int reply_findnclose(char *inbuf,char *outbuf,int length,int bufsize); -int reply_transs2(char *inbuf,char *outbuf,int length,int bufsize); -int reply_trans2(char *inbuf,char *outbuf,int length,int bufsize); +int reply_findclose(connection_struct *conn, + char *inbuf,char *outbuf,int length,int bufsize); +int reply_findnclose(connection_struct *conn, + char *inbuf,char *outbuf,int length,int bufsize); +int reply_transs2(connection_struct *conn, + char *inbuf,char *outbuf,int length,int bufsize); +int reply_trans2(connection_struct *conn, + char *inbuf,char *outbuf,int length,int bufsize); /*The following definitions come from smbd/uid.c */ void init_uid(void); BOOL become_guest(void); -BOOL become_user(connection_struct *conn, int cnum, uint16 vuid); +BOOL become_user(connection_struct *conn, uint16 vuid); BOOL unbecome_user(void ); -int smbrun(char *cmd,char *outfile,BOOL shared); void become_root(BOOL save_dir) ; void unbecome_root(BOOL restore_dir); diff --git a/source3/include/smb.h b/source3/include/smb.h index bbd404b217..b060134d8e 100644 --- a/source3/include/smb.h +++ b/source3/include/smb.h @@ -98,9 +98,20 @@ typedef unsigned short uint16; * the #ifdef directive and will read both definitions, thus creating two * diffferent prototype declarations), so we must do these by hand. */ +/* I know the __attribute__ stuff is ugly, but it does ensure we get the + arguemnts to DEBUG() right. We have got them wrong too often in the + past */ #ifdef HAVE_STDARG_H -int Debug1( char *, ... ); -BOOL dbgtext( char *, ... ); +int Debug1( char *, ... ) +#ifdef __GNUC__ + __attribute__ ((format (printf, 1, 2))) +#endif +; +BOOL dbgtext( char *, ... ) +#ifdef __GNUC__ + __attribute__ ((format (printf, 1, 2))) +#endif +; #else int Debug1(); BOOL dbgtext(); @@ -451,14 +462,6 @@ struct cli_state { }; -struct current_user -{ - int cnum, vuid; - int uid, gid; - int ngroups; - GID_T *groups; -}; - typedef struct { int size; @@ -515,32 +518,6 @@ typedef struct time_t status_time; } dir_status_struct; -typedef struct -{ - int cnum; - file_fd_struct *fd_ptr; - int pos; - uint32 size; - int mode; - int vuid; - char *mmap_ptr; - uint32 mmap_size; - write_bmpx_struct *wbmpx_ptr; - struct timeval open_time; - BOOL open; - BOOL can_lock; - BOOL can_read; - BOOL can_write; - BOOL share_mode; - BOOL print_file; - BOOL modified; - BOOL granted_oplock; - BOOL sent_oplock_break; - BOOL is_directory; - BOOL reserved; - char *name; -} files_struct; - struct uid_cache { int entries; int list[UID_CACHE_SIZE]; @@ -554,38 +531,74 @@ typedef struct typedef struct { - int service; - BOOL force_user; - struct uid_cache uid_cache; - void *dirptr; - BOOL open; - BOOL printer; - BOOL ipc; - BOOL read_only; - BOOL admin_user; - char *dirpath; - char *connectpath; - char *origpath; - char *user; /* name of user who *opened* this connection */ - int uid; /* uid of user who *opened* this connection */ - int gid; /* gid of user who *opened* this connection */ - - uint16 vuid; /* vuid of user who *opened* this connection, or UID_FIELD_INVALID */ - - /* following groups stuff added by ih */ + unsigned cnum; /* an index passed over the wire */ + int service; + BOOL force_user; + struct uid_cache uid_cache; + void *dirptr; + BOOL open; + BOOL printer; + BOOL ipc; + BOOL read_only; + BOOL admin_user; + char *dirpath; + char *connectpath; + char *origpath; + char *user; /* name of user who *opened* this connection */ + int uid; /* uid of user who *opened* this connection */ + int gid; /* gid of user who *opened* this connection */ + + uint16 vuid; /* vuid of user who *opened* this connection, or UID_FIELD_INVALID */ + + /* following groups stuff added by ih */ + + /* This groups info is valid for the user that *opened* the connection */ + int ngroups; + GID_T *groups; + + time_t lastused; + BOOL used; + int num_files_open; + name_compare_entry *hide_list; /* Per-share list of files to return as hidden. */ + name_compare_entry *veto_list; /* Per-share list of files to veto (never show). */ + name_compare_entry *veto_oplock_list; /* Per-share list of files to refuse oplocks on. */ +} connection_struct; - /* This groups info is valid for the user that *opened* the connection */ - int ngroups; - GID_T *groups; +struct current_user +{ + connection_struct *conn; + int vuid; + int uid, gid; + int ngroups; + GID_T *groups; +}; - time_t lastused; - BOOL used; - int num_files_open; - name_compare_entry *hide_list; /* Per-share list of files to return as hidden. */ - name_compare_entry *veto_list; /* Per-share list of files to veto (never show). */ - name_compare_entry *veto_oplock_list; /* Per-share list of files to refuse oplocks on. */ +typedef struct +{ + connection_struct *conn; + file_fd_struct *fd_ptr; + int pos; + uint32 size; + int mode; + int vuid; + char *mmap_ptr; + uint32 mmap_size; + write_bmpx_struct *wbmpx_ptr; + struct timeval open_time; + BOOL open; + BOOL can_lock; + BOOL can_read; + BOOL can_write; + BOOL share_mode; + BOOL print_file; + BOOL modified; + BOOL granted_oplock; + BOOL sent_oplock_break; + BOOL is_directory; + BOOL reserved; + char *fsp_name; +} files_struct; -} connection_struct; /* Domain controller authentication protocol info */ struct dcinfo @@ -679,9 +692,9 @@ typedef struct to support the following operations */ struct share_ops { BOOL (*stop_mgmt)(void); - BOOL (*lock_entry)(int , uint32 , uint32 , int *); - BOOL (*unlock_entry)(int , uint32 , uint32 , int ); - int (*get_entries)(int , int , uint32 , uint32 , share_mode_entry **); + BOOL (*lock_entry)(connection_struct *, uint32 , uint32 , int *); + BOOL (*unlock_entry)(connection_struct *, uint32 , uint32 , int ); + int (*get_entries)(connection_struct *, int , uint32 , uint32 , share_mode_entry **); void (*del_entry)(int , int ); BOOL (*set_entry)(int , int , uint16 , uint16 ); BOOL (*remove_oplock)(int , int); @@ -848,12 +861,12 @@ struct parm_struct #define VALID_FNUM(fnum) (((fnum) >= 0) && ((fnum) < MAX_FNUMS)) #define OPEN_FNUM(fnum) (VALID_FNUM(fnum) && Files[fnum].open && !Files[fnum].is_directory) #define VALID_CNUM(cnum) (((cnum) >= 0) && ((cnum) < MAX_CONNECTIONS)) -#define OPEN_CNUM(cnum) (VALID_CNUM(cnum) && Connections[cnum].open) -#define IS_IPC(cnum) (VALID_CNUM(cnum) && Connections[cnum].ipc) -#define IS_PRINT(cnum) (VALID_CNUM(cnum) && Connections[cnum].printer) -#define FNUM_OK(fnum,c) (OPEN_FNUM(fnum) && (c)==Files[fnum].cnum) +#define OPEN_CNUM(conn) ((conn) && (conn)->open) +#define IS_IPC(conn) ((conn) && (conn)->ipc) +#define IS_PRINT(conn) ((conn) && (conn)->printer) +#define FNUM_OK(fnum,c) (OPEN_FNUM(fnum) && (c)==Files[fnum].conn) -#define CHECK_FNUM(fnum,c) if (!FNUM_OK(fnum,c)) \ +#define CHECK_FNUM(fnum,conn) if (!FNUM_OK(fnum,conn)) \ return(ERROR(ERRDOS,ERRbadfid)) #define CHECK_READ(fnum) if (!Files[fnum].can_read) \ return(ERROR(ERRDOS,ERRbadaccess)) @@ -863,26 +876,25 @@ struct parm_struct return(CACHED_ERROR(fnum)) /* translates a connection number into a service number */ -#define SNUM(cnum) (Connections[cnum].service) +#define SNUM(conn) ((conn)?(conn)->service:-1) /* access various service details */ #define SERVICE(snum) (lp_servicename(snum)) #define PRINTCAP (lp_printcapname()) #define PRINTCOMMAND(snum) (lp_printcommand(snum)) #define PRINTERNAME(snum) (lp_printername(snum)) -#define CAN_WRITE(cnum) (OPEN_CNUM(cnum) && !Connections[cnum].read_only) +#define CAN_WRITE(conn) (OPEN_CNUM(conn) && !conn->read_only) #define VALID_SNUM(snum) (lp_snum_ok(snum)) #define GUEST_OK(snum) (VALID_SNUM(snum) && lp_guest_ok(snum)) #define GUEST_ONLY(snum) (VALID_SNUM(snum) && lp_guest_only(snum)) #define CAN_SETDIR(snum) (!lp_no_set_dir(snum)) -#define CAN_PRINT(cnum) (OPEN_CNUM(cnum) && lp_print_ok(SNUM(cnum))) -#define POSTSCRIPT(cnum) (OPEN_CNUM(cnum) && lp_postscript(SNUM(cnum))) -#define MAP_HIDDEN(cnum) (OPEN_CNUM(cnum) && lp_map_hidden(SNUM(cnum))) -#define MAP_SYSTEM(cnum) (OPEN_CNUM(cnum) && lp_map_system(SNUM(cnum))) -#define MAP_ARCHIVE(cnum) (OPEN_CNUM(cnum) && lp_map_archive(SNUM(cnum))) -#define IS_HIDDEN_PATH(cnum,path) (is_in_path((path),Connections[(cnum)].hide_list)) -#define IS_VETO_PATH(cnum,path) (is_in_path((path),Connections[(cnum)].veto_list)) -#define IS_VETO_OPLOCK_PATH(cnum,path) (is_in_path((path),Connections[(cnum)].veto_oplock_list)) +#define CAN_PRINT(conn) ((conn) && lp_print_ok((conn)->service)) +#define MAP_HIDDEN(conn) ((conn) && lp_map_hidden((conn)->service)) +#define MAP_SYSTEM(conn) ((conn) && lp_map_system((conn)->service)) +#define MAP_ARCHIVE(conn) ((conn) && lp_map_archive((conn)->service)) +#define IS_HIDDEN_PATH(conn,path) ((conn) && is_in_path((path),(conn)->hide_list)) +#define IS_VETO_PATH(conn,path) ((conn) && is_in_path((path),(conn)->veto_list)) +#define IS_VETO_OPLOCK_PATH(conn,path) ((conn) && is_in_path((path),(conn)->veto_oplock_list)) #define SMBENCRYPT() (lp_encrypted_passwords()) @@ -1228,7 +1240,11 @@ struct parm_struct #define ERRCMD 0xFF /* Command was not in the "SMB" format. */ #ifdef HAVE_STDARG_H -int slprintf(char *str, int n, char *format, ...); +int slprintf(char *str, int n, char *format, ...) +#ifdef __GNUC__ + __attribute__ ((format (printf, 3, 4))) +#endif +; #else int slprintf(); #endif diff --git a/source3/lib/smbrun.c b/source3/lib/smbrun.c new file mode 100644 index 0000000000..0388b3f1bd --- /dev/null +++ b/source3/lib/smbrun.c @@ -0,0 +1,173 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + run a command as a specified user + Copyright (C) Andrew Tridgell 1992-1998 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +/* need to move this from here!! need some sleep ... */ +struct current_user current_user; + +extern int DEBUGLEVEL; + +/**************************************************************************** +This is a utility function of smbrun(). It must be called only from +the child as it may leave the caller in a privilaged state. +****************************************************************************/ +static BOOL setup_stdout_file(char *outfile,BOOL shared) +{ + int fd; + struct stat st; + mode_t mode = S_IWUSR|S_IRUSR|S_IRGRP|S_IROTH; + int flags = O_RDWR|O_CREAT|O_TRUNC|O_EXCL; + + close(1); + + if (shared) { + /* become root - unprivilaged users can't delete these files */ +#ifdef HAVE_SETRESUID + setresgid(0,0,0); + setresuid(0,0,0); +#else + setuid(0); + seteuid(0); +#endif + } + + if(stat(outfile, &st) == 0) { + /* Check we're not deleting a device file. */ + if(st.st_mode & S_IFREG) + unlink(outfile); + else + flags = O_RDWR; + } + /* now create the file */ + fd = open(outfile,flags,mode); + + if (fd == -1) return False; + + if (fd != 1) { + if (dup2(fd,1) != 0) { + DEBUG(2,("Failed to create stdout file descriptor\n")); + close(fd); + return False; + } + close(fd); + } + return True; +} + + +/**************************************************************************** +run a command being careful about uid/gid handling and putting the output in +outfile (or discard it if outfile is NULL). + +if shared is True then ensure the file will be writeable by all users +but created such that its owned by root. This overcomes a security hole. + +if shared is not set then open the file with O_EXCL set +****************************************************************************/ +int smbrun(char *cmd,char *outfile,BOOL shared) +{ + extern struct current_user current_user; + int fd,pid; + int uid = current_user.uid; + int gid = current_user.gid; + +#ifndef HAVE_EXECL + int ret; + pstring syscmd; + char *path = lp_smbrun(); + + /* in the old method we use system() to execute smbrun which then + executes the command (using system() again!). This involves lots + of shell launches and is very slow. It also suffers from a + potential security hole */ + if (!file_exist(path,NULL)) { + DEBUG(0,("SMBRUN ERROR: Can't find %s. Installation problem?\n",path)); + return(1); + } + + slprintf(syscmd,sizeof(syscmd)-1,"%s %d %d \"(%s 2>&1) > %s\"", + path,uid,gid,cmd, + outfile?outfile:"/dev/null"); + + DEBUG(5,("smbrun - running %s ",syscmd)); + ret = system(syscmd); + DEBUG(5,("gave %d\n",ret)); + return(ret); +#else + /* in this newer method we will exec /bin/sh with the correct + arguments, after first setting stdout to point at the file */ + + if ((pid=fork())) { + int status=0; + /* the parent just waits for the child to exit */ + if (sys_waitpid(pid,&status,0) != pid) { + DEBUG(2,("waitpid(%d) : %s\n",pid,strerror(errno))); + return -1; + } + return status; + } + + + /* we are in the child. we exec /bin/sh to do the work for us. we + don't directly exec the command we want because it may be a + pipeline or anything else the config file specifies */ + + /* point our stdout at the file we want output to go into */ + if (outfile && !setup_stdout_file(outfile,shared)) { + exit(80); + } + + /* now completely lose our privilages. This is a fairly paranoid + way of doing it, but it does work on all systems that I know of */ +#ifdef HAVE_SETRESUID + setresgid(0,0,0); + setresuid(0,0,0); + setresgid(gid,gid,gid); + setresuid(uid,uid,uid); +#else + setuid(0); + seteuid(0); + setgid(gid); + setegid(gid); + setuid(uid); + seteuid(uid); +#endif + + if (getuid() != uid || geteuid() != uid || + getgid() != gid || getegid() != gid) { + /* we failed to lose our privilages - do not execute + the command */ + exit(81); /* we can't print stuff at this stage, + instead use exit codes for debugging */ + } + + /* close all other file descriptors, leaving only 0, 1 and 2. 0 and + 2 point to /dev/null from the startup code */ + for (fd=3;fd<256;fd++) close(fd); + + execl("/bin/sh","sh","-c",cmd,NULL); + + /* not reached */ + exit(82); +#endif + return 1; +} diff --git a/source3/lib/system.c b/source3/lib/system.c index ab65339f6e..255b1c7b49 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -129,7 +129,7 @@ a simple opendir() wrapper ********************************************************************/ DIR *sys_opendir(char *dname) { - return(opendir(dos_to_unix(dname,False))); + return(opendir(dos_to_unix(dname,False))); } @@ -342,15 +342,15 @@ for getwd ********************************************************************/ char *sys_getwd(char *s) { - char *wd; + char *wd; #ifdef HAVE_GETCWD - wd = (char *)getcwd(s, sizeof (pstring)); + wd = (char *)getcwd(s, sizeof (pstring)); #else - wd = (char *)getwd(s); + wd = (char *)getwd(s); #endif - if (wd) - unix_to_dos (wd, True); - return wd; + if (wd) + unix_to_dos(wd, True); + return wd; } /******************************************************************* diff --git a/source3/lib/util.c b/source3/lib/util.c index fb2a6fa119..863e2d94af 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -2752,7 +2752,7 @@ static BOOL unix_do_match(char *str, char *regexp, int case_sig) while(*str) { while(*str && (case_sig ? (*p != *str) : (toupper(*p)!=toupper(*str)))) str++; - if(do_match(str,p,case_sig)) + if(unix_do_match(str,p,case_sig)) return True; if(!*str) return False; @@ -2846,8 +2846,8 @@ static BOOL unix_mask_match(char *str, char *regexp, int case_sig,BOOL trans2) } } - matched = do_match(sbase,ebase,case_sig) && - (trans2 || do_match(sext,eext,case_sig)); + matched = unix_do_match(sbase,ebase,case_sig) && + (trans2 || unix_do_match(sext,eext,case_sig)); DEBUG(8,("unix_mask_match returning %d\n", matched)); @@ -4134,6 +4134,67 @@ void standard_sub_basic(char *str) return; } + +/**************************************************************************** +do some standard substitutions in a string +****************************************************************************/ +void standard_sub(connection_struct *conn,char *str) +{ + char *p, *s, *home; + + for (s=str; (p=strchr(s, '%'));s=p) { + switch (*(p+1)) { + case 'H': + if ((home = get_home_dir(conn->user))) { + string_sub(p,"%H",home); + } else { + p += 2; + } + break; + + case 'P': + string_sub(p,"%P",conn->connectpath); + break; + + case 'S': + string_sub(p,"%S", + lp_servicename(SNUM(conn))); + break; + + case 'g': + string_sub(p,"%g", + gidtoname(conn->gid)); + break; + case 'u': + string_sub(p,"%u",conn->user); + break; + + /* Patch from jkf@soton.ac.uk Left the %N (NIS + * server name) in standard_sub_basic as it is + * a feature for logon servers, hence uses the + * username. The %p (NIS server path) code is + * here as it is used instead of the default + * "path =" string in [homes] and so needs the + * service name, not the username. */ + case 'p': + string_sub(p,"%p", + automount_path(lp_servicename(SNUM(conn)))); + break; + case '\0': + p++; + break; /* don't run off the end of the string + */ + + default: p+=2; + break; + } + } + + standard_sub_basic(str); +} + + + /******************************************************************* are two IPs on the same subnet? ********************************************************************/ @@ -5064,3 +5125,28 @@ BOOL string_to_sid(DOM_SID *sidout, char *sidstr) return True; } + +/***************************************************************************** + * Provide a checksum on a string + * + * Input: s - the nul-terminated character string for which the checksum + * will be calculated. + * + * Output: The checksum value calculated for s. + * + * **************************************************************************** + */ +int str_checksum(char *s) +{ + int res = 0; + int c; + int i=0; + + while(*s) { + c = *s; + res ^= (c << (i % 15)) ^ (c >> (15-(i%15))); + s++; + i++; + } + return(res); +} /* str_checksum */ diff --git a/source3/libsmb/credentials.c b/source3/libsmb/credentials.c index c9f7ee429b..26d5c13bc9 100644 --- a/source3/libsmb/credentials.c +++ b/source3/libsmb/credentials.c @@ -96,7 +96,7 @@ void cred_create(uchar session_key[8], DOM_CHAL *stor_cred, UTIME timestamp, DEBUG(5,(" sess_key : %s\n", credstr(session_key))); DEBUG(5,(" stor_cred: %s\n", credstr(stor_cred->data))); - DEBUG(5,(" timestamp: %lx\n" , timestamp.time)); + DEBUG(5,(" timestamp: %x\n" , timestamp.time)); DEBUG(5,(" timecred : %s\n", credstr(time_cred.data))); DEBUG(5,(" calc_cred: %s\n", credstr(cred->data))); } @@ -200,12 +200,12 @@ BOOL deal_with_creds(uchar sess_key[8], new_cred = IVAL(sto_clnt_cred->challenge.data, 0); new_cred += new_clnt_time.time; - DEBUG(5,("deal_with_creds: new_cred[0]=%lx\n", new_cred)); + DEBUG(5,("deal_with_creds: new_cred[0]=%x\n", new_cred)); /* doesn't matter that server time is 0 */ rtn_srv_cred->timestamp.time = 0; - DEBUG(5,("deal_with_creds: new_clnt_time=%lx\n", new_clnt_time.time)); + DEBUG(5,("deal_with_creds: new_clnt_time=%x\n", new_clnt_time.time)); /* create return credentials for inclusion in the reply */ cred_create(sess_key, &(sto_clnt_cred->challenge), new_clnt_time, diff --git a/source3/libsmb/nmblib.c b/source3/libsmb/nmblib.c index 9c7a606a26..c887ff55de 100644 --- a/source3/libsmb/nmblib.c +++ b/source3/libsmb/nmblib.c @@ -90,7 +90,7 @@ static void debug_nmb_res_rec(struct res_rec *res, char *hdr) DEBUGADD(4, ("%c", x)); } - DEBUGADD(4, (" hex ", i)); + DEBUGADD(4, (" hex ")); for (j = 0; j < 16; j++) { diff --git a/source3/locking/locking.c b/source3/locking/locking.c index c1c0659496..bb852b07d6 100644 --- a/source3/locking/locking.c +++ b/source3/locking/locking.c @@ -33,7 +33,6 @@ #include "includes.h" extern int DEBUGLEVEL; -extern connection_struct Connections[]; extern files_struct Files[]; extern int Client; @@ -147,13 +146,10 @@ static void blocking_lock_reply_error(blocking_lock_record *blr, int eclass, int uint16 num_ulocks = SVAL(inbuf,smb_vwv6); uint16 num_locks = SVAL(inbuf,smb_vwv7); uint32 count, offset; - int cnum; int lock_num = blr->lock_num; char *data; int i; - cnum = SVAL(inbuf,smb_tid); - data = smb_buf(inbuf) + 10*num_ulocks; /* @@ -164,7 +160,7 @@ static void blocking_lock_reply_error(blocking_lock_record *blr, int eclass, int for(i = blr->lock_num; i >= 0; i--) { count = IVAL(data,SMB_LKLEN_OFFSET(i)); offset = IVAL(data,SMB_LKOFF_OFFSET(i)); - do_unlock(fnum,cnum,count,offset,&dummy1,&dummy2); + do_unlock(fnum,conn,count,offset,&dummy1,&dummy2); } construct_reply_common(inbuf, outbuf); @@ -185,14 +181,11 @@ static BOOL blocking_lock_record_process(blocking_lock_record *blr) uint16 num_ulocks = SVAL(inbuf,smb_vwv6); uint16 num_locks = SVAL(inbuf,smb_vwv7); uint32 count, offset; - int cnum; int lock_num = blr->lock_num; char *data; int eclass=0; uint32 ecode=0; - cnum = SVAL(inbuf,smb_tid); - data = smb_buf(inbuf) + 10*num_ulocks; /* @@ -203,7 +196,7 @@ static BOOL blocking_lock_record_process(blocking_lock_record *blr) for(; blr->lock_num < num_locks; blr->lock_num++) { count = IVAL(data,SMB_LKLEN_OFFSET(blr->lock_num)); offset = IVAL(data,SMB_LKOFF_OFFSET(blr->lock_num)); - if(!do_lock(fnum,cnum,count,offset, ((locktype & 1) ? F_RDLCK : F_WRLCK), + if(!do_lock(fnum,conn,count,offset, ((locktype & 1) ? F_RDLCK : F_WRLCK), &eclass, &ecode)) break; } @@ -214,8 +207,8 @@ static BOOL blocking_lock_record_process(blocking_lock_record *blr) * Success - we got all the locks. */ - DEBUG(3,("blocking_lock_record_process fnum=%d cnum=%d type=%d num_locks=%d\n", - fnum, cnum, (unsigned int)locktype, num_locks) ); + DEBUG(3,("blocking_lock_record_process fnum=%d type=%d num_locks=%d\n", + fnum, (unsigned int)locktype, num_locks) ); blocking_lock_reply_success(blr); return True; @@ -260,7 +253,6 @@ void process_blocking_lock_queue(time_t t) while(blr != NULL) { int fnum = GETFNUM(blr->inbuf,smb_vwv2); - int cnum = SVAL(blr->inbuf,smb_tid); files_struct *fsp = &Files[fnum]; uint16 vuid = (lp_security() == SEC_SHARE) ? UID_FIELD_INVALID : SVAL(blr->inbuf,smb_uid); @@ -282,7 +274,7 @@ void process_blocking_lock_queue(time_t t) continue; } - if(!become_user(&Connections[cnum],cnum,vuid)) { + if(!become_user(conn,vuid)) { DEBUG(0,("process_blocking_lock_queue: Unable to become user vuid=%d.\n", vuid )); /* @@ -294,9 +286,8 @@ void process_blocking_lock_queue(time_t t) continue; } - if(!become_service(cnum,True)) { - DEBUG(0,("process_blocking_lock_queue: Unable to become service cnum=%d. \ -Error was %s.\n", cnum, strerror(errno) )); + if(!become_service(conn,True)) { + DEBUG(0,("process_blocking_lock_queue: Unable to become service Error was %s.\n", strerror(errno) )); /* * Remove the entry and return an error to the client. */ @@ -365,39 +356,39 @@ static int map_lock_type( files_struct *fsp, int lock_type) /**************************************************************************** Utility function called to see if a file region is locked. ****************************************************************************/ - -BOOL is_locked(int fnum,int cnum,uint32 count,uint32 offset, int lock_type) +BOOL is_locked(int fnum,connection_struct *conn, + uint32 count,uint32 offset, int lock_type) { - int snum = SNUM(cnum); - files_struct *fsp = &Files[fnum]; + int snum = SNUM(conn); + files_struct *fsp = &Files[fnum]; - if (count == 0) - return(False); + if (count == 0) + return(False); - if (!lp_locking(snum) || !lp_strict_locking(snum)) - return(False); - - /* - * Note that most UNIX's can *test* for a write lock on - * a read-only fd, just not *set* a write lock on a read-only - * fd. So we don't need to use map_lock_type here. - */ + if (!lp_locking(snum) || !lp_strict_locking(snum)) + return(False); - return(fcntl_lock(fsp->fd_ptr->fd,F_GETLK,offset,count,lock_type)); + /* + * Note that most UNIX's can *test* for a write lock on + * a read-only fd, just not *set* a write lock on a read-only + * fd. So we don't need to use map_lock_type here. + */ + + return(fcntl_lock(fsp->fd_ptr->fd,F_GETLK,offset,count,lock_type)); } /**************************************************************************** Utility function called by locking requests. ****************************************************************************/ - -BOOL do_lock(int fnum,int cnum,uint32 count,uint32 offset,int lock_type, +BOOL do_lock(int fnum,connection_struct *conn, + uint32 count,uint32 offset,int lock_type, int *eclass,uint32 *ecode) { BOOL ok = False; files_struct *fsp = &Files[fnum]; - if (!lp_locking(SNUM(cnum))) + if (!lp_locking(SNUM(conn))) return(True); if (count == 0) { @@ -406,7 +397,7 @@ BOOL do_lock(int fnum,int cnum,uint32 count,uint32 offset,int lock_type, return False; } - if (OPEN_FNUM(fnum) && fsp->can_lock && (fsp->cnum == cnum)) + if (OPEN_FNUM(fnum) && fsp->can_lock && (fsp->conn == conn)) ok = fcntl_lock(fsp->fd_ptr->fd,F_SETLK,offset,count, map_lock_type(fsp,lock_type)); @@ -422,16 +413,16 @@ BOOL do_lock(int fnum,int cnum,uint32 count,uint32 offset,int lock_type, /**************************************************************************** Utility function called by unlocking requests. ****************************************************************************/ - -BOOL do_unlock(int fnum,int cnum,uint32 count,uint32 offset,int *eclass,uint32 *ecode) +BOOL do_unlock(int fnum,connection_struct *conn, + uint32 count,uint32 offset,int *eclass,uint32 *ecode) { BOOL ok = False; files_struct *fsp = &Files[fnum]; - if (!lp_locking(SNUM(cnum))) + if (!lp_locking(SNUM(conn))) return(True); - if (OPEN_FNUM(fnum) && fsp->can_lock && (fsp->cnum == cnum)) + if (OPEN_FNUM(fnum) && fsp->can_lock && (fsp->conn == conn)) ok = fcntl_lock(fsp->fd_ptr->fd,F_SETLK,offset,count,F_UNLCK); if (!ok) { @@ -481,29 +472,29 @@ BOOL locking_end(void) /******************************************************************* Lock a hash bucket entry. ******************************************************************/ - -BOOL lock_share_entry(int cnum, uint32 dev, uint32 inode, int *ptok) +BOOL lock_share_entry(connection_struct *conn, + uint32 dev, uint32 inode, int *ptok) { - return share_ops->lock_entry(cnum, dev, inode, ptok); + return share_ops->lock_entry(conn, dev, inode, ptok); } /******************************************************************* Unlock a hash bucket entry. ******************************************************************/ - -BOOL unlock_share_entry(int cnum, uint32 dev, uint32 inode, int token) +BOOL unlock_share_entry(connection_struct *conn, + uint32 dev, uint32 inode, int token) { - return share_ops->unlock_entry(cnum, dev, inode, token); + return share_ops->unlock_entry(conn, dev, inode, token); } /******************************************************************* Get all share mode entries for a dev/inode pair. ********************************************************************/ - -int get_share_modes(int cnum, int token, uint32 dev, uint32 inode, +int get_share_modes(connection_struct *conn, + int token, uint32 dev, uint32 inode, share_mode_entry **shares) { - return share_ops->get_entries(cnum, token, dev, inode, shares); + return share_ops->get_entries(conn, token, dev, inode, shares); } /******************************************************************* diff --git a/source3/locking/locking_shm.c b/source3/locking/locking_shm.c index 43a927e14c..84310d3a33 100644 --- a/source3/locking/locking_shm.c +++ b/source3/locking/locking_shm.c @@ -37,7 +37,6 @@ #ifdef FAST_SHARE_MODES extern int DEBUGLEVEL; -extern connection_struct Connections[]; extern files_struct Files[]; static struct shmem_ops *shmops; @@ -79,15 +78,17 @@ static BOOL shm_stop_share_mode_mgmt(void) /******************************************************************* lock a hash bucket entry in shared memory for share_mode management ******************************************************************/ -static BOOL shm_lock_share_entry(int cnum, uint32 dev, uint32 inode, int *ptok) +static BOOL shm_lock_share_entry(connection_struct *conn, + uint32 dev, uint32 inode, int *ptok) { - return shmops->lock_hash_entry(HASH_ENTRY(dev, inode)); + return shmops->lock_hash_entry(HASH_ENTRY(dev, inode)); } /******************************************************************* unlock a hash bucket entry in shared memory for share_mode management ******************************************************************/ -static BOOL shm_unlock_share_entry(int cnum, uint32 dev, uint32 inode, int token) +static BOOL shm_unlock_share_entry(connection_struct *conn, + uint32 dev, uint32 inode, int token) { return shmops->unlock_hash_entry(HASH_ENTRY(dev, inode)); } @@ -95,7 +96,8 @@ static BOOL shm_unlock_share_entry(int cnum, uint32 dev, uint32 inode, int token /******************************************************************* get all share mode entries in shared memory for a dev/inode pair. ********************************************************************/ -static int shm_get_share_modes(int cnum, int token, uint32 dev, uint32 inode, +static int shm_get_share_modes(connection_struct *conn, + int token, uint32 dev, uint32 inode, share_mode_entry **old_shares) { int *mode_array; @@ -426,7 +428,7 @@ static BOOL shm_set_share_mode(int token, int fnum, uint16 port, uint16 op_type) /* We must create a share_mode_record */ share_mode_record *new_mode_p = NULL; int new_offset = shmops->shm_alloc(sizeof(share_mode_record) + - strlen(fs_p->name) + 1); + strlen(fs_p->fsp_name) + 1); if(new_offset == 0) { DEBUG(0,("ERROR:set_share_mode shmops->shm_alloc fail!\n")); return False; @@ -437,7 +439,7 @@ static BOOL shm_set_share_mode(int token, int fnum, uint16 port, uint16 op_type) new_mode_p->st_ino = inode; new_mode_p->num_share_mode_entries = 0; new_mode_p->share_mode_entries = 0; - pstrcpy(new_mode_p->file_name, fs_p->name); + pstrcpy(new_mode_p->file_name, fs_p->fsp_name); /* Chain onto the start of the hash chain (in the hope we will be used first). */ new_mode_p->next_offset = mode_array[hash_entry]; @@ -446,7 +448,7 @@ static BOOL shm_set_share_mode(int token, int fnum, uint16 port, uint16 op_type) file_scanner_p = new_mode_p; DEBUG(3,("set_share_mode: Created share record for %s (dev %d inode %d)\n", - fs_p->name, dev, inode)); + fs_p->fsp_name, dev, inode)); } /* Now create the share mode entry */ @@ -485,7 +487,7 @@ static BOOL shm_set_share_mode(int token, int fnum, uint16 port, uint16 op_type) file_scanner_p->num_share_mode_entries += 1; DEBUG(3,("set_share_mode: Created share entry for %s with mode 0x%X pid=%d\n", - fs_p->name, fs_p->share_mode, new_entry_p->e.pid)); + fs_p->fsp_name, fs_p->share_mode, new_entry_p->e.pid)); return(True); } diff --git a/source3/locking/locking_slow.c b/source3/locking/locking_slow.c index 1f8f962ac9..9135ae29d2 100644 --- a/source3/locking/locking_slow.c +++ b/source3/locking/locking_slow.c @@ -37,7 +37,6 @@ #ifndef FAST_SHARE_MODES extern int DEBUGLEVEL; -extern connection_struct Connections[]; extern files_struct Files[]; /* @@ -82,23 +81,24 @@ static BOOL slow_stop_share_mode_mgmt(void) /******************************************************************* name a share file ******************************************************************/ -static BOOL share_name(int cnum, uint32 dev, uint32 inode, char *name) +static BOOL share_name(connection_struct *conn, + uint32 dev, uint32 inode, char *name) { - int len; - pstrcpy(name,lp_lockdir()); - trim_string(name,"","/"); - if (!*name) return(False); - len = strlen(name); - name += len; - - slprintf(name, sizeof(pstring) - len - 1, "/share.%u.%u",dev,inode); - return(True); + int len; + pstrcpy(name,lp_lockdir()); + trim_string(name,"","/"); + if (!*name) return(False); + len = strlen(name); + name += len; + + slprintf(name, sizeof(pstring) - len - 1, "/share.%u.%u",dev,inode); + return(True); } /******************************************************************* Force a share file to be deleted. ********************************************************************/ -static int delete_share_file( int cnum, char *fname ) +static int delete_share_file(connection_struct *conn, char *fname ) { if (read_only) return -1; @@ -124,7 +124,8 @@ static int delete_share_file( int cnum, char *fname ) /******************************************************************* lock a share mode file. ******************************************************************/ -static BOOL slow_lock_share_entry(int cnum, uint32 dev, uint32 inode, int *ptok) +static BOOL slow_lock_share_entry(connection_struct *conn, + uint32 dev, uint32 inode, int *ptok) { pstring fname; int fd; @@ -132,7 +133,7 @@ static BOOL slow_lock_share_entry(int cnum, uint32 dev, uint32 inode, int *ptok) *ptok = (int)-1; - if(!share_name(cnum, dev, inode, fname)) + if(!share_name(conn, dev, inode, fname)) return False; if (read_only) return True; @@ -216,7 +217,8 @@ static BOOL slow_lock_share_entry(int cnum, uint32 dev, uint32 inode, int *ptok) /******************************************************************* unlock a share mode file. ******************************************************************/ -static BOOL slow_unlock_share_entry(int cnum, uint32 dev, uint32 inode, int token) +static BOOL slow_unlock_share_entry(connection_struct *conn, + uint32 dev, uint32 inode, int token) { int fd = (int)token; int ret = True; @@ -228,7 +230,7 @@ static BOOL slow_unlock_share_entry(int cnum, uint32 dev, uint32 inode, int toke /* Fix for zero length share files from Gerald Werner <wernerg@mfldclin.edu> */ - share_name(cnum, dev, inode, fname); + share_name(conn, dev, inode, fname); /* get the share mode file size */ if(fstat((int)token, &sb) != 0) @@ -246,7 +248,7 @@ static BOOL slow_unlock_share_entry(int cnum, uint32 dev, uint32 inode, int toke /* remove the share file if zero length */ if(sb.st_size == 0) - delete_share_file(cnum, fname); + delete_share_file(conn, fname); /* token is the fd of the open share mode file. */ /* Unlock the first byte. */ @@ -264,7 +266,7 @@ static BOOL slow_unlock_share_entry(int cnum, uint32 dev, uint32 inode, int toke /******************************************************************* Read a share file into a buffer. ********************************************************************/ -static int read_share_file(int cnum, int fd, char *fname, char **out, BOOL *p_new_file) +static int read_share_file(connection_struct *conn, int fd, char *fname, char **out, BOOL *p_new_file) { struct stat sb; char *buf; @@ -317,7 +319,7 @@ locking version (was %d, should be %d).\n",fname, IVAL(buf,SMF_VERSION_OFFSET), LOCKING_VERSION)); if(buf) free(buf); - delete_share_file(cnum, fname); + delete_share_file(conn, fname); return -1; } @@ -335,7 +337,7 @@ locking version (was %d, should be %d).\n",fname, deleting it.\n", fname)); if(buf) free(buf); - delete_share_file(cnum, fname); + delete_share_file(conn, fname); return -1; } @@ -346,7 +348,7 @@ deleting it.\n", fname)); /******************************************************************* get all share mode entries in a share file for a dev/inode pair. ********************************************************************/ -static int slow_get_share_modes(int cnum, int token, uint32 dev, uint32 inode, +static int slow_get_share_modes(connection_struct *conn, int token, uint32 dev, uint32 inode, share_mode_entry **old_shares) { int fd = (int)token; @@ -377,9 +379,9 @@ static int slow_get_share_modes(int cnum, int token, uint32 dev, uint32 inode, 16 - oplock port (if oplocks in use) - 2 bytes. */ - share_name(cnum, dev, inode, fname); + share_name(conn, dev, inode, fname); - if(read_share_file( cnum, fd, fname, &buf, &new_file) != 0) + if(read_share_file( conn, fd, fname, &buf, &new_file) != 0) { DEBUG(0,("ERROR: get_share_modes: Failed to read share file %s\n", fname)); @@ -419,7 +421,7 @@ for share file %d\n", num_entries, fname)); fname)); if(buf) free(buf); - delete_share_file(cnum, fname); + delete_share_file(conn, fname); return 0; } @@ -460,7 +462,7 @@ it left a share mode entry with mode 0x%X in share file %s\n", *old_shares = 0; if(buf) free(buf); - delete_share_file(cnum, fname); + delete_share_file(conn, fname); return 0; } @@ -546,10 +548,10 @@ static void slow_del_share_mode(int token, int fnum) BOOL deleted = False; BOOL new_file; - share_name(fs_p->cnum, fs_p->fd_ptr->dev, + share_name(fs_p->conn, fs_p->fd_ptr->dev, fs_p->fd_ptr->inode, fname); - if(read_share_file( fs_p->cnum, fd, fname, &buf, &new_file) != 0) + if(read_share_file( fs_p->conn, fd, fname, &buf, &new_file) != 0) { DEBUG(0,("ERROR: del_share_mode: Failed to read share file %s\n", fname)); @@ -560,7 +562,7 @@ static void slow_del_share_mode(int token, int fnum) { DEBUG(0,("ERROR:del_share_mode: share file %s is new (size zero), deleting it.\n", fname)); - delete_share_file(fs_p->cnum, fname); + delete_share_file(fs_p->conn, fname); return; } @@ -584,7 +586,7 @@ for share file %d\n", num_entries, fname)); fname)); if(buf) free(buf); - delete_share_file(fs_p->cnum, fname); + delete_share_file(fs_p->conn, fname); return; } @@ -635,7 +637,7 @@ for share file %d\n", num_entries, fname)); fname)); if(buf) free(buf); - delete_share_file(fs_p->cnum,fname); + delete_share_file(fs_p->conn,fname); return; } @@ -685,7 +687,7 @@ static BOOL slow_set_share_mode(int token,int fnum, uint16 port, uint16 op_type) int header_size; char *p; - share_name(fs_p->cnum, fs_p->fd_ptr->dev, + share_name(fs_p->conn, fs_p->fd_ptr->dev, fs_p->fd_ptr->inode, fname); if(fstat(fd, &sb) != 0) @@ -733,7 +735,7 @@ locking version (was %d, should be %d).\n",fname, IVAL(buf,SMF_VERSION_OFFSET), LOCKING_VERSION)); if(buf) free(buf); - delete_share_file(fs_p->cnum, fname); + delete_share_file(fs_p->conn, fname); return False; } @@ -746,7 +748,7 @@ locking version (was %d, should be %d).\n",fname, IVAL(buf,SMF_VERSION_OFFSET), deleting it.\n", fname)); if(buf) free(buf); - delete_share_file(fs_p->cnum, fname); + delete_share_file(fs_p->conn, fname); return False; } @@ -794,7 +796,7 @@ deleting it.\n", fname)); { DEBUG(2,("ERROR: set_share_mode: Failed to write share file %s - \ deleting it (%s).\n",fname, strerror(errno))); - delete_share_file(fs_p->cnum, fname); + delete_share_file(fs_p->conn, fname); if(buf) free(buf); return False; @@ -838,10 +840,10 @@ static BOOL slow_remove_share_oplock(int fnum, int token) BOOL found = False; BOOL new_file; - share_name(fs_p->cnum, fs_p->fd_ptr->dev, + share_name(fs_p->conn, fs_p->fd_ptr->dev, fs_p->fd_ptr->inode, fname); - if(read_share_file( fs_p->cnum, fd, fname, &buf, &new_file) != 0) + if(read_share_file( fs_p->conn, fd, fname, &buf, &new_file) != 0) { DEBUG(0,("ERROR: remove_share_oplock: Failed to read share file %s\n", fname)); @@ -852,7 +854,7 @@ static BOOL slow_remove_share_oplock(int fnum, int token) { DEBUG(0,("ERROR: remove_share_oplock: share file %s is new (size zero), \ deleting it.\n", fname)); - delete_share_file(fs_p->cnum, fname); + delete_share_file(fs_p->conn, fname); return False; } @@ -876,7 +878,7 @@ for share file %d\n", num_entries, fname)); fname)); if(buf) free(buf); - delete_share_file(fs_p->cnum, fname); + delete_share_file(fs_p->conn, fname); return False; } diff --git a/source3/locking/shmem.c b/source3/locking/shmem.c index 48f78d2a5b..dd97d5c76c 100644 --- a/source3/locking/shmem.c +++ b/source3/locking/shmem.c @@ -128,7 +128,7 @@ static BOOL smb_shm_global_unlock(void) if(smb_shm_times_locked == 0) { - DEBUG(0,("ERROR smb_shm_global_unlock : shmem not locked\n",smb_shm_fd)); + DEBUG(0,("ERROR smb_shm_global_unlock : shmem not locked\n")); return False; } diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 9df30adc8c..24f4951612 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -153,7 +153,8 @@ static BOOL dump_core(void) #endif - DEBUG( 0, ( "Dumping core in %s\n",dname ) ); + DEBUG(0,("Dumping core in %s\n",dname)); + abort(); return( True ); } /* dump_core */ #endif diff --git a/source3/nmbd/nmbd_browserdb.c b/source3/nmbd/nmbd_browserdb.c index 293a129d42..8e32dbd570 100644 --- a/source3/nmbd/nmbd_browserdb.c +++ b/source3/nmbd/nmbd_browserdb.c @@ -124,7 +124,7 @@ struct browse_cache_record *create_browser_in_lmb_cache( char *work_name, Debug1( "nmbd_browserdb:create_browser_in_lmb_cache()\n" ); Debug1( " Added lmb cache entry for workgroup %s ", browc->work_group ); Debug1( "name %s IP %s ", browc->lmb_name, inet_ntoa(ip) ); - Debug1( "ttl %d\n", browc->death_time ); + Debug1( "ttl %d\n", (int)browc->death_time ); } return( browc ); diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c index 270a3ef6a5..05b549d30f 100644 --- a/source3/nmbd/nmbd_nameregister.c +++ b/source3/nmbd/nmbd_nameregister.c @@ -207,7 +207,7 @@ responding.\n", inet_ntoa(rrec->packet->ip))); rrec->repeat_time = time(NULL) + rrec->repeat_interval; DEBUG(5,("register_name_timeout_response: increasing WINS timeout to %d seconds.\n", - rrec->repeat_interval)); + (int)rrec->repeat_interval)); return; /* Don't remove the response record. */ } } diff --git a/source3/nmbd/nmbd_namerelease.c b/source3/nmbd/nmbd_namerelease.c index b58bab3a1d..558ab6ab16 100644 --- a/source3/nmbd/nmbd_namerelease.c +++ b/source3/nmbd/nmbd_namerelease.c @@ -165,7 +165,7 @@ responding.\n", inet_ntoa(rrec->packet->ip))); rrec->repeat_time = time(NULL) + rrec->repeat_interval; DEBUG(5,("release_name_timeout_response: increasing WINS timeout to %d seconds.\n", - rrec->repeat_interval)); + (int)rrec->repeat_interval)); return; /* Don't remove the response record. */ } } diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 1f216e3111..d557414a27 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -112,7 +112,7 @@ static void debug_browse_data(char *outbuf, int len) DEBUGADD( 4, ( "%c", x ) ); } - DEBUGADD( 4, ( " hex ", i ) ); + DEBUGADD( 4, ( " hex ") ); for (j = 0; j < 16; j++) { diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index 3936b7e92e..6c9f67ab21 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -398,7 +398,8 @@ void announce_myself_to_domain_master_browser(time_t t) if ((t-announce_timer_last) < (CHECK_TIME_MST_ANNOUNCE * 60)) { DEBUG(10,("announce_myself_to_domain_master_browser: t (%d) - last(%d) < %d\n", - t, announce_timer_last, CHECK_TIME_MST_ANNOUNCE * 60 )); + (int)t, (int)announce_timer_last, + CHECK_TIME_MST_ANNOUNCE * 60 )); return; } diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c index 1c0b044598..6fcd1eaf9b 100644 --- a/source3/param/loadparm.c +++ b/source3/param/loadparm.c @@ -2298,67 +2298,46 @@ BOOL lp_snum_ok(int iService) /*************************************************************************** -auto-load some homes and printer services +auto-load some home services ***************************************************************************/ static void lp_add_auto_services(char *str) { - char *s; - char *p; - int homes, printers; - - if (!str) - return; - - s = strdup(str); - if (!s) return; + char *s; + char *p; + int homes; - homes = lp_servicenumber(HOMES_NAME); - printers = lp_servicenumber(PRINTERS_NAME); + if (!str) return; - for (p=strtok(s,LIST_SEP);p;p=strtok(NULL,LIST_SEP)) { - char *home = get_home_dir(p); + s = strdup(str); + if (!s) return; - if (lp_servicenumber(p) >= 0) continue; - - if (home && homes >= 0) { - lp_add_home(p,homes,home); - continue; - } - - if (printers >= 0 && pcap_printername_ok(p,NULL)) { - lp_add_printer(p,printers); - } - } - free(s); + homes = lp_servicenumber(HOMES_NAME); + + for (p=strtok(s,LIST_SEP);p;p=strtok(NULL,LIST_SEP)) { + char *home = get_home_dir(p); + + if (lp_servicenumber(p) >= 0) continue; + + if (home && homes >= 0) { + lp_add_home(p,homes,home); + } + } + free(s); } /*************************************************************************** auto-load one printer ***************************************************************************/ -static void lp_add_one_printer(char *name,char *comment) +void lp_add_one_printer(char *name,char *comment) { - int printers = lp_servicenumber(PRINTERS_NAME); - int i; - - if (lp_servicenumber(name) < 0) - { - lp_add_printer(name,printers); - if ((i=lp_servicenumber(name)) >= 0) - string_set(&iSERVICE(i).comment,comment); - } -} - - -/*************************************************************************** -auto-load printer services -***************************************************************************/ -static void lp_add_all_printers(void) -{ - int printers = lp_servicenumber(PRINTERS_NAME); - - if (printers < 0) return; + int printers = lp_servicenumber(PRINTERS_NAME); + int i; - pcap_printer_fn(lp_add_one_printer); + if (lp_servicenumber(name) < 0) { + lp_add_printer(name,printers); + if ((i=lp_servicenumber(name)) >= 0) + string_set(&iSERVICE(i).comment,comment); + } } /*************************************************************************** @@ -2460,8 +2439,6 @@ BOOL lp_load(char *pszFname,BOOL global_only, BOOL save_defaults, BOOL add_ipc) bRetval = service_ok(iServiceIndex); lp_add_auto_services(lp_auto_services()); - if (lp_load_printers()) - lp_add_all_printers(); if (add_ipc) lp_add_ipc(); @@ -2540,26 +2517,6 @@ char *volume_label(int snum) return(ret); } -#if 0 -/* - * nmbd only loads the global section. There seems to be no way to - * determine exactly is a service is printable by only looking at the - * [global] section so for now always announce as a print server. This - * will need looking at in the future. Jeremy (jallison@whistle.com). - */ -/******************************************************************* - Return true if any printer services are defined. - ******************************************************************/ -static BOOL lp_printer_services(void) -{ - int iService; - - for (iService = iNumServices - 1; iService >= 0; iService--) - if (VALID(iService) && iSERVICE(iService).bPrint_ok) - return True; - return False; -} -#endif /******************************************************************* Set the server type we will announce as via nmbd. @@ -2575,15 +2532,6 @@ static void set_default_server_announce_type() else if(lp_announce_as() == ANNOUNCE_AS_WFW) default_server_announce |= SV_TYPE_WFW; default_server_announce |= (lp_time_server() ? SV_TYPE_TIME_SOURCE : 0); -/* - * nmbd only loads the [global] section. There seems to be no way to - * determine exactly if any service is printable by only looking at the - * [global] section so for now always announce as a print server. This - * will need looking at in the future. Jeremy (jallison@whistle.com). - */ -#if 0 - default_server_announce |= (lp_printer_services() ? SV_TYPE_PRINTQ_SERVER : 0); -#endif } diff --git a/source3/passdb/smbpass.c b/source3/passdb/smbpass.c index abdcb9eb50..268394631f 100644 --- a/source3/passdb/smbpass.c +++ b/source3/passdb/smbpass.c @@ -248,8 +248,8 @@ static struct smb_passwd *getsmbfilepwent(void *vp) the NT password. */ } - DEBUG(5, ("getsmbfilepwent: returning passwd entry for user %s, uid %d\n", - user_name, uidval)); + DEBUG(5,("getsmbfilepwent: returning passwd entry for user %s, uid %ld\n", + user_name, uidval)); if (*p == '[') { diff --git a/source3/printing/printing.c b/source3/printing/printing.c index 6fa7091677..00ff869278 100644 --- a/source3/printing/printing.c +++ b/source3/printing/printing.c @@ -21,8 +21,6 @@ #include "includes.h" extern int DEBUGLEVEL; -extern connection_struct Connections[]; -extern files_struct Files[]; static BOOL * lpq_cache_reset=NULL; @@ -51,92 +49,84 @@ Build the print command in the supplied buffer. This means getting the print command for the service and inserting the printer name and the print file name. Return NULL on error, else the passed buffer pointer. ****************************************************************************/ -static char *build_print_command(int cnum, char *command, char *syscmd, char *filename1) +static char *build_print_command(connection_struct *conn, + char *command, + char *syscmd, char *filename1) { - int snum = SNUM(cnum); - char *tstr; - pstring filename; + int snum = SNUM(conn); + char *tstr; + pstring filename; - /* get the print command for the service. */ - tstr = command; - if (!syscmd || !tstr) { - DEBUG(0,("No print command for service `%s'\n", SERVICE(snum))); - return (NULL); - } + /* get the print command for the service. */ + tstr = command; + if (!syscmd || !tstr) { + DEBUG(0,("No print command for service `%s'\n", + SERVICE(snum))); + return (NULL); + } - /* copy the command into the buffer for extensive meddling. */ - StrnCpy(syscmd, tstr, sizeof(pstring) - 1); + /* copy the command into the buffer for extensive meddling. */ + StrnCpy(syscmd, tstr, sizeof(pstring) - 1); - /* look for "%s" in the string. If there is no %s, we cannot print. */ - if (!strstr(syscmd, "%s") && !strstr(syscmd, "%f")) { - DEBUG(2,("WARNING! No placeholder for the filename in the print command for service %s!\n", SERVICE(snum))); - } + /* look for "%s" in the string. If there is no %s, we cannot print. */ + if (!strstr(syscmd, "%s") && !strstr(syscmd, "%f")) { + DEBUG(2,("WARNING! No placeholder for the filename in the print command for service %s!\n", SERVICE(snum))); + } - if (strstr(syscmd,"%s")) { - int iOffset = PTR_DIFF(strstr(syscmd, "%s"),syscmd); + if (strstr(syscmd,"%s")) { + pstrcpy(filename,filename1); - /* construct the full path for the filename, shouldn't be necessary unless - the subshell causes a "cd" to be executed. - Only use the full path if there isn't a / preceding the %s */ - if (iOffset==0 || syscmd[iOffset-1] != '/') { - StrnCpy(filename,Connections[cnum].connectpath,sizeof(filename)-1); - trim_string(filename,"","/"); - pstrcat(filename,"/"); - pstrcat(filename,filename1); - } - else - pstrcpy(filename,filename1); - - string_sub(syscmd, "%s", filename); - } + string_sub(syscmd, "%s", filename); + } - string_sub(syscmd, "%f", filename1); + string_sub(syscmd, "%f", filename1); - /* Does the service have a printername? If not, make a fake and empty */ - /* printer name. That way a %p is treated sanely if no printer */ - /* name was specified to replace it. This eventuality is logged. */ - tstr = PRINTERNAME(snum); - if (tstr == NULL || tstr[0] == '\0') { - DEBUG(3,( "No printer name - using %s.\n", SERVICE(snum))); - tstr = SERVICE(snum); - } + /* Does the service have a printername? If not, make a fake + and empty */ + /* printer name. That way a %p is treated sanely if no printer */ + /* name was specified to replace it. This eventuality is logged. */ + tstr = PRINTERNAME(snum); + if (tstr == NULL || tstr[0] == '\0') { + DEBUG(3,( "No printer name - using %s.\n", SERVICE(snum))); + tstr = SERVICE(snum); + } - string_sub(syscmd, "%p", tstr); + string_sub(syscmd, "%p", tstr); - standard_sub(cnum,syscmd); + standard_sub(conn,syscmd); - return (syscmd); + return (syscmd); } /**************************************************************************** print a file - called on closing the file ****************************************************************************/ -void print_file(int fnum) +void print_file(connection_struct *conn, files_struct *file) { - pstring syscmd; - int cnum = Files[fnum].cnum; - int snum=SNUM(cnum); - char *tempstr; + pstring syscmd; + int snum = SNUM(conn); + char *tempstr; - *syscmd = 0; + *syscmd = 0; - if (file_size(Files[fnum].name) <= 0) { - DEBUG(3,("Discarding null print job %s\n",Files[fnum].name)); - sys_unlink(Files[fnum].name); - return; - } + if (file_size(file->fsp_name) <= 0) { + DEBUG(3,("Discarding null print job %s\n",file->fsp_name)); + sys_unlink(file->fsp_name); + return; + } - tempstr = build_print_command(cnum, PRINTCOMMAND(snum), syscmd, Files[fnum].name); - if (tempstr != NULL) - { - int ret = smbrun(syscmd,NULL,False); - DEBUG(3,("Running the command `%s' gave %d\n",syscmd,ret)); - } - else - DEBUG(0,("Null print command?\n")); + tempstr = build_print_command(conn, + PRINTCOMMAND(snum), + syscmd, file->fsp_name); + if (tempstr != NULL) { + int ret = smbrun(syscmd,NULL,False); + DEBUG(3,("Running the command `%s' gave %d\n",syscmd,ret)); + } else { + DEBUG(0,("Null print command?\n")); + } - lpq_reset(snum); + lpq_reset(snum); } static char *Months[13] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", @@ -1023,105 +1013,102 @@ static BOOL parse_lpq_entry(int snum,char *line, /**************************************************************************** get a printer queue ****************************************************************************/ -int get_printqueue(int snum,int cnum,print_queue_struct **queue, +int get_printqueue(int snum, + connection_struct *conn,print_queue_struct **queue, print_status_struct *status) { - char *lpq_command = lp_lpqcommand(snum); - char *printername = PRINTERNAME(snum); - int ret=0,count=0; - pstring syscmd; - fstring outfile; - pstring line; - FILE *f; - struct stat sbuf; - BOOL dorun=True; - int cachetime = lp_lpqcachetime(); - - *line = 0; - check_lpq_cache(snum); - - if (!printername || !*printername) - { - DEBUG(6,("xx replacing printer name with service (snum=(%s,%d))\n", - lp_servicename(snum),snum)); - printername = lp_servicename(snum); - } + char *lpq_command = lp_lpqcommand(snum); + char *printername = PRINTERNAME(snum); + int ret=0,count=0; + pstring syscmd; + fstring outfile; + pstring line; + FILE *f; + struct stat sbuf; + BOOL dorun=True; + int cachetime = lp_lpqcachetime(); + + *line = 0; + check_lpq_cache(snum); + + if (!printername || !*printername) { + DEBUG(6,("xx replacing printer name with service (snum=(%s,%d))\n", + lp_servicename(snum),snum)); + printername = lp_servicename(snum); + } - if (!lpq_command || !(*lpq_command)) - { - DEBUG(5,("No lpq command\n")); - return(0); - } + if (!lpq_command || !(*lpq_command)) { + DEBUG(5,("No lpq command\n")); + return(0); + } - pstrcpy(syscmd,lpq_command); - string_sub(syscmd,"%p",printername); + pstrcpy(syscmd,lpq_command); + string_sub(syscmd,"%p",printername); - standard_sub(cnum,syscmd); + standard_sub(conn,syscmd); - slprintf(outfile,sizeof(outfile)-1, "%s/lpq.%08x",tmpdir(),str_checksum(syscmd)); + slprintf(outfile,sizeof(outfile)-1, "%s/lpq.%08x",tmpdir(),str_checksum(syscmd)); - if (!lpq_cache_reset[snum] && cachetime && !stat(outfile,&sbuf)) - { - if (time(NULL) - sbuf.st_mtime < cachetime) { - DEBUG(3,("Using cached lpq output\n")); - dorun = False; - } - } - - if (dorun) { - ret = smbrun(syscmd,outfile,True); - DEBUG(3,("Running the command `%s' gave %d\n",syscmd,ret)); - } - - lpq_cache_reset[snum] = False; + if (!lpq_cache_reset[snum] && cachetime && !stat(outfile,&sbuf)) { + if (time(NULL) - sbuf.st_mtime < cachetime) { + DEBUG(3,("Using cached lpq output\n")); + dorun = False; + } + } - f = fopen(outfile,"r"); - if (!f) { - return(0); - } + if (dorun) { + ret = smbrun(syscmd,outfile,True); + DEBUG(3,("Running the command `%s' gave %d\n",syscmd,ret)); + } - if (status) { - fstrcpy(status->message,""); - status->status = LPSTAT_OK; - } - - while (fgets(line,sizeof(pstring),f)) - { - DEBUG(6,("QUEUE2: %s\n",line)); + lpq_cache_reset[snum] = False; - *queue = Realloc(*queue,sizeof(print_queue_struct)*(count+1)); - if (! *queue) - { - count = 0; - break; + f = fopen(outfile,"r"); + if (!f) { + return(0); } - bzero((char *)&(*queue)[count],sizeof(**queue)); - - /* parse it */ - if (!parse_lpq_entry(snum,line,&(*queue)[count],status,count==0)) - continue; + if (status) { + fstrcpy(status->message,""); + status->status = LPSTAT_OK; + } + + while (fgets(line,sizeof(pstring),f)) { + DEBUG(6,("QUEUE2: %s\n",line)); + + *queue = Realloc(*queue,sizeof(print_queue_struct)*(count+1)); + if (! *queue) { + count = 0; + break; + } + + bzero((char *)&(*queue)[count],sizeof(**queue)); - count++; - } - - fclose(f); - - if (!cachetime) { - unlink(outfile); - } else { - /* we only expect this to succeed on trapdoor systems, on normal systems - the file is owned by root */ - chmod(outfile,0666); - } - return(count); + /* parse it */ + if (!parse_lpq_entry(snum,line, + &(*queue)[count],status,count==0)) + continue; + + count++; + } + + fclose(f); + + if (!cachetime) { + unlink(outfile); + } else { + /* we only expect this to succeed on trapdoor systems, + on normal systems the file is owned by root */ + chmod(outfile,0666); + } + return(count); } /**************************************************************************** delete a printer queue entry ****************************************************************************/ -void del_printqueue(int cnum,int snum,int jobid) +void del_printqueue(connection_struct *conn,int snum,int jobid) { char *lprm_command = lp_lprmcommand(snum); char *printername = PRINTERNAME(snum); @@ -1147,7 +1134,7 @@ void del_printqueue(int cnum,int snum,int jobid) pstrcpy(syscmd,lprm_command); string_sub(syscmd,"%p",printername); string_sub(syscmd,"%j",jobstr); - standard_sub(cnum,syscmd); + standard_sub(conn,syscmd); ret = smbrun(syscmd,NULL,False); DEBUG(3,("Running the command `%s' gave %d\n",syscmd,ret)); @@ -1157,7 +1144,7 @@ void del_printqueue(int cnum,int snum,int jobid) /**************************************************************************** change status of a printer queue entry ****************************************************************************/ -void status_printjob(int cnum,int snum,int jobid,int status) +void status_printjob(connection_struct *conn,int snum,int jobid,int status) { char *lpstatus_command = (status==LPQ_PAUSED?lp_lppausecommand(snum):lp_lpresumecommand(snum)); @@ -1185,7 +1172,7 @@ void status_printjob(int cnum,int snum,int jobid,int status) pstrcpy(syscmd,lpstatus_command); string_sub(syscmd,"%p",printername); string_sub(syscmd,"%j",jobstr); - standard_sub(cnum,syscmd); + standard_sub(conn,syscmd); ret = smbrun(syscmd,NULL,False); DEBUG(3,("Running the command `%s' gave %d\n",syscmd,ret)); @@ -1218,7 +1205,7 @@ void printjob_decode(int jobid, int *snum, int *job) Change status of a printer queue ****************************************************************************/ -void status_printqueue(int cnum,int snum,int status) +void status_printqueue(connection_struct *conn,int snum,int status) { char *queuestatus_command = (status==LPSTAT_STOPPED ? lp_queuepausecommand(snum):lp_queueresumecommand(snum)); @@ -1240,9 +1227,57 @@ void status_printqueue(int cnum,int snum,int status) pstrcpy(syscmd,queuestatus_command); string_sub(syscmd,"%p",printername); - standard_sub(cnum,syscmd); + standard_sub(conn,syscmd); ret = smbrun(syscmd,NULL,False); DEBUG(3,("Running the command `%s' gave %d\n",syscmd,ret)); lpq_reset(snum); /* queue has changed */ } + + + +/*************************************************************************** +auto-load printer services +***************************************************************************/ +static void add_all_printers(void) +{ + int printers = lp_servicenumber(PRINTERS_NAME); + + if (printers < 0) return; + + pcap_printer_fn(lp_add_one_printer); +} + +/*************************************************************************** +auto-load some homes and printer services +***************************************************************************/ +static void add_auto_printers(void) +{ + char *p; + int printers; + char *str = lp_auto_services(); + + if (!str) return; + + printers = lp_servicenumber(PRINTERS_NAME); + + if (printers < 0) return; + + for (p=strtok(str,LIST_SEP);p;p=strtok(NULL,LIST_SEP)) { + if (lp_servicenumber(p) >= 0) continue; + + if (pcap_printername_ok(p,NULL)) { + lp_add_printer(p,printers); + } + } +} + +/*************************************************************************** +load automatic printer services +***************************************************************************/ +void load_printers(void) +{ + add_auto_printers(); + if (lp_load_printers()) + add_all_printers(); +} diff --git a/source3/rpc_client/cli_netlogon.c b/source3/rpc_client/cli_netlogon.c index 7d79d88c46..ebe35abbcb 100644 --- a/source3/rpc_client/cli_netlogon.c +++ b/source3/rpc_client/cli_netlogon.c @@ -122,7 +122,7 @@ BOOL cli_net_auth2(struct cli_state *cli, uint16 sec_chan, /* create and send a MSRPC command with api NET_AUTH2 */ - DEBUG(4,("cli_net_auth2: srv:%s acct:%s sc:%x mc: %s chal %s neg: %lx\n", + DEBUG(4,("cli_net_auth2: srv:%s acct:%s sc:%x mc: %s chal %s neg: %x\n", cli->srv_name_slash, cli->mach_acct, sec_chan, global_myname, credstr(cli->clnt_cred.challenge.data), neg_flags)); @@ -171,7 +171,7 @@ password ?).\n", cli->desthost )); if (ok && r_a.srv_flgs.neg_flags != q_a.clnt_flgs.neg_flags) { /* report different neg_flags */ - DEBUG(0,("cli_net_auth2: error neg_flags (q,r) differ - (%lx,%lx)\n", + DEBUG(0,("cli_net_auth2: error neg_flags (q,r) differ - (%x,%x)\n", q_a.clnt_flgs.neg_flags, r_a.srv_flgs.neg_flags)); ok = False; } @@ -264,7 +264,7 @@ BOOL cli_net_srv_pwset(struct cli_state *cli, uint8 hashed_mach_pwd[16]) /* create and send a MSRPC command with api NET_SRV_PWSET */ - DEBUG(4,("cli_net_srv_pwset: srv:%s acct:%s sc: %d mc: %s clnt %s %lx\n", + DEBUG(4,("cli_net_srv_pwset: srv:%s acct:%s sc: %d mc: %s clnt %s %x\n", cli->srv_name_slash, cli->mach_acct, sec_chan_type, global_myname, credstr(new_clnt_cred.challenge.data), new_clnt_cred.timestamp.time)); @@ -331,7 +331,7 @@ BOOL cli_net_sam_logon(struct cli_state *cli, NET_ID_INFO_CTR *ctr, /* create and send a MSRPC command with api NET_SAMLOGON */ - DEBUG(4,("cli_net_sam_logon: srv:%s mc:%s clnt %s %lx ll: %d\n", + DEBUG(4,("cli_net_sam_logon: srv:%s mc:%s clnt %s %x ll: %d\n", cli->srv_name_slash, global_myname, credstr(new_clnt_cred.challenge.data), cli->clnt_cred.timestamp.time, ctr->switch_value)); @@ -416,7 +416,7 @@ BOOL cli_net_sam_logoff(struct cli_state *cli, NET_ID_INFO_CTR *ctr) /* create and send a MSRPC command with api NET_SAMLOGOFF */ - DEBUG(4,("cli_net_sam_logoff: srv:%s mc:%s clnt %s %lx ll: %d\n", + DEBUG(4,("cli_net_sam_logoff: srv:%s mc:%s clnt %s %x ll: %d\n", cli->srv_name_slash, global_myname, credstr(new_clnt_cred.challenge.data), new_clnt_cred.timestamp.time, ctr->switch_value)); diff --git a/source3/rpc_parse/parse_lsa.c b/source3/rpc_parse/parse_lsa.c index 6bd916ed32..f32ff58efb 100644 --- a/source3/rpc_parse/parse_lsa.c +++ b/source3/rpc_parse/parse_lsa.c @@ -140,7 +140,7 @@ void lsa_io_obj_attr(char *desc, LSA_OBJ_ATTR *attr, prs_struct *ps, int depth) if (attr->len != ps->offset - start) { - DEBUG(3,("lsa_io_obj_attr: length %lx does not match size %lx\n", + DEBUG(3,("lsa_io_obj_attr: length %x does not match size %x\n", attr->len, ps->offset - start)); } } diff --git a/source3/rpc_parse/parse_samr.c b/source3/rpc_parse/parse_samr.c index a85b6a692d..44503ee8c9 100644 --- a/source3/rpc_parse/parse_samr.c +++ b/source3/rpc_parse/parse_samr.c @@ -721,7 +721,8 @@ void make_samr_r_enum_dom_users(SAMR_R_ENUM_DOM_USERS *r_u, if (num_sam_entries >= MAX_SAM_ENTRIES) { num_sam_entries = MAX_SAM_ENTRIES; - DEBUG(5,("limiting number of entries to %d %s\n", num_sam_entries)); + DEBUG(5,("limiting number of entries to %d\n", + num_sam_entries)); } r_u->total_num_entries = total_num_entries; @@ -853,7 +854,8 @@ void make_samr_r_enum_dom_aliases(SAMR_R_ENUM_DOM_ALIASES *r_u, if (num_sam_entries >= MAX_SAM_ENTRIES) { num_sam_entries = MAX_SAM_ENTRIES; - DEBUG(5,("limiting number of entries to %d %s\n", num_sam_entries)); + DEBUG(5,("limiting number of entries to %d\n", + num_sam_entries)); } r_u->num_entries = num_sam_entries; @@ -988,7 +990,8 @@ void make_sam_info_2(SAM_INFO_2 *sam, uint32 acb_mask, if (num_sam_entries >= MAX_SAM_ENTRIES) { num_sam_entries = MAX_SAM_ENTRIES; - DEBUG(5,("limiting number of entries to %d %s\n", num_sam_entries)); + DEBUG(5,("limiting number of entries to %d\n", + num_sam_entries)); } for (i = start_idx, entries_added = 0; i < num_sam_entries; i++) @@ -1065,7 +1068,8 @@ void make_sam_info_1(SAM_INFO_1 *sam, uint32 acb_mask, if (num_sam_entries >= MAX_SAM_ENTRIES) { num_sam_entries = MAX_SAM_ENTRIES; - DEBUG(5,("limiting number of entries to %d %s\n", num_sam_entries)); + DEBUG(5,("limiting number of entries to %d\n", + num_sam_entries)); } for (i = start_idx, entries_added = 0; i < num_sam_entries; i++) @@ -1261,7 +1265,8 @@ void make_samr_r_enum_dom_groups(SAMR_R_ENUM_DOM_GROUPS *r_u, if (num_sam_entries >= MAX_SAM_ENTRIES) { num_sam_entries = MAX_SAM_ENTRIES; - DEBUG(5,("limiting number of entries to %d %s\n", num_sam_entries)); + DEBUG(5,("limiting number of entries to %d\n", + num_sam_entries)); } if (status == 0x0) diff --git a/source3/rpc_parse/parse_srv.c b/source3/rpc_parse/parse_srv.c index 592aece439..72cc34da9e 100644 --- a/source3/rpc_parse/parse_srv.c +++ b/source3/rpc_parse/parse_srv.c @@ -1364,7 +1364,7 @@ void srv_io_info_ctr(char *desc, SRV_INFO_CTR *ctr, prs_struct *ps, int depth) } default: { - DEBUG(5,("%s% no server info at switch_value %d\n", + DEBUG(5,("%s no server info at switch_value %d\n", tab_depth(depth), ctr->switch_value)); break; } diff --git a/source3/rpc_server/srv_pipe_hnd.c b/source3/rpc_server/srv_pipe_hnd.c index 8abfb54c8f..d792a16426 100644 --- a/source3/rpc_server/srv_pipe_hnd.c +++ b/source3/rpc_server/srv_pipe_hnd.c @@ -40,7 +40,7 @@ static int chain_pnum = -1; pipes_struct Pipes[MAX_OPEN_PIPES]; #define P_OPEN(p) ((p)->open) -#define P_OK(p,c) (P_OPEN(p) && (c)==((p)->cnum)) +#define P_OK(p,c) (P_OPEN(p) && (c)==((p)->conn)) #define VALID_PNUM(pnum) (((pnum) >= 0) && ((pnum) < MAX_OPEN_PIPES)) #define OPEN_PNUM(pnum) (VALID_PNUM(pnum) && P_OPEN(&(Pipes[pnum]))) #define PNUM_OK(pnum,c) (OPEN_PNUM(pnum) && (c)==Pipes[pnum].cnum) @@ -93,44 +93,43 @@ void init_rpc_pipe_hnd(void) /**************************************************************************** find first available file slot ****************************************************************************/ -int open_rpc_pipe_hnd(char *pipe_name, int cnum, uint16 vuid) +int open_rpc_pipe_hnd(char *pipe_name, connection_struct *conn, uint16 vuid) { int i; /* we start at 1 here for an obscure reason I can't now remember, but I think is important :-) */ - for (i = 1; i < MAX_OPEN_PIPES; i++) - { - if (!Pipes[i].open) - { - Pipes[i].open = True; - Pipes[i].device_state = 0; - Pipes[i].cnum = cnum; - Pipes[i].uid = vuid; - - Pipes[i].rhdr.data = NULL; - Pipes[i].rdata.data = NULL; - Pipes[i].rhdr.offset = 0; - Pipes[i].rdata.offset = 0; - - Pipes[i].file_offset = 0; - Pipes[i].hdr_offsets = 0; - Pipes[i].frag_len_left = 0; - Pipes[i].next_frag_start = 0; - - fstrcpy(Pipes[i].name, pipe_name); - - DEBUG(4,("Opened pipe %s with handle %x\n", - pipe_name, i + PIPE_HANDLE_OFFSET)); - - set_chain_pnum(i); - - return(i); - } + for (i = 1; i < MAX_OPEN_PIPES; i++) { + if (!Pipes[i].open) break; } - DEBUG(1,("ERROR! Out of pipe structures - perhaps increase MAX_OPEN_PIPES?\n")); + if (i == MAX_OPEN_PIPES) { + DEBUG(1,("ERROR! Out of pipe structures\n")); + return(-1); + } - return(-1); + Pipes[i].open = True; + Pipes[i].device_state = 0; + Pipes[i].conn = conn; + Pipes[i].uid = vuid; + + Pipes[i].rhdr.data = NULL; + Pipes[i].rdata.data = NULL; + Pipes[i].rhdr.offset = 0; + Pipes[i].rdata.offset = 0; + + Pipes[i].file_offset = 0; + Pipes[i].hdr_offsets = 0; + Pipes[i].frag_len_left = 0; + Pipes[i].next_frag_start = 0; + + fstrcpy(Pipes[i].name, pipe_name); + + DEBUG(4,("Opened pipe %s with handle %x\n", + pipe_name, i + PIPE_HANDLE_OFFSET)); + + set_chain_pnum(i); + + return(i); } /**************************************************************************** @@ -151,9 +150,8 @@ int read_pipe(uint16 pnum, char *data, uint32 pos, int n) if (VALID_PNUM(pnum - PIPE_HANDLE_OFFSET)) { - DEBUG(6,("name: %s cnum: %d open: %s pos: %d len: %d", + DEBUG(6,("name: %s open: %s pos: %d len: %d", p->name, - p->cnum, BOOLSTR(p->open), pos, n)); } @@ -269,9 +267,8 @@ BOOL get_rpc_pipe(int pnum, pipes_struct **p) if (VALID_PNUM(pnum - PIPE_HANDLE_OFFSET)) { - DEBUG(6,("name: %s cnum: %d open: %s ", + DEBUG(6,("name: %s open: %s ", Pipes[pnum - PIPE_HANDLE_OFFSET].name, - Pipes[pnum - PIPE_HANDLE_OFFSET].cnum, BOOLSTR(Pipes[pnum - PIPE_HANDLE_OFFSET].open))); } if (OPEN_PNUM(pnum - PIPE_HANDLE_OFFSET)) @@ -306,8 +303,8 @@ BOOL set_rpc_pipe_hnd_state(pipes_struct *p, uint16 device_state) if (P_OPEN(p)) { - DEBUG(3,("%s Setting pipe device state=%x on pipe (name=%s cnum=%d)\n", - timestring(), device_state, p->name, p->cnum)); + DEBUG(3,("%s Setting pipe device state=%x on pipe (name=%s)\n", + timestring(), device_state, p->name)); p->device_state = device_state; @@ -315,8 +312,8 @@ BOOL set_rpc_pipe_hnd_state(pipes_struct *p, uint16 device_state) } else { - DEBUG(3,("%s Error setting pipe device state=%x (name=%s cnum=%d)\n", - timestring(), device_state, p->name, p->cnum)); + DEBUG(3,("%s Error setting pipe device state=%x (name=%s)\n", + timestring(), device_state, p->name)); return False; } } @@ -324,32 +321,30 @@ BOOL set_rpc_pipe_hnd_state(pipes_struct *p, uint16 device_state) /**************************************************************************** close an rpc pipe ****************************************************************************/ -BOOL close_rpc_pipe_hnd(int pnum, int cnum) +BOOL close_rpc_pipe_hnd(int pnum, connection_struct *conn) { pipes_struct *p = NULL; get_rpc_pipe(pnum, &p); - /* mapping is PIPE_HANDLE_OFFSET up... */ + /* mapping is PIPE_HANDLE_OFFSET up... */ - if (p != NULL && P_OK(p, cnum)) - { - DEBUG(3,("%s Closed pipe name %s pnum=%x cnum=%d\n", - timestring(),Pipes[pnum-PIPE_HANDLE_OFFSET].name, pnum,cnum)); + if (p != NULL && P_OK(p, conn)) { + DEBUG(3,("%s Closed pipe name %s pnum=%x\n", + timestring(),Pipes[pnum-PIPE_HANDLE_OFFSET].name, + pnum)); - p->open = False; - - p->rdata.offset = 0; - p->rhdr.offset = 0; - mem_buf_free(&(p->rdata.data)); - mem_buf_free(&(p->rhdr .data)); - - return True; - } - else - { - DEBUG(3,("%s Error closing pipe pnum=%x cnum=%d\n", - timestring(),pnum, cnum)); - return False; - } + p->open = False; + + p->rdata.offset = 0; + p->rhdr.offset = 0; + mem_buf_free(&(p->rdata.data)); + mem_buf_free(&(p->rhdr .data)); + + return True; + } else { + DEBUG(3,("%s Error closing pipe pnum=%x\n", + timestring(),pnum)); + return False; + } } /**************************************************************************** diff --git a/source3/script/mkproto.awk b/source3/script/mkproto.awk index 5505878b37..28a68e29e2 100644 --- a/source3/script/mkproto.awk +++ b/source3/script/mkproto.awk @@ -80,7 +80,7 @@ END { next; } -!/^uid_t|^gid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^struct|^BOOL|^void|^time|^smb_shm_offset_t|^shm_offset_t|^enum remote_arch_types|^FILE/ { +!/^connection_struct|^uid_t|^gid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^struct|^BOOL|^void|^time|^smb_shm_offset_t|^shm_offset_t|^enum remote_arch_types|^FILE/ { next; } diff --git a/source3/smbd/chgpasswd.c b/source3/smbd/chgpasswd.c index af6746a699..6594c5f48c 100644 --- a/source3/smbd/chgpasswd.c +++ b/source3/smbd/chgpasswd.c @@ -80,7 +80,7 @@ static int findpty(char **slave) #else /* HAVE_GRANTPT */ fstrcpy( line, "/dev/ptyXX" ); - dirp = OpenDir(-1, "/dev", False); + dirp = OpenDir(NULL, "/dev", False); if (!dirp) return(-1); while ((dpname = ReadDirName(dirp)) != NULL) { if (strncmp(dpname, "pty", 3) == 0 && strlen(dpname) == 5) { diff --git a/source3/smbd/connection.c b/source3/smbd/connection.c index 64b3f153cf..342a5f43bc 100644 --- a/source3/smbd/connection.c +++ b/source3/smbd/connection.c @@ -22,7 +22,6 @@ #include "includes.h" -extern connection_struct Connections[MAX_CONNECTIONS]; extern fstring remote_machine; extern int DEBUGLEVEL; @@ -30,7 +29,7 @@ extern int DEBUGLEVEL; /**************************************************************************** simple routines to do connection counting ****************************************************************************/ -BOOL yield_connection(int cnum,char *name,int max_connections) +BOOL yield_connection(connection_struct *conn,char *name,int max_connections) { struct connect_record crec; pstring fname; @@ -38,7 +37,7 @@ BOOL yield_connection(int cnum,char *name,int max_connections) int mypid = getpid(); int i; - DEBUG(3,("Yielding connection to %d %s\n",cnum,name)); + DEBUG(3,("Yielding connection to %s\n",name)); if (max_connections <= 0) return(True); @@ -73,11 +72,11 @@ BOOL yield_connection(int cnum,char *name,int max_connections) close(fd); return(False); } - if (crec.pid == mypid && crec.cnum == cnum) + if (crec.pid == mypid && crec.cnum == conn->cnum) break; } - if (crec.pid != mypid || crec.cnum != cnum) { + if (crec.pid != mypid || crec.cnum != conn->cnum) { if (fcntl_lock(fd,F_SETLKW,0,1,F_UNLCK)==False) { DEBUG(0,("ERROR: can't release lock on %s\n", fname)); } @@ -113,7 +112,7 @@ BOOL yield_connection(int cnum,char *name,int max_connections) /**************************************************************************** simple routines to do connection counting ****************************************************************************/ -BOOL claim_connection(int cnum,char *name,int max_connections,BOOL Clear) +BOOL claim_connection(connection_struct *conn,char *name,int max_connections,BOOL Clear) { extern int Client; struct connect_record crec; @@ -192,11 +191,14 @@ BOOL claim_connection(int cnum,char *name,int max_connections,BOOL Clear) bzero((void *)&crec,sizeof(crec)); crec.magic = 0x280267; crec.pid = getpid(); - crec.cnum = cnum; - if (cnum != -1) { - crec.uid = Connections[cnum].uid; - crec.gid = Connections[cnum].gid; - StrnCpy(crec.name,lp_servicename(SNUM(cnum)),sizeof(crec.name)-1); + if (conn) { + crec.cnum = conn->cnum; + crec.uid = conn->uid; + crec.gid = conn->gid; + StrnCpy(crec.name, + lp_servicename(SNUM(conn)),sizeof(crec.name)-1); + } else { + crec.cnum = -1; } crec.start = time(NULL); diff --git a/source3/smbd/dir.c b/source3/smbd/dir.c index 44e0556f20..42ed68f713 100644 --- a/source3/smbd/dir.c +++ b/source3/smbd/dir.c @@ -22,7 +22,6 @@ #include "includes.h" extern int DEBUGLEVEL; -extern connection_struct Connections[]; /* This module implements directory related functions for Samba. @@ -36,18 +35,17 @@ static uint32 dircounter = 0; #define NUMDIRPTRS 256 -static struct dptr_struct -{ - int pid; - int cnum; - uint32 lastused; - void *ptr; - BOOL valid; - BOOL finished; - BOOL expect_close; - char *wcard; /* Field only used for lanman2 trans2_findfirst/next searches */ - uint16 attr; /* Field only used for lanman2 trans2_findfirst/next searches */ - char *path; +static struct dptr_struct { + int pid; + connection_struct *conn; + uint32 lastused; + void *ptr; + BOOL valid; + BOOL finished; + BOOL expect_close; + char *wcard; /* Field only used for trans2_ searches */ + uint16 attr; /* Field only used for trans2_ searches */ + char *path; } dirptrs[NUMDIRPTRS]; @@ -110,20 +108,20 @@ get the dir ptr for a dir index ****************************************************************************/ static void *dptr_get(int key,uint32 lastused) { - struct dptr_struct *dp = &dirptrs[key]; - - if (dp->valid) { - if (lastused) dp->lastused = lastused; - if (!dp->ptr) { - if (dptrs_open >= MAX_OPEN_DIRECTORIES) - dptr_idleoldest(); - DEBUG(4,("Reopening dptr key %d\n",key)); - if ((dp->ptr = OpenDir(dp->cnum, dp->path, True))) - dptrs_open++; - } - return(dp->ptr); - } - return(NULL); + struct dptr_struct *dp = &dirptrs[key]; + + if (dp->valid) { + if (lastused) dp->lastused = lastused; + if (!dp->ptr) { + if (dptrs_open >= MAX_OPEN_DIRECTORIES) + dptr_idleoldest(); + DEBUG(4,("Reopening dptr key %d\n",key)); + if ((dp->ptr = OpenDir(dp->conn, dp->path, True))) + dptrs_open++; + } + return(dp->ptr); + } + return(NULL); } /**************************************************************************** @@ -217,22 +215,22 @@ void dptr_close(int key) /**************************************************************************** close all dptrs for a cnum ****************************************************************************/ -void dptr_closecnum(int cnum) +void dptr_closecnum(connection_struct *conn) { int i; for (i=0;i<NUMDIRPTRS;i++) - if (dirptrs[i].valid && dirptrs[i].cnum == cnum) + if (dirptrs[i].valid && dirptrs[i].conn == conn) dptr_close(i); } /**************************************************************************** idle all dptrs for a cnum ****************************************************************************/ -void dptr_idlecnum(int cnum) +void dptr_idlecnum(connection_struct *conn) { int i; for (i=0;i<NUMDIRPTRS;i++) - if (dirptrs[i].valid && dirptrs[i].cnum == cnum && dirptrs[i].ptr) + if (dirptrs[i].valid && dirptrs[i].conn == conn && dirptrs[i].ptr) dptr_idle(i); } @@ -251,37 +249,37 @@ void dptr_closepath(char *path,int pid) /**************************************************************************** start a directory listing ****************************************************************************/ -static BOOL start_dir(int cnum,char *directory) +static BOOL start_dir(connection_struct *conn,char *directory) { - DEBUG(5,("start_dir cnum=%d dir=%s\n",cnum,directory)); + DEBUG(5,("start_dir dir=%s\n",directory)); - if (!check_name(directory,cnum)) - return(False); + if (!check_name(directory,conn)) + return(False); - if (! *directory) - directory = "."; - - Connections[cnum].dirptr = OpenDir(cnum, directory, True); - if (Connections[cnum].dirptr) { - dptrs_open++; - string_set(&Connections[cnum].dirpath,directory); - return(True); - } + if (! *directory) + directory = "."; + + conn->dirptr = OpenDir(conn, directory, True); + if (conn->dirptr) { + dptrs_open++; + string_set(&conn->dirpath,directory); + return(True); + } - return(False); + return(False); } /**************************************************************************** create a new dir ptr ****************************************************************************/ -int dptr_create(int cnum,char *path, BOOL expect_close,int pid) +int dptr_create(connection_struct *conn,char *path, BOOL expect_close,int pid) { int i; uint32 old; int oldi; - if (!start_dir(cnum,path)) + if (!start_dir(conn,path)) return(-2); /* Code to say use a unix error return code. */ if (dptrs_open >= MAX_OPEN_DIRECTORIES) @@ -325,11 +323,11 @@ int dptr_create(int cnum,char *path, BOOL expect_close,int pid) if (dirptrs[i].valid) dptr_close(i); - dirptrs[i].ptr = Connections[cnum].dirptr; + dirptrs[i].ptr = conn->dirptr; string_set(&dirptrs[i].path,path); dirptrs[i].lastused = dircounter++; dirptrs[i].finished = False; - dirptrs[i].cnum = cnum; + dirptrs[i].conn = conn; dirptrs[i].pid = pid; dirptrs[i].expect_close = expect_close; dirptrs[i].wcard = NULL; /* Only used in lanman2 searches */ @@ -357,7 +355,7 @@ BOOL dptr_fill(char *buf1,unsigned int key) return(False); } offset = TellDir(p); - DEBUG(6,("fill on key %d dirptr 0x%x now at %d\n",key,p,offset)); + DEBUG(6,("fill on key %d dirptr 0x%x now at %d\n",key,(unsigned)p,offset)); buf[0] = key; SIVAL(buf,1,offset | DPTR_MASK); return(True); @@ -410,7 +408,7 @@ void *dptr_fetch_lanman2(int dptr_num) /**************************************************************************** check a filetype for being valid ****************************************************************************/ -BOOL dir_check_ftype(int cnum,int mode,struct stat *st,int dirtype) +BOOL dir_check_ftype(connection_struct *conn,int mode,struct stat *st,int dirtype) { if (((mode & ~dirtype) & (aHIDDEN | aSYSTEM | aDIR)) != 0) return False; @@ -420,7 +418,7 @@ BOOL dir_check_ftype(int cnum,int mode,struct stat *st,int dirtype) /**************************************************************************** get a directory entry ****************************************************************************/ -BOOL get_dir_entry(int cnum,char *mask,int dirtype,char *fname,int *size,int *mode,time_t *date,BOOL check_descend) +BOOL get_dir_entry(connection_struct *conn,char *mask,int dirtype,char *fname,int *size,int *mode,time_t *date,BOOL check_descend) { char *dname; BOOL found = False; @@ -434,22 +432,22 @@ BOOL get_dir_entry(int cnum,char *mask,int dirtype,char *fname,int *size,int *mo *path = *pathreal = *filename = 0; - isrootdir = (strequal(Connections[cnum].dirpath,"./") || - strequal(Connections[cnum].dirpath,".") || - strequal(Connections[cnum].dirpath,"/")); + isrootdir = (strequal(conn->dirpath,"./") || + strequal(conn->dirpath,".") || + strequal(conn->dirpath,"/")); needslash = - ( Connections[cnum].dirpath[strlen(Connections[cnum].dirpath) -1] != '/'); + ( conn->dirpath[strlen(conn->dirpath) -1] != '/'); - if (!Connections[cnum].dirptr) + if (!conn->dirptr) return(False); while (!found) { - dname = ReadDirName(Connections[cnum].dirptr); + dname = ReadDirName(conn->dirptr); DEBUG(6,("readdir on dirptr 0x%x now at offset %d\n", - Connections[cnum].dirptr,TellDir(Connections[cnum].dirptr))); + (unsigned)conn->dirptr,TellDir(conn->dirptr))); if (dname == NULL) return(False); @@ -459,7 +457,7 @@ BOOL get_dir_entry(int cnum,char *mask,int dirtype,char *fname,int *size,int *mo pstrcpy(filename,dname); if ((strcmp(filename,mask) == 0) || - (name_map_mangle(filename,True,SNUM(cnum)) && + (name_map_mangle(filename,True,SNUM(conn)) && mask_match(filename,mask,False,False))) { if (isrootdir && (strequal(filename,"..") || strequal(filename,"."))) @@ -467,7 +465,7 @@ BOOL get_dir_entry(int cnum,char *mask,int dirtype,char *fname,int *size,int *mo pstrcpy(fname,filename); *path = 0; - pstrcpy(path,Connections[cnum].dirpath); + pstrcpy(path,conn->dirpath); if(needslash) pstrcat(path,"/"); pstrcpy(pathreal,path); @@ -483,9 +481,9 @@ BOOL get_dir_entry(int cnum,char *mask,int dirtype,char *fname,int *size,int *mo !strequal(fname,".") && !strequal(fname,"..")) continue; - *mode = dos_mode(cnum,pathreal,&sbuf); + *mode = dos_mode(conn,pathreal,&sbuf); - if (!dir_check_ftype(cnum,*mode,&sbuf,dirtype)) { + if (!dir_check_ftype(conn,*mode,&sbuf,dirtype)) { DEBUG(5,("[%s] attribs didn't match %x\n",filename,dirtype)); continue; } @@ -517,7 +515,7 @@ typedef struct /******************************************************************* open a directory ********************************************************************/ -void *OpenDir(int cnum, char *name, BOOL use_veto) +void *OpenDir(connection_struct *conn, char *name, BOOL use_veto) { Dir *dirp; char *n; @@ -538,7 +536,7 @@ void *OpenDir(int cnum, char *name, BOOL use_veto) int l = strlen(n)+1; /* If it's a vetoed file, pretend it doesn't even exist */ - if (use_veto && IS_VETO_PATH(cnum, n)) continue; + if (use_veto && conn && IS_VETO_PATH(conn, n)) continue; if (used + l > dirp->mallocsize) { int s = MAX(used+l,used+2000); diff --git a/source3/smbd/groupname.c b/source3/smbd/groupname.c index 33ce3adbfe..689fdbbbd9 100644 --- a/source3/smbd/groupname.c +++ b/source3/smbd/groupname.c @@ -197,8 +197,8 @@ Error was %s.\n", unixname, strerror(errno) )); ubi_slAddHead( &groupname_map_list, (ubi_slNode *)new_ep); } - DEBUG(10,("load_groupname_map: Added %d entries to groupname map.\n", - ubi_slCount( &groupname_map_list ) )); + DEBUG(10,("load_groupname_map: Added %ld entries to groupname map.\n", + ubi_slCount(&groupname_map_list))); fclose(fp); } diff --git a/source3/smbd/ipc.c b/source3/smbd/ipc.c index f1467a7f8a..a72b442735 100644 --- a/source3/smbd/ipc.c +++ b/source3/smbd/ipc.c @@ -37,7 +37,6 @@ extern int DEBUGLEVEL; extern int max_send; extern files_struct Files[]; -extern connection_struct Connections[]; extern fstring local_machine; extern fstring global_myworkgroup; @@ -65,31 +64,32 @@ extern int Client; extern int oplock_sock; extern int smb_read_error; -static BOOL api_Unsupported(int cnum,uint16 vuid, char *param,char *data, +static BOOL api_Unsupported(connection_struct *conn,uint16 vuid, char *param,char *data, int mdrcnt,int mprcnt, char **rdata,char **rparam, int *rdata_len,int *rparam_len); -static BOOL api_TooSmall(int cnum,uint16 vuid, char *param,char *data, +static BOOL api_TooSmall(connection_struct *conn,uint16 vuid, char *param,char *data, int mdrcnt,int mprcnt, char **rdata,char **rparam, int *rdata_len,int *rparam_len); -static int CopyExpanded(int cnum, int snum, char** dst, char* src, int* n) +static int CopyExpanded(connection_struct *conn, + int snum, char** dst, char* src, int* n) { - pstring buf; - int l; + pstring buf; + int l; - if (!src || !dst || !n || !(*dst)) return(0); + if (!src || !dst || !n || !(*dst)) return(0); - StrnCpy(buf,src,sizeof(buf)/2); - string_sub(buf,"%S",lp_servicename(snum)); - standard_sub(cnum,buf); - StrnCpy(*dst,buf,*n); - l = strlen(*dst) + 1; - (*dst) += l; - (*n) -= l; - return l; + StrnCpy(buf,src,sizeof(buf)/2); + string_sub(buf,"%S",lp_servicename(snum)); + standard_sub(conn,buf); + StrnCpy(*dst,buf,*n); + l = strlen(*dst) + 1; + (*dst) += l; + (*n) -= l; + return l; } static int CopyAndAdvance(char** dst, char* src, int* n) @@ -103,24 +103,24 @@ static int CopyAndAdvance(char** dst, char* src, int* n) return l; } -static int StrlenExpanded(int cnum, int snum, char* s) +static int StrlenExpanded(connection_struct *conn, int snum, char* s) { - pstring buf; - if (!s) return(0); - StrnCpy(buf,s,sizeof(buf)/2); - string_sub(buf,"%S",lp_servicename(snum)); - standard_sub(cnum,buf); - return strlen(buf) + 1; + pstring buf; + if (!s) return(0); + StrnCpy(buf,s,sizeof(buf)/2); + string_sub(buf,"%S",lp_servicename(snum)); + standard_sub(conn,buf); + return strlen(buf) + 1; } -static char* Expand(int cnum, int snum, char* s) +static char* Expand(connection_struct *conn, int snum, char* s) { - static pstring buf; - if (!s) return(NULL); - StrnCpy(buf,s,sizeof(buf)/2); - string_sub(buf,"%S",lp_servicename(snum)); - standard_sub(cnum,buf); - return &buf[0]; + static pstring buf; + if (!s) return(NULL); + StrnCpy(buf,s,sizeof(buf)/2); + string_sub(buf,"%S",lp_servicename(snum)); + standard_sub(conn,buf); + return &buf[0]; } /******************************************************************* @@ -530,7 +530,7 @@ static int check_printq_info(struct pack_desc* desc, return True; } -static void fill_printjob_info(int cnum, int snum, int uLevel, +static void fill_printjob_info(connection_struct *conn, int snum, int uLevel, struct pack_desc* desc, print_queue_struct* queue, int n) { @@ -577,7 +577,7 @@ static void fill_printjob_info(int cnum, int snum, int uLevel, } } -static void fill_printq_info(int cnum, int snum, int uLevel, +static void fill_printq_info(connection_struct *conn, int snum, int uLevel, struct pack_desc* desc, int count, print_queue_struct* queue, print_status_struct* status) @@ -590,7 +590,7 @@ static void fill_printq_info(int cnum, int snum, int uLevel, case 3: case 4: case 5: - PACKS(desc,"z",Expand(cnum,snum,SERVICE(snum))); + PACKS(desc,"z",Expand(conn,snum,SERVICE(snum))); break; } @@ -608,7 +608,7 @@ static void fill_printq_info(int cnum, int snum, int uLevel, PACKI(desc,"W",LPSTAT_ERROR); } else if (!status || !status->message[0]) { - PACKS(desc,"z",Expand(cnum,snum,lp_comment(snum))); + PACKS(desc,"z",Expand(conn,snum,lp_comment(snum))); PACKI(desc,"W",LPSTAT_OK); /* status */ } else { PACKS(desc,"z",status->message); @@ -625,7 +625,7 @@ static void fill_printq_info(int cnum, int snum, int uLevel, PACKS(desc,"z","WinPrint"); /* pszPrProc */ PACKS(desc,"z",""); /* pszParms */ if (!status || !status->message[0]) { - PACKS(desc,"z",Expand(cnum,snum,lp_comment(snum))); /* pszComment */ + PACKS(desc,"z",Expand(conn,snum,lp_comment(snum))); /* pszComment */ PACKI(desc,"W",LPSTAT_OK); /* fsStatus */ } else { PACKS(desc,"z",status->message); /* pszComment */ @@ -639,7 +639,7 @@ static void fill_printq_info(int cnum, int snum, int uLevel, if (uLevel == 2 || uLevel == 4) { int i; for (i=0;i<count;i++) - fill_printjob_info(cnum,snum,uLevel == 2 ? 1 : 2,desc,&queue[i],i); + fill_printjob_info(conn,snum,uLevel == 2 ? 1 : 2,desc,&queue[i],i); } if (uLevel==52) { @@ -788,7 +788,8 @@ int get_printerdrivernumber(int snum) return(i); } -static BOOL api_DosPrintQGetInfo(int cnum,uint16 vuid, char *param,char *data, +static BOOL api_DosPrintQGetInfo(connection_struct *conn, + uint16 vuid, char *param,char *data, int mdrcnt,int mprcnt, char **rdata,char **rparam, int *rdata_len,int *rparam_len) @@ -837,16 +838,16 @@ static BOOL api_DosPrintQGetInfo(int cnum,uint16 vuid, char *param,char *data, { count = get_printerdrivernumber(snum); DEBUG(3,("api_DosPrintQGetInfo: Driver files count: %d\n",count)); + } else { + count = get_printqueue(SNUM(conn), conn,&queue,&status); } - else - count = get_printqueue(snum,cnum,&queue,&status); if (mdrcnt > 0) *rdata = REALLOC(*rdata,mdrcnt); desc.base = *rdata; desc.buflen = mdrcnt; if (init_package(&desc,1,count)) { desc.subcount = count; - fill_printq_info(cnum,snum,uLevel,&desc,count,queue,&status); + fill_printq_info(conn,snum,uLevel,&desc,count,queue,&status); } *rdata_len = desc.usedlen; @@ -868,7 +869,7 @@ static BOOL api_DosPrintQGetInfo(int cnum,uint16 vuid, char *param,char *data, /**************************************************************************** view list of all print jobs on all queues ****************************************************************************/ -static BOOL api_DosPrintQEnum(int cnum, uint16 vuid, char* param, char* data, +static BOOL api_DosPrintQEnum(connection_struct *conn, uint16 vuid, char* param, char* data, int mdrcnt, int mprcnt, char **rdata, char** rparam, int *rdata_len, int *rparam_len) @@ -907,7 +908,7 @@ static BOOL api_DosPrintQEnum(int cnum, uint16 vuid, char* param, char* data, n = 0; for (i = 0; i < services; i++) if (lp_snum_ok(i) && lp_print_ok(i) && lp_browseable(i)) { - subcntarr[n] = get_printqueue(i,cnum,&queue[n],&status[n]); + subcntarr[n] = get_printqueue(i, conn,&queue[n],&status[n]); subcnt += subcntarr[n]; n++; } @@ -921,7 +922,7 @@ static BOOL api_DosPrintQEnum(int cnum, uint16 vuid, char* param, char* data, succnt = 0; for (i = 0; i < services; i++) if (lp_snum_ok(i) && lp_print_ok(i) && lp_browseable(i)) { - fill_printq_info(cnum,i,uLevel,&desc,subcntarr[n],queue[n],&status[n]); + fill_printq_info(conn,i,uLevel,&desc,subcntarr[n],queue[n],&status[n]); n++; if (desc.errcode == NERR_Success) succnt = n; } @@ -1180,7 +1181,7 @@ static BOOL srv_comp(struct srv_info_struct *s1,struct srv_info_struct *s2) view list of servers available (or possibly domains). The info is extracted from lists saved by nmbd on the local host ****************************************************************************/ -static BOOL api_RNetServerEnum(int cnum, uint16 vuid, char *param, char *data, +static BOOL api_RNetServerEnum(connection_struct *conn, uint16 vuid, char *param, char *data, int mdrcnt, int mprcnt, char **rdata, char **rparam, int *rdata_len, int *rparam_len) { @@ -1306,7 +1307,7 @@ static BOOL api_RNetServerEnum(int cnum, uint16 vuid, char *param, char *data, /**************************************************************************** command 0x34 - suspected of being a "Lookup Names" stub api ****************************************************************************/ -static BOOL api_RNetGroupGetUsers(int cnum, uint16 vuid, char *param, char *data, +static BOOL api_RNetGroupGetUsers(connection_struct *conn, uint16 vuid, char *param, char *data, int mdrcnt, int mprcnt, char **rdata, char **rparam, int *rdata_len, int *rparam_len) { @@ -1360,7 +1361,7 @@ static BOOL check_share_info(int uLevel, char* id) return True; } -static int fill_share_info(int cnum, int snum, int uLevel, +static int fill_share_info(connection_struct *conn, int snum, int uLevel, char** buf, int* buflen, char** stringbuf, int* stringspace, char* baseaddr) { @@ -1382,7 +1383,7 @@ static int fill_share_info(int cnum, int snum, int uLevel, if (!buf) { len = 0; - if (uLevel > 0) len += StrlenExpanded(cnum,snum,lp_comment(snum)); + if (uLevel > 0) len += StrlenExpanded(conn,snum,lp_comment(snum)); if (uLevel > 1) len += strlen(lp_pathname(snum)) + 1; if (buflen) *buflen = struct_len; if (stringspace) *stringspace = len; @@ -1415,7 +1416,7 @@ static int fill_share_info(int cnum, int snum, int uLevel, if (strequal("IPC$",lp_servicename(snum))) type = STYPE_IPC; SSVAL(p,14,type); /* device type */ SIVAL(p,16,PTR_DIFF(p2,baseaddr)); - len += CopyExpanded(cnum,snum,&p2,lp_comment(snum),&l2); + len += CopyExpanded(conn,snum,&p2,lp_comment(snum),&l2); } if (uLevel > 1) @@ -1455,7 +1456,7 @@ static int fill_share_info(int cnum, int snum, int uLevel, return len; } -static BOOL api_RNetShareGetInfo(int cnum,uint16 vuid, char *param,char *data, +static BOOL api_RNetShareGetInfo(connection_struct *conn,uint16 vuid, char *param,char *data, int mdrcnt,int mprcnt, char **rdata,char **rparam, int *rdata_len,int *rparam_len) @@ -1475,7 +1476,7 @@ static BOOL api_RNetShareGetInfo(int cnum,uint16 vuid, char *param,char *data, *rdata = REALLOC(*rdata,mdrcnt); p = *rdata; - *rdata_len = fill_share_info(cnum,snum,uLevel,&p,&mdrcnt,0,0,0); + *rdata_len = fill_share_info(conn,snum,uLevel,&p,&mdrcnt,0,0,0); if (*rdata_len < 0) return False; *rparam_len = 6; @@ -1490,7 +1491,7 @@ static BOOL api_RNetShareGetInfo(int cnum,uint16 vuid, char *param,char *data, /**************************************************************************** view list of shares available ****************************************************************************/ -static BOOL api_RNetShareEnum(int cnum,uint16 vuid, char *param,char *data, +static BOOL api_RNetShareEnum(connection_struct *conn,uint16 vuid, char *param,char *data, int mdrcnt,int mprcnt, char **rdata,char **rparam, int *rdata_len,int *rparam_len) @@ -1516,7 +1517,7 @@ static BOOL api_RNetShareEnum(int cnum,uint16 vuid, char *param,char *data, if (lp_browseable(i) && lp_snum_ok(i)) { total++; - data_len += fill_share_info(cnum,i,uLevel,0,&f_len,0,&s_len,0); + data_len += fill_share_info(conn,i,uLevel,0,&f_len,0,&s_len,0); if (data_len <= buf_len) { counted++; @@ -1536,7 +1537,7 @@ static BOOL api_RNetShareEnum(int cnum,uint16 vuid, char *param,char *data, s_len = string_len; for (i = 0; i < count;i++) if (lp_browseable(i) && lp_snum_ok(i)) - if (fill_share_info(cnum,i,uLevel,&p,&f_len,&p2,&s_len,*rdata) < 0) + if (fill_share_info(conn,i,uLevel,&p,&f_len,&p2,&s_len,*rdata) < 0) break; *rparam_len = 8; @@ -1557,7 +1558,7 @@ static BOOL api_RNetShareEnum(int cnum,uint16 vuid, char *param,char *data, /**************************************************************************** get the time of day info ****************************************************************************/ -static BOOL api_NetRemoteTOD(int cnum,uint16 vuid, char *param,char *data, +static BOOL api_NetRemoteTOD(connection_struct *conn,uint16 vuid, char *param,char *data, int mdrcnt,int mprcnt, char **rdata,char **rparam, int *rdata_len,int *rparam_len) @@ -1606,7 +1607,7 @@ static BOOL api_NetRemoteTOD(int cnum,uint16 vuid, char *param,char *data, /**************************************************************************** set the user password ****************************************************************************/ -static BOOL api_SetUserPassword(int cnum,uint16 vuid, char *param,char *data, +static BOOL api_SetUserPassword(connection_struct *conn,uint16 vuid, char *param,char *data, int mdrcnt,int mprcnt, char **rdata,char **rparam, int *rdata_len,int *rparam_len) @@ -1682,7 +1683,7 @@ static BOOL api_SetUserPassword(int cnum,uint16 vuid, char *param,char *data, Set the user password (SamOEM version - gets plaintext). ****************************************************************************/ -static BOOL api_SamOEMChangePassword(int cnum,uint16 vuid, char *param,char *data, +static BOOL api_SamOEMChangePassword(connection_struct *conn,uint16 vuid, char *param,char *data, int mdrcnt,int mprcnt, char **rdata,char **rparam, int *rdata_len,int *rparam_len) @@ -1760,7 +1761,7 @@ static BOOL api_SamOEMChangePassword(int cnum,uint16 vuid, char *param,char *dat delete a print job Form: <W> <> ****************************************************************************/ -static BOOL api_RDosPrintJobDel(int cnum,uint16 vuid, char *param,char *data, +static BOOL api_RDosPrintJobDel(connection_struct *conn,uint16 vuid, char *param,char *data, int mdrcnt,int mprcnt, char **rdata,char **rparam, int *rdata_len,int *rparam_len) @@ -1789,7 +1790,7 @@ static BOOL api_RDosPrintJobDel(int cnum,uint16 vuid, char *param,char *data, { print_queue_struct *queue=NULL; lpq_reset(snum); - count = get_printqueue(snum,cnum,&queue,NULL); + count = get_printqueue(snum,conn,&queue,NULL); for (i=0;i<count;i++) if ((queue[i].job&0xFF) == jobid) @@ -1797,13 +1798,13 @@ static BOOL api_RDosPrintJobDel(int cnum,uint16 vuid, char *param,char *data, switch (function) { case 81: /* delete */ DEBUG(3,("Deleting queue entry %d\n",queue[i].job)); - del_printqueue(cnum,snum,queue[i].job); + del_printqueue(conn,snum,queue[i].job); break; case 82: /* pause */ case 83: /* resume */ DEBUG(3,("%s queue entry %d\n", (function==82?"pausing":"resuming"),queue[i].job)); - status_printjob(cnum,snum,queue[i].job, + status_printjob(conn,snum,queue[i].job, (function==82?LPQ_PAUSED:LPQ_QUEUED)); break; } @@ -1824,7 +1825,7 @@ static BOOL api_RDosPrintJobDel(int cnum,uint16 vuid, char *param,char *data, /**************************************************************************** Purge a print queue - or pause or resume it. ****************************************************************************/ -static BOOL api_WPrintQueuePurge(int cnum,uint16 vuid, char *param,char *data, +static BOOL api_WPrintQueuePurge(connection_struct *conn,uint16 vuid, char *param,char *data, int mdrcnt,int mprcnt, char **rdata,char **rparam, int *rdata_len,int *rparam_len) @@ -1862,7 +1863,7 @@ static BOOL api_WPrintQueuePurge(int cnum,uint16 vuid, char *param,char *data, switch (function) { case 74: /* Pause queue */ case 75: /* Resume queue */ - status_printqueue(cnum,snum,(function==74?LPSTAT_STOPPED:LPSTAT_OK)); + status_printqueue(conn,snum,(function==74?LPSTAT_STOPPED:LPSTAT_OK)); DEBUG(3,("Print queue %s, queue=%s\n", (function==74?"pause":"resume"),QueueName)); break; @@ -1870,9 +1871,9 @@ static BOOL api_WPrintQueuePurge(int cnum,uint16 vuid, char *param,char *data, { print_queue_struct *queue=NULL; int i, count; - count = get_printqueue(snum,cnum,&queue,NULL); + count = get_printqueue(snum,conn,&queue,NULL); for (i = 0; i < count; i++) - del_printqueue(cnum,snum,queue[i].job); + del_printqueue(conn,snum,queue[i].job); if (queue) free(queue); DEBUG(3,("Print queue purge, queue=%s\n",QueueName)); @@ -1907,7 +1908,7 @@ static int check_printjob_info(struct pack_desc* desc, return True; } -static BOOL api_PrintJobInfo(int cnum,uint16 vuid,char *param,char *data, +static BOOL api_PrintJobInfo(connection_struct *conn,uint16 vuid,char *param,char *data, int mdrcnt,int mprcnt, char **rdata,char **rparam, int *rdata_len,int *rparam_len) @@ -1941,7 +1942,7 @@ static BOOL api_PrintJobInfo(int cnum,uint16 vuid,char *param,char *data, int count; lpq_reset(snum); - count = get_printqueue(snum,cnum,&queue,NULL); + count = get_printqueue(snum,conn,&queue,NULL); for (i=0;i<count;i++) /* find job */ if ((queue[i].job&0xFF) == jobid) break; @@ -1987,16 +1988,17 @@ static BOOL api_PrintJobInfo(int cnum,uint16 vuid,char *param,char *data, if (Files[i].open && Files[i].print_file) { pstring wd; - int fcnum = Files[i].cnum; + connection_struct *fconn = Files[i].conn; GetWd(wd); unbecome_user(); - if (!become_user(&Connections[fcnum], fcnum,vuid) || - !become_service(fcnum,True)) + if (!become_user(fconn,vuid) || + !become_service(fconn,True)) break; - if (sys_rename(Files[i].name,name) == 0) - string_set(&Files[i].name,name); + if (sys_rename(Files[i].fsp_name,name) == 0) { + string_set(&Files[i].fsp_name,name); + } break; } @@ -2019,7 +2021,7 @@ static BOOL api_PrintJobInfo(int cnum,uint16 vuid,char *param,char *data, /**************************************************************************** get info about the server ****************************************************************************/ -static BOOL api_RNetServerGetInfo(int cnum,uint16 vuid, char *param,char *data, +static BOOL api_RNetServerGetInfo(connection_struct *conn,uint16 vuid, char *param,char *data, int mdrcnt,int mprcnt, char **rdata,char **rparam, int *rdata_len,int *rparam_len) @@ -2102,7 +2104,7 @@ static BOOL api_RNetServerGetInfo(int cnum,uint16 vuid, char *param,char *data, SIVAL(p,6,0); } else { SIVAL(p,6,PTR_DIFF(p2,*rdata)); - standard_sub(cnum,comment); + standard_sub(conn,comment); StrnCpy(p2,comment,MAX(mdrcnt - struct_len,0)); p2 = skip_string(p2,1); } @@ -2127,7 +2129,7 @@ static BOOL api_RNetServerGetInfo(int cnum,uint16 vuid, char *param,char *data, /**************************************************************************** get info about the server ****************************************************************************/ -static BOOL api_NetWkstaGetInfo(int cnum,uint16 vuid, char *param,char *data, +static BOOL api_NetWkstaGetInfo(connection_struct *conn,uint16 vuid, char *param,char *data, int mdrcnt,int mprcnt, char **rdata,char **rparam, int *rdata_len,int *rparam_len) @@ -2364,7 +2366,7 @@ There is no auxiliary data in the response. #define AF_OP_ACCOUNTS 3 -static BOOL api_RNetUserGetInfo(int cnum,uint16 vuid, char *param,char *data, +static BOOL api_RNetUserGetInfo(connection_struct *conn,uint16 vuid, char *param,char *data, int mdrcnt,int mprcnt, char **rdata,char **rparam, int *rdata_len,int *rparam_len) @@ -2437,7 +2439,7 @@ static BOOL api_RNetUserGetInfo(int cnum,uint16 vuid, char *param,char *data, if (uLevel == 11) /* modelled after NTAS 3.51 reply */ { - SSVAL(p,usri11_priv,Connections[cnum].admin_user?USER_PRIV_ADMIN:USER_PRIV_USER); + SSVAL(p,usri11_priv,conn->admin_user?USER_PRIV_ADMIN:USER_PRIV_USER); SIVAL(p,usri11_auth_flags,AF_OP_PRINT); /* auth flags */ SIVALS(p,usri11_password_age,-1); /* password age */ SIVAL(p,usri11_homedir,PTR_DIFF(p2,p)); /* home dir */ @@ -2475,7 +2477,7 @@ static BOOL api_RNetUserGetInfo(int cnum,uint16 vuid, char *param,char *data, memset(p+22,' ',16); /* password */ SIVALS(p,38,-1); /* password age */ SSVAL(p,42, - Connections[cnum].admin_user?USER_PRIV_ADMIN:USER_PRIV_USER); + conn->admin_user?USER_PRIV_ADMIN:USER_PRIV_USER); SIVAL(p,44,PTR_DIFF(p2,*rdata)); /* home dir */ pstrcpy(p2,lp_logon_path()); p2 = skip_string(p2,1); @@ -2523,7 +2525,7 @@ static BOOL api_RNetUserGetInfo(int cnum,uint16 vuid, char *param,char *data, /******************************************************************* get groups that a user is a member of ******************************************************************/ -static BOOL api_NetUserGetGroups(int cnum,uint16 vuid, char *param,char *data, +static BOOL api_NetUserGetGroups(connection_struct *conn,uint16 vuid, char *param,char *data, int mdrcnt,int mprcnt, char **rdata,char **rparam, int *rdata_len,int *rparam_len) @@ -2570,7 +2572,7 @@ static BOOL api_NetUserGetGroups(int cnum,uint16 vuid, char *param,char *data, } -static BOOL api_WWkstaUserLogon(int cnum,uint16 vuid, char *param,char *data, +static BOOL api_WWkstaUserLogon(connection_struct *conn,uint16 vuid, char *param,char *data, int mdrcnt,int mprcnt, char **rdata,char **rparam, int *rdata_len,int *rparam_len) @@ -2605,7 +2607,7 @@ static BOOL api_WWkstaUserLogon(int cnum,uint16 vuid, char *param,char *data, PACKS(&desc,"B21",name); /* eff. name */ PACKS(&desc,"B",""); /* pad */ PACKI(&desc,"W", - Connections[cnum].admin_user?USER_PRIV_ADMIN:USER_PRIV_USER); + conn->admin_user?USER_PRIV_ADMIN:USER_PRIV_USER); PACKI(&desc,"D",0); /* auth flags XXX */ PACKI(&desc,"W",0); /* num logons */ PACKI(&desc,"W",0); /* bad pw count */ @@ -2628,7 +2630,7 @@ static BOOL api_WWkstaUserLogon(int cnum,uint16 vuid, char *param,char *data, /* JHT - By calling lp_logon_script() and standard_sub() we have */ /* made sure all macros are fully substituted and available */ logon_script = lp_logon_script(); - standard_sub( cnum, logon_script ); + standard_sub( conn, logon_script ); PACKS(&desc,"z", logon_script); /* script path */ /* End of JHT mods */ @@ -2650,7 +2652,7 @@ static BOOL api_WWkstaUserLogon(int cnum,uint16 vuid, char *param,char *data, /**************************************************************************** api_WAccessGetUserPerms ****************************************************************************/ -static BOOL api_WAccessGetUserPerms(int cnum,uint16 vuid, char *param,char *data, +static BOOL api_WAccessGetUserPerms(connection_struct *conn,uint16 vuid, char *param,char *data, int mdrcnt,int mprcnt, char **rdata,char **rparam, int *rdata_len,int *rparam_len) @@ -2678,7 +2680,7 @@ static BOOL api_WAccessGetUserPerms(int cnum,uint16 vuid, char *param,char *data /**************************************************************************** api_WPrintJobEnumerate ****************************************************************************/ -static BOOL api_WPrintJobGetInfo(int cnum,uint16 vuid, char *param,char *data, +static BOOL api_WPrintJobGetInfo(connection_struct *conn,uint16 vuid, char *param,char *data, int mdrcnt,int mprcnt, char **rdata,char **rparam, int *rdata_len,int *rparam_len) @@ -2711,7 +2713,7 @@ static BOOL api_WPrintJobGetInfo(int cnum,uint16 vuid, char *param,char *data, if (snum < 0 || !VALID_SNUM(snum)) return(False); - count = get_printqueue(snum,cnum,&queue,&status); + count = get_printqueue(snum,conn,&queue,&status); for (i = 0; i < count; i++) { if ((queue[i].job & 0xFF) == job) break; } @@ -2721,7 +2723,7 @@ static BOOL api_WPrintJobGetInfo(int cnum,uint16 vuid, char *param,char *data, if (init_package(&desc,1,0)) { if (i < count) { - fill_printjob_info(cnum,snum,uLevel,&desc,&queue[i],i); + fill_printjob_info(conn,snum,uLevel,&desc,&queue[i],i); *rdata_len = desc.usedlen; } else { @@ -2742,7 +2744,7 @@ static BOOL api_WPrintJobGetInfo(int cnum,uint16 vuid, char *param,char *data, return(True); } -static BOOL api_WPrintJobEnumerate(int cnum,uint16 vuid, char *param,char *data, +static BOOL api_WPrintJobEnumerate(connection_struct *conn,uint16 vuid, char *param,char *data, int mdrcnt,int mprcnt, char **rdata,char **rparam, int *rdata_len,int *rparam_len) @@ -2784,7 +2786,7 @@ static BOOL api_WPrintJobEnumerate(int cnum,uint16 vuid, char *param,char *data, if (snum < 0 || !VALID_SNUM(snum)) return(False); - count = get_printqueue(snum,cnum,&queue,&status); + count = get_printqueue(snum,conn,&queue,&status); if (mdrcnt > 0) *rdata = REALLOC(*rdata,mdrcnt); desc.base = *rdata; desc.buflen = mdrcnt; @@ -2792,7 +2794,7 @@ static BOOL api_WPrintJobEnumerate(int cnum,uint16 vuid, char *param,char *data, if (init_package(&desc,count,0)) { succnt = 0; for (i = 0; i < count; i++) { - fill_printjob_info(cnum,snum,uLevel,&desc,&queue[i],i); + fill_printjob_info(conn,snum,uLevel,&desc,&queue[i],i); if (desc.errcode == NERR_Success) succnt = i+1; } } @@ -2827,7 +2829,7 @@ static int check_printdest_info(struct pack_desc* desc, return True; } -static void fill_printdest_info(int cnum, int snum, int uLevel, +static void fill_printdest_info(connection_struct *conn, int snum, int uLevel, struct pack_desc* desc) { char buf[100]; @@ -2860,7 +2862,7 @@ static void fill_printdest_info(int cnum, int snum, int uLevel, } } -static BOOL api_WPrintDestGetInfo(int cnum,uint16 vuid, char *param,char *data, +static BOOL api_WPrintDestGetInfo(connection_struct *conn,uint16 vuid, char *param,char *data, int mdrcnt,int mprcnt, char **rdata,char **rparam, int *rdata_len,int *rparam_len) @@ -2904,7 +2906,7 @@ static BOOL api_WPrintDestGetInfo(int cnum,uint16 vuid, char *param,char *data, desc.base = *rdata; desc.buflen = mdrcnt; if (init_package(&desc,1,0)) { - fill_printdest_info(cnum,snum,uLevel,&desc); + fill_printdest_info(conn,snum,uLevel,&desc); } *rdata_len = desc.usedlen; } @@ -2919,7 +2921,7 @@ static BOOL api_WPrintDestGetInfo(int cnum,uint16 vuid, char *param,char *data, return(True); } -static BOOL api_WPrintDestEnum(int cnum,uint16 vuid, char *param,char *data, +static BOOL api_WPrintDestEnum(connection_struct *conn,uint16 vuid, char *param,char *data, int mdrcnt,int mprcnt, char **rdata,char **rparam, int *rdata_len,int *rparam_len) @@ -2957,7 +2959,7 @@ static BOOL api_WPrintDestEnum(int cnum,uint16 vuid, char *param,char *data, n = 0; for (i = 0; i < services; i++) { if (lp_snum_ok(i) && lp_print_ok(i) && lp_browseable(i)) { - fill_printdest_info(cnum,i,uLevel,&desc); + fill_printdest_info(conn,i,uLevel,&desc); n++; if (desc.errcode == NERR_Success) succnt = n; } @@ -2977,7 +2979,7 @@ static BOOL api_WPrintDestEnum(int cnum,uint16 vuid, char *param,char *data, return(True); } -static BOOL api_WPrintDriverEnum(int cnum,uint16 vuid, char *param,char *data, +static BOOL api_WPrintDriverEnum(connection_struct *conn,uint16 vuid, char *param,char *data, int mdrcnt,int mprcnt, char **rdata,char **rparam, int *rdata_len,int *rparam_len) @@ -3022,7 +3024,7 @@ static BOOL api_WPrintDriverEnum(int cnum,uint16 vuid, char *param,char *data, return(True); } -static BOOL api_WPrintQProcEnum(int cnum,uint16 vuid, char *param,char *data, +static BOOL api_WPrintQProcEnum(connection_struct *conn,uint16 vuid, char *param,char *data, int mdrcnt,int mprcnt, char **rdata,char **rparam, int *rdata_len,int *rparam_len) @@ -3068,7 +3070,7 @@ static BOOL api_WPrintQProcEnum(int cnum,uint16 vuid, char *param,char *data, return(True); } -static BOOL api_WPrintPortEnum(int cnum,uint16 vuid, char *param,char *data, +static BOOL api_WPrintPortEnum(connection_struct *conn,uint16 vuid, char *param,char *data, int mdrcnt,int mprcnt, char **rdata,char **rparam, int *rdata_len,int *rparam_len) @@ -3366,7 +3368,7 @@ static BOOL api_no_reply(char *outbuf, int max_rdata_len) /**************************************************************************** handle remote api calls delivered to a named pipe already opened. ****************************************************************************/ -static int api_fd_reply(int cnum,uint16 vuid,char *outbuf, +static int api_fd_reply(connection_struct *conn,uint16 vuid,char *outbuf, uint16 *setup,char *data,char *params, int suwcnt,int tdscnt,int tpscnt,int mdrcnt,int mprcnt) { @@ -3407,8 +3409,6 @@ static int api_fd_reply(int cnum,uint16 vuid,char *outbuf, { DEBUG(3,("Got API command 0x%x on pipe \"%s\" (pnum %x)", subcommand, p->name, pnum)); - DEBUG(3,("(tdscnt=%d,tpscnt=%d,mdrcnt=%d,mprcnt=%d,cnum=%d,vuid=%d)\n", - tdscnt,tpscnt,mdrcnt,mprcnt,cnum,vuid)); /* record maximum data length that can be transmitted in an SMBtrans */ p->file_offset = mdrcnt; @@ -3447,7 +3447,7 @@ static int api_fd_reply(int cnum,uint16 vuid,char *outbuf, /**************************************************************************** the buffer was too small ****************************************************************************/ -static BOOL api_TooSmall(int cnum,uint16 vuid, char *param,char *data, +static BOOL api_TooSmall(connection_struct *conn,uint16 vuid, char *param,char *data, int mdrcnt,int mprcnt, char **rdata,char **rparam, int *rdata_len,int *rparam_len) @@ -3468,7 +3468,7 @@ static BOOL api_TooSmall(int cnum,uint16 vuid, char *param,char *data, /**************************************************************************** the request is not supported ****************************************************************************/ -static BOOL api_Unsupported(int cnum,uint16 vuid, char *param,char *data, +static BOOL api_Unsupported(connection_struct *conn,uint16 vuid, char *param,char *data, int mdrcnt,int mprcnt, char **rdata,char **rparam, int *rdata_len,int *rparam_len) @@ -3493,7 +3493,8 @@ struct { char *name; int id; - BOOL (*fn)(int,uint16,char *,char *,int,int,char **,char **,int *,int *); + BOOL (*fn)(connection_struct *,uint16,char *,char *, + int,int,char **,char **,int *,int *); int flags; } api_commands[] = { {"RNetShareEnum", 0, api_RNetShareEnum,0}, @@ -3531,7 +3532,7 @@ struct /**************************************************************************** handle remote api calls ****************************************************************************/ -static int api_reply(int cnum,uint16 vuid,char *outbuf,char *data,char *params, +static int api_reply(connection_struct *conn,uint16 vuid,char *outbuf,char *data,char *params, int tdscnt,int tpscnt,int mdrcnt,int mprcnt) { int api_command = SVAL(params,0); @@ -3558,21 +3559,21 @@ static int api_reply(int cnum,uint16 vuid,char *outbuf,char *data,char *params, rdata = (char *)malloc(1024); if (rdata) bzero(rdata,1024); rparam = (char *)malloc(1024); if (rparam) bzero(rparam,1024); - reply = api_commands[i].fn(cnum,vuid,params,data,mdrcnt,mprcnt, + reply = api_commands[i].fn(conn,vuid,params,data,mdrcnt,mprcnt, &rdata,&rparam,&rdata_len,&rparam_len); if (rdata_len > mdrcnt || rparam_len > mprcnt) { - reply = api_TooSmall(cnum,vuid,params,data,mdrcnt,mprcnt, + reply = api_TooSmall(conn,vuid,params,data,mdrcnt,mprcnt, &rdata,&rparam,&rdata_len,&rparam_len); } /* if we get False back then it's actually unsupported */ if (!reply) - api_Unsupported(cnum,vuid,params,data,mdrcnt,mprcnt, + api_Unsupported(conn,vuid,params,data,mdrcnt,mprcnt, &rdata,&rparam,&rdata_len,&rparam_len); @@ -3597,7 +3598,7 @@ static int api_reply(int cnum,uint16 vuid,char *outbuf,char *data,char *params, /**************************************************************************** handle named pipe commands ****************************************************************************/ -static int named_pipe(int cnum,uint16 vuid, char *outbuf,char *name, +static int named_pipe(connection_struct *conn,uint16 vuid, char *outbuf,char *name, uint16 *setup,char *data,char *params, int suwcnt,int tdscnt,int tpscnt, int msrcnt,int mdrcnt,int mprcnt) @@ -3606,12 +3607,12 @@ static int named_pipe(int cnum,uint16 vuid, char *outbuf,char *name, if (strequal(name,"LANMAN")) { - return api_reply(cnum,vuid,outbuf,data,params,tdscnt,tpscnt,mdrcnt,mprcnt); + return api_reply(conn,vuid,outbuf,data,params,tdscnt,tpscnt,mdrcnt,mprcnt); } if (strlen(name) < 1) { - return api_fd_reply(cnum,vuid,outbuf,setup,data,params,suwcnt,tdscnt,tpscnt,mdrcnt,mprcnt); + return api_fd_reply(conn,vuid,outbuf,setup,data,params,suwcnt,tdscnt,tpscnt,mdrcnt,mprcnt); } if (setup) @@ -3626,141 +3627,132 @@ static int named_pipe(int cnum,uint16 vuid, char *outbuf,char *name, /**************************************************************************** reply to a SMBtrans ****************************************************************************/ -int reply_trans(char *inbuf,char *outbuf, int size, int bufsize) -{ - fstring name; - - char *data=NULL,*params=NULL; - uint16 *setup=NULL; - - int outsize = 0; - int cnum = SVAL(inbuf,smb_tid); - uint16 vuid = SVAL(inbuf,smb_uid); - - int tpscnt = SVAL(inbuf,smb_vwv0); - int tdscnt = SVAL(inbuf,smb_vwv1); - int mprcnt = SVAL(inbuf,smb_vwv2); - int mdrcnt = SVAL(inbuf,smb_vwv3); - int msrcnt = CVAL(inbuf,smb_vwv4); - BOOL close_on_completion = BITSETW(inbuf+smb_vwv5,0); - BOOL one_way = BITSETW(inbuf+smb_vwv5,1); - int pscnt = SVAL(inbuf,smb_vwv9); - int psoff = SVAL(inbuf,smb_vwv10); - int dscnt = SVAL(inbuf,smb_vwv11); - int dsoff = SVAL(inbuf,smb_vwv12); - int suwcnt = CVAL(inbuf,smb_vwv13); - - bzero(name, sizeof(name)); - fstrcpy(name,smb_buf(inbuf)); - - if (dscnt > tdscnt || pscnt > tpscnt) { - exit_server("invalid trans parameters\n"); - } +int reply_trans(connection_struct *conn, char *inbuf,char *outbuf, int size, int bufsize) +{ + fstring name; + + char *data=NULL,*params=NULL; + uint16 *setup=NULL; + int outsize = 0; + uint16 vuid = SVAL(inbuf,smb_uid); + int tpscnt = SVAL(inbuf,smb_vwv0); + int tdscnt = SVAL(inbuf,smb_vwv1); + int mprcnt = SVAL(inbuf,smb_vwv2); + int mdrcnt = SVAL(inbuf,smb_vwv3); + int msrcnt = CVAL(inbuf,smb_vwv4); + BOOL close_on_completion = BITSETW(inbuf+smb_vwv5,0); + BOOL one_way = BITSETW(inbuf+smb_vwv5,1); + int pscnt = SVAL(inbuf,smb_vwv9); + int psoff = SVAL(inbuf,smb_vwv10); + int dscnt = SVAL(inbuf,smb_vwv11); + int dsoff = SVAL(inbuf,smb_vwv12); + int suwcnt = CVAL(inbuf,smb_vwv13); + + bzero(name, sizeof(name)); + fstrcpy(name,smb_buf(inbuf)); + + if (dscnt > tdscnt || pscnt > tpscnt) { + exit_server("invalid trans parameters\n"); + } - if (tdscnt) - { - data = (char *)malloc(tdscnt); - memcpy(data,smb_base(inbuf)+dsoff,dscnt); - } - if (tpscnt) - { - params = (char *)malloc(tpscnt); - memcpy(params,smb_base(inbuf)+psoff,pscnt); - } + if (tdscnt) { + data = (char *)malloc(tdscnt); + memcpy(data,smb_base(inbuf)+dsoff,dscnt); + } - if (suwcnt) - { - int i; - setup = (uint16 *)malloc(suwcnt*sizeof(setup[0])); - for (i=0;i<suwcnt;i++) - setup[i] = SVAL(inbuf,smb_vwv14+i*SIZEOFWORD); - } + if (tpscnt) { + params = (char *)malloc(tpscnt); + memcpy(params,smb_base(inbuf)+psoff,pscnt); + } + if (suwcnt) { + int i; + setup = (uint16 *)malloc(suwcnt*sizeof(setup[0])); + for (i=0;i<suwcnt;i++) + setup[i] = SVAL(inbuf,smb_vwv14+i*SIZEOFWORD); + } - if (pscnt < tpscnt || dscnt < tdscnt) - { - /* We need to send an interim response then receive the rest - of the parameter/data bytes */ - outsize = set_message(outbuf,0,0,True); - show_msg(outbuf); - send_smb(Client,outbuf); - } - /* receive the rest of the trans packet */ - while (pscnt < tpscnt || dscnt < tdscnt) - { - BOOL ret; - int pcnt,poff,dcnt,doff,pdisp,ddisp; - - ret = receive_next_smb(Client,oplock_sock,inbuf,bufsize,SMB_SECONDARY_WAIT); - - if ((ret && (CVAL(inbuf, smb_com) != SMBtrans)) || !ret) { - if(ret) { - DEBUG(0,("reply_trans: Invalid secondary trans packet\n")); - } else { - DEBUG(0,("reply_trans: %s in getting secondary trans response.\n", - (smb_read_error == READ_ERROR) ? "error" : "timeout" )); - } - if (params) free(params); - if (data) free(data); - if (setup) free(setup); - return(ERROR(ERRSRV,ERRerror)); - } + if (pscnt < tpscnt || dscnt < tdscnt) { + /* We need to send an interim response then receive the rest + of the parameter/data bytes */ + outsize = set_message(outbuf,0,0,True); + show_msg(outbuf); + send_smb(Client,outbuf); + } - show_msg(inbuf); + /* receive the rest of the trans packet */ + while (pscnt < tpscnt || dscnt < tdscnt) { + BOOL ret; + int pcnt,poff,dcnt,doff,pdisp,ddisp; - tpscnt = SVAL(inbuf,smb_vwv0); - tdscnt = SVAL(inbuf,smb_vwv1); + ret = receive_next_smb(Client,oplock_sock,inbuf,bufsize,SMB_SECONDARY_WAIT); + + if ((ret && (CVAL(inbuf, smb_com) != SMBtrans)) || !ret) { + if(ret) { + DEBUG(0,("reply_trans: Invalid secondary trans packet\n")); + } else { + DEBUG(0,("reply_trans: %s in getting secondary trans response.\n", + (smb_read_error == READ_ERROR) ? "error" : "timeout" )); + } + if (params) free(params); + if (data) free(data); + if (setup) free(setup); + return(ERROR(ERRSRV,ERRerror)); + } - pcnt = SVAL(inbuf,smb_vwv2); - poff = SVAL(inbuf,smb_vwv3); - pdisp = SVAL(inbuf,smb_vwv4); - - dcnt = SVAL(inbuf,smb_vwv5); - doff = SVAL(inbuf,smb_vwv6); - ddisp = SVAL(inbuf,smb_vwv7); + show_msg(inbuf); - pscnt += pcnt; - dscnt += dcnt; - - if (dscnt > tdscnt || pscnt > tpscnt) { - exit_server("invalid trans parameters\n"); - } - - if (pcnt) - memcpy(params+pdisp,smb_base(inbuf)+poff,pcnt); - if (dcnt) - memcpy(data+ddisp,smb_base(inbuf)+doff,dcnt); - } - - - DEBUG(3,("trans <%s> data=%d params=%d setup=%d\n",name,tdscnt,tpscnt,suwcnt)); - - if (strncmp(name,"\\PIPE\\",strlen("\\PIPE\\")) == 0) - { - DEBUG(5,("calling named_pipe\n")); - outsize = named_pipe(cnum,vuid,outbuf,name+strlen("\\PIPE\\"),setup,data,params, - suwcnt,tdscnt,tpscnt,msrcnt,mdrcnt,mprcnt); - } - else - { - DEBUG(3,("invalid pipe name\n")); - outsize = 0; - } - - - if (data) free(data); - if (params) free(params); - if (setup) free(setup); - - if (close_on_completion) - close_cnum(cnum,vuid); + tpscnt = SVAL(inbuf,smb_vwv0); + tdscnt = SVAL(inbuf,smb_vwv1); + + pcnt = SVAL(inbuf,smb_vwv2); + poff = SVAL(inbuf,smb_vwv3); + pdisp = SVAL(inbuf,smb_vwv4); + + dcnt = SVAL(inbuf,smb_vwv5); + doff = SVAL(inbuf,smb_vwv6); + ddisp = SVAL(inbuf,smb_vwv7); + + pscnt += pcnt; + dscnt += dcnt; + + if (dscnt > tdscnt || pscnt > tpscnt) { + exit_server("invalid trans parameters\n"); + } + + if (pcnt) + memcpy(params+pdisp,smb_base(inbuf)+poff,pcnt); + if (dcnt) + memcpy(data+ddisp,smb_base(inbuf)+doff,dcnt); + } + + + DEBUG(3,("trans <%s> data=%d params=%d setup=%d\n", + name,tdscnt,tpscnt,suwcnt)); + + if (strncmp(name,"\\PIPE\\",strlen("\\PIPE\\")) == 0) { + DEBUG(5,("calling named_pipe\n")); + outsize = named_pipe(conn,vuid,outbuf,name+strlen("\\PIPE\\"),setup,data,params, + suwcnt,tdscnt,tpscnt,msrcnt,mdrcnt,mprcnt); + } else { + DEBUG(3,("invalid pipe name\n")); + outsize = 0; + } - if (one_way) - return(-1); - - if (outsize == 0) - return(ERROR(ERRSRV,ERRnosupport)); + + if (data) free(data); + if (params) free(params); + if (setup) free(setup); + + if (close_on_completion) + close_cnum(conn,vuid); - return(outsize); + if (one_way) + return(-1); + + if (outsize == 0) + return(ERROR(ERRSRV,ERRnosupport)); + + return(outsize); } diff --git a/source3/smbd/mangle.c b/source3/smbd/mangle.c index f33b8ac2e6..0703a4a74e 100644 --- a/source3/smbd/mangle.c +++ b/source3/smbd/mangle.c @@ -418,31 +418,6 @@ BOOL is_8_3( char *fname, BOOL check_case ) return( True ); } /* is_8_3 */ -/* ************************************************************************** ** - * Provide a checksum on a string - * - * Input: s - the nul-terminated character string for which the checksum - * will be calculated. - * - * Output: The checksum value calculated for s. - * - * ************************************************************************** ** - */ -int str_checksum( char *s ) - { - int res = 0; - int c; - int i=0; - - while( *s ) - { - c = *s; - res ^= (c << (i % 15)) ^ (c >> (15-(i%15))); - s++; - i++; - } - return(res); - } /* str_checksum */ /* ************************************************************************** ** * Compare two cache keys and return a value indicating their ordinal diff --git a/source3/smbd/message.c b/source3/smbd/message.c index 44ae272bdd..001fc652b2 100644 --- a/source3/smbd/message.c +++ b/source3/smbd/message.c @@ -78,7 +78,7 @@ static void msg_deliver(void) string_sub(s,"%s",name); string_sub(s,"%f",msgfrom); string_sub(s,"%t",msgto); - standard_sub(-1,s); + standard_sub_basic(s); smbrun(s,NULL,False); } @@ -90,7 +90,8 @@ static void msg_deliver(void) /**************************************************************************** reply to a sends ****************************************************************************/ -int reply_sends(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_sends(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { int len; char *orig,*dest,*msg; @@ -128,7 +129,8 @@ int reply_sends(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) /**************************************************************************** reply to a sendstrt ****************************************************************************/ -int reply_sendstrt(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_sendstrt(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { char *orig,*dest; int outsize = 0; @@ -155,7 +157,8 @@ int reply_sendstrt(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) /**************************************************************************** reply to a sendtxt ****************************************************************************/ -int reply_sendtxt(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_sendtxt(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { int len; int outsize = 0; @@ -183,7 +186,8 @@ int reply_sendtxt(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) /**************************************************************************** reply to a sendend ****************************************************************************/ -int reply_sendend(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_sendend(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { int outsize = 0; @@ -192,7 +196,7 @@ int reply_sendend(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) outsize = set_message(outbuf,0,0,True); - DEBUG( 3, ( "%s SMBsendend\n" ) ); + DEBUG(3,("SMBsendend\n")); msg_deliver(); diff --git a/source3/smbd/nttrans.c b/source3/smbd/nttrans.c index 8709b9c646..bff61b6736 100644 --- a/source3/smbd/nttrans.c +++ b/source3/smbd/nttrans.c @@ -25,7 +25,6 @@ extern int DEBUGLEVEL; extern int Protocol; extern int chain_fnum; -extern connection_struct Connections[]; extern files_struct Files[]; extern int Client; extern int oplock_sock; @@ -363,10 +362,9 @@ static int map_share_mode( uint32 desired_access, uint32 share_access, uint32 fi /**************************************************************************** Reply to an NT create and X call on a pipe. ****************************************************************************/ - -static int nt_open_pipe(char *fname, char *inbuf, char *outbuf, int *ppnum) +static int nt_open_pipe(char *fname, connection_struct *conn, + char *inbuf, char *outbuf, int *ppnum) { - int cnum = SVAL(inbuf,smb_tid); int pnum = -1; uint16 vuid = SVAL(inbuf, smb_uid); int i; @@ -386,7 +384,7 @@ static int nt_open_pipe(char *fname, char *inbuf, char *outbuf, int *ppnum) DEBUG(3,("nt_open_pipe: Known pipe %s opening.\n", fname)); - pnum = open_rpc_pipe_hnd(fname, cnum, vuid); + pnum = open_rpc_pipe_hnd(fname, conn, vuid); if (pnum < 0) return(ERROR(ERRSRV,ERRnofids)); @@ -397,280 +395,291 @@ static int nt_open_pipe(char *fname, char *inbuf, char *outbuf, int *ppnum) /**************************************************************************** Reply to an NT create and X call. ****************************************************************************/ - -int reply_ntcreate_and_X(char *inbuf,char *outbuf,int length,int bufsize) +int reply_ntcreate_and_X(connection_struct *conn, + char *inbuf,char *outbuf,int length,int bufsize) { - pstring fname; - int cnum = SVAL(inbuf,smb_tid); - int fnum = -1; - uint32 flags = IVAL(inbuf,smb_ntcreate_Flags); - uint32 desired_access = IVAL(inbuf,smb_ntcreate_DesiredAccess); - uint32 file_attributes = IVAL(inbuf,smb_ntcreate_FileAttributes); - uint32 share_access = IVAL(inbuf,smb_ntcreate_ShareAccess); - uint32 create_disposition = IVAL(inbuf,smb_ntcreate_CreateDisposition); - uint32 fname_len = MIN(((uint32)SVAL(inbuf,smb_ntcreate_NameLength)), - ((uint32)sizeof(fname)-1)); - int smb_ofun; - int smb_open_mode; - int smb_attr = (file_attributes & SAMBA_ATTRIBUTES_MASK); - /* Breakout the oplock request bits so we can set the - reply bits separately. */ - int oplock_request = 0; - int unixmode; - int fmode=0,mtime=0,rmode=0; - off_t file_len = 0; - struct stat sbuf; - int smb_action = 0; - BOOL bad_path = False; - files_struct *fsp; - char *p = NULL; - - /* - * We need to construct the open_and_X ofun value from the - * NT values, as that's what our code is structured to accept. - */ - - if((smb_ofun = map_create_disposition( create_disposition )) == -1) - return(ERROR(ERRDOS,ERRbadaccess)); - - /* - * Now contruct the smb_open_mode value from the desired access - * and the share access. - */ - - if((smb_open_mode = map_share_mode( desired_access, share_access, file_attributes)) == -1) - return(ERROR(ERRDOS,ERRbadaccess)); - - /* - * Get the file name. - */ - StrnCpy(fname,smb_buf(inbuf),fname_len); - fname[fname_len] = '\0'; - - /* If it's an IPC, use the pipe handler. */ - if (IS_IPC(cnum)) { - int ret = nt_open_pipe(fname, inbuf, outbuf, &fnum); - if(ret != 0) - return ret; - smb_action = FILE_WAS_OPENED; - } else { - - /* - * Ordinary file or directory. - */ - - /* - * Check if POSIX semantics are wanted. - */ - - set_posix_case_semantics(file_attributes); - - unix_convert(fname,cnum,0,&bad_path); - - fnum = find_free_file(); - if (fnum < 0) { - restore_case_semantics(file_attributes); - return(ERROR(ERRSRV,ERRnofids)); - } - - fsp = &Files[fnum]; - - if (!check_name(fname,cnum)) { - if((errno == ENOENT) && bad_path) { - unix_ERR_class = ERRDOS; - unix_ERR_code = ERRbadpath; - } - fsp->reserved = False; - - restore_case_semantics(file_attributes); - - return(UNIXERROR(ERRDOS,ERRnoaccess)); - } - - unixmode = unix_mode(cnum,smb_attr | aARCH); - - oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0; - oplock_request |= (flags & REQUEST_BATCH_OPLOCK) ? BATCH_OPLOCK : 0; - - /* - * If it's a request for a directory open, deal with it separately. - */ - - if(flags & OPEN_DIRECTORY) { - oplock_request = 0; - - open_directory(fnum, cnum, fname, smb_ofun, unixmode, &smb_action); - - restore_case_semantics(file_attributes); - - if(!fsp->open) { - fsp->reserved = False; - return(UNIXERROR(ERRDOS,ERRnoaccess)); - } - } else { - - /* - * Ordinary file case. - */ - - /* - * NB. We have a potential bug here. If we cause an oplock - * break to ourselves, then we could end up processing filename - * related SMB requests whilst we await the oplock break - * response. As we may have changed the filename case - * semantics to be POSIX-like, this could mean a filename - * request could fail when it should succeed. This is a - * rare condition, but eventually we must arrange to restore - * the correct case semantics before issuing an oplock break - * request to our client. JRA. - */ - - open_file_shared(fnum,cnum,fname,smb_open_mode,smb_ofun,unixmode, - oplock_request,&rmode,&smb_action); - - if (!fsp->open) { - /* - * We cheat here. The only case we care about is a directory - * rename, where the NT client will attempt to open the source - * directory for DELETE access. Note that when the NT client - * does this it does *not* set the directory bit in the - * request packet. This is translated into a read/write open - * request. POSIX states that any open for write request on a directory - * will generate an EISDIR error, so we can catch this here and open - * a pseudo handle that is flagged as a directory. JRA. - */ - - if(errno == EISDIR) { - oplock_request = 0; - - open_directory(fnum, cnum, fname, smb_ofun, unixmode, &smb_action); - - if(!fsp->open) { - fsp->reserved = False; - restore_case_semantics(file_attributes); - return(UNIXERROR(ERRDOS,ERRnoaccess)); - } - } else { - if((errno == ENOENT) && bad_path) { - unix_ERR_class = ERRDOS; - unix_ERR_code = ERRbadpath; - } - - fsp->reserved = False; - - restore_case_semantics(file_attributes); + pstring fname; + int fnum = -1; + uint32 flags = IVAL(inbuf,smb_ntcreate_Flags); + uint32 desired_access = IVAL(inbuf,smb_ntcreate_DesiredAccess); + uint32 file_attributes = IVAL(inbuf,smb_ntcreate_FileAttributes); + uint32 share_access = IVAL(inbuf,smb_ntcreate_ShareAccess); + uint32 create_disposition = IVAL(inbuf,smb_ntcreate_CreateDisposition); + uint32 fname_len = MIN(((uint32)SVAL(inbuf,smb_ntcreate_NameLength)), + ((uint32)sizeof(fname)-1)); + int smb_ofun; + int smb_open_mode; + int smb_attr = (file_attributes & SAMBA_ATTRIBUTES_MASK); + /* Breakout the oplock request bits so we can set the + reply bits separately. */ + int oplock_request = 0; + int unixmode; + int fmode=0,mtime=0,rmode=0; + off_t file_len = 0; + struct stat sbuf; + int smb_action = 0; + BOOL bad_path = False; + files_struct *fsp=NULL; + char *p = NULL; + + /* + * We need to construct the open_and_X ofun value from the + * NT values, as that's what our code is structured to accept. + */ + + if((smb_ofun = map_create_disposition( create_disposition )) == -1) + return(ERROR(ERRDOS,ERRbadaccess)); + + /* + * Now contruct the smb_open_mode value from the desired access + * and the share access. + */ + + if((smb_open_mode = map_share_mode(desired_access, + share_access, + file_attributes)) == -1) { + return(ERROR(ERRDOS,ERRbadaccess)); + } - return(UNIXERROR(ERRDOS,ERRnoaccess)); - } - } - } - - if(fsp->is_directory) { - if(sys_stat(fsp->name, &sbuf) != 0) { - close_directory(fnum); - restore_case_semantics(file_attributes); - return(ERROR(ERRDOS,ERRnoaccess)); - } - } else { - if (fstat(fsp->fd_ptr->fd,&sbuf) != 0) { - close_file(fnum,False); - restore_case_semantics(file_attributes); - return(ERROR(ERRDOS,ERRnoaccess)); - } - } - - restore_case_semantics(file_attributes); - - file_len = sbuf.st_size; - fmode = dos_mode(cnum,fname,&sbuf); - if(fmode == 0) - fmode = FILE_ATTRIBUTE_NORMAL; - mtime = sbuf.st_mtime; - if (!fsp->is_directory && (fmode & aDIR)) { - close_file(fnum,False); - return(ERROR(ERRDOS,ERRnoaccess)); - } - - /* - * If the caller set the extended oplock request bit - * and we granted one (by whatever means) - set the - * correct bit for extended oplock reply. - */ + /* + * Get the file name. + */ + StrnCpy(fname,smb_buf(inbuf),fname_len); + fname[fname_len] = '\0'; + + /* If it's an IPC, use the pipe handler. */ + if (IS_IPC(conn)) { + int ret = nt_open_pipe(fname, conn, inbuf, outbuf, &fnum); + if(ret != 0) + return ret; + smb_action = FILE_WAS_OPENED; + } else { + + /* + * Ordinary file or directory. + */ + + /* + * Check if POSIX semantics are wanted. + */ + + set_posix_case_semantics(file_attributes); + + unix_convert(fname,conn,0,&bad_path); + + fnum = find_free_file(); + if (fnum < 0) { + restore_case_semantics(file_attributes); + return(ERROR(ERRSRV,ERRnofids)); + } + + fsp = &Files[fnum]; + + if (!check_name(fname,conn)) { + if((errno == ENOENT) && bad_path) { + unix_ERR_class = ERRDOS; + unix_ERR_code = ERRbadpath; + } + fsp->reserved = False; + + restore_case_semantics(file_attributes); + + return(UNIXERROR(ERRDOS,ERRnoaccess)); + } + + unixmode = unix_mode(conn,smb_attr | aARCH); - if (oplock_request && lp_fake_oplocks(SNUM(cnum))) - smb_action |= EXTENDED_OPLOCK_GRANTED; - - if(oplock_request && fsp->granted_oplock) - smb_action |= EXTENDED_OPLOCK_GRANTED; - } - - set_message(outbuf,34,0,True); - - p = outbuf + smb_vwv2; - - /* - * Currently as we don't support level II oplocks we just report - * exclusive & batch here. - */ - - SCVAL(p,0, (smb_action & EXTENDED_OPLOCK_GRANTED ? 1 : 0)); - p++; - SSVAL(p,0,fnum); - p += 2; - SIVAL(p,0,smb_action); - p += 4; - - if (IS_IPC(cnum)) { - /* - * Deal with pipe return. - */ - p += 32; - SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */ - p += 20; - /* File type. */ - SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE); - /* Device state. */ - SSVAL(p,2, 0x5FF); /* ? */ - } else { - /* - * Deal with file return. - */ - /* Create time. */ - put_long_date(p,get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(cnum)))); - p += 8; - put_long_date(p,sbuf.st_atime); /* access time */ - p += 8; - put_long_date(p,sbuf.st_mtime); /* write time */ - p += 8; - put_long_date(p,sbuf.st_mtime); /* change time */ - p += 8; - SIVAL(p,0,fmode); /* File Attributes. */ - p += 12; + oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0; + oplock_request |= (flags & REQUEST_BATCH_OPLOCK) ? BATCH_OPLOCK : 0; + + /* + * If it's a request for a directory open, deal with it separately. + */ + + if(flags & OPEN_DIRECTORY) { + oplock_request = 0; + + open_directory(fnum, conn, fname, smb_ofun, + unixmode, &smb_action); + + restore_case_semantics(file_attributes); + + if(!fsp->open) { + fsp->reserved = False; + return(UNIXERROR(ERRDOS,ERRnoaccess)); + } + } else { + /* + * Ordinary file case. + */ + + /* NB. We have a potential bug here. If we + * cause an oplock break to ourselves, then we + * could end up processing filename related + * SMB requests whilst we await the oplock + * break response. As we may have changed the + * filename case semantics to be POSIX-like, + * this could mean a filename request could + * fail when it should succeed. This is a rare + * condition, but eventually we must arrange + * to restore the correct case semantics + * before issuing an oplock break request to + * our client. JRA. */ + + open_file_shared(fnum,conn,fname,smb_open_mode, + smb_ofun,unixmode, + oplock_request,&rmode,&smb_action); + + if (!fsp->open) { + /* We cheat here. The only case we + * care about is a directory rename, + * where the NT client will attempt to + * open the source directory for + * DELETE access. Note that when the + * NT client does this it does *not* + * set the directory bit in the * + * request packet. This is translated + * into a read/write open * + * request. POSIX states that any open + * for write request on a directory * + * will generate an EISDIR error, so + * we can catch this here and open * a + * pseudo handle that is flagged as a + * directory. JRA. */ + + if(errno == EISDIR) { + oplock_request = 0; + + open_directory(fnum, conn, fname, smb_ofun, unixmode, &smb_action); + + if(!fsp->open) { + fsp->reserved = False; + restore_case_semantics(file_attributes); + return(UNIXERROR(ERRDOS,ERRnoaccess)); + } + } else { + if((errno == ENOENT) && bad_path) { + unix_ERR_class = ERRDOS; + unix_ERR_code = ERRbadpath; + } + + fsp->reserved = False; + + restore_case_semantics(file_attributes); + + return(UNIXERROR(ERRDOS,ERRnoaccess)); + } + } + } + + if(fsp->is_directory) { + if(sys_stat(fsp->fsp_name, &sbuf) != 0) { + close_directory(fnum); + restore_case_semantics(file_attributes); + return(ERROR(ERRDOS,ERRnoaccess)); + } + } else { + if (fstat(fsp->fd_ptr->fd,&sbuf) != 0) { + close_file(fnum,False); + restore_case_semantics(file_attributes); + return(ERROR(ERRDOS,ERRnoaccess)); + } + } + + restore_case_semantics(file_attributes); + + file_len = sbuf.st_size; + fmode = dos_mode(conn,fname,&sbuf); + if(fmode == 0) + fmode = FILE_ATTRIBUTE_NORMAL; + mtime = sbuf.st_mtime; + if (!fsp->is_directory && (fmode & aDIR)) { + close_file(fnum,False); + return(ERROR(ERRDOS,ERRnoaccess)); + } + + /* + * If the caller set the extended oplock request bit + * and we granted one (by whatever means) - set the + * correct bit for extended oplock reply. + */ + + if (oplock_request && lp_fake_oplocks(SNUM(conn))) + smb_action |= EXTENDED_OPLOCK_GRANTED; + + if(oplock_request && fsp->granted_oplock) + smb_action |= EXTENDED_OPLOCK_GRANTED; + } + + set_message(outbuf,34,0,True); + + p = outbuf + smb_vwv2; + + /* + * Currently as we don't support level II oplocks we just report + * exclusive & batch here. + */ + + SCVAL(p,0, (smb_action & EXTENDED_OPLOCK_GRANTED ? 1 : 0)); + p++; + SSVAL(p,0,fnum); + p += 2; + SIVAL(p,0,smb_action); + p += 4; + + if (IS_IPC(conn)) { + /* + * Deal with pipe return. + */ + p += 32; + SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */ + p += 20; + /* File type. */ + SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE); + /* Device state. */ + SSVAL(p,2, 0x5FF); /* ? */ + } else { + /* + * Deal with file return. + */ + /* Create time. */ + put_long_date(p,get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(conn)))); + p += 8; + put_long_date(p,sbuf.st_atime); /* access time */ + p += 8; + put_long_date(p,sbuf.st_mtime); /* write time */ + p += 8; + put_long_date(p,sbuf.st_mtime); /* change time */ + p += 8; + SIVAL(p,0,fmode); /* File Attributes. */ + p += 12; #if OFF_T_IS_64_BITS - SIVAL(p,0, file_len & 0xFFFFFFFF); - SIVAL(p,4, file_len >> 32); + SIVAL(p,0, file_len & 0xFFFFFFFF); + SIVAL(p,4, file_len >> 32); #else /* OFF_T_IS_64_BITS */ - SIVAL(p,0,file_len); + SIVAL(p,0,file_len); #endif /* OFF_T_IS_64_BITS */ - p += 12; - SCVAL(p,0,fsp->is_directory ? 1 : 0); - } - - chain_fnum = fnum; + p += 12; + SCVAL(p,0,fsp->is_directory ? 1 : 0); + } + + chain_fnum = fnum; - DEBUG(5,("reply_ntcreate_and_X: open fnum = %d, name = %s\n", - fnum, fsp->name )); + + DEBUG(5,("reply_ntcreate_and_X: open fnum = %d, name = %s\n", + fnum, fsp?fsp->fsp_name:"NULL")); - return chain_reply(inbuf,outbuf,length,bufsize); + return chain_reply(inbuf,outbuf,length,bufsize); } /**************************************************************************** Reply to a NT_TRANSACT_CREATE call (needs to process SD's). ****************************************************************************/ - -static int call_nt_transact_create(char *inbuf, char *outbuf, int length, - int bufsize, int cnum, - char **ppsetup, char **ppparams, char **ppdata) +static int call_nt_transact_create(connection_struct *conn, + char *inbuf, char *outbuf, int length, + int bufsize, + char **ppsetup, char **ppparams, + char **ppdata) { pstring fname; int fnum = -1; @@ -721,8 +730,8 @@ static int call_nt_transact_create(char *inbuf, char *outbuf, int length, fname[fname_len] = '\0'; /* If it's an IPC, use the pipe handler. */ - if (IS_IPC(cnum)) { - int ret = nt_open_pipe(fname, inbuf, outbuf, &fnum); + if (IS_IPC(conn)) { + int ret = nt_open_pipe(fname, conn, inbuf, outbuf, &fnum); if(ret != 0) return ret; smb_action = FILE_WAS_OPENED; @@ -733,7 +742,7 @@ static int call_nt_transact_create(char *inbuf, char *outbuf, int length, set_posix_case_semantics(file_attributes); - unix_convert(fname,cnum,0,&bad_path); + unix_convert(fname,conn,0,&bad_path); fnum = find_free_file(); if (fnum < 0) { @@ -743,7 +752,7 @@ static int call_nt_transact_create(char *inbuf, char *outbuf, int length, fsp = &Files[fnum]; - if (!check_name(fname,cnum)) { + if (!check_name(fname,conn)) { if((errno == ENOENT) && bad_path) { unix_ERR_class = ERRDOS; unix_ERR_code = ERRbadpath; @@ -755,7 +764,7 @@ static int call_nt_transact_create(char *inbuf, char *outbuf, int length, return(UNIXERROR(ERRDOS,ERRnoaccess)); } - unixmode = unix_mode(cnum,smb_attr | aARCH); + unixmode = unix_mode(conn,smb_attr | aARCH); oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0; oplock_request |= (flags & REQUEST_BATCH_OPLOCK) ? BATCH_OPLOCK : 0; @@ -774,7 +783,7 @@ static int call_nt_transact_create(char *inbuf, char *outbuf, int length, * CreateDirectory() call. */ - open_directory(fnum, cnum, fname, smb_ofun, unixmode, &smb_action); + open_directory(fnum, conn, fname, smb_ofun, unixmode, &smb_action); if(!fsp->open) { fsp->reserved = False; @@ -786,7 +795,7 @@ static int call_nt_transact_create(char *inbuf, char *outbuf, int length, * Ordinary file case. */ - open_file_shared(fnum,cnum,fname,smb_open_mode,smb_ofun,unixmode, + open_file_shared(fnum,conn,fname,smb_open_mode,smb_ofun,unixmode, oplock_request,&rmode,&smb_action); if (!fsp->open) { @@ -810,7 +819,7 @@ static int call_nt_transact_create(char *inbuf, char *outbuf, int length, } file_len = sbuf.st_size; - fmode = dos_mode(cnum,fname,&sbuf); + fmode = dos_mode(conn,fname,&sbuf); if(fmode == 0) fmode = FILE_ATTRIBUTE_NORMAL; mtime = sbuf.st_mtime; @@ -827,7 +836,7 @@ static int call_nt_transact_create(char *inbuf, char *outbuf, int length, * correct bit for extended oplock reply. */ - if (oplock_request && lp_fake_oplocks(SNUM(cnum))) + if (oplock_request && lp_fake_oplocks(SNUM(conn))) smb_action |= EXTENDED_OPLOCK_GRANTED; if(oplock_request && fsp->granted_oplock) @@ -850,7 +859,7 @@ static int call_nt_transact_create(char *inbuf, char *outbuf, int length, SIVAL(p,0,smb_action); p += 8; - if (IS_IPC(cnum)) { + if (IS_IPC(conn)) { /* * Deal with pipe return. */ @@ -866,7 +875,7 @@ static int call_nt_transact_create(char *inbuf, char *outbuf, int length, * Deal with file return. */ /* Create time. */ - put_long_date(p,get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(cnum)))); + put_long_date(p,get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(conn)))); p += 8; put_long_date(p,sbuf.st_atime); /* access time */ p += 8; @@ -893,39 +902,39 @@ static int call_nt_transact_create(char *inbuf, char *outbuf, int length, /**************************************************************************** Reply to a NT CANCEL request. ****************************************************************************/ - -int reply_ntcancel(char *inbuf,char *outbuf,int length,int bufsize) +int reply_ntcancel(connection_struct *conn, + char *inbuf,char *outbuf,int length,int bufsize) { - /* - * Go through and cancel any pending change notifies. - * TODO: When we add blocking locks we will add cancel - * for them here too. - */ - - int mid = SVAL(inbuf,smb_mid); - remove_pending_change_notify_requests_by_mid(mid); - - DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", mid)); - - return(-1); + /* + * Go through and cancel any pending change notifies. + * TODO: When we add blocking locks we will add cancel + * for them here too. + */ + + int mid = SVAL(inbuf,smb_mid); + remove_pending_change_notify_requests_by_mid(mid); + + DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", mid)); + + return(-1); } /**************************************************************************** Reply to an unsolicited SMBNTtranss - just ignore it! ****************************************************************************/ - -int reply_nttranss(char *inbuf,char *outbuf,int length,int bufsize) +int reply_nttranss(connection_struct *conn, + char *inbuf,char *outbuf,int length,int bufsize) { - DEBUG(4,("Ignoring nttranss of length %d\n",length)); - return(-1); + DEBUG(4,("Ignoring nttranss of length %d\n",length)); + return(-1); } /**************************************************************************** Reply to an NT transact rename command. ****************************************************************************/ - -static int call_nt_transact_rename(char *inbuf, char *outbuf, int length, - int bufsize, int cnum, +static int call_nt_transact_rename(connection_struct *conn, + char *inbuf, char *outbuf, int length, + int bufsize, char **ppsetup, char **ppparams, char **ppdata) { char *params = *ppparams; @@ -936,11 +945,11 @@ static int call_nt_transact_rename(char *inbuf, char *outbuf, int length, ((uint32)sizeof(new_name)-1)); int outsize = 0; - CHECK_FNUM(fnum, cnum); + CHECK_FNUM(fnum, conn); StrnCpy(new_name,params+4,fname_len); new_name[fname_len] = '\0'; - outsize = rename_internals(inbuf, outbuf, Files[fnum].name, + outsize = rename_internals(conn, inbuf, outbuf, Files[fnum].fsp_name, new_name, replace_if_exists); if(outsize == 0) { /* @@ -949,7 +958,7 @@ static int call_nt_transact_rename(char *inbuf, char *outbuf, int length, send_nt_replies(outbuf, bufsize, NULL, 0, NULL, 0); DEBUG(3,("nt transact rename from = %s, to = %s succeeded.\n", - Files[fnum].name, new_name)); + Files[fnum].fsp_name, new_name)); outsize = -1; } @@ -967,7 +976,7 @@ static int call_nt_transact_rename(char *inbuf, char *outbuf, int length, typedef struct { ubi_slNode msg_next; int fnum; - int cnum; + connection_struct *conn; time_t next_check_time; time_t modify_time; /* Info from the directory we're monitoring. */ time_t status_time; /* Info from the directory we're monitoring. */ @@ -1076,12 +1085,12 @@ void process_pending_change_notify_queue(time_t t) while((cnbp != NULL) && (cnbp->next_check_time <= t)) { struct stat st; int fnum = cnbp->fnum; - int cnum = cnbp->cnum; + connection_struct *conn = cnbp->conn; files_struct *fsp = &Files[fnum]; uint16 vuid = (lp_security() == SEC_SHARE) ? UID_FIELD_INVALID : SVAL(cnbp->request_buf,smb_uid); - if(!become_user(&Connections[cnum],cnum,vuid)) { + if(!become_user(conn,vuid)) { DEBUG(0,("process_pending_change_notify_queue: Unable to become user vuid=%d.\n", vuid )); /* @@ -1093,9 +1102,8 @@ void process_pending_change_notify_queue(time_t t) continue; } - if(!become_service(cnum,True)) { - DEBUG(0,("process_pending_change_notify_queue: Unable to become service cnum=%d. \ -Error was %s.\n", cnum, strerror(errno) )); + if(!become_service(conn,True)) { + DEBUG(0,("process_pending_change_notify_queue: Unable to become service Error was %s.\n", strerror(errno) )); /* * Remove the entry and return an error to the client. */ @@ -1106,9 +1114,9 @@ Error was %s.\n", cnum, strerror(errno) )); continue; } - if(sys_stat(fsp->name, &st) < 0) { + if(sys_stat(fsp->fsp_name, &st) < 0) { DEBUG(0,("process_pending_change_notify_queue: Unable to stat directory %s. \ -Error was %s.\n", fsp->name, strerror(errno) )); +Error was %s.\n", fsp->fsp_name, strerror(errno) )); /* * Remove the entry and return an error to the client. */ @@ -1125,7 +1133,7 @@ Error was %s.\n", fsp->name, strerror(errno) )); * Remove the entry and return a change notify to the client. */ DEBUG(5,("process_pending_change_notify_queue: directory fnum = %d, name = %s changed\n", - fnum, fsp->name )); + fnum, fsp->fsp_name )); change_notify_reply_packet(cnbp->request_buf,0,NT_STATUS_NOTIFY_ENUM_DIR); free((char *)ubi_slRemNext( &change_notify_queue, prev)); cnbp = (change_notify_buf *)(prev ? ubi_slNext(prev) : ubi_slFirst(&change_notify_queue)); @@ -1147,10 +1155,11 @@ Error was %s.\n", fsp->name, strerror(errno) )); Reply to a notify change - queue the request and don't allow a directory to be opened. ****************************************************************************/ - -static int call_nt_transact_notify_change(char *inbuf, char *outbuf, int length, - int bufsize, int cnum, - char **ppsetup, char **ppparams, char **ppdata) +static int call_nt_transact_notify_change(connection_struct *conn, + char *inbuf, char *outbuf, int length, + int bufsize, + char **ppsetup, + char **ppparams, char **ppdata) { char *setup = *ppsetup; files_struct *fsp; @@ -1167,7 +1176,7 @@ static int call_nt_transact_notify_change(char *inbuf, char *outbuf, int length, fsp = &Files[fnum]; - if((!fsp->open) || (!fsp->is_directory) || (cnum != fsp->cnum)) + if((!fsp->open) || (!fsp->is_directory) || (conn != fsp->conn)) return(ERROR(ERRDOS,ERRbadfid)); /* @@ -1187,16 +1196,16 @@ static int call_nt_transact_notify_change(char *inbuf, char *outbuf, int length, * Store the current timestamp on the directory we are monitoring. */ - if(sys_stat(fsp->name, &st) < 0) { + if(sys_stat(fsp->fsp_name, &st) < 0) { DEBUG(0,("call_nt_transact_notify_change: Unable to stat fnum = %d, name = %s. \ -Error was %s\n", fnum, fsp->name, strerror(errno) )); +Error was %s\n", fnum, fsp->fsp_name, strerror(errno) )); free((char *)cnbp); return(UNIXERROR(ERRDOS,ERRbadfid)); } memcpy(cnbp->request_buf, inbuf, smb_size); cnbp->fnum = fnum; - cnbp->cnum = cnum; + cnbp->conn = conn; cnbp->modify_time = st.st_mtime; cnbp->status_time = st.st_ctime; @@ -1211,7 +1220,7 @@ Error was %s\n", fnum, fsp->name, strerror(errno) )); ubi_slAddTail(&change_notify_queue, cnbp); DEBUG(3,("call_nt_transact_notify_change: notify change called on directory \ -fid=%d, name = %s\n", fnum, fsp->name )); +fid=%d, name = %s\n", fnum, fsp->fsp_name )); return -1; } @@ -1220,9 +1229,10 @@ fid=%d, name = %s\n", fnum, fsp->name )); Reply to query a security descriptor - currently this is not implemented (it is planned to be though). ****************************************************************************/ - -static int call_nt_transact_query_security_desc(char *inbuf, char *outbuf, int length, - int bufsize, int cnum, +static int call_nt_transact_query_security_desc(connection_struct *conn, + char *inbuf, char *outbuf, + int length, + int bufsize, char **ppsetup, char **ppparams, char **ppdata) { DEBUG(0,("call_nt_transact_query_security_desc: Currently not implemented.\n")); @@ -1233,21 +1243,23 @@ static int call_nt_transact_query_security_desc(char *inbuf, char *outbuf, int l Reply to set a security descriptor - currently this is not implemented (it is planned to be though). ****************************************************************************/ - -static int call_nt_transact_set_security_desc(char *inbuf, char *outbuf, int length, - int bufsize, int cnum, - char **ppsetup, char **ppparams, char **ppdata) +static int call_nt_transact_set_security_desc(connection_struct *conn, + char *inbuf, char *outbuf, + int length, + int bufsize, + char **ppsetup, + char **ppparams, char **ppdata) { - DEBUG(0,("call_nt_transact_set_security_desc: Currently not implemented.\n")); - return(ERROR(ERRSRV,ERRnosupport)); + DEBUG(0,("call_nt_transact_set_security_desc: Currently not implemented.\n")); + return(ERROR(ERRSRV,ERRnosupport)); } /**************************************************************************** Reply to IOCTL - not implemented - no plans. ****************************************************************************/ - -static int call_nt_transact_ioctl(char *inbuf, char *outbuf, int length, - int bufsize, int cnum, +static int call_nt_transact_ioctl(connection_struct *conn, + char *inbuf, char *outbuf, int length, + int bufsize, char **ppsetup, char **ppparams, char **ppdata) { DEBUG(0,("call_nt_transact_ioctl: Currently not implemented.\n")); @@ -1257,11 +1269,10 @@ static int call_nt_transact_ioctl(char *inbuf, char *outbuf, int length, /**************************************************************************** Reply to a SMBNTtrans. ****************************************************************************/ - -int reply_nttrans(char *inbuf,char *outbuf,int length,int bufsize) +int reply_nttrans(connection_struct *conn, + char *inbuf,char *outbuf,int length,int bufsize) { int outsize = 0; - int cnum = SVAL(inbuf,smb_tid); #if 0 /* Not used. */ uint16 max_setup_count = CVAL(inbuf, smb_nt_MaxSetupCount); uint32 max_parameter_count = IVAL(inbuf, smb_nt_MaxParameterCount); @@ -1394,39 +1405,45 @@ due to being in oplock break state.\n" )); /* Now we must call the relevant NT_TRANS function */ switch(function_code) { case NT_TRANSACT_CREATE: - outsize = call_nt_transact_create(inbuf, outbuf, length, bufsize, cnum, + outsize = call_nt_transact_create(conn, inbuf, outbuf, length, bufsize, &setup, ¶ms, &data); break; case NT_TRANSACT_IOCTL: - outsize = call_nt_transact_ioctl(inbuf, outbuf, length, bufsize, cnum, + outsize = call_nt_transact_ioctl(conn, + inbuf, outbuf, length, bufsize, &setup, ¶ms, &data); break; case NT_TRANSACT_SET_SECURITY_DESC: - outsize = call_nt_transact_set_security_desc(inbuf, outbuf, length, bufsize, cnum, + outsize = call_nt_transact_set_security_desc(conn, inbuf, outbuf, + length, bufsize, &setup, ¶ms, &data); break; case NT_TRANSACT_NOTIFY_CHANGE: - outsize = call_nt_transact_notify_change(inbuf, outbuf, length, bufsize, cnum, + outsize = call_nt_transact_notify_change(conn, inbuf, outbuf, + length, bufsize, &setup, ¶ms, &data); break; case NT_TRANSACT_RENAME: - outsize = call_nt_transact_rename(inbuf, outbuf, length, bufsize, cnum, + outsize = call_nt_transact_rename(conn, inbuf, outbuf, length, + bufsize, &setup, ¶ms, &data); break; + case NT_TRANSACT_QUERY_SECURITY_DESC: - outsize = call_nt_transact_query_security_desc(inbuf, outbuf, length, bufsize, cnum, + outsize = call_nt_transact_query_security_desc(conn, inbuf, outbuf, + length, bufsize, &setup, ¶ms, &data); break; - default: - /* Error in request */ - DEBUG(0,("reply_nttrans: Unknown request %d in nttrans call\n", function_code)); - if(setup) - free(setup); - if(params) - free(params); - if(data) - free(data); - return (ERROR(ERRSRV,ERRerror)); + default: + /* Error in request */ + DEBUG(0,("reply_nttrans: Unknown request %d in nttrans call\n", function_code)); + if(setup) + free(setup); + if(params) + free(params); + if(data) + free(data); + return (ERROR(ERRSRV,ERRerror)); } /* As we do not know how many data packets will need to be diff --git a/source3/smbd/pipes.c b/source3/smbd/pipes.c index 34884aa6d3..2a51e83946 100644 --- a/source3/smbd/pipes.c +++ b/source3/smbd/pipes.c @@ -58,10 +58,10 @@ extern struct pipe_id_info pipe_names[]; This code is basically stolen from reply_open_and_X with some wrinkles to handle pipes. ****************************************************************************/ -int reply_open_pipe_and_X(char *inbuf,char *outbuf,int length,int bufsize) +int reply_open_pipe_and_X(connection_struct *conn, + char *inbuf,char *outbuf,int length,int bufsize) { pstring fname; - uint16 cnum = SVAL(inbuf, smb_tid); uint16 vuid = SVAL(inbuf, smb_uid); int pnum = -1; int smb_ofun = SVAL(inbuf,smb_vwv8); @@ -95,7 +95,7 @@ int reply_open_pipe_and_X(char *inbuf,char *outbuf,int length,int bufsize) DEBUG(3,("Known pipe %s opening.\n",fname)); smb_ofun |= 0x10; /* Add Create it not exists flag */ - pnum = open_rpc_pipe_hnd(fname, cnum, vuid); + pnum = open_rpc_pipe_hnd(fname, conn, vuid); if (pnum < 0) return(ERROR(ERRSRV,ERRnofids)); /* Prepare the reply */ @@ -134,13 +134,10 @@ int reply_pipe_read_and_X(char *inbuf,char *outbuf,int length,int bufsize) uint32 smb_offs = IVAL(inbuf,smb_vwv3); int smb_maxcnt = SVAL(inbuf,smb_vwv5); int smb_mincnt = SVAL(inbuf,smb_vwv6); - int cnum; int nread = -1; char *data; BOOL ok = False; - cnum = SVAL(inbuf,smb_tid); - /* CHECK_FNUM(fnum,cnum); CHECK_READ(fnum); @@ -161,8 +158,8 @@ int reply_pipe_read_and_X(char *inbuf,char *outbuf,int length,int bufsize) SSVAL(outbuf,smb_vwv6,smb_offset(data,outbuf)); SSVAL(smb_buf(outbuf),-2,nread); - DEBUG( 3, ( "readX pnum=%04x cnum=%d min=%d max=%d nread=%d\n", - pnum, cnum, smb_mincnt, smb_maxcnt, nread ) ); + DEBUG(3,("readX pnum=%04x min=%d max=%d nread=%d\n", + pnum, smb_mincnt, smb_maxcnt, nread)); set_chain_pnum(pnum); @@ -171,15 +168,14 @@ int reply_pipe_read_and_X(char *inbuf,char *outbuf,int length,int bufsize) /**************************************************************************** reply to a close ****************************************************************************/ -int reply_pipe_close(char *inbuf,char *outbuf) +int reply_pipe_close(connection_struct *conn, char *inbuf,char *outbuf) { int pnum = get_rpc_pipe_num(inbuf,smb_vwv0); - int cnum = SVAL(inbuf,smb_tid); int outsize = set_message(outbuf,0,0,True); - DEBUG(5,("reply_pipe_close: pnum:%x cnum:%x\n", pnum, cnum)); + DEBUG(5,("reply_pipe_close: pnum:%x\n", pnum)); - if (!close_rpc_pipe_hnd(pnum, cnum)) return(ERROR(ERRDOS,ERRbadfid)); + if (!close_rpc_pipe_hnd(pnum, conn)) return(ERROR(ERRDOS,ERRbadfid)); return(outsize); } diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c index b0509bf3d5..66d1dd2839 100644 --- a/source3/smbd/reply.c +++ b/source3/smbd/reply.c @@ -35,7 +35,6 @@ extern int max_send; extern int max_recv; extern int chain_fnum; extern char magic_char; -extern connection_struct Connections[]; extern files_struct Files[]; extern BOOL case_sensitive; extern BOOL case_preserve; @@ -82,7 +81,7 @@ int reply_special(char *inbuf,char *outbuf) *name1 = *name2 = 0; - bzero(outbuf,smb_size); + bzero(outbuf,smb_size); smb_setlen(outbuf,0); @@ -127,7 +126,7 @@ int reply_special(char *inbuf,char *outbuf) reopen_logs(); if (lp_status(-1)) { - claim_connection(-1,"STATUS.",MAXSTATUS,True); + claim_connection(NULL,"STATUS.",MAXSTATUS,True); } break; @@ -149,8 +148,8 @@ int reply_special(char *inbuf,char *outbuf) return(0); } - DEBUG( 5, ( "init msg_type=0x%x msg_flags=0x%x\n", - msg_type, msg_flags ) ); + DEBUG(5,("init msg_type=0x%x msg_flags=0x%x\n", + msg_type, msg_flags)); return(outsize); } @@ -159,26 +158,13 @@ int reply_special(char *inbuf,char *outbuf) /******************************************************************* work out what error to give to a failed connection ********************************************************************/ -static int connection_error(char *inbuf,char *outbuf,int connection_num) +static int connection_error(char *inbuf,char *outbuf,int ecode) { - switch (connection_num) - { - case -8: - return(ERROR(ERRSRV,ERRnoresource)); - case -7: - return(ERROR(ERRSRV,ERRbaduid)); - case -6: - return(ERROR(ERRSRV,ERRinvdevice)); - case -5: - return(ERROR(ERRSRV,ERRinvnetname)); - case -4: - return(ERROR(ERRSRV,ERRaccess)); - case -3: - return(ERROR(ERRDOS,ERRnoipc)); - case -2: - return(ERROR(ERRSRV,ERRinvnetname)); - } - return(ERROR(ERRSRV,ERRbadpw)); + if (ecode == ERRnoipc) { + return(ERROR(ERRDOS,ERRnoipc)); + } + + return(ERROR(ERRSRV,ecode)); } @@ -223,147 +209,145 @@ static void parse_connect(char *p,char *service,char *user, /**************************************************************************** reply to a tcon ****************************************************************************/ -int reply_tcon(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_tcon(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { - pstring service; - pstring user; - pstring password; - pstring dev; - int connection_num; - int outsize = 0; - uint16 vuid = SVAL(inbuf,smb_uid); - int pwlen=0; - - *service = *user = *password = *dev = 0; - - parse_connect(smb_buf(inbuf)+1,service,user,password,&pwlen,dev); - - /* - * Pass the user through the NT -> unix user mapping - * function. - */ + pstring service; + pstring user; + pstring password; + pstring dev; + int outsize = 0; + uint16 vuid = SVAL(inbuf,smb_uid); + int pwlen=0; + int ecode = -1; + + *service = *user = *password = *dev = 0; + + parse_connect(smb_buf(inbuf)+1,service,user,password,&pwlen,dev); + + /* + * Pass the user through the NT -> unix user mapping + * function. + */ - (void)map_username(user); + (void)map_username(user); - /* - * Do any UNIX username case mangling. - */ - (void)Get_Pwnam( user, True); + /* + * Do any UNIX username case mangling. + */ + (void)Get_Pwnam( user, True); - connection_num = make_connection(service,user,password,pwlen,dev,vuid); + conn = make_connection(service,user,password,pwlen,dev,vuid,&ecode); - if (connection_num < 0) - return(connection_error(inbuf,outbuf,connection_num)); + if (!conn) { + return(connection_error(inbuf,outbuf,ecode)); + } - outsize = set_message(outbuf,2,0,True); - SSVAL(outbuf,smb_vwv0,max_recv); - SSVAL(outbuf,smb_vwv1,connection_num); - SSVAL(outbuf,smb_tid,connection_num); + outsize = set_message(outbuf,2,0,True); + SSVAL(outbuf,smb_vwv0,max_recv); + SSVAL(outbuf,smb_vwv1,conn->cnum); + SSVAL(outbuf,smb_tid,conn->cnum); - DEBUG(3,("tcon service=%s user=%s cnum=%d\n", service, user, connection_num)); + DEBUG(3,("tcon service=%s user=%s cnum=%d\n", + service, user, conn->cnum)); - return(outsize); + return(outsize); } /**************************************************************************** reply to a tcon and X ****************************************************************************/ -int reply_tcon_and_X(char *inbuf,char *outbuf,int length,int bufsize) +int reply_tcon_and_X(connection_struct *conn, char *inbuf,char *outbuf,int length,int bufsize) { - pstring service; - pstring user; - pstring password; - pstring devicename; - int connection_num; - uint16 vuid = SVAL(inbuf,smb_uid); - int passlen = SVAL(inbuf,smb_vwv3); - - *service = *user = *password = *devicename = 0; - - /* we might have to close an old one */ - if ((SVAL(inbuf,smb_vwv2) & 0x1) != 0) - close_cnum(SVAL(inbuf,smb_tid),vuid); - - if (passlen > MAX_PASS_LEN) { - overflow_attack(passlen); - } - - { - char *path; - char *p; - memcpy(password,smb_buf(inbuf),passlen); - password[passlen]=0; - path = smb_buf(inbuf) + passlen; - - if (passlen != 24) { - if (strequal(password," ")) - *password = 0; - passlen = strlen(password); - } - - fstrcpy(service,path+2); - p = strchr(service,'\\'); - if (!p) - return(ERROR(ERRSRV,ERRinvnetname)); - *p = 0; - fstrcpy(service,p+1); - p = strchr(service,'%'); - if (p) - { - *p++ = 0; - fstrcpy(user,p); - } - StrnCpy(devicename,path + strlen(path) + 1,6); - DEBUG(4,("Got device type %s\n",devicename)); - } - - /* - * Pass the user through the NT -> unix user mapping - * function. - */ - - (void)map_username(user); + pstring service; + pstring user; + pstring password; + pstring devicename; + int ecode = -1; + uint16 vuid = SVAL(inbuf,smb_uid); + int passlen = SVAL(inbuf,smb_vwv3); + char *path; + char *p; + + *service = *user = *password = *devicename = 0; - /* - * Do any UNIX username case mangling. - */ - (void)Get_Pwnam( user, True); + /* we might have to close an old one */ + if ((SVAL(inbuf,smb_vwv2) & 0x1) && conn) { + close_cnum(conn,vuid); + } - connection_num = make_connection(service,user,password,passlen,devicename,vuid); + if (passlen > MAX_PASS_LEN) { + overflow_attack(passlen); + } - if (connection_num < 0) - return(connection_error(inbuf,outbuf,connection_num)); + memcpy(password,smb_buf(inbuf),passlen); + password[passlen]=0; + path = smb_buf(inbuf) + passlen; - if (Protocol < PROTOCOL_NT1) - { - set_message(outbuf,2,strlen(devicename)+1,True); - pstrcpy(smb_buf(outbuf),devicename); - } - else - { - char *fsname = FSTYPE_STRING; - char *p; + if (passlen != 24) { + if (strequal(password," ")) + *password = 0; + passlen = strlen(password); + } + + fstrcpy(service,path+2); + p = strchr(service,'\\'); + if (!p) + return(ERROR(ERRSRV,ERRinvnetname)); + *p = 0; + fstrcpy(service,p+1); + p = strchr(service,'%'); + if (p) { + *p++ = 0; + fstrcpy(user,p); + } + StrnCpy(devicename,path + strlen(path) + 1,6); + DEBUG(4,("Got device type %s\n",devicename)); - set_message(outbuf,3,3,True); + /* + * Pass the user through the NT -> unix user mapping + * function. + */ + + (void)map_username(user); + + /* + * Do any UNIX username case mangling. + */ + (void)Get_Pwnam(user, True); + + conn = make_connection(service,user,password,passlen,devicename,vuid,&ecode); + + if (!conn) + return(connection_error(inbuf,outbuf,ecode)); - p = smb_buf(outbuf); - pstrcpy(p,devicename); p = skip_string(p,1); /* device name */ - pstrcpy(p,fsname); p = skip_string(p,1); /* filesystem type e.g NTFS */ + if (Protocol < PROTOCOL_NT1) { + set_message(outbuf,2,strlen(devicename)+1,True); + pstrcpy(smb_buf(outbuf),devicename); + } else { + char *fsname = FSTYPE_STRING; + char *p; - set_message(outbuf,3,PTR_DIFF(p,smb_buf(outbuf)),False); + set_message(outbuf,3,3,True); - SSVAL(outbuf, smb_vwv2, 0x0); /* optional support */ - } + p = smb_buf(outbuf); + pstrcpy(p,devicename); p = skip_string(p,1); /* device name */ + pstrcpy(p,fsname); p = skip_string(p,1); /* filesystem type e.g NTFS */ + + set_message(outbuf,3,PTR_DIFF(p,smb_buf(outbuf)),False); + + SSVAL(outbuf, smb_vwv2, 0x0); /* optional support */ + } - DEBUG( 3, ( "tconX service=%s user=%s cnum=%d\n", - service, user, connection_num ) ); + DEBUG(3,("tconX service=%s user=%s\n", + service, user)); - /* set the incoming and outgoing tid to the just created one */ - SSVAL(inbuf,smb_tid,connection_num); - SSVAL(outbuf,smb_tid,connection_num); + /* set the incoming and outgoing tid to the just created one */ + SSVAL(inbuf,smb_tid,conn->cnum); + SSVAL(outbuf,smb_tid,conn->cnum); - return chain_reply(inbuf,outbuf,length,bufsize); + return chain_reply(inbuf,outbuf,length,bufsize); } @@ -372,37 +356,36 @@ int reply_tcon_and_X(char *inbuf,char *outbuf,int length,int bufsize) ****************************************************************************/ int reply_unknown(char *inbuf,char *outbuf) { - int cnum; - int type; - cnum = SVAL(inbuf,smb_tid); - type = CVAL(inbuf,smb_com); + int type; + type = CVAL(inbuf,smb_com); - DEBUG(0,("unknown command type (%s): cnum=%d type=%d (0x%X)\n", - smb_fn_name(type), cnum, type, type)); + DEBUG(0,("unknown command type (%s): type=%d (0x%X)\n", + smb_fn_name(type), type, type)); - return(ERROR(ERRSRV,ERRunknownsmb)); + return(ERROR(ERRSRV,ERRunknownsmb)); } /**************************************************************************** reply to an ioctl ****************************************************************************/ -int reply_ioctl(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_ioctl(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { - DEBUG(3,("ignoring ioctl\n")); + DEBUG(3,("ignoring ioctl\n")); #if 0 - /* we just say it succeeds and hope its all OK. - some day it would be nice to interpret them individually */ - return set_message(outbuf,1,0,True); + /* we just say it succeeds and hope its all OK. + some day it would be nice to interpret them individually */ + return set_message(outbuf,1,0,True); #else - return(ERROR(ERRSRV,ERRnosupport)); + return(ERROR(ERRSRV,ERRnosupport)); #endif } /**************************************************************************** always return an error: it's just a matter of which one... ****************************************************************************/ -static int session_trust_account(char *inbuf, char *outbuf, char *user, +static int session_trust_account(connection_struct *conn, char *inbuf, char *outbuf, char *user, char *smb_passwd, int smb_passlen, char *smb_nt_passwd, int smb_nt_passlen) { @@ -472,7 +455,7 @@ static int session_trust_account(char *inbuf, char *outbuf, char *user, /**************************************************************************** reply to a session setup command ****************************************************************************/ -int reply_sesssetup_and_X(char *inbuf,char *outbuf,int length,int bufsize) +int reply_sesssetup_and_X(connection_struct *conn, char *inbuf,char *outbuf,int length,int bufsize) { uint16 sess_vuid; int gid; @@ -602,7 +585,7 @@ int reply_sesssetup_and_X(char *inbuf,char *outbuf,int length,int bufsize) /* say yes to everything ending in $. */ if ((user[strlen(user) - 1] == '$') && (smb_apasslen == 24) && (smb_ntpasslen == 24)) { - return session_trust_account(inbuf, outbuf, user, + return session_trust_account(conn, inbuf, outbuf, user, smb_apasswd, smb_apasslen, smb_ntpasswd, smb_ntpasslen); } @@ -769,22 +752,20 @@ int reply_sesssetup_and_X(char *inbuf,char *outbuf,int length,int bufsize) /**************************************************************************** reply to a chkpth ****************************************************************************/ -int reply_chkpth(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_chkpth(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { int outsize = 0; - int cnum,mode; + int mode; pstring name; BOOL ok = False; BOOL bad_path = False; - cnum = SVAL(inbuf,smb_tid); - pstrcpy(name,smb_buf(inbuf) + 1); - unix_convert(name,cnum,0,&bad_path); + unix_convert(name,conn,0,&bad_path); mode = SVAL(inbuf,smb_vwv0); - if (check_name(name,cnum)) + if (check_name(name,conn)) ok = directory_exist(name,NULL); if (!ok) @@ -815,7 +796,7 @@ int reply_chkpth(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) outsize = set_message(outbuf,0,0,True); - DEBUG( 3, ( "chkpth %s cnum=%d mode=%d\n", name, cnum, mode ) ); + DEBUG(3,("chkpth %s mode=%d\n", name, mode)); return(outsize); } @@ -824,10 +805,9 @@ int reply_chkpth(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) /**************************************************************************** reply to a getatr ****************************************************************************/ -int reply_getatr(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_getatr(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { pstring fname; - int cnum; int outsize = 0; struct stat sbuf; BOOL ok = False; @@ -836,27 +816,25 @@ int reply_getatr(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) time_t mtime=0; BOOL bad_path = False; - cnum = SVAL(inbuf,smb_tid); - pstrcpy(fname,smb_buf(inbuf) + 1); - unix_convert(fname,cnum,0,&bad_path); + unix_convert(fname,conn,0,&bad_path); /* dos smetimes asks for a stat of "" - it returns a "hidden directory" under WfWg - weird! */ if (! (*fname)) { mode = aHIDDEN | aDIR; - if (!CAN_WRITE(cnum)) mode |= aRONLY; + if (!CAN_WRITE(conn)) mode |= aRONLY; size = 0; mtime = 0; ok = True; } else - if (check_name(fname,cnum)) + if (check_name(fname,conn)) { if (sys_stat(fname,&sbuf) == 0) { - mode = dos_mode(cnum,fname,&sbuf); + mode = dos_mode(conn,fname,&sbuf); size = sbuf.st_size; mtime = sbuf.st_mtime; if (mode & aDIR) @@ -881,7 +859,7 @@ int reply_getatr(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) outsize = set_message(outbuf,10,0,True); SSVAL(outbuf,smb_vwv0,mode); - if(lp_dos_filetime_resolution(SNUM(cnum)) ) + if(lp_dos_filetime_resolution(SNUM(conn)) ) put_dos_date3(outbuf,smb_vwv1,mtime & ~1); else put_dos_date3(outbuf,smb_vwv1,mtime); @@ -904,30 +882,27 @@ int reply_getatr(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) /**************************************************************************** reply to a setatr ****************************************************************************/ -int reply_setatr(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_setatr(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { pstring fname; - int cnum; int outsize = 0; BOOL ok=False; int mode; time_t mtime; BOOL bad_path = False; - cnum = SVAL(inbuf,smb_tid); - pstrcpy(fname,smb_buf(inbuf) + 1); - unix_convert(fname,cnum,0,&bad_path); + unix_convert(fname,conn,0,&bad_path); mode = SVAL(inbuf,smb_vwv0); mtime = make_unix_date3(inbuf+smb_vwv1); if (directory_exist(fname,NULL)) mode |= aDIR; - if (check_name(fname,cnum)) - ok = (dos_chmod(cnum,fname,mode,NULL) == 0); + if (check_name(fname,conn)) + ok = (dos_chmod(conn,fname,mode,NULL) == 0); if (ok) - ok = set_filetime(cnum,fname,mtime); + ok = set_filetime(conn,fname,mtime); if (!ok) { @@ -951,14 +926,11 @@ int reply_setatr(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) /**************************************************************************** reply to a dskattr ****************************************************************************/ -int reply_dskattr(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_dskattr(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { - int cnum; int outsize = 0; int dfree,dsize,bsize; - cnum = SVAL(inbuf,smb_tid); - sys_disk_free(".",&bsize,&dfree,&dsize); outsize = set_message(outbuf,5,0,True); @@ -968,7 +940,7 @@ int reply_dskattr(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) SSVAL(outbuf,smb_vwv2,512); SSVAL(outbuf,smb_vwv3,dfree); - DEBUG( 3, ( "dskattr cnum=%d dfree=%d\n", cnum, dfree ) ); + DEBUG(3,("dskattr dfree=%d\n", dfree)); return(outsize); } @@ -978,7 +950,7 @@ int reply_dskattr(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) reply to a search Can be called from SMBsearch, SMBffirst or SMBfunique. ****************************************************************************/ -int reply_search(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_search(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { pstring mask; pstring directory; @@ -986,7 +958,6 @@ int reply_search(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) int size,mode; time_t date; int dirtype; - int cnum; int outsize = 0; int numentries = 0; BOOL finished = False; @@ -1009,8 +980,6 @@ int reply_search(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) if(CVAL(inbuf,smb_com) == SMBffirst) expect_close = True; - cnum = SVAL(inbuf,smb_tid); - outsize = set_message(outbuf,1,3,True); maxentries = SVAL(inbuf,smb_vwv0); dirtype = SVAL(inbuf,smb_vwv1); @@ -1029,10 +998,10 @@ int reply_search(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) pstrcpy(directory,smb_buf(inbuf)+1); pstrcpy(dir2,smb_buf(inbuf)+1); - unix_convert(directory,cnum,0,&bad_path); + unix_convert(directory,conn,0,&bad_path); unix_format(dir2); - if (!check_name(directory,cnum)) + if (!check_name(directory,conn)) can_open = False; p = strrchr(dir2,'/'); @@ -1064,10 +1033,10 @@ int reply_search(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) memcpy(mask,status+1,11); mask[11] = 0; dirtype = CVAL(status,0) & 0x1F; - Connections[cnum].dirptr = dptr_fetch(status+12,&dptr_num); - if (!Connections[cnum].dirptr) + conn->dirptr = dptr_fetch(status+12,&dptr_num); + if (!conn->dirptr) goto SearchEmpty; - string_set(&Connections[cnum].dirpath,dptr_path(dptr_num)); + string_set(&conn->dirpath,dptr_path(dptr_num)); if (!case_sensitive) strnorm(mask); } @@ -1119,7 +1088,7 @@ int reply_search(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) if (status_len == 0) { - dptr_num = dptr_create(cnum,directory,expect_close,SVAL(inbuf,smb_pid)); + dptr_num = dptr_create(conn,directory,expect_close,SVAL(inbuf,smb_pid)); if (dptr_num < 0) { if(dptr_num == -2) @@ -1142,7 +1111,7 @@ int reply_search(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) if ((dirtype&0x1F) == aVOLID) { memcpy(p,status,21); - make_dir_struct(p,"???????????",volume_label(SNUM(cnum)),0,aVOLID,0); + make_dir_struct(p,"???????????",volume_label(SNUM(conn)),0,aVOLID,0); dptr_fill(p+12,dptr_num); if (dptr_zero(p+12) && (status_len==0)) numentries = 1; @@ -1152,15 +1121,16 @@ int reply_search(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) } else { - DEBUG(8,("dirpath=<%s> dontdescend=<%s>\n",Connections[cnum].dirpath,lp_dontdescend(SNUM(cnum)))); - if (in_list(Connections[cnum].dirpath, - lp_dontdescend(SNUM(cnum)),True)) + DEBUG(8,("dirpath=<%s> dontdescend=<%s>\n", + conn->dirpath,lp_dontdescend(SNUM(conn)))); + if (in_list(conn->dirpath, + lp_dontdescend(SNUM(conn)),True)) check_descend = True; for (i=numentries;(i<maxentries) && !finished;i++) { finished = - !get_dir_entry(cnum,mask,dirtype,fname,&size,&mode,&date,check_descend); + !get_dir_entry(conn,mask,dirtype,fname,&size,&mode,&date,check_descend); if (!finished) { memcpy(p,status,21); @@ -1215,9 +1185,9 @@ int reply_search(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) if ((! *directory) && dptr_path(dptr_num)) slprintf(directory, sizeof(directory)-1, "(%s)",dptr_path(dptr_num)); - DEBUG( 4, ( "%s mask=%s path=%s cnum=%d dtype=%d nument=%d of %d\n", + DEBUG( 4, ( "%s mask=%s path=%s dtype=%d nument=%d of %d\n", smb_fn_name(CVAL(inbuf,smb_com)), - mask, directory, cnum, dirtype, numentries, maxentries ) ); + mask, directory, dirtype, numentries, maxentries ) ); return(outsize); } @@ -1226,17 +1196,14 @@ int reply_search(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) /**************************************************************************** reply to a fclose (stop directory search) ****************************************************************************/ -int reply_fclose(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_fclose(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { - int cnum; int outsize = 0; int status_len; char *path; char status[21]; int dptr_num= -1; - cnum = SVAL(inbuf,smb_tid); - outsize = set_message(outbuf,1,0,True); path = smb_buf(inbuf) + 1; status_len = SVAL(smb_buf(inbuf),3 + strlen(path)); @@ -1254,7 +1221,7 @@ int reply_fclose(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) SSVAL(outbuf,smb_vwv0,0); - DEBUG( 3, ( "%s search close cnum=%d\n", cnum ) ); + DEBUG(3,("search close\n")); return(outsize); } @@ -1263,10 +1230,9 @@ int reply_fclose(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) /**************************************************************************** reply to an open ****************************************************************************/ -int reply_open(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_open(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { pstring fname; - int cnum; int fnum = -1; int outsize = 0; int fmode=0; @@ -1280,12 +1246,10 @@ int reply_open(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) files_struct *fsp; int oplock_request = CORE_OPLOCK_REQUEST(inbuf); - cnum = SVAL(inbuf,smb_tid); - share_mode = SVAL(inbuf,smb_vwv0); pstrcpy(fname,smb_buf(inbuf)+1); - unix_convert(fname,cnum,0,&bad_path); + unix_convert(fname,conn,0,&bad_path); fnum = find_free_file(); if (fnum < 0) @@ -1293,7 +1257,7 @@ int reply_open(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) fsp = &Files[fnum]; - if (!check_name(fname,cnum)) + if (!check_name(fname,conn)) { if((errno == ENOENT) && bad_path) { @@ -1304,9 +1268,9 @@ int reply_open(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) return(UNIXERROR(ERRDOS,ERRnoaccess)); } - unixmode = unix_mode(cnum,aARCH); + unixmode = unix_mode(conn,aARCH); - open_file_shared(fnum,cnum,fname,share_mode,3,unixmode, + open_file_shared(fnum,conn,fname,share_mode,3,unixmode, oplock_request,&rmode,NULL); if (!fsp->open) @@ -1326,7 +1290,7 @@ int reply_open(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) } size = sbuf.st_size; - fmode = dos_mode(cnum,fname,&sbuf); + fmode = dos_mode(conn,fname,&sbuf); mtime = sbuf.st_mtime; if (fmode & aDIR) { @@ -1338,14 +1302,14 @@ int reply_open(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) outsize = set_message(outbuf,7,0,True); SSVAL(outbuf,smb_vwv0,fnum); SSVAL(outbuf,smb_vwv1,fmode); - if(lp_dos_filetime_resolution(SNUM(cnum)) ) + if(lp_dos_filetime_resolution(SNUM(conn)) ) put_dos_date3(outbuf,smb_vwv2,mtime & ~1); else put_dos_date3(outbuf,smb_vwv2,mtime); SIVAL(outbuf,smb_vwv4,size); SSVAL(outbuf,smb_vwv6,rmode); - if (oplock_request && lp_fake_oplocks(SNUM(cnum))) { + if (oplock_request && lp_fake_oplocks(SNUM(conn))) { CVAL(outbuf,smb_flg) |= CORE_OPLOCK_GRANTED; } @@ -1358,10 +1322,9 @@ int reply_open(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) /**************************************************************************** reply to an open and X ****************************************************************************/ -int reply_open_and_X(char *inbuf,char *outbuf,int length,int bufsize) +int reply_open_and_X(connection_struct *conn, char *inbuf,char *outbuf,int length,int bufsize) { pstring fname; - int cnum = SVAL(inbuf,smb_tid); int fnum = -1; int smb_mode = SVAL(inbuf,smb_vwv3); int smb_attr = SVAL(inbuf,smb_vwv5); @@ -1384,13 +1347,13 @@ int reply_open_and_X(char *inbuf,char *outbuf,int length,int bufsize) files_struct *fsp; /* If it's an IPC, pass off the pipe handler. */ - if (IS_IPC(cnum)) - return reply_open_pipe_and_X(inbuf,outbuf,length,bufsize); + if (IS_IPC(conn)) + return reply_open_pipe_and_X(conn, inbuf,outbuf,length,bufsize); /* XXXX we need to handle passed times, sattr and flags */ pstrcpy(fname,smb_buf(inbuf)); - unix_convert(fname,cnum,0,&bad_path); + unix_convert(fname,conn,0,&bad_path); fnum = find_free_file(); if (fnum < 0) @@ -1398,7 +1361,7 @@ int reply_open_and_X(char *inbuf,char *outbuf,int length,int bufsize) fsp = &Files[fnum]; - if (!check_name(fname,cnum)) + if (!check_name(fname,conn)) { if((errno == ENOENT) && bad_path) { @@ -1409,9 +1372,9 @@ int reply_open_and_X(char *inbuf,char *outbuf,int length,int bufsize) return(UNIXERROR(ERRDOS,ERRnoaccess)); } - unixmode = unix_mode(cnum,smb_attr | aARCH); + unixmode = unix_mode(conn,smb_attr | aARCH); - open_file_shared(fnum,cnum,fname,smb_mode,smb_ofun,unixmode, + open_file_shared(fnum,conn,fname,smb_mode,smb_ofun,unixmode, oplock_request, &rmode,&smb_action); if (!fsp->open) @@ -1431,7 +1394,7 @@ int reply_open_and_X(char *inbuf,char *outbuf,int length,int bufsize) } size = sbuf.st_size; - fmode = dos_mode(cnum,fname,&sbuf); + fmode = dos_mode(conn,fname,&sbuf); mtime = sbuf.st_mtime; if (fmode & aDIR) { close_file(fnum,False); @@ -1443,7 +1406,7 @@ int reply_open_and_X(char *inbuf,char *outbuf,int length,int bufsize) correct bit for extended oplock reply. */ - if (ex_oplock_request && lp_fake_oplocks(SNUM(cnum))) { + if (ex_oplock_request && lp_fake_oplocks(SNUM(conn))) { smb_action |= EXTENDED_OPLOCK_GRANTED; } @@ -1456,7 +1419,7 @@ int reply_open_and_X(char *inbuf,char *outbuf,int length,int bufsize) correct bit for core oplock reply. */ - if (core_oplock_request && lp_fake_oplocks(SNUM(cnum))) { + if (core_oplock_request && lp_fake_oplocks(SNUM(conn))) { CVAL(outbuf,smb_flg) |= CORE_OPLOCK_GRANTED; } @@ -1467,7 +1430,7 @@ int reply_open_and_X(char *inbuf,char *outbuf,int length,int bufsize) set_message(outbuf,15,0,True); SSVAL(outbuf,smb_vwv2,fnum); SSVAL(outbuf,smb_vwv3,fmode); - if(lp_dos_filetime_resolution(SNUM(cnum)) ) + if(lp_dos_filetime_resolution(SNUM(conn)) ) put_dos_date3(outbuf,smb_vwv4,mtime & ~1); else put_dos_date3(outbuf,smb_vwv4,mtime); @@ -1484,7 +1447,7 @@ int reply_open_and_X(char *inbuf,char *outbuf,int length,int bufsize) /**************************************************************************** reply to a SMBulogoffX ****************************************************************************/ -int reply_ulogoffX(char *inbuf,char *outbuf,int length,int bufsize) +int reply_ulogoffX(connection_struct *conn, char *inbuf,char *outbuf,int length,int bufsize) { uint16 vuid = SVAL(inbuf,smb_uid); user_struct *vuser = get_valid_user_struct(vuid); @@ -1521,10 +1484,10 @@ int reply_ulogoffX(char *inbuf,char *outbuf,int length,int bufsize) /**************************************************************************** reply to a mknew or a create ****************************************************************************/ -int reply_mknew(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_mknew(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { pstring fname; - int cnum,com; + int com; int fnum = -1; int outsize = 0; int createmode; @@ -1535,18 +1498,17 @@ int reply_mknew(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) int oplock_request = CORE_OPLOCK_REQUEST(inbuf); com = SVAL(inbuf,smb_com); - cnum = SVAL(inbuf,smb_tid); createmode = SVAL(inbuf,smb_vwv0); pstrcpy(fname,smb_buf(inbuf)+1); - unix_convert(fname,cnum,0,&bad_path); + unix_convert(fname,conn,0,&bad_path); if (createmode & aVOLID) { DEBUG(0,("Attempt to create file (%s) with volid set - please report this\n",fname)); } - unixmode = unix_mode(cnum,createmode); + unixmode = unix_mode(conn,createmode); fnum = find_free_file(); if (fnum < 0) @@ -1554,7 +1516,7 @@ int reply_mknew(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) fsp = &Files[fnum]; - if (!check_name(fname,cnum)) + if (!check_name(fname,conn)) { if((errno == ENOENT) && bad_path) { @@ -1577,7 +1539,7 @@ int reply_mknew(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) } /* Open file in dos compatibility share mode. */ - open_file_shared(fnum,cnum,fname,(DENY_FCB<<4)|0xF, ofun, unixmode, + open_file_shared(fnum,conn,fname,(DENY_FCB<<4)|0xF, ofun, unixmode, oplock_request, NULL, NULL); if (!fsp->open) @@ -1594,7 +1556,7 @@ int reply_mknew(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) outsize = set_message(outbuf,1,0,True); SSVAL(outbuf,smb_vwv0,fnum); - if (oplock_request && lp_fake_oplocks(SNUM(cnum))) { + if (oplock_request && lp_fake_oplocks(SNUM(conn))) { CVAL(outbuf,smb_flg) |= CORE_OPLOCK_GRANTED; } @@ -1602,8 +1564,8 @@ int reply_mknew(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) CVAL(outbuf,smb_flg) |= CORE_OPLOCK_GRANTED; DEBUG( 2, ( "new file %s\n", fname ) ); - DEBUG( 3, ( "mknew %s fd=%d fnum=%d cnum=%d dmode=%d umode=%o\n", - fname, fsp->fd_ptr->fd, fnum, cnum, createmode, unixmode ) ); + DEBUG( 3, ( "mknew %s fd=%d fnum=%d dmode=%d umode=%o\n", + fname, fsp->fd_ptr->fd, fnum, createmode, unixmode ) ); return(outsize); } @@ -1612,11 +1574,10 @@ int reply_mknew(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) /**************************************************************************** reply to a create temporary file ****************************************************************************/ -int reply_ctemp(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_ctemp(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { pstring fname; pstring fname2; - int cnum; int fnum = -1; int outsize = 0; int createmode; @@ -1625,13 +1586,12 @@ int reply_ctemp(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) files_struct *fsp; int oplock_request = CORE_OPLOCK_REQUEST(inbuf); - cnum = SVAL(inbuf,smb_tid); createmode = SVAL(inbuf,smb_vwv0); pstrcpy(fname,smb_buf(inbuf)+1); pstrcat(fname,"/TMXXXXXX"); - unix_convert(fname,cnum,0,&bad_path); + unix_convert(fname,conn,0,&bad_path); - unixmode = unix_mode(cnum,createmode); + unixmode = unix_mode(conn,createmode); fnum = find_free_file(); if (fnum < 0) @@ -1639,7 +1599,7 @@ int reply_ctemp(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) fsp = &Files[fnum]; - if (!check_name(fname,cnum)) + if (!check_name(fname,conn)) { if((errno == ENOENT) && bad_path) { @@ -1654,7 +1614,7 @@ int reply_ctemp(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) /* Open file in dos compatibility share mode. */ /* We should fail if file exists. */ - open_file_shared(fnum,cnum,fname2,(DENY_FCB<<4)|0xF, 0x10, unixmode, + open_file_shared(fnum,conn,fname2,(DENY_FCB<<4)|0xF, 0x10, unixmode, oplock_request, NULL, NULL); if (!fsp->open) @@ -1673,7 +1633,7 @@ int reply_ctemp(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) CVAL(smb_buf(outbuf),0) = 4; pstrcpy(smb_buf(outbuf) + 1,fname2); - if (oplock_request && lp_fake_oplocks(SNUM(cnum))) { + if (oplock_request && lp_fake_oplocks(SNUM(conn))) { CVAL(outbuf,smb_flg) |= CORE_OPLOCK_GRANTED; } @@ -1681,8 +1641,8 @@ int reply_ctemp(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) CVAL(outbuf,smb_flg) |= CORE_OPLOCK_GRANTED; DEBUG( 2, ( "created temp file %s\n", fname2 ) ); - DEBUG( 3, ( "ctemp %s fd=%d fnum=%d cnum=%d dmode=%d umode=%o\n", - fname2, fsp->fd_ptr->fd, fnum, cnum, createmode, unixmode ) ); + DEBUG( 3, ( "ctemp %s fd=%d fnum=%d dmode=%d umode=%o\n", + fname2, fsp->fd_ptr->fd, fnum, createmode, unixmode ) ); return(outsize); } @@ -1691,33 +1651,32 @@ int reply_ctemp(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) /******************************************************************* check if a user is allowed to delete a file ********************************************************************/ -static BOOL can_delete(char *fname,int cnum,int dirtype) +static BOOL can_delete(char *fname,connection_struct *conn, int dirtype) { struct stat sbuf; int fmode; - if (!CAN_WRITE(cnum)) return(False); + if (!CAN_WRITE(conn)) return(False); if (sys_lstat(fname,&sbuf) != 0) return(False); - fmode = dos_mode(cnum,fname,&sbuf); + fmode = dos_mode(conn,fname,&sbuf); if (fmode & aDIR) return(False); - if (!lp_delete_readonly(SNUM(cnum))) { + if (!lp_delete_readonly(SNUM(conn))) { if (fmode & aRONLY) return(False); } if ((fmode & ~dirtype) & (aHIDDEN | aSYSTEM)) return(False); - if (!check_file_sharing(cnum,fname,False)) return(False); + if (!check_file_sharing(conn,fname,False)) return(False); return(True); } /**************************************************************************** reply to a unlink ****************************************************************************/ -int reply_unlink(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_unlink(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { int outsize = 0; pstring name; - int cnum; int dirtype; pstring directory; pstring mask; @@ -1730,14 +1689,13 @@ int reply_unlink(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) *directory = *mask = 0; - cnum = SVAL(inbuf,smb_tid); dirtype = SVAL(inbuf,smb_vwv0); pstrcpy(name,smb_buf(inbuf) + 1); DEBUG(3,("reply_unlink : %s\n",name)); - unix_convert(name,cnum,0,&bad_path); + unix_convert(name,conn,0,&bad_path); p = strrchr(name,'/'); if (!p) { @@ -1757,14 +1715,14 @@ int reply_unlink(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) if (!has_wild) { pstrcat(directory,"/"); pstrcat(directory,mask); - if (can_delete(directory,cnum,dirtype) && !sys_unlink(directory)) count++; + if (can_delete(directory,conn,dirtype) && !sys_unlink(directory)) count++; if (!count) exists = file_exist(directory,NULL); } else { void *dirptr = NULL; char *dname; - if (check_name(directory,cnum)) - dirptr = OpenDir(cnum, directory, True); + if (check_name(directory,conn)) + dirptr = OpenDir(conn, directory, True); /* XXXX the CIFS spec says that if bit0 of the flags2 field is set then the pattern matches against the long name, otherwise the short name @@ -1787,7 +1745,7 @@ int reply_unlink(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) error = ERRnoaccess; slprintf(fname,sizeof(fname)-1, "%s/%s",directory,dname); - if (!can_delete(fname,cnum,dirtype)) continue; + if (!can_delete(fname,conn,dirtype)) continue; if (!sys_unlink(fname)) count++; DEBUG(3,("reply_unlink : doing unlink on %s\n",fname)); } @@ -1818,9 +1776,9 @@ int reply_unlink(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) /**************************************************************************** reply to a readbraw (core+ protocol) ****************************************************************************/ -int reply_readbraw(char *inbuf, char *outbuf, int dum_size, int dum_buffsize) +int reply_readbraw(connection_struct *conn, char *inbuf, char *outbuf, int dum_size, int dum_buffsize) { - int cnum,maxcount,mincount,fnum; + int maxcount,mincount,fnum; int nread = 0; uint32 startpos; char *header = outbuf; @@ -1843,7 +1801,6 @@ int reply_readbraw(char *inbuf, char *outbuf, int dum_size, int dum_buffsize) return -1; } - cnum = SVAL(inbuf,smb_tid); fnum = GETFNUM(inbuf,smb_vwv0); startpos = IVAL(inbuf,smb_vwv1); @@ -1854,7 +1811,7 @@ int reply_readbraw(char *inbuf, char *outbuf, int dum_size, int dum_buffsize) maxcount = MIN(65535,maxcount); maxcount = MAX(mincount,maxcount); - if (!FNUM_OK(fnum,cnum) || !Files[fnum].can_read) + if (!FNUM_OK(fnum,conn) || !Files[fnum].can_read) { DEBUG(3,("fnum %d not open in readbraw - cache prime?\n",fnum)); _smb_setlen(header,0); @@ -1866,11 +1823,11 @@ int reply_readbraw(char *inbuf, char *outbuf, int dum_size, int dum_buffsize) fsp = &Files[fnum]; fd = fsp->fd_ptr->fd; - fname = fsp->name; + fname = fsp->fsp_name; } - if (!is_locked(fnum,cnum,maxcount,startpos, F_RDLCK)) + if (!is_locked(fnum,conn,maxcount,startpos, F_RDLCK)) { int size = fsp->size; int sizeneeded = startpos + maxcount; @@ -1889,8 +1846,8 @@ int reply_readbraw(char *inbuf, char *outbuf, int dum_size, int dum_buffsize) if (nread < mincount) nread = 0; - DEBUG( 3, ( "readbraw fnum=%d cnum=%d start=%d max=%d min=%d nread=%d\n", - fnum, cnum, startpos, + DEBUG( 3, ( "readbraw fnum=%d start=%d max=%d min=%d nread=%d\n", + fnum, startpos, maxcount, mincount, nread ) ); #if UNSAFE_READRAW @@ -1930,9 +1887,9 @@ int reply_readbraw(char *inbuf, char *outbuf, int dum_size, int dum_buffsize) /**************************************************************************** reply to a lockread (core+ protocol) ****************************************************************************/ -int reply_lockread(char *inbuf,char *outbuf, int dum_size, int dum_buffsiz) +int reply_lockread(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsiz) { - int cnum,fnum; + int fnum; int nread = -1; char *data; int outsize = 0; @@ -1940,10 +1897,9 @@ int reply_lockread(char *inbuf,char *outbuf, int dum_size, int dum_buffsiz) int eclass; uint32 ecode; - cnum = SVAL(inbuf,smb_tid); fnum = GETFNUM(inbuf,smb_vwv0); - CHECK_FNUM(fnum,cnum); + CHECK_FNUM(fnum,conn); CHECK_READ(fnum); CHECK_ERROR(fnum); @@ -1954,7 +1910,7 @@ int reply_lockread(char *inbuf,char *outbuf, int dum_size, int dum_buffsiz) numtoread = MIN(BUFFER_SIZE-outsize,numtoread); data = smb_buf(outbuf) + 3; - if(!do_lock( fnum, cnum, numtoread, startpos, F_RDLCK, &eclass, &ecode)) + if(!do_lock( fnum, conn, numtoread, startpos, F_RDLCK, &eclass, &ecode)) return (ERROR(eclass,ecode)); nread = read_file(fnum,data,startpos,numtoread); @@ -1967,8 +1923,8 @@ int reply_lockread(char *inbuf,char *outbuf, int dum_size, int dum_buffsiz) SSVAL(outbuf,smb_vwv5,nread+3); SSVAL(smb_buf(outbuf),1,nread); - DEBUG( 3, ( "lockread fnum=%d cnum=%d num=%d nread=%d\n", - fnum, cnum, numtoread, nread ) ); + DEBUG( 3, ( "lockread fnum=%d num=%d nread=%d\n", + fnum, numtoread, nread ) ); return(outsize); } @@ -1977,18 +1933,17 @@ int reply_lockread(char *inbuf,char *outbuf, int dum_size, int dum_buffsiz) /**************************************************************************** reply to a read ****************************************************************************/ -int reply_read(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_read(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { - int cnum,numtoread,fnum; + int numtoread,fnum; int nread = 0; char *data; uint32 startpos; int outsize = 0; - cnum = SVAL(inbuf,smb_tid); fnum = GETFNUM(inbuf,smb_vwv0); - CHECK_FNUM(fnum,cnum); + CHECK_FNUM(fnum,conn); CHECK_READ(fnum); CHECK_ERROR(fnum); @@ -1999,7 +1954,7 @@ int reply_read(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) numtoread = MIN(BUFFER_SIZE-outsize,numtoread); data = smb_buf(outbuf) + 3; - if (is_locked(fnum,cnum,numtoread,startpos, F_RDLCK)) + if (is_locked(fnum,conn,numtoread,startpos, F_RDLCK)) return(ERROR(ERRDOS,ERRlock)); if (numtoread > 0) @@ -2014,8 +1969,8 @@ int reply_read(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) CVAL(smb_buf(outbuf),0) = 1; SSVAL(smb_buf(outbuf),1,nread); - DEBUG( 3, ( "read fnum=%d cnum=%d num=%d nread=%d\n", - fnum, cnum, numtoread, nread ) ); + DEBUG( 3, ( "read fnum=%d num=%d nread=%d\n", + fnum, numtoread, nread ) ); return(outsize); } @@ -2024,31 +1979,28 @@ int reply_read(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) /**************************************************************************** reply to a read and X ****************************************************************************/ -int reply_read_and_X(char *inbuf,char *outbuf,int length,int bufsize) +int reply_read_and_X(connection_struct *conn, char *inbuf,char *outbuf,int length,int bufsize) { int fnum = GETFNUM(inbuf,smb_vwv2); uint32 smb_offs = IVAL(inbuf,smb_vwv3); int smb_maxcnt = SVAL(inbuf,smb_vwv5); int smb_mincnt = SVAL(inbuf,smb_vwv6); - int cnum; int nread = -1; char *data; BOOL ok = False; - cnum = SVAL(inbuf,smb_tid); - /* If it's an IPC, pass off the pipe handler. */ - if (IS_IPC(cnum)) + if (IS_IPC(conn)) return reply_pipe_read_and_X(inbuf,outbuf,length,bufsize); - CHECK_FNUM(fnum,cnum); + CHECK_FNUM(fnum,conn); CHECK_READ(fnum); CHECK_ERROR(fnum); set_message(outbuf,12,0,True); data = smb_buf(outbuf); - if (is_locked(fnum,cnum,smb_maxcnt,smb_offs, F_RDLCK)) + if (is_locked(fnum,conn,smb_maxcnt,smb_offs, F_RDLCK)) return(ERROR(ERRDOS,ERRlock)); nread = read_file(fnum,data,smb_offs,smb_maxcnt); ok = True; @@ -2060,9 +2012,8 @@ int reply_read_and_X(char *inbuf,char *outbuf,int length,int bufsize) SSVAL(outbuf,smb_vwv6,smb_offset(data,outbuf)); SSVAL(smb_buf(outbuf),-2,nread); - DEBUG( 3, ( "readX fnum=%d cnum=%d min=%d max=%d nread=%d\n", - fnum, cnum, - smb_mincnt, smb_maxcnt, nread ) ); + DEBUG( 3, ( "readX fnum=%d min=%d max=%d nread=%d\n", + fnum, smb_mincnt, smb_maxcnt, nread ) ); chain_fnum = fnum; @@ -2073,22 +2024,21 @@ int reply_read_and_X(char *inbuf,char *outbuf,int length,int bufsize) /**************************************************************************** reply to a writebraw (core+ or LANMAN1.0 protocol) ****************************************************************************/ -int reply_writebraw(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_writebraw(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { int nwritten=0; int total_written=0; int numtowrite=0; - int cnum,fnum; + int fnum; int outsize = 0; long startpos; char *data=NULL; BOOL write_through; int tcount; - cnum = SVAL(inbuf,smb_tid); fnum = GETFNUM(inbuf,smb_vwv0); - CHECK_FNUM(fnum,cnum); + CHECK_FNUM(fnum,conn); CHECK_WRITE(fnum); CHECK_ERROR(fnum); @@ -2110,17 +2060,17 @@ int reply_writebraw(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) CVAL(inbuf,smb_com) = SMBwritec; CVAL(outbuf,smb_com) = SMBwritec; - if (is_locked(fnum,cnum,tcount,startpos, F_WRLCK)) + if (is_locked(fnum,conn,tcount,startpos, F_WRLCK)) return(ERROR(ERRDOS,ERRlock)); if (seek_file(fnum,startpos) != startpos) - DEBUG(0,("couldn't seek to %d in writebraw\n",startpos)); + DEBUG(0,("couldn't seek to %ld in writebraw\n",startpos)); if (numtowrite>0) nwritten = write_file(fnum,data,numtowrite); - DEBUG( 3, ( "writebraw1 fnum=%d cnum=%d start=%d num=%d wrote=%d sync=%d\n", - fnum, cnum, startpos, numtowrite, nwritten, write_through ) ); + DEBUG(3,("writebraw1 fnum=%d start=%ld num=%d wrote=%d sync=%d\n", + fnum, startpos, numtowrite, nwritten, write_through)); if (nwritten < numtowrite) return(UNIXERROR(ERRHRD,ERRdiskfull)); @@ -2162,11 +2112,11 @@ int reply_writebraw(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) SSVAL(outbuf,smb_err,ERRdiskfull); } - if (lp_syncalways(SNUM(cnum)) || write_through) - sync_file(cnum,fnum); + if (lp_syncalways(SNUM(conn)) || write_through) + sync_file(conn,fnum); - DEBUG( 3, ( "writebraw2 fnum=%d cnum=%d start=%d num=%d wrote=%d\n", - fnum, cnum, startpos, numtowrite, total_written ) ); + DEBUG(3,("writebraw2 fnum=%d start=%ld num=%d wrote=%d\n", + fnum, startpos, numtowrite, total_written)); /* we won't return a status if write through is not selected - this follows what WfWg does */ @@ -2180,9 +2130,9 @@ int reply_writebraw(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) /**************************************************************************** reply to a writeunlock (core+) ****************************************************************************/ -int reply_writeunlock(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_writeunlock(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { - int cnum,fnum; + int fnum; int nwritten = -1; int outsize = 0; char *data; @@ -2190,10 +2140,9 @@ int reply_writeunlock(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) int eclass; uint32 ecode; - cnum = SVAL(inbuf,smb_tid); fnum = GETFNUM(inbuf,smb_vwv0); - CHECK_FNUM(fnum,cnum); + CHECK_FNUM(fnum,conn); CHECK_WRITE(fnum); CHECK_ERROR(fnum); @@ -2201,7 +2150,7 @@ int reply_writeunlock(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) startpos = IVAL(inbuf,smb_vwv2); data = smb_buf(inbuf) + 3; - if (is_locked(fnum,cnum,numtowrite,startpos, F_WRLCK)) + if (is_locked(fnum,conn,numtowrite,startpos, F_WRLCK)) return(ERROR(ERRDOS,ERRlock)); seek_file(fnum,startpos); @@ -2214,21 +2163,21 @@ int reply_writeunlock(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) else nwritten = write_file(fnum,data,numtowrite); - if (lp_syncalways(SNUM(cnum))) - sync_file(cnum,fnum); + if (lp_syncalways(SNUM(conn))) + sync_file(conn,fnum); if(((nwritten == 0) && (numtowrite != 0))||(nwritten < 0)) return(UNIXERROR(ERRDOS,ERRnoaccess)); - if(!do_unlock(fnum, cnum, numtowrite, startpos, &eclass, &ecode)) + if(!do_unlock(fnum, conn, numtowrite, startpos, &eclass, &ecode)) return(ERROR(eclass,ecode)); outsize = set_message(outbuf,1,0,True); SSVAL(outbuf,smb_vwv0,nwritten); - DEBUG( 3, ( "writeunlock fnum=%d cnum=%d num=%d wrote=%d\n", - fnum, cnum, numtowrite, nwritten ) ); + DEBUG( 3, ( "writeunlock fnum=%d num=%d wrote=%d\n", + fnum, numtowrite, nwritten ) ); return(outsize); } @@ -2237,18 +2186,17 @@ int reply_writeunlock(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) /**************************************************************************** reply to a write ****************************************************************************/ -int reply_write(char *inbuf,char *outbuf,int dum_size,int dum_buffsize) +int reply_write(connection_struct *conn, char *inbuf,char *outbuf,int dum_size,int dum_buffsize) { - int cnum,numtowrite,fnum; + int numtowrite,fnum; int nwritten = -1; int outsize = 0; int startpos; char *data; - cnum = SVAL(inbuf,smb_tid); fnum = GETFNUM(inbuf,smb_vwv0); - CHECK_FNUM(fnum,cnum); + CHECK_FNUM(fnum,conn); CHECK_WRITE(fnum); CHECK_ERROR(fnum); @@ -2256,7 +2204,7 @@ int reply_write(char *inbuf,char *outbuf,int dum_size,int dum_buffsize) startpos = IVAL(inbuf,smb_vwv2); data = smb_buf(inbuf) + 3; - if (is_locked(fnum,cnum,numtowrite,startpos, F_WRLCK)) + if (is_locked(fnum,conn,numtowrite,startpos, F_WRLCK)) return(ERROR(ERRDOS,ERRlock)); seek_file(fnum,startpos); @@ -2269,8 +2217,8 @@ int reply_write(char *inbuf,char *outbuf,int dum_size,int dum_buffsize) else nwritten = write_file(fnum,data,numtowrite); - if (lp_syncalways(SNUM(cnum))) - sync_file(cnum,fnum); + if (lp_syncalways(SNUM(conn))) + sync_file(conn,fnum); if(((nwritten == 0) && (numtowrite != 0))||(nwritten < 0)) return(UNIXERROR(ERRDOS,ERRnoaccess)); @@ -2284,8 +2232,8 @@ int reply_write(char *inbuf,char *outbuf,int dum_size,int dum_buffsize) SSVAL(outbuf,smb_err,ERRdiskfull); } - DEBUG( 3, ( "%s write fnum=%d cnum=%d num=%d wrote=%d\n", - fnum, cnum, numtowrite, nwritten ) ); + DEBUG(3,("write fnum=%d num=%d wrote=%d\n", + fnum, numtowrite, nwritten)); return(outsize); } @@ -2294,26 +2242,23 @@ int reply_write(char *inbuf,char *outbuf,int dum_size,int dum_buffsize) /**************************************************************************** reply to a write and X ****************************************************************************/ -int reply_write_and_X(char *inbuf,char *outbuf,int length,int bufsize) +int reply_write_and_X(connection_struct *conn, char *inbuf,char *outbuf,int length,int bufsize) { int fnum = GETFNUM(inbuf,smb_vwv2); uint32 smb_offs = IVAL(inbuf,smb_vwv3); int smb_dsize = SVAL(inbuf,smb_vwv10); int smb_doff = SVAL(inbuf,smb_vwv11); BOOL write_through = BITSETW(inbuf+smb_vwv7,0); - int cnum; int nwritten = -1; char *data; - cnum = SVAL(inbuf,smb_tid); - - CHECK_FNUM(fnum,cnum); + CHECK_FNUM(fnum,conn); CHECK_WRITE(fnum); CHECK_ERROR(fnum); data = smb_base(inbuf) + smb_doff; - if (is_locked(fnum,cnum,smb_dsize,smb_offs, F_WRLCK)) + if (is_locked(fnum,conn,smb_dsize,smb_offs, F_WRLCK)) return(ERROR(ERRDOS,ERRlock)); seek_file(fnum,smb_offs); @@ -2339,13 +2284,13 @@ int reply_write_and_X(char *inbuf,char *outbuf,int length,int bufsize) SSVAL(outbuf,smb_err,ERRdiskfull); } - DEBUG( 3, ( "%s writeX fnum=%d cnum=%d num=%d wrote=%d\n", - fnum, cnum, smb_dsize, nwritten ) ); + DEBUG(3,("writeX fnum=%d num=%d wrote=%d\n", + fnum, smb_dsize, nwritten)); chain_fnum = fnum; - if (lp_syncalways(SNUM(cnum)) || write_through) - sync_file(cnum,fnum); + if (lp_syncalways(SNUM(conn)) || write_through) + sync_file(conn,fnum); return chain_reply(inbuf,outbuf,length,bufsize); } @@ -2354,19 +2299,18 @@ int reply_write_and_X(char *inbuf,char *outbuf,int length,int bufsize) /**************************************************************************** reply to a lseek ****************************************************************************/ -int reply_lseek(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_lseek(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { - int cnum,fnum; + int fnum; uint32 startpos; int32 res= -1; int mode,umode; int outsize = 0; files_struct *fsp; - cnum = SVAL(inbuf,smb_tid); fnum = GETFNUM(inbuf,smb_vwv0); - CHECK_FNUM(fnum,cnum); + CHECK_FNUM(fnum,conn); CHECK_ERROR(fnum); mode = SVAL(inbuf,smb_vwv1) & 3; @@ -2389,8 +2333,8 @@ int reply_lseek(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) outsize = set_message(outbuf,2,0,True); SIVALS(outbuf,smb_vwv0,res); - DEBUG( 3, ( "lseek fnum=%d cnum=%d ofs=%d mode=%d\n", - fnum, cnum, startpos, mode ) ); + DEBUG(3,("lseek fnum=%d ofs=%d mode=%d\n", + fnum, startpos, mode)); return(outsize); } @@ -2399,28 +2343,28 @@ int reply_lseek(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) /**************************************************************************** reply to a flush ****************************************************************************/ -int reply_flush(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_flush(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { - int cnum, fnum; + int fnum; int outsize = set_message(outbuf,0,0,True); - cnum = SVAL(inbuf,smb_tid); fnum = GETFNUM(inbuf,smb_vwv0); if (fnum != 0xFFFF) { - CHECK_FNUM(fnum,cnum); + CHECK_FNUM(fnum,conn); CHECK_ERROR(fnum); } - if (fnum == 0xFFFF) - { - int i; - for (i=0;i<MAX_FNUMS;i++) - if (OPEN_FNUM(i)) - sync_file(cnum,i); - } - else - sync_file(cnum,fnum); + if (fnum == 0xFFFF) { + int i; + for (i=0;i<MAX_FNUMS;i++) { + if (OPEN_FNUM(i)) { + sync_file(conn,i); + } + } + } else { + sync_file(conn,fnum); + } DEBUG( 3, ( "flush fnum=%d\n", fnum ) ); return(outsize); @@ -2430,187 +2374,185 @@ int reply_flush(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) /**************************************************************************** reply to a exit ****************************************************************************/ -int reply_exit(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_exit(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { - int outsize = set_message(outbuf,0,0,True); - DEBUG( 3, ( "exit\n" ) ); + int outsize = set_message(outbuf,0,0,True); + DEBUG(3,("exit\n")); - return(outsize); + return(outsize); } /**************************************************************************** Reply to a close - has to deal with closing a directory opened by NT SMB's. ****************************************************************************/ - -int reply_close(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_close(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { - int fnum,cnum; - int outsize = 0; - time_t mtime; - int32 eclass = 0, err = 0; - files_struct *fsp = NULL; - - outsize = set_message(outbuf,0,0,True); + int fnum; + int outsize = 0; + time_t mtime; + int32 eclass = 0, err = 0; + files_struct *fsp = NULL; - cnum = SVAL(inbuf,smb_tid); + outsize = set_message(outbuf,0,0,True); - /* If it's an IPC, pass off to the pipe handler. */ - if (IS_IPC(cnum)) - return reply_pipe_close(inbuf,outbuf); + /* If it's an IPC, pass off to the pipe handler. */ + if (IS_IPC(conn)) { + return reply_pipe_close(conn, inbuf,outbuf); + } - fnum = GETFNUM(inbuf,smb_vwv0); + fnum = GETFNUM(inbuf,smb_vwv0); - /* - * We can only use CHECK_FNUM if we know it's not a directory. - */ + /* + * We can only use CHECK_FNUM if we know it's not a directory. + */ - if(!(VALID_FNUM(fnum) && Files[fnum].open && Files[fnum].is_directory)) - CHECK_FNUM(fnum,cnum); + if(!(VALID_FNUM(fnum) && Files[fnum].open && Files[fnum].is_directory)) + CHECK_FNUM(fnum,conn); - fsp = &Files[fnum]; + fsp = &Files[fnum]; - if(HAS_CACHED_ERROR(fnum)) { - eclass = fsp->wbmpx_ptr->wr_errclass; - err = fsp->wbmpx_ptr->wr_error; - } - - if(fsp->is_directory) { - /* - * Special case - close NT SMB directory - * handle. - */ - DEBUG( 3, ( "close directory fnum=%d cnum=%d\n", - fnum, cnum ) ); - close_directory( fnum ); - } else { - /* - * Close ordinary file. - */ - mtime = make_unix_date3(inbuf+smb_vwv1); + if(HAS_CACHED_ERROR(fnum)) { + eclass = fsp->wbmpx_ptr->wr_errclass; + err = fsp->wbmpx_ptr->wr_error; + } - /* try and set the date */ - set_filetime(cnum, fsp->name,mtime); + if(fsp->is_directory) { + /* + * Special case - close NT SMB directory + * handle. + */ + DEBUG(3,("close directory fnum=%d\n", fnum)); + close_directory(fnum); + } else { + /* + * Close ordinary file. + */ + mtime = make_unix_date3(inbuf+smb_vwv1); + + /* try and set the date */ + set_filetime(conn, fsp->fsp_name,mtime); - DEBUG( 3, ( "close fd=%d fnum=%d cnum=%d (numopen=%d)\n", - fsp->fd_ptr->fd, fnum, cnum, - Connections[cnum].num_files_open ) ); + DEBUG(3,("close fd=%d fnum=%d (numopen=%d)\n", + fsp->fd_ptr->fd, fnum, + conn->num_files_open)); - close_file(fnum,True); - } + close_file(fnum,True); + } - /* We have a cached error */ - if(eclass || err) - return(ERROR(eclass,err)); + /* We have a cached error */ + if(eclass || err) + return(ERROR(eclass,err)); - return(outsize); + return(outsize); } /**************************************************************************** reply to a writeclose (Core+ protocol) ****************************************************************************/ -int reply_writeclose(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_writeclose(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { - int cnum,numtowrite,fnum; - int nwritten = -1; - int outsize = 0; - int startpos; - char *data; - time_t mtime; - - cnum = SVAL(inbuf,smb_tid); - fnum = GETFNUM(inbuf,smb_vwv0); - - CHECK_FNUM(fnum,cnum); - CHECK_WRITE(fnum); - CHECK_ERROR(fnum); - - numtowrite = SVAL(inbuf,smb_vwv1); - startpos = IVAL(inbuf,smb_vwv2); - mtime = make_unix_date3(inbuf+smb_vwv4); - data = smb_buf(inbuf) + 1; - - if (is_locked(fnum,cnum,numtowrite,startpos, F_WRLCK)) - return(ERROR(ERRDOS,ERRlock)); + int numtowrite,fnum; + int nwritten = -1; + int outsize = 0; + int startpos; + char *data; + time_t mtime; + + fnum = GETFNUM(inbuf,smb_vwv0); + + CHECK_FNUM(fnum,conn); + CHECK_WRITE(fnum); + CHECK_ERROR(fnum); + + numtowrite = SVAL(inbuf,smb_vwv1); + startpos = IVAL(inbuf,smb_vwv2); + mtime = make_unix_date3(inbuf+smb_vwv4); + data = smb_buf(inbuf) + 1; + + if (is_locked(fnum,conn,numtowrite,startpos, F_WRLCK)) + return(ERROR(ERRDOS,ERRlock)); - seek_file(fnum,startpos); + seek_file(fnum,startpos); - nwritten = write_file(fnum,data,numtowrite); + nwritten = write_file(fnum,data,numtowrite); - set_filetime(cnum, Files[fnum].name,mtime); + set_filetime(conn, Files[fnum].fsp_name,mtime); - close_file(fnum,True); + close_file(fnum,True); - DEBUG( 3, ( "writeclose fnum=%d cnum=%d num=%d wrote=%d (numopen=%d)\n", - fnum, cnum, numtowrite, nwritten, - Connections[cnum].num_files_open ) ); + DEBUG(3,("writeclose fnum=%d num=%d wrote=%d (numopen=%d)\n", + fnum, numtowrite, nwritten, + conn->num_files_open)); - if (nwritten <= 0) - return(UNIXERROR(ERRDOS,ERRnoaccess)); + if (nwritten <= 0) + return(UNIXERROR(ERRDOS,ERRnoaccess)); - outsize = set_message(outbuf,1,0,True); + outsize = set_message(outbuf,1,0,True); - SSVAL(outbuf,smb_vwv0,nwritten); - return(outsize); + SSVAL(outbuf,smb_vwv0,nwritten); + return(outsize); } /**************************************************************************** reply to a lock ****************************************************************************/ -int reply_lock(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_lock(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { - int fnum,cnum; - int outsize = set_message(outbuf,0,0,True); - uint32 count,offset; - int eclass; - uint32 ecode; + int fnum; + int outsize = set_message(outbuf,0,0,True); + uint32 count,offset; + int eclass; + uint32 ecode; - cnum = SVAL(inbuf,smb_tid); - fnum = GETFNUM(inbuf,smb_vwv0); + fnum = GETFNUM(inbuf,smb_vwv0); - CHECK_FNUM(fnum,cnum); - CHECK_ERROR(fnum); + CHECK_FNUM(fnum,conn); + CHECK_ERROR(fnum); - count = IVAL(inbuf,smb_vwv1); - offset = IVAL(inbuf,smb_vwv3); + count = IVAL(inbuf,smb_vwv1); + offset = IVAL(inbuf,smb_vwv3); - DEBUG( 3, ("lock fd=%d fnum=%d cnum=%d ofs=%d cnt=%d\n", - Files[fnum].fd_ptr->fd, fnum, cnum, offset, count ) ); + DEBUG(3,("lock fd=%d fnum=%d ofs=%d cnt=%d\n", + Files[fnum].fd_ptr->fd, fnum, offset, count)); - if(!do_lock( fnum, cnum, count, offset, F_WRLCK, &eclass, &ecode)) - return (ERROR(eclass,ecode)); + if (!do_lock(fnum, conn, count, offset, F_WRLCK, &eclass, &ecode)) + return (ERROR(eclass,ecode)); - return(outsize); + return(outsize); } /**************************************************************************** reply to a unlock ****************************************************************************/ -int reply_unlock(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_unlock(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { - int fnum,cnum; + int fnum; int outsize = set_message(outbuf,0,0,True); uint32 count,offset; int eclass; uint32 ecode; - cnum = SVAL(inbuf,smb_tid); fnum = GETFNUM(inbuf,smb_vwv0); - CHECK_FNUM(fnum,cnum); + CHECK_FNUM(fnum,conn); CHECK_ERROR(fnum); count = IVAL(inbuf,smb_vwv1); offset = IVAL(inbuf,smb_vwv3); - if(!do_unlock(fnum, cnum, count, offset, &eclass, &ecode)) + if(!do_unlock(fnum, conn, count, offset, &eclass, &ecode)) return (ERROR(eclass,ecode)); - DEBUG( 3, ( "unlock fd=%d fnum=%d cnum=%d ofs=%d cnt=%d\n", - Files[fnum].fd_ptr->fd, fnum, cnum, offset, count ) ); + DEBUG( 3, ( "unlock fd=%d fnum=%d ofs=%d cnt=%d\n", + Files[fnum].fd_ptr->fd, fnum, offset, count ) ); return(outsize); } @@ -2619,27 +2561,24 @@ int reply_unlock(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) /**************************************************************************** reply to a tdis ****************************************************************************/ -int reply_tdis(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_tdis(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { - int cnum; - int outsize = set_message(outbuf,0,0,True); - uint16 vuid; + int outsize = set_message(outbuf,0,0,True); + uint16 vuid; - cnum = SVAL(inbuf,smb_tid); - vuid = SVAL(inbuf,smb_uid); + vuid = SVAL(inbuf,smb_uid); - if (!OPEN_CNUM(cnum)) { - DEBUG(4,("Invalid cnum in tdis (%d)\n",cnum)); - return(ERROR(ERRSRV,ERRinvnid)); - } + if (!conn) { + DEBUG(4,("Invalid connection in tdis\n")); + return(ERROR(ERRSRV,ERRinvnid)); + } - Connections[cnum].used = False; + conn->used = False; - close_cnum(cnum,vuid); + close_cnum(conn,vuid); - DEBUG( 3, ( "tdis cnum=%d\n", cnum ) ); - - return outsize; + return outsize; } @@ -2647,261 +2586,217 @@ int reply_tdis(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) /**************************************************************************** reply to a echo ****************************************************************************/ -int reply_echo(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_echo(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { - int cnum; - int smb_reverb = SVAL(inbuf,smb_vwv0); - int seq_num; - int data_len = smb_buflen(inbuf); - int outsize = set_message(outbuf,1,data_len,True); - - cnum = SVAL(inbuf,smb_tid); - - /* According to the latest CIFS spec we shouldn't - care what the TID is. - */ - -#if 0 - if (cnum != 0xFFFF && !OPEN_CNUM(cnum)) - { - DEBUG(4,("Invalid cnum in echo (%d)\n",cnum)); - return(ERROR(ERRSRV,ERRinvnid)); - } -#endif + int smb_reverb = SVAL(inbuf,smb_vwv0); + int seq_num; + int data_len = smb_buflen(inbuf); + int outsize = set_message(outbuf,1,data_len,True); + + /* copy any incoming data back out */ + if (data_len > 0) + memcpy(smb_buf(outbuf),smb_buf(inbuf),data_len); - /* copy any incoming data back out */ - if (data_len > 0) - memcpy(smb_buf(outbuf),smb_buf(inbuf),data_len); + if (smb_reverb > 100) { + DEBUG(0,("large reverb (%d)?? Setting to 100\n",smb_reverb)); + smb_reverb = 100; + } - if (smb_reverb > 100) - { - DEBUG(0,("large reverb (%d)?? Setting to 100\n",smb_reverb)); - smb_reverb = 100; - } + for (seq_num =1 ; seq_num <= smb_reverb ; seq_num++) { + SSVAL(outbuf,smb_vwv0,seq_num); - for (seq_num =1 ; seq_num <= smb_reverb ; seq_num++) - { - SSVAL(outbuf,smb_vwv0,seq_num); + smb_setlen(outbuf,outsize - 4); - smb_setlen(outbuf,outsize - 4); - - send_smb(Client,outbuf); - } + send_smb(Client,outbuf); + } - DEBUG( 3, ( "echo %d times cnum=%d\n", smb_reverb, cnum ) ); + DEBUG(3,("echo %d times\n", smb_reverb)); - return -1; + return -1; } /**************************************************************************** reply to a printopen ****************************************************************************/ -int reply_printopen(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_printopen(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { - pstring fname; - pstring fname2; - int cnum; - int fnum = -1; - int outsize = 0; - files_struct *fsp; - - *fname = *fname2 = 0; - - cnum = SVAL(inbuf,smb_tid); - - if (!CAN_PRINT(cnum)) - return(ERROR(ERRDOS,ERRnoaccess)); - - { - pstring s; - char *p; - pstrcpy(s,smb_buf(inbuf)+1); - p = s; - while (*p) - { - if (!(isalnum(*p) || strchr("._-",*p))) - *p = 'X'; - p++; - } + pstring fname; + pstring fname2; + int fnum = -1; + int outsize = 0; + files_struct *fsp; + + *fname = *fname2 = 0; + + if (!CAN_PRINT(conn)) + return(ERROR(ERRDOS,ERRnoaccess)); - if (strlen(s) > 10) s[10] = 0; + { + pstring s; + char *p; + pstrcpy(s,smb_buf(inbuf)+1); + p = s; + while (*p) { + if (!(isalnum(*p) || strchr("._-",*p))) + *p = 'X'; + p++; + } - slprintf(fname,sizeof(fname)-1, "%s.XXXXXX",s); - } + if (strlen(s) > 10) s[10] = 0; - fnum = find_free_file(); - if (fnum < 0) - return(ERROR(ERRSRV,ERRnofids)); + slprintf(fname,sizeof(fname)-1, "%s.XXXXXX",s); + } - fsp = &Files[fnum]; + fnum = find_free_file(); + if (fnum < 0) + return(ERROR(ERRSRV,ERRnofids)); - pstrcpy(fname2,(char *)mktemp(fname)); + fsp = &Files[fnum]; + + pstrcpy(fname2,(char *)mktemp(fname)); - if (!check_name(fname2,cnum)) { - fsp->reserved = False; - return(ERROR(ERRDOS,ERRnoaccess)); - } + if (!check_name(fname2,conn)) { + fsp->reserved = False; + return(ERROR(ERRDOS,ERRnoaccess)); + } - /* Open for exclusive use, write only. */ - open_file_shared(fnum,cnum,fname2,(DENY_ALL<<4)|1, 0x12, unix_mode(cnum,0), - 0, NULL, NULL); + /* Open for exclusive use, write only. */ + open_file_shared(fnum,conn,fname2, + (DENY_ALL<<4)|1, 0x12, unix_mode(conn,0), + 0, NULL, NULL); - if (!fsp->open) { - fsp->reserved = False; - return(UNIXERROR(ERRDOS,ERRnoaccess)); - } + if (!fsp->open) { + fsp->reserved = False; + return(UNIXERROR(ERRDOS,ERRnoaccess)); + } - /* force it to be a print file */ - fsp->print_file = True; + /* force it to be a print file */ + fsp->print_file = True; - outsize = set_message(outbuf,1,0,True); - SSVAL(outbuf,smb_vwv0,fnum); + outsize = set_message(outbuf,1,0,True); + SSVAL(outbuf,smb_vwv0,fnum); - DEBUG( 3, ("openprint %s fd=%d fnum=%d cnum=%d\n", - fname2, fsp->fd_ptr->fd, fnum, cnum ) ); + DEBUG(3,("openprint %s fd=%d fnum=%d\n", + fname2, fsp->fd_ptr->fd, fnum)); - return(outsize); + return(outsize); } /**************************************************************************** reply to a printclose ****************************************************************************/ -int reply_printclose(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_printclose(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { - int fnum,cnum; - int outsize = set_message(outbuf,0,0,True); + int fnum; + int outsize = set_message(outbuf,0,0,True); - cnum = SVAL(inbuf,smb_tid); - fnum = GETFNUM(inbuf,smb_vwv0); + fnum = GETFNUM(inbuf,smb_vwv0); - CHECK_FNUM(fnum,cnum); - CHECK_ERROR(fnum); + CHECK_FNUM(fnum,conn); + CHECK_ERROR(fnum); - if (!CAN_PRINT(cnum)) - return(ERROR(ERRDOS,ERRnoaccess)); + if (!CAN_PRINT(conn)) + return(ERROR(ERRDOS,ERRnoaccess)); - DEBUG( 3, ( "printclose fd=%d fnum=%d cnum=%d\n", - Files[fnum].fd_ptr->fd,fnum,cnum)); + DEBUG(3,("printclose fd=%d fnum=%d\n", + Files[fnum].fd_ptr->fd,fnum)); - close_file(fnum,True); + close_file(fnum,True); - return(outsize); + return(outsize); } /**************************************************************************** reply to a printqueue ****************************************************************************/ -int reply_printqueue(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_printqueue(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { - int cnum; - int outsize = set_message(outbuf,2,3,True); - int max_count = SVAL(inbuf,smb_vwv0); - int start_index = SVAL(inbuf,smb_vwv1); - uint16 vuid; - - cnum = SVAL(inbuf,smb_tid); - vuid = SVAL(inbuf,smb_uid); - -/* allow checking the queue for anyone */ -#if 0 - if (!CAN_PRINT(cnum)) - return(ERROR(ERRDOS,ERRnoaccess)); -#endif - - SSVAL(outbuf,smb_vwv0,0); - SSVAL(outbuf,smb_vwv1,0); - CVAL(smb_buf(outbuf),0) = 1; - SSVAL(smb_buf(outbuf),1,0); + int outsize = set_message(outbuf,2,3,True); + int max_count = SVAL(inbuf,smb_vwv0); + int start_index = SVAL(inbuf,smb_vwv1); + uint16 vuid; + + vuid = SVAL(inbuf,smb_uid); + + /* we used to allow the client to get the cnum wrong, but that + is really quite gross and only worked when there was only + one printer - I think we should now only accept it if they + get it right (tridge) */ + if (!CAN_PRINT(conn)) + return(ERROR(ERRDOS,ERRnoaccess)); + + SSVAL(outbuf,smb_vwv0,0); + SSVAL(outbuf,smb_vwv1,0); + CVAL(smb_buf(outbuf),0) = 1; + SSVAL(smb_buf(outbuf),1,0); - DEBUG( 3, ( "printqueue cnum=%d start_index=%d max_count=%d\n", - cnum, start_index, max_count ) ); - - if (!OPEN_CNUM(cnum) || !Connections[cnum].printer) - { - int i; - cnum = -1; - - for (i=0;i<MAX_CONNECTIONS;i++) - if (CAN_PRINT(i) && Connections[i].printer) - cnum = i; - - if (cnum == -1) - for (i=0;i<MAX_CONNECTIONS;i++) - if (OPEN_CNUM(i)) - cnum = i; - - if (!OPEN_CNUM(cnum)) - return(ERROR(ERRSRV,ERRinvnid)); - - DEBUG(5,("connection not open or not a printer, using cnum %d\n",cnum)); - } - - if (!become_user(&Connections[cnum], cnum, vuid)) - return(ERROR(ERRSRV,ERRinvnid)); - - { - print_queue_struct *queue = NULL; - char *p = smb_buf(outbuf) + 3; - int count = get_printqueue(SNUM(cnum),cnum,&queue,NULL); - int num_to_get = ABS(max_count); - int first = (max_count>0?start_index:start_index+max_count+1); - int i; + DEBUG(3,("printqueue start_index=%d max_count=%d\n", + start_index, max_count)); - if (first >= count) - num_to_get = 0; - else - num_to_get = MIN(num_to_get,count-first); + { + print_queue_struct *queue = NULL; + char *p = smb_buf(outbuf) + 3; + int count = get_printqueue(SNUM(conn), conn,&queue,NULL); + int num_to_get = ABS(max_count); + int first = (max_count>0?start_index:start_index+max_count+1); + int i; + + if (first >= count) + num_to_get = 0; + else + num_to_get = MIN(num_to_get,count-first); - for (i=first;i<first+num_to_get;i++) - { - put_dos_date2(p,0,queue[i].time); - CVAL(p,4) = (queue[i].status==LPQ_PRINTING?2:3); - SSVAL(p,5,printjob_encode(SNUM(cnum), queue[i].job)); - SIVAL(p,7,queue[i].size); - CVAL(p,11) = 0; - StrnCpy(p+12,queue[i].user,16); - p += 28; - } + for (i=first;i<first+num_to_get;i++) { + put_dos_date2(p,0,queue[i].time); + CVAL(p,4) = (queue[i].status==LPQ_PRINTING?2:3); + SSVAL(p,5,printjob_encode(SNUM(conn), + queue[i].job)); + SIVAL(p,7,queue[i].size); + CVAL(p,11) = 0; + StrnCpy(p+12,queue[i].user,16); + p += 28; + } - if (count > 0) - { - outsize = set_message(outbuf,2,28*count+3,False); - SSVAL(outbuf,smb_vwv0,count); - SSVAL(outbuf,smb_vwv1,(max_count>0?first+count:first-1)); - CVAL(smb_buf(outbuf),0) = 1; - SSVAL(smb_buf(outbuf),1,28*count); - } + if (count > 0) { + outsize = set_message(outbuf,2,28*count+3,False); + SSVAL(outbuf,smb_vwv0,count); + SSVAL(outbuf,smb_vwv1,(max_count>0?first+count:first-1)); + CVAL(smb_buf(outbuf),0) = 1; + SSVAL(smb_buf(outbuf),1,28*count); + } - if (queue) free(queue); + if (queue) free(queue); - DEBUG(3,("%d entries returned in queue\n",count)); - } + DEBUG(3,("%d entries returned in queue\n",count)); + } - return(outsize); + return(outsize); } /**************************************************************************** reply to a printwrite ****************************************************************************/ -int reply_printwrite(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_printwrite(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { - int cnum,numtowrite,fnum; + int numtowrite,fnum; int outsize = set_message(outbuf,0,0,True); char *data; - cnum = SVAL(inbuf,smb_tid); - - if (!CAN_PRINT(cnum)) + if (!CAN_PRINT(conn)) return(ERROR(ERRDOS,ERRnoaccess)); fnum = GETFNUM(inbuf,smb_vwv0); - CHECK_FNUM(fnum,cnum); + CHECK_FNUM(fnum,conn); CHECK_WRITE(fnum); CHECK_ERROR(fnum); @@ -2911,7 +2806,7 @@ int reply_printwrite(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) if (write_file(fnum,data,numtowrite) != numtowrite) return(UNIXERROR(ERRDOS,ERRnoaccess)); - DEBUG( 3, ( "printwrite fnum=%d cnum=%d num=%d\n", fnum, cnum, numtowrite ) ); + DEBUG( 3, ( "printwrite fnum=%d num=%d\n", fnum, numtowrite ) ); return(outsize); } @@ -2920,19 +2815,17 @@ int reply_printwrite(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) /**************************************************************************** reply to a mkdir ****************************************************************************/ -int reply_mkdir(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_mkdir(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { pstring directory; - int cnum; int outsize,ret= -1; BOOL bad_path = False; pstrcpy(directory,smb_buf(inbuf) + 1); - cnum = SVAL(inbuf,smb_tid); - unix_convert(directory,cnum,0,&bad_path); + unix_convert(directory,conn,0,&bad_path); - if (check_name(directory,cnum)) - ret = sys_mkdir(directory,unix_mode(cnum,aDIR)); + if (check_name(directory, conn)) + ret = sys_mkdir(directory,unix_mode(conn,aDIR)); if (ret < 0) { @@ -2946,7 +2839,7 @@ int reply_mkdir(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) outsize = set_message(outbuf,0,0,True); - DEBUG( 3, ( "mkdir %s cnum=%d ret=%d\n", directory, cnum, ret ) ); + DEBUG( 3, ( "mkdir %s ret=%d\n", directory, ret ) ); return(outsize); } @@ -2959,7 +2852,7 @@ static BOOL recursive_rmdir(char *directory) { char *dname = NULL; BOOL ret = False; - void *dirptr = OpenDir(-1, directory, False); + void *dirptr = OpenDir(NULL, directory, False); if(dirptr == NULL) return True; @@ -3015,24 +2908,22 @@ static BOOL recursive_rmdir(char *directory) /**************************************************************************** reply to a rmdir ****************************************************************************/ -int reply_rmdir(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_rmdir(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { pstring directory; - int cnum; int outsize = 0; BOOL ok = False; BOOL bad_path = False; - cnum = SVAL(inbuf,smb_tid); pstrcpy(directory,smb_buf(inbuf) + 1); - unix_convert(directory,cnum,0,&bad_path); + unix_convert(directory,conn, NULL,&bad_path); - if (check_name(directory,cnum)) + if (check_name(directory,conn)) { dptr_closepath(directory,SVAL(inbuf,smb_pid)); ok = (sys_rmdir(directory) == 0); - if(!ok && (errno == ENOTEMPTY) && lp_veto_files(SNUM(cnum))) + if(!ok && (errno == ENOTEMPTY) && lp_veto_files(SNUM(conn))) { /* Check to see if the only thing in this directory are vetoed files/directories. If so then delete them and @@ -3040,7 +2931,7 @@ int reply_rmdir(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) do a recursive delete) then fail the rmdir. */ BOOL all_veto_files = True; char *dname; - void *dirptr = OpenDir(cnum, directory, False); + void *dirptr = OpenDir(conn, directory, False); if(dirptr != NULL) { @@ -3049,7 +2940,7 @@ int reply_rmdir(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { if((strcmp(dname, ".") == 0) || (strcmp(dname, "..")==0)) continue; - if(!IS_VETO_PATH(cnum, dname)) + if(!IS_VETO_PATH(conn, dname)) { all_veto_files = False; break; @@ -3080,7 +2971,7 @@ int reply_rmdir(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) break; if(st.st_mode & S_IFDIR) { - if(lp_recursive_veto_delete(SNUM(cnum))) + if(lp_recursive_veto_delete(SNUM(conn))) { if(recursive_rmdir(fullname) != 0) break; @@ -3192,14 +3083,14 @@ static BOOL resolve_wildcards(char *name1,char *name2) /******************************************************************* check if a user is allowed to rename a file ********************************************************************/ -static BOOL can_rename(char *fname,int cnum) +static BOOL can_rename(char *fname,connection_struct *conn) { struct stat sbuf; - if (!CAN_WRITE(cnum)) return(False); + if (!CAN_WRITE(conn)) return(False); if (sys_lstat(fname,&sbuf) != 0) return(False); - if (!check_file_sharing(cnum,fname,True)) return(False); + if (!check_file_sharing(conn,fname,True)) return(False); return(True); } @@ -3208,204 +3099,205 @@ static BOOL can_rename(char *fname,int cnum) The guts of the rename command, split out so it may be called by the NT SMB code. ****************************************************************************/ - -int rename_internals(char *inbuf, char *outbuf, char *name, char *newname, BOOL replace_if_exists) +int rename_internals(connection_struct *conn, + char *inbuf, char *outbuf, char *name, + char *newname, BOOL replace_if_exists) { - int cnum; - pstring directory; - pstring mask; - pstring newname_last_component; - char *p; - BOOL has_wild; - BOOL bad_path1 = False; - BOOL bad_path2 = False; - int count=0; - int error = ERRnoaccess; - BOOL exists=False; - - cnum = SVAL(inbuf,smb_tid); - - *directory = *mask = 0; - - unix_convert(name,cnum,0,&bad_path1); - unix_convert(newname,cnum,newname_last_component,&bad_path2); - - /* - * Split the old name into directory and last component - * strings. Note that unix_convert may have stripped off a - * leading ./ from both name and newname if the rename is - * at the root of the share. We need to make sure either both - * name and newname contain a / character or neither of them do - * as this is checked in resolve_wildcards(). - */ - - p = strrchr(name,'/'); - if (!p) { - pstrcpy(directory,"."); - pstrcpy(mask,name); - } else { - *p = 0; - pstrcpy(directory,name); - pstrcpy(mask,p+1); - *p = '/'; /* Replace needed for exceptional test below. */ - } - - if (is_mangled(mask)) - check_mangled_cache( mask ); - - has_wild = strchr(mask,'*') || strchr(mask,'?'); - - if (!has_wild) { - /* - * No wildcards - just process the one file. - */ - BOOL is_short_name = is_8_3(name, True); - - /* Add a terminating '/' to the directory name. */ - pstrcat(directory,"/"); - pstrcat(directory,mask); + pstring directory; + pstring mask; + pstring newname_last_component; + char *p; + BOOL has_wild; + BOOL bad_path1 = False; + BOOL bad_path2 = False; + int count=0; + int error = ERRnoaccess; + BOOL exists=False; + + *directory = *mask = 0; + + unix_convert(name,conn,0,&bad_path1); + unix_convert(newname,conn,newname_last_component,&bad_path2); + + /* + * Split the old name into directory and last component + * strings. Note that unix_convert may have stripped off a + * leading ./ from both name and newname if the rename is + * at the root of the share. We need to make sure either both + * name and newname contain a / character or neither of them do + * as this is checked in resolve_wildcards(). + */ + + p = strrchr(name,'/'); + if (!p) { + pstrcpy(directory,"."); + pstrcpy(mask,name); + } else { + *p = 0; + pstrcpy(directory,name); + pstrcpy(mask,p+1); + *p = '/'; /* Replace needed for exceptional test below. */ + } - /* Ensure newname contains a '/' also */ - if(strrchr(newname,'/') == 0) { - pstring tmpstr; + if (is_mangled(mask)) + check_mangled_cache( mask ); - pstrcpy(tmpstr, "./"); - pstrcat(tmpstr, newname); - pstrcpy(newname, tmpstr); - } - - DEBUG(3,("rename_internals: case_sensitive = %d, case_preserve = %d, short case preserve = %d, directory = %s, newname = %s, newname_last_component = %s, is_8_3 = %d\n", - case_sensitive, case_preserve, short_case_preserve, directory, - newname, newname_last_component, is_short_name)); + has_wild = strchr(mask,'*') || strchr(mask,'?'); - /* - * Check for special case with case preserving and not - * case sensitive, if directory and newname are identical, - * and the old last component differs from the original - * last component only by case, then we should allow - * the rename (user is trying to change the case of the - * filename). - */ - if((case_sensitive == False) && ( ((case_preserve == True) && (is_short_name == False)) || - ((short_case_preserve == True) && (is_short_name == True))) && - strcsequal(directory, newname)) { - pstring newname_modified_last_component; - - /* - * Get the last component of the modified name. - * Note that we guarantee that newname contains a '/' - * character above. - */ - p = strrchr(newname,'/'); - pstrcpy(newname_modified_last_component,p+1); + if (!has_wild) { + /* + * No wildcards - just process the one file. + */ + BOOL is_short_name = is_8_3(name, True); - if(strcsequal(newname_modified_last_component, - newname_last_component) == False) { - /* - * Replace the modified last component with - * the original. - */ - pstrcpy(p+1, newname_last_component); - } - } - - if(replace_if_exists) { - /* - * NT SMB specific flag - rename can overwrite - * file with the same name so don't check for - * file_exist(). - */ - if(resolve_wildcards(directory,newname) && - can_rename(directory,cnum) && - !sys_rename(directory,newname)) - count++; - } else { - if (resolve_wildcards(directory,newname) && - can_rename(directory,cnum) && - !file_exist(newname,NULL) && - !sys_rename(directory,newname)) - count++; - } + /* Add a terminating '/' to the directory name. */ + pstrcat(directory,"/"); + pstrcat(directory,mask); + + /* Ensure newname contains a '/' also */ + if(strrchr(newname,'/') == 0) { + pstring tmpstr; + + pstrcpy(tmpstr, "./"); + pstrcat(tmpstr, newname); + pstrcpy(newname, tmpstr); + } + + DEBUG(3,("rename_internals: case_sensitive = %d, case_preserve = %d, short case preserve = %d, directory = %s, newname = %s, newname_last_component = %s, is_8_3 = %d\n", + case_sensitive, case_preserve, short_case_preserve, directory, + newname, newname_last_component, is_short_name)); + + /* + * Check for special case with case preserving and not + * case sensitive, if directory and newname are identical, + * and the old last component differs from the original + * last component only by case, then we should allow + * the rename (user is trying to change the case of the + * filename). + */ + if((case_sensitive == False) && + (((case_preserve == True) && + (is_short_name == False)) || + ((short_case_preserve == True) && + (is_short_name == True))) && + strcsequal(directory, newname)) { + pstring newname_modified_last_component; + + /* + * Get the last component of the modified name. + * Note that we guarantee that newname contains a '/' + * character above. + */ + p = strrchr(newname,'/'); + pstrcpy(newname_modified_last_component,p+1); + + if(strcsequal(newname_modified_last_component, + newname_last_component) == False) { + /* + * Replace the modified last component with + * the original. + */ + pstrcpy(p+1, newname_last_component); + } + } + + if(replace_if_exists) { + /* + * NT SMB specific flag - rename can overwrite + * file with the same name so don't check for + * file_exist(). + */ + if(resolve_wildcards(directory,newname) && + can_rename(directory,conn) && + !sys_rename(directory,newname)) + count++; + } else { + if (resolve_wildcards(directory,newname) && + can_rename(directory,conn) && + !file_exist(newname,NULL) && + !sys_rename(directory,newname)) + count++; + } - DEBUG(3,("rename_internals: %s doing rename on %s -> %s\n",(count != 0) ? "succeeded" : "failed", + DEBUG(3,("rename_internals: %s doing rename on %s -> %s\n",(count != 0) ? "succeeded" : "failed", directory,newname)); - - if (!count) exists = file_exist(directory,NULL); - if (!count && exists && file_exist(newname,NULL)) { - exists = True; - error = 183; - } - } else { - /* - * Wildcards - process each file that matches. - */ - void *dirptr = NULL; - char *dname; - pstring destname; - - if (check_name(directory,cnum)) - dirptr = OpenDir(cnum, directory, True); - - if (dirptr) { - error = ERRbadfile; - - if (strequal(mask,"????????.???")) - pstrcpy(mask,"*"); - - while ((dname = ReadDirName(dirptr))) { - pstring fname; - pstrcpy(fname,dname); - - if(!mask_match(fname, mask, case_sensitive, False)) - continue; - - error = ERRnoaccess; - slprintf(fname,sizeof(fname)-1,"%s/%s",directory,dname); - if (!can_rename(fname,cnum)) { - DEBUG(6,("rename %s refused\n", fname)); - continue; - } - pstrcpy(destname,newname); - - if (!resolve_wildcards(fname,destname)) { - DEBUG(6,("resolve_wildcards %s %s failed\n", fname, destname)); - continue; - } - - if (!replace_if_exists && file_exist(destname,NULL)) { - DEBUG(6,("file_exist %s\n", destname)); - error = 183; - continue; - } - - if (!sys_rename(fname,destname)) - count++; - DEBUG(3,("rename_internals: doing rename on %s -> %s\n",fname,destname)); - } - CloseDir(dirptr); - } - } - - if (count == 0) { - if (exists) - return(ERROR(ERRDOS,error)); - else { - if((errno == ENOENT) && (bad_path1 || bad_path2)) { - unix_ERR_class = ERRDOS; - unix_ERR_code = ERRbadpath; - } - return(UNIXERROR(ERRDOS,error)); - } - } - - return 0; + + if (!count) exists = file_exist(directory,NULL); + if (!count && exists && file_exist(newname,NULL)) { + exists = True; + error = 183; + } + } else { + /* + * Wildcards - process each file that matches. + */ + void *dirptr = NULL; + char *dname; + pstring destname; + + if (check_name(directory,conn)) + dirptr = OpenDir(conn, directory, True); + + if (dirptr) { + error = ERRbadfile; + + if (strequal(mask,"????????.???")) + pstrcpy(mask,"*"); + + while ((dname = ReadDirName(dirptr))) { + pstring fname; + pstrcpy(fname,dname); + + if(!mask_match(fname, mask, case_sensitive, False)) + continue; + + error = ERRnoaccess; + slprintf(fname,sizeof(fname)-1,"%s/%s",directory,dname); + if (!can_rename(fname,conn)) { + DEBUG(6,("rename %s refused\n", fname)); + continue; + } + pstrcpy(destname,newname); + + if (!resolve_wildcards(fname,destname)) { + DEBUG(6,("resolve_wildcards %s %s failed\n", fname, destname)); + continue; + } + + if (!replace_if_exists && file_exist(destname,NULL)) { + DEBUG(6,("file_exist %s\n", destname)); + error = 183; + continue; + } + + if (!sys_rename(fname,destname)) + count++; + DEBUG(3,("rename_internals: doing rename on %s -> %s\n",fname,destname)); + } + CloseDir(dirptr); + } + } + + if (count == 0) { + if (exists) + return(ERROR(ERRDOS,error)); + else { + if((errno == ENOENT) && (bad_path1 || bad_path2)) { + unix_ERR_class = ERRDOS; + unix_ERR_code = ERRbadpath; + } + return(UNIXERROR(ERRDOS,error)); + } + } + + return 0; } /**************************************************************************** Reply to a mv. ****************************************************************************/ -int reply_mv(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_mv(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { int outsize = 0; pstring name; @@ -3416,7 +3308,7 @@ int reply_mv(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) DEBUG(3,("reply_mv : %s -> %s\n",name,newname)); - outsize = rename_internals(inbuf, outbuf, name, newname, False); + outsize = rename_internals(conn, inbuf, outbuf, name, newname, False); if(outsize == 0) outsize = set_message(outbuf,0,0,True); @@ -3426,7 +3318,7 @@ int reply_mv(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) /******************************************************************* copy a file as part of a reply_copy ******************************************************************/ -static BOOL copy_file(char *src,char *dest1,int cnum,int ofun, +static BOOL copy_file(char *src,char *dest1,connection_struct *conn, int ofun, int count,BOOL target_is_directory) { int Access,action; @@ -3450,7 +3342,7 @@ static BOOL copy_file(char *src,char *dest1,int cnum,int ofun, fnum1 = find_free_file(); if (fnum1<0) return(False); - open_file_shared(fnum1,cnum,src,(DENY_NONE<<4), + open_file_shared(fnum1,conn,src,(DENY_NONE<<4), 1,0,0,&Access,&action); if (!Files[fnum1].open) { @@ -3466,7 +3358,7 @@ static BOOL copy_file(char *src,char *dest1,int cnum,int ofun, close_file(fnum1,False); return(False); } - open_file_shared(fnum2,cnum,dest,(DENY_NONE<<4)|1, + open_file_shared(fnum2,conn,dest,(DENY_NONE<<4)|1, ofun,st.st_mode,0,&Access,&action); if (!Files[fnum2].open) { @@ -3494,11 +3386,10 @@ static BOOL copy_file(char *src,char *dest1,int cnum,int ofun, /**************************************************************************** reply to a file copy. ****************************************************************************/ -int reply_copy(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_copy(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { int outsize = 0; pstring name; - int cnum; pstring directory; pstring mask,newname; char *p; @@ -3515,21 +3406,19 @@ int reply_copy(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) *directory = *mask = 0; - cnum = SVAL(inbuf,smb_tid); - pstrcpy(name,smb_buf(inbuf)); pstrcpy(newname,smb_buf(inbuf) + 1 + strlen(name)); DEBUG(3,("reply_copy : %s -> %s\n",name,newname)); - if (tid2 != cnum) { + if (tid2 != conn->cnum) { /* can't currently handle inter share copies XXXX */ DEBUG(3,("Rejecting inter-share copy\n")); return(ERROR(ERRSRV,ERRinvdevice)); } - unix_convert(name,cnum,0,&bad_path1); - unix_convert(newname,cnum,0,&bad_path2); + unix_convert(name,conn,0,&bad_path1); + unix_convert(newname,conn,0,&bad_path2); target_is_directory = directory_exist(newname,NULL); @@ -3566,7 +3455,7 @@ int reply_copy(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) pstrcat(directory,"/"); pstrcat(directory,mask); if (resolve_wildcards(directory,newname) && - copy_file(directory,newname,cnum,ofun, + copy_file(directory,newname,conn,ofun, count,target_is_directory)) count++; if (!count) exists = file_exist(directory,NULL); } else { @@ -3574,8 +3463,8 @@ int reply_copy(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) char *dname; pstring destname; - if (check_name(directory,cnum)) - dirptr = OpenDir(cnum, directory, True); + if (check_name(directory,conn)) + dirptr = OpenDir(conn, directory, True); if (dirptr) { @@ -3595,7 +3484,7 @@ int reply_copy(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) slprintf(fname,sizeof(fname)-1, "%s/%s",directory,dname); pstrcpy(destname,newname); if (resolve_wildcards(fname,destname) && - copy_file(directory,newname,cnum,ofun, + copy_file(directory,newname,conn,ofun, count,target_is_directory)) count++; DEBUG(3,("reply_copy : doing copy on %s -> %s\n",fname,destname)); } @@ -3628,38 +3517,36 @@ int reply_copy(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) /**************************************************************************** reply to a setdir ****************************************************************************/ -int reply_setdir(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_setdir(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { - int cnum,snum; + int snum; int outsize = 0; BOOL ok = False; pstring newdir; - cnum = SVAL(inbuf,smb_tid); - - snum = Connections[cnum].service; + snum = SNUM(conn); if (!CAN_SETDIR(snum)) return(ERROR(ERRDOS,ERRnoaccess)); pstrcpy(newdir,smb_buf(inbuf) + 1); strlower(newdir); - if (strlen(newdir) == 0) - ok = True; - else - { - ok = directory_exist(newdir,NULL); - if (ok) - string_set(&Connections[cnum].connectpath,newdir); - } + if (strlen(newdir) == 0) { + ok = True; + } else { + ok = directory_exist(newdir,NULL); + if (ok) { + string_set(&conn->connectpath,newdir); + } + } if (!ok) - return(ERROR(ERRDOS,ERRbadpath)); + return(ERROR(ERRDOS,ERRbadpath)); outsize = set_message(outbuf,0,0,True); CVAL(outbuf,smb_reh) = CVAL(inbuf,smb_reh); - - DEBUG( 3, ( "setdir %s cnum=%d\n", newdir, cnum ) ); + + DEBUG(3,("setdir %s\n", newdir)); return(outsize); } @@ -3668,7 +3555,7 @@ int reply_setdir(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) /**************************************************************************** reply to a lockingX request ****************************************************************************/ -int reply_lockingX(char *inbuf,char *outbuf,int length,int bufsize) +int reply_lockingX(connection_struct *conn, char *inbuf,char *outbuf,int length,int bufsize) { int fnum = GETFNUM(inbuf,smb_vwv2); unsigned char locktype = CVAL(inbuf,smb_vwv3); @@ -3679,15 +3566,12 @@ int reply_lockingX(char *inbuf,char *outbuf,int length,int bufsize) uint16 num_locks = SVAL(inbuf,smb_vwv7); uint32 count, offset; int32 lock_timeout = IVAL(inbuf,smb_vwv4); - int cnum; int i; char *data; uint32 ecode=0, dummy2; int eclass=0, dummy1; - cnum = SVAL(inbuf,smb_tid); - - CHECK_FNUM(fnum,cnum); + CHECK_FNUM(fnum,conn); CHECK_ERROR(fnum); data = smb_buf(inbuf); @@ -3715,14 +3599,14 @@ no oplock granted on this file.\n", fnum)); } /* Remove the oplock flag from the sharemode. */ - lock_share_entry(fsp->cnum, dev, inode, &token); + lock_share_entry(fsp->conn, dev, inode, &token); if(remove_share_oplock( fnum, token)==False) { DEBUG(0,("reply_lockingX: failed to remove share oplock for fnum %d, \ dev = %x, inode = %x\n", fnum, dev, inode)); - unlock_share_entry(fsp->cnum, dev, inode, token); + unlock_share_entry(fsp->conn, dev, inode, token); } else { - unlock_share_entry(fsp->cnum, dev, inode, token); + unlock_share_entry(fsp->conn, dev, inode, token); /* Clear the granted flag and return. */ fsp->granted_oplock = False; @@ -3745,7 +3629,7 @@ dev = %x, inode = %x\n", for(i = 0; i < (int)num_ulocks; i++) { count = IVAL(data,SMB_LKLEN_OFFSET(i)); offset = IVAL(data,SMB_LKOFF_OFFSET(i)); - if(!do_unlock(fnum,cnum,count,offset,&eclass, &ecode)) + if(!do_unlock(fnum,conn,count,offset,&eclass, &ecode)) return ERROR(eclass,ecode); } @@ -3759,7 +3643,7 @@ dev = %x, inode = %x\n", for(i = 0; i < (int)num_locks; i++) { count = IVAL(data,SMB_LKLEN_OFFSET(i)); offset = IVAL(data,SMB_LKOFF_OFFSET(i)); - if(!do_lock(fnum,cnum,count,offset, ((locktype & 1) ? F_RDLCK : F_WRLCK), + if(!do_lock(fnum,conn,count,offset, ((locktype & 1) ? F_RDLCK : F_WRLCK), &eclass, &ecode)) #if 0 /* JRATEST - blocking lock code. */ if((ecode == ERRlock) && (lock_timeout != 0)) { @@ -3780,15 +3664,15 @@ dev = %x, inode = %x\n", for(; i >= 0; i--) { count = IVAL(data,SMB_LKLEN_OFFSET(i)); offset = IVAL(data,SMB_LKOFF_OFFSET(i)); - do_unlock(fnum,cnum,count,offset,&dummy1,&dummy2); + do_unlock(fnum,conn,count,offset,&dummy1,&dummy2); } return ERROR(eclass,ecode); } set_message(outbuf,2,0,True); - DEBUG( 3, ( "lockingX fnum=%d cnum=%d type=%d num_locks=%d num_ulocks=%d\n", - fnum, cnum, (unsigned int)locktype, num_locks, num_ulocks ) ); + DEBUG( 3, ( "lockingX fnum=%d type=%d num_locks=%d num_ulocks=%d\n", + fnum, (unsigned int)locktype, num_locks, num_ulocks ) ); chain_fnum = fnum; @@ -3799,9 +3683,9 @@ dev = %x, inode = %x\n", /**************************************************************************** reply to a SMBreadbmpx (read block multiplex) request ****************************************************************************/ -int reply_readbmpx(char *inbuf,char *outbuf,int length,int bufsize) +int reply_readbmpx(connection_struct *conn, char *inbuf,char *outbuf,int length,int bufsize) { - int cnum,fnum; + int fnum; int nread = -1; int total_read; char *data; @@ -3817,10 +3701,9 @@ int reply_readbmpx(char *inbuf,char *outbuf,int length,int bufsize) outsize = set_message(outbuf,8,0,True); - cnum = SVAL(inbuf,smb_tid); fnum = GETFNUM(inbuf,smb_vwv0); - CHECK_FNUM(fnum,cnum); + CHECK_FNUM(fnum,conn); CHECK_READ(fnum); CHECK_ERROR(fnum); @@ -3837,7 +3720,7 @@ int reply_readbmpx(char *inbuf,char *outbuf,int length,int bufsize) tcount = maxcount; total_read = 0; - if (is_locked(fnum,cnum,maxcount,startpos, F_RDLCK)) + if (is_locked(fnum,conn,maxcount,startpos, F_RDLCK)) return(ERROR(ERRDOS,ERRlock)); do @@ -3871,19 +3754,18 @@ int reply_readbmpx(char *inbuf,char *outbuf,int length,int bufsize) /**************************************************************************** reply to a SMBwritebmpx (write block multiplex primary) request ****************************************************************************/ -int reply_writebmpx(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_writebmpx(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { - int cnum,numtowrite,fnum; + int numtowrite,fnum; int nwritten = -1; int outsize = 0; uint32 startpos; int tcount, write_through, smb_doff; char *data; - cnum = SVAL(inbuf,smb_tid); fnum = GETFNUM(inbuf,smb_vwv0); - CHECK_FNUM(fnum,cnum); + CHECK_FNUM(fnum,conn); CHECK_WRITE(fnum); CHECK_ERROR(fnum); @@ -3899,14 +3781,14 @@ int reply_writebmpx(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) not an SMBwritebmpx - set this up now so we don't forget */ CVAL(outbuf,smb_com) = SMBwritec; - if (is_locked(fnum,cnum,tcount,startpos,F_WRLCK)) + if (is_locked(fnum,conn,tcount,startpos,F_WRLCK)) return(ERROR(ERRDOS,ERRlock)); seek_file(fnum,startpos); nwritten = write_file(fnum,data,numtowrite); - if(lp_syncalways(SNUM(cnum)) || write_through) - sync_file(cnum,fnum); + if(lp_syncalways(SNUM(conn)) || write_through) + sync_file(conn,fnum); if(nwritten < numtowrite) return(UNIXERROR(ERRHRD,ERRdiskfull)); @@ -3943,8 +3825,8 @@ int reply_writebmpx(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) SSVALS(outbuf,smb_vwv0,-1); /* We don't support smb_remaining */ - DEBUG( 3, ( "writebmpx fnum=%d cnum=%d num=%d wrote=%d\n", - fnum, cnum, numtowrite, nwritten ) ); + DEBUG( 3, ( "writebmpx fnum=%d num=%d wrote=%d\n", + fnum, numtowrite, nwritten ) ); if (write_through && tcount==nwritten) { /* we need to send both a primary and a secondary response */ @@ -3964,9 +3846,9 @@ int reply_writebmpx(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) /**************************************************************************** reply to a SMBwritebs (write block multiplex secondary) request ****************************************************************************/ -int reply_writebs(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_writebs(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { - int cnum,numtowrite,fnum; + int numtowrite,fnum; int nwritten = -1; int outsize = 0; int32 startpos; @@ -3975,9 +3857,8 @@ int reply_writebs(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) write_bmpx_struct *wbms; BOOL send_response = False; - cnum = SVAL(inbuf,smb_tid); fnum = GETFNUM(inbuf,smb_vwv0); - CHECK_FNUM(fnum,cnum); + CHECK_FNUM(fnum,conn); CHECK_WRITE(fnum); tcount = SVAL(inbuf,smb_vwv1); @@ -4006,8 +3887,8 @@ int reply_writebs(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) seek_file(fnum,startpos); nwritten = write_file(fnum,data,numtowrite); - if(lp_syncalways(SNUM(cnum)) || write_through) - sync_file(cnum,fnum); + if(lp_syncalways(SNUM(conn)) || write_through) + sync_file(conn,fnum); if (nwritten < numtowrite) { @@ -4045,18 +3926,17 @@ int reply_writebs(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) /**************************************************************************** reply to a SMBsetattrE ****************************************************************************/ -int reply_setattrE(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_setattrE(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { - int cnum,fnum; + int fnum; struct utimbuf unix_times; int outsize = 0; outsize = set_message(outbuf,0,0,True); - cnum = SVAL(inbuf,smb_tid); fnum = GETFNUM(inbuf,smb_vwv0); - CHECK_FNUM(fnum,cnum); + CHECK_FNUM(fnum,conn); CHECK_ERROR(fnum); /* Convert the DOS times into unix times. Ignore create @@ -4075,7 +3955,7 @@ int reply_setattrE(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) /* Ignore request */ if( DEBUGLVL( 3 ) ) { - dbgtext( "reply_setattrE fnum=%d cnum=%d ", fnum, cnum ); + dbgtext( "reply_setattrE fnum=%d ", fnum); dbgtext( "ignoring zero request - not setting timestamps of 0\n" ); } return(outsize); @@ -4087,11 +3967,11 @@ int reply_setattrE(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) } /* Set the date on this file */ - if(file_utime(cnum, Files[fnum].name, &unix_times)) + if(file_utime(conn, Files[fnum].fsp_name, &unix_times)) return(ERROR(ERRDOS,ERRnoaccess)); - DEBUG( 3, ( "reply_setattrE fnum=%d cnum=%d actime=%d modtime=%d\n", - fnum, cnum, unix_times.actime, unix_times.modtime ) ); + DEBUG( 3, ( "reply_setattrE fnum=%d actime=%d modtime=%d\n", + fnum, (int)unix_times.actime, (int)unix_times.modtime ) ); return(outsize); } @@ -4100,31 +3980,30 @@ int reply_setattrE(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) /**************************************************************************** reply to a SMBgetattrE ****************************************************************************/ -int reply_getattrE(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +int reply_getattrE(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize) { - int cnum,fnum; + int fnum; struct stat sbuf; int outsize = 0; int mode; outsize = set_message(outbuf,11,0,True); - cnum = SVAL(inbuf,smb_tid); fnum = GETFNUM(inbuf,smb_vwv0); - CHECK_FNUM(fnum,cnum); + CHECK_FNUM(fnum,conn); CHECK_ERROR(fnum); /* Do an fstat on this file */ if(fstat(Files[fnum].fd_ptr->fd, &sbuf)) return(UNIXERROR(ERRDOS,ERRnoaccess)); - mode = dos_mode(cnum,Files[fnum].name,&sbuf); + mode = dos_mode(conn,Files[fnum].fsp_name,&sbuf); /* Convert the times into dos times. Set create date to be last modify date as UNIX doesn't save this */ - put_dos_date2(outbuf,smb_vwv0,get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(cnum)))); + put_dos_date2(outbuf,smb_vwv0,get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(conn)))); put_dos_date2(outbuf,smb_vwv2,sbuf.st_atime); put_dos_date2(outbuf,smb_vwv4,sbuf.st_mtime); if (mode & aDIR) @@ -4139,7 +4018,7 @@ int reply_getattrE(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) } SSVAL(outbuf,smb_vwv10, mode); - DEBUG( 3, ( "reply_getattrE fnum=%d cnum=%d\n", fnum, cnum ) ); + DEBUG( 3, ( "reply_getattrE fnum=%d\n", fnum)); return(outsize); } diff --git a/source3/smbd/server.c b/source3/smbd/server.c index 143b45e9ef..9c7bafd9dd 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -65,7 +65,7 @@ extern int dcelogin_atmost_once; */ extern DOM_SID global_machine_sid; -connection_struct Connections[MAX_CONNECTIONS]; +static connection_struct Connections[MAX_CONNECTIONS]; files_struct Files[MAX_FNUMS]; /* @@ -116,8 +116,6 @@ extern int extra_time_offset; extern pstring myhostname; -static int find_free_connection(int hash); - /* for readability... */ #define IS_DOS_READONLY(test_mode) (((test_mode) & aRONLY) != 0) #define IS_DOS_DIR(test_mode) (((test_mode) & aDIR) != 0) @@ -156,7 +154,7 @@ void killkids(void) Then apply create mask, then add force bits. ****************************************************************************/ -mode_t unix_mode(int cnum,int dosmode) +mode_t unix_mode(connection_struct *conn,int dosmode) { mode_t result = (S_IRUSR | S_IRGRP | S_IROTH); @@ -168,23 +166,23 @@ mode_t unix_mode(int cnum,int dosmode) can always create a file in a read-only directory. */ result |= (S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH | S_IWUSR); /* Apply directory mask */ - result &= lp_dir_mode(SNUM(cnum)); + result &= lp_dir_mode(SNUM(conn)); /* Add in force bits */ - result |= lp_force_dir_mode(SNUM(cnum)); + result |= lp_force_dir_mode(SNUM(conn)); } else { - if (MAP_ARCHIVE(cnum) && IS_DOS_ARCHIVE(dosmode)) + if (lp_map_archive(SNUM(conn)) && IS_DOS_ARCHIVE(dosmode)) result |= S_IXUSR; - if (MAP_SYSTEM(cnum) && IS_DOS_SYSTEM(dosmode)) + if (lp_map_system(SNUM(conn)) && IS_DOS_SYSTEM(dosmode)) result |= S_IXGRP; - if (MAP_HIDDEN(cnum) && IS_DOS_HIDDEN(dosmode)) + if (lp_map_hidden(SNUM(conn)) && IS_DOS_HIDDEN(dosmode)) result |= S_IXOTH; /* Apply mode mask */ - result &= lp_create_mode(SNUM(cnum)); + result &= lp_create_mode(SNUM(conn)); /* Add in force bits */ - result |= lp_force_create_mode(SNUM(cnum)); + result |= lp_force_create_mode(SNUM(conn)); } return(result); } @@ -193,16 +191,16 @@ mode_t unix_mode(int cnum,int dosmode) /**************************************************************************** change a unix mode to a dos mode ****************************************************************************/ -int dos_mode(int cnum,char *path,struct stat *sbuf) +int dos_mode(connection_struct *conn,char *path,struct stat *sbuf) { int result = 0; extern struct current_user current_user; - DEBUG(8,("dos_mode: %d %s\n", cnum, path)); + DEBUG(8,("dos_mode: %s\n", path)); - if (CAN_WRITE(cnum) && !lp_alternate_permissions(SNUM(cnum))) { + if (CAN_WRITE(conn) && !lp_alternate_permissions(SNUM(conn))) { if (!((sbuf->st_mode & S_IWOTH) || - Connections[cnum].admin_user || + conn->admin_user || ((sbuf->st_mode & S_IWUSR) && current_user.uid==sbuf->st_uid) || ((sbuf->st_mode & S_IWGRP) && in_group(sbuf->st_gid,current_user.gid, @@ -213,13 +211,13 @@ int dos_mode(int cnum,char *path,struct stat *sbuf) result |= aRONLY; } - if (MAP_ARCHIVE(cnum) && ((sbuf->st_mode & S_IXUSR) != 0)) + if (MAP_ARCHIVE(conn) && ((sbuf->st_mode & S_IXUSR) != 0)) result |= aARCH; - if (MAP_SYSTEM(cnum) && ((sbuf->st_mode & S_IXGRP) != 0)) + if (MAP_SYSTEM(conn) && ((sbuf->st_mode & S_IXGRP) != 0)) result |= aSYSTEM; - if (MAP_HIDDEN(cnum) && ((sbuf->st_mode & S_IXOTH) != 0)) + if (MAP_HIDDEN(conn) && ((sbuf->st_mode & S_IXOTH) != 0)) result |= aHIDDEN; if (S_ISDIR(sbuf->st_mode)) @@ -233,7 +231,7 @@ int dos_mode(int cnum,char *path,struct stat *sbuf) #endif /* hide files with a name starting with a . */ - if (lp_hide_dot_files(SNUM(cnum))) + if (lp_hide_dot_files(SNUM(conn))) { char *p = strrchr(path,'/'); if (p) @@ -247,7 +245,7 @@ int dos_mode(int cnum,char *path,struct stat *sbuf) /* Optimization : Only call is_hidden_path if it's not already hidden. */ - if (!(result & aHIDDEN) && IS_HIDDEN_PATH(cnum,path)) + if (!(result & aHIDDEN) && IS_HIDDEN_PATH(conn,path)) { result |= aHIDDEN; } @@ -268,7 +266,7 @@ int dos_mode(int cnum,char *path,struct stat *sbuf) /******************************************************************* chmod a file - but preserve some bits ********************************************************************/ -int dos_chmod(int cnum,char *fname,int dosmode,struct stat *st) +int dos_chmod(connection_struct *conn,char *fname,int dosmode,struct stat *st) { struct stat st1; int mask=0; @@ -282,9 +280,9 @@ int dos_chmod(int cnum,char *fname,int dosmode,struct stat *st) if (S_ISDIR(st->st_mode)) dosmode |= aDIR; - if (dos_mode(cnum,fname,st) == dosmode) return(0); + if (dos_mode(conn,fname,st) == dosmode) return(0); - unixmode = unix_mode(cnum,dosmode); + unixmode = unix_mode(conn,dosmode); /* preserve the s bits */ mask |= (S_ISUID | S_ISGID); @@ -295,9 +293,9 @@ int dos_chmod(int cnum,char *fname,int dosmode,struct stat *st) #endif /* possibly preserve the x bits */ - if (!MAP_ARCHIVE(cnum)) mask |= S_IXUSR; - if (!MAP_SYSTEM(cnum)) mask |= S_IXGRP; - if (!MAP_HIDDEN(cnum)) mask |= S_IXOTH; + if (!MAP_ARCHIVE(conn)) mask |= S_IXUSR; + if (!MAP_SYSTEM(conn)) mask |= S_IXGRP; + if (!MAP_HIDDEN(conn)) mask |= S_IXOTH; unixmode |= (st->st_mode & mask); @@ -323,7 +321,7 @@ Wrapper around sys_utime that possibly allows DOS semantics rather than POSIX. *******************************************************************/ -int file_utime(int cnum, char *fname, struct utimbuf *times) +int file_utime(connection_struct *conn, char *fname, struct utimbuf *times) { extern struct current_user current_user; struct stat sb; @@ -337,7 +335,7 @@ int file_utime(int cnum, char *fname, struct utimbuf *times) if((errno != EPERM) && (errno != EACCES)) return -1; - if(!lp_dos_filetimes(SNUM(cnum))) + if(!lp_dos_filetimes(SNUM(conn))) return -1; /* We have permission (given by the Samba admin) to @@ -350,9 +348,9 @@ int file_utime(int cnum, char *fname, struct utimbuf *times) return -1; /* Check if we have write access. */ - if (CAN_WRITE(cnum)) { + if (CAN_WRITE(conn)) { if (((sb.st_mode & S_IWOTH) || - Connections[cnum].admin_user || + conn->admin_user || ((sb.st_mode & S_IWUSR) && current_user.uid==sb.st_uid) || ((sb.st_mode & S_IWGRP) && in_group(sb.st_gid,current_user.gid, @@ -371,7 +369,7 @@ int file_utime(int cnum, char *fname, struct utimbuf *times) Change a filetime - possibly allowing DOS semantics. *******************************************************************/ -BOOL set_filetime(int cnum, char *fname, time_t mtime) +BOOL set_filetime(connection_struct *conn, char *fname, time_t mtime) { struct utimbuf times; @@ -379,7 +377,7 @@ BOOL set_filetime(int cnum, char *fname, time_t mtime) times.modtime = times.actime = mtime; - if (file_utime(cnum, fname, ×)) { + if (file_utime(conn, fname, ×)) { DEBUG(4,("set_filetime(%s) failed: %s\n",fname,strerror(errno))); } @@ -445,7 +443,7 @@ scan a directory to find a filename, matching without case sensitivity If the name looks like a mangled name then try via the mangling functions ****************************************************************************/ -static BOOL scan_directory(char *path, char *name,int cnum,BOOL docache) +static BOOL scan_directory(char *path, char *name,connection_struct *conn,BOOL docache) { void *cur_dir; char *dname; @@ -458,7 +456,7 @@ static BOOL scan_directory(char *path, char *name,int cnum,BOOL docache) if (*path == 0) path = "."; - if (docache && (dname = DirCacheCheck(path,name,SNUM(cnum)))) { + if (docache && (dname = DirCacheCheck(path,name,SNUM(conn)))) { pstrcpy(name, dname); return(True); } @@ -474,7 +472,7 @@ static BOOL scan_directory(char *path, char *name,int cnum,BOOL docache) mangled = !check_mangled_cache( name ); /* open the directory */ - if (!(cur_dir = OpenDir(cnum, path, True))) + if (!(cur_dir = OpenDir(conn, path, True))) { DEBUG(3,("scan dir didn't open dir [%s]\n",path)); return(False); @@ -488,13 +486,13 @@ static BOOL scan_directory(char *path, char *name,int cnum,BOOL docache) continue; pstrcpy(name2,dname); - if (!name_map_mangle(name2,False,SNUM(cnum))) continue; + if (!name_map_mangle(name2,False,SNUM(conn))) continue; if ((mangled && mangled_equal(name,name2)) || fname_equal(name, name2)) { /* we've found the file, change it's name and return */ - if (docache) DirCacheAdd(path,name,dname,SNUM(cnum)); + if (docache) DirCacheAdd(path,name,dname,SNUM(conn)); pstrcpy(name, dname); CloseDir(cur_dir); return(True); @@ -526,7 +524,7 @@ used to pick the correct error code to return between ENOENT and ENOTDIR as Windows applications depend on ERRbadpath being returned if a component of a pathname does not exist. ****************************************************************************/ -BOOL unix_convert(char *name,int cnum,pstring saved_last_component, BOOL *bad_path) +BOOL unix_convert(char *name,connection_struct *conn,char *saved_last_component, BOOL *bad_path) { struct stat st; char *start, *end; @@ -563,7 +561,7 @@ BOOL unix_convert(char *name,int cnum,pstring saved_last_component, BOOL *bad_pa strnorm(name); /* check if it's a printer file */ - if (Connections[cnum].printer) + if (conn->printer) { if ((! *name) || strchr(name,'/') || !is_8_3(name, True)) { @@ -584,7 +582,7 @@ BOOL unix_convert(char *name,int cnum,pstring saved_last_component, BOOL *bad_pa saved_errno = errno; - DEBUG(5,("unix_convert(%s,%d)\n",name,cnum)); + DEBUG(5,("unix_convert(%s)\n",name)); /* a special case - if we don't have any mangling chars and are case sensitive then searching won't help */ @@ -637,7 +635,7 @@ BOOL unix_convert(char *name,int cnum,pstring saved_last_component, BOOL *bad_pa /* try to find this part of the path in the directory */ if (strchr(start,'?') || strchr(start,'*') || - !scan_directory(dirpath, start, cnum, end?True:False)) + !scan_directory(dirpath, start, conn, end?True:False)) { if (end) { @@ -701,26 +699,25 @@ This is called by every routine before it allows an operation on a filename. It does any final confirmation necessary to ensure that the filename is a valid one for the user to access. ****************************************************************************/ -BOOL check_name(char *name,int cnum) +BOOL check_name(char *name,connection_struct *conn) { BOOL ret; errno = 0; - if( IS_VETO_PATH(cnum, name)) - { - DEBUG(5,("file path name %s vetoed\n",name)); - return(0); - } + if (IS_VETO_PATH(conn, name)) { + DEBUG(5,("file path name %s vetoed\n",name)); + return(0); + } - ret = reduce_name(name,Connections[cnum].connectpath,lp_widelinks(SNUM(cnum))); + ret = reduce_name(name,conn->connectpath,lp_widelinks(SNUM(conn))); /* Check if we are allowing users to follow symlinks */ /* Patch from David Clerc <David.Clerc@cui.unige.ch> University of Geneva */ #ifdef S_ISLNK - if (!lp_symlinks(SNUM(cnum))) + if (!lp_symlinks(SNUM(conn))) { struct stat statbuf; if ( (sys_lstat(name,&statbuf) != -1) && @@ -1037,7 +1034,8 @@ static BOOL check_access_allowed_for_current_user( char *fname, int accmode ) /**************************************************************************** open a file ****************************************************************************/ -static void open_file(int fnum,int cnum,char *fname1,int flags,int mode, struct stat *sbuf) +static void open_file(int fnum,connection_struct *conn, + char *fname1,int flags,int mode, struct stat *sbuf) { extern struct current_user current_user; pstring fname; @@ -1065,14 +1063,13 @@ static void open_file(int fnum,int cnum,char *fname1,int flags,int mode, struct * JRA. */ - if (!CAN_WRITE(cnum) && !Connections[cnum].printer) { + if (conn->read_only && !conn->printer) { /* It's a read-only share - fail if we wanted to write. */ if(accmode != O_RDONLY) { DEBUG(3,("Permission denied opening %s\n",fname)); check_for_pipe(fname); return; - } - else if(flags & O_CREAT) { + } else if(flags & O_CREAT) { /* We don't want to write - but we must make sure that O_CREAT doesn't create the file if we have write access into the directory. @@ -1083,8 +1080,9 @@ static void open_file(int fnum,int cnum,char *fname1,int flags,int mode, struct /* this handles a bug in Win95 - it doesn't say to create the file when it should */ - if (Connections[cnum].printer) - flags |= O_CREAT; + if (conn->printer) { + flags |= O_CREAT; + } /* if (flags == O_WRONLY) @@ -1212,7 +1210,7 @@ static void open_file(int fnum,int cnum,char *fname1,int flags,int mode, struct } if ((fd_ptr->fd >=0) && - Connections[cnum].printer && lp_minprintspace(SNUM(cnum))) { + conn->printer && lp_minprintspace(SNUM(conn))) { pstring dname; int dum1,dum2,dum3; char *p; @@ -1220,7 +1218,7 @@ static void open_file(int fnum,int cnum,char *fname1,int flags,int mode, struct p = strrchr(dname,'/'); if (p) *p = 0; if (sys_disk_free(dname,&dum1,&dum2,&dum3) < - lp_minprintspace(SNUM(cnum))) { + lp_minprintspace(SNUM(conn))) { fd_attempt_close(fd_ptr); fsp->fd_ptr = 0; if(fd_ptr->ref_count == 0) @@ -1260,7 +1258,7 @@ static void open_file(int fnum,int cnum,char *fname1,int flags,int mode, struct fd_ptr->inode = (uint32)sbuf->st_ino; fsp->fd_ptr = fd_ptr; - Connections[cnum].num_files_open++; + conn->num_files_open++; fsp->mode = sbuf->st_mode; GetTimeOfDay(&fsp->open_time); fsp->vuid = current_user.vuid; @@ -1273,12 +1271,12 @@ static void open_file(int fnum,int cnum,char *fname1,int flags,int mode, struct fsp->can_read = ((flags & O_WRONLY)==0); fsp->can_write = ((flags & (O_WRONLY|O_RDWR))!=0); fsp->share_mode = 0; - fsp->print_file = Connections[cnum].printer; + fsp->print_file = conn->printer; fsp->modified = False; fsp->granted_oplock = False; fsp->sent_oplock_break = False; fsp->is_directory = False; - fsp->cnum = cnum; + fsp->conn = conn; /* * Note that the file name here is the *untranslated* name * ie. it is still in the DOS codepage sent from the client. @@ -1286,7 +1284,7 @@ static void open_file(int fnum,int cnum,char *fname1,int flags,int mode, struct * functions which will do the dos_to_unix translation before * mapping into a UNIX filename. JRA. */ - string_set(&fsp->name,fname); + string_set(&fsp->fsp_name,fname); fsp->wbmpx_ptr = NULL; /* @@ -1296,32 +1294,30 @@ static void open_file(int fnum,int cnum,char *fname1,int flags,int mode, struct * This has a similar effect as CtrlD=0 in WIN.INI file. * tim@fsg.com 09/06/94 */ - if (fsp->print_file && POSTSCRIPT(cnum) && fsp->can_write) - { - DEBUG(3,("Writing postscript line\n")); - write_file(fnum,"%!\n",3); + if (fsp->print_file && lp_postscript(SNUM(conn)) && fsp->can_write) { + DEBUG(3,("Writing postscript line\n")); + write_file(fnum,"%!\n",3); } - DEBUG( 2, ( "%s opened file %s read=%s write=%s (numopen=%d fnum=%d)\n", - *sesssetup_user ? sesssetup_user : Connections[cnum].user,fname, - BOOLSTR(fsp->can_read), BOOLSTR(fsp->can_write), - Connections[cnum].num_files_open,fnum ) ); + DEBUG(2,("%s opened file %s read=%s write=%s (numopen=%d fnum=%d)\n", + *sesssetup_user ? sesssetup_user : conn->user,fname, + BOOLSTR(fsp->can_read), BOOLSTR(fsp->can_write), + conn->num_files_open,fnum)); } #if WITH_MMAP /* mmap it if read-only */ - if (!fsp->can_write) - { - fsp->mmap_size = file_size(fname); - fsp->mmap_ptr = (char *)mmap(NULL,fsp->mmap_size, - PROT_READ,MAP_SHARED,fsp->fd_ptr->fd,0); - - if (fsp->mmap_ptr == (char *)-1 || !fsp->mmap_ptr) - { - DEBUG(3,("Failed to mmap() %s - %s\n",fname,strerror(errno))); - fsp->mmap_ptr = NULL; - } + if (!fsp->can_write) { + fsp->mmap_size = file_size(fname); + fsp->mmap_ptr = (char *)mmap(NULL,fsp->mmap_size, + PROT_READ,MAP_SHARED,fsp->fd_ptr->fd,0); + + if (fsp->mmap_ptr == (char *)-1 || !fsp->mmap_ptr) { + DEBUG(3,("Failed to mmap() %s - %s\n", + fname,strerror(errno))); + fsp->mmap_ptr = NULL; + } } #endif } @@ -1329,10 +1325,10 @@ static void open_file(int fnum,int cnum,char *fname1,int flags,int mode, struct /******************************************************************* sync a file ********************************************************************/ -void sync_file(int cnum, int fnum) +void sync_file(connection_struct *conn, int fnum) { #ifdef HAVE_FSYNC - if(lp_strict_sync(SNUM(cnum))) + if(lp_strict_sync(SNUM(conn))) fsync(Files[fnum].fd_ptr->fd); #endif } @@ -1340,21 +1336,21 @@ void sync_file(int cnum, int fnum) /**************************************************************************** run a file if it is a magic script ****************************************************************************/ -static void check_magic(int fnum,int cnum) +static void check_magic(int fnum,connection_struct *conn) { - if (!*lp_magicscript(SNUM(cnum))) + if (!*lp_magicscript(SNUM(conn))) return; - DEBUG(5,("checking magic for %s\n",Files[fnum].name)); + DEBUG(5,("checking magic for %s\n",Files[fnum].fsp_name)); { char *p; - if (!(p = strrchr(Files[fnum].name,'/'))) - p = Files[fnum].name; + if (!(p = strrchr(Files[fnum].fsp_name,'/'))) + p = Files[fnum].fsp_name; else p++; - if (!strequal(lp_magicscript(SNUM(cnum)),p)) + if (!strequal(lp_magicscript(SNUM(conn)),p)) return; } @@ -1362,10 +1358,10 @@ static void check_magic(int fnum,int cnum) int ret; pstring magic_output; pstring fname; - pstrcpy(fname,Files[fnum].name); + pstrcpy(fname,Files[fnum].fsp_name); - if (*lp_magicoutput(SNUM(cnum))) - pstrcpy(magic_output,lp_magicoutput(SNUM(cnum))); + if (*lp_magicoutput(SNUM(conn))) + pstrcpy(magic_output,lp_magicoutput(SNUM(conn))); else slprintf(magic_output,sizeof(fname)-1, "%s.out",fname); @@ -1379,28 +1375,25 @@ static void check_magic(int fnum,int cnum) /**************************************************************************** Common code to close a file or a directory. ****************************************************************************/ - static void close_filestruct(files_struct *fsp) { - int cnum = fsp->cnum; + connection_struct *conn = fsp->conn; - fsp->reserved = False; - fsp->open = False; - fsp->is_directory = False; + fsp->reserved = False; + fsp->open = False; + fsp->is_directory = False; - Connections[cnum].num_files_open--; - if(fsp->wbmpx_ptr) - { - free((char *)fsp->wbmpx_ptr); - fsp->wbmpx_ptr = NULL; - } + conn->num_files_open--; + if(fsp->wbmpx_ptr) { + free((char *)fsp->wbmpx_ptr); + fsp->wbmpx_ptr = NULL; + } #if WITH_MMAP - if(fsp->mmap_ptr) - { - munmap(fsp->mmap_ptr,fsp->mmap_size); - fsp->mmap_ptr = NULL; - } + if(fsp->mmap_ptr) { + munmap(fsp->mmap_ptr,fsp->mmap_size); + fsp->mmap_ptr = NULL; + } #endif } @@ -1412,55 +1405,54 @@ static void close_filestruct(files_struct *fsp) the closing of the connection. In the latter case printing and magic scripts are not run. ****************************************************************************/ - void close_file(int fnum, BOOL normal_close) { - files_struct *fs_p = &Files[fnum]; - int cnum = fs_p->cnum; - uint32 dev = fs_p->fd_ptr->dev; - uint32 inode = fs_p->fd_ptr->inode; - int token; + files_struct *fs_p = &Files[fnum]; + uint32 dev = fs_p->fd_ptr->dev; + uint32 inode = fs_p->fd_ptr->inode; + int token; + connection_struct *conn = fs_p->conn; - close_filestruct(fs_p); + close_filestruct(fs_p); #if USE_READ_PREDICTION - invalidate_read_prediction(fs_p->fd_ptr->fd); + invalidate_read_prediction(fs_p->fd_ptr->fd); #endif - if (lp_share_modes(SNUM(cnum))) - { - lock_share_entry( cnum, dev, inode, &token); - del_share_mode(token, fnum); - } + if (lp_share_modes(SNUM(conn))) { + lock_share_entry(conn, dev, inode, &token); + del_share_mode(token, fnum); + } - fd_attempt_close(fs_p->fd_ptr); + fd_attempt_close(fs_p->fd_ptr); - if (lp_share_modes(SNUM(cnum))) - unlock_share_entry( cnum, dev, inode, token); + if (lp_share_modes(SNUM(conn))) + unlock_share_entry(conn, dev, inode, token); - /* NT uses smbclose to start a print - weird */ - if (normal_close && fs_p->print_file) - print_file(fnum); + /* NT uses smbclose to start a print - weird */ + if (normal_close && fs_p->print_file) + print_file(conn, fs_p); - /* check for magic scripts */ - if (normal_close) - check_magic(fnum,cnum); + /* check for magic scripts */ + if (normal_close) { + check_magic(fnum,conn); + } - if(fs_p->granted_oplock == True) - global_oplocks_open--; + if(fs_p->granted_oplock == True) + global_oplocks_open--; - fs_p->sent_oplock_break = False; + fs_p->sent_oplock_break = False; - DEBUG( 2, ( "%s closed file %s (numopen=%d)\n", - Connections[cnum].user,fs_p->name, - Connections[cnum].num_files_open ) ); + DEBUG(2,("%s closed file %s (numopen=%d)\n", + conn->user,fs_p->fsp_name, + conn->num_files_open)); - if (fs_p->name) { - string_free(&fs_p->name); - } + if (fs_p->fsp_name) { + string_free(&fs_p->fsp_name); + } - /* we will catch bugs faster by zeroing this structure */ - memset(fs_p, 0, sizeof(*fs_p)); + /* we will catch bugs faster by zeroing this structure */ + memset(fs_p, 0, sizeof(*fs_p)); } /**************************************************************************** @@ -1482,8 +1474,8 @@ void close_directory(int fnum) */ close_filestruct(fsp); - if (fsp->name) - string_free(&fsp->name); + if (fsp->fsp_name) + string_free(&fsp->fsp_name); /* we will catch bugs faster by zeroing this structure */ memset(fsp, 0, sizeof(*fsp)); @@ -1492,83 +1484,81 @@ void close_directory(int fnum) /**************************************************************************** Open a directory from an NT SMB call. ****************************************************************************/ - -int open_directory(int fnum,int cnum,char *fname, int smb_ofun, int unixmode, int *action) +int open_directory(int fnum,connection_struct *conn, + char *fname, int smb_ofun, int unixmode, int *action) { - extern struct current_user current_user; - files_struct *fsp = &Files[fnum]; - struct stat st; - - if (smb_ofun & 0x10) { - /* - * Create the directory. - */ - - if(sys_mkdir(fname, unixmode) < 0) { - DEBUG(0,("open_directory: unable to create %s. Error was %s\n", - fname, strerror(errno) )); - return -1; - } - - *action = FILE_WAS_CREATED; - - } else { - - /* - * Check that it *was* a directory. - */ - - if(sys_stat(fname, &st) < 0) { - DEBUG(0,("open_directory: unable to stat name = %s. Error was %s\n", - fname, strerror(errno) )); - return -1; - } + extern struct current_user current_user; + files_struct *fsp = &Files[fnum]; + struct stat st; + + if (smb_ofun & 0x10) { + /* + * Create the directory. + */ + + if(sys_mkdir(fname, unixmode) < 0) { + DEBUG(0,("open_directory: unable to create %s. Error was %s\n", + fname, strerror(errno) )); + return -1; + } - if(!S_ISDIR(st.st_mode)) { - DEBUG(0,("open_directory: %s is not a directory !\n", fname )); - return -1; - } - *action = FILE_WAS_OPENED; - } + *action = FILE_WAS_CREATED; + } else { + /* + * Check that it *was* a directory. + */ - DEBUG(5,("open_directory: opening directory %s, fnum = %d\n", - fname, fnum )); + if(sys_stat(fname, &st) < 0) { + DEBUG(0,("open_directory: unable to stat name = %s. Error was %s\n", + fname, strerror(errno) )); + return -1; + } - /* - * Setup the files_struct for it. - */ + if(!S_ISDIR(st.st_mode)) { + DEBUG(0,("open_directory: %s is not a directory !\n", fname )); + return -1; + } + *action = FILE_WAS_OPENED; + } + + DEBUG(5,("open_directory: opening directory %s, fnum = %d\n", + fname, fnum )); - fsp->fd_ptr = NULL; - Connections[cnum].num_files_open++; - fsp->mode = 0; - GetTimeOfDay(&fsp->open_time); - fsp->vuid = current_user.vuid; - fsp->size = 0; - fsp->pos = -1; - fsp->open = True; - fsp->mmap_ptr = NULL; - fsp->mmap_size = 0; - fsp->can_lock = True; - fsp->can_read = False; - fsp->can_write = False; - fsp->share_mode = 0; - fsp->print_file = False; - fsp->modified = False; - fsp->granted_oplock = False; - fsp->sent_oplock_break = False; - fsp->is_directory = True; - fsp->cnum = cnum; - /* - * Note that the file name here is the *untranslated* name - * ie. it is still in the DOS codepage sent from the client. - * All use of this filename will pass though the sys_xxxx - * functions which will do the dos_to_unix translation before - * mapping into a UNIX filename. JRA. - */ - string_set(&fsp->name,fname); - fsp->wbmpx_ptr = NULL; + /* + * Setup the files_struct for it. + */ + + fsp->fd_ptr = NULL; + conn->num_files_open++; + fsp->mode = 0; + GetTimeOfDay(&fsp->open_time); + fsp->vuid = current_user.vuid; + fsp->size = 0; + fsp->pos = -1; + fsp->open = True; + fsp->mmap_ptr = NULL; + fsp->mmap_size = 0; + fsp->can_lock = True; + fsp->can_read = False; + fsp->can_write = False; + fsp->share_mode = 0; + fsp->print_file = False; + fsp->modified = False; + fsp->granted_oplock = False; + fsp->sent_oplock_break = False; + fsp->is_directory = True; + fsp->conn = conn; + /* + * Note that the file name here is the *untranslated* name + * ie. it is still in the DOS codepage sent from the client. + * All use of this filename will pass though the sys_xxxx + * functions which will do the dos_to_unix translation before + * mapping into a UNIX filename. JRA. + */ + string_set(&fsp->fsp_name,fname); + fsp->wbmpx_ptr = NULL; - return 0; + return 0; } enum {AFAIL,AREAD,AWRITE,AALL}; @@ -1628,7 +1618,7 @@ static int access_table(int new_deny,int old_deny,int old_mode, check if the share mode on a file allows it to be deleted or unlinked return True if sharing doesn't prevent the operation ********************************************************************/ -BOOL check_file_sharing(int cnum,char *fname, BOOL rename_op) +BOOL check_file_sharing(connection_struct *conn,char *fname, BOOL rename_op) { int i; int ret = False; @@ -1639,7 +1629,7 @@ BOOL check_file_sharing(int cnum,char *fname, BOOL rename_op) int pid = getpid(); uint32 dev, inode; - if(!lp_share_modes(SNUM(cnum))) + if(!lp_share_modes(SNUM(conn))) return True; if (sys_stat(fname,&sbuf) == -1) return(True); @@ -1647,8 +1637,8 @@ BOOL check_file_sharing(int cnum,char *fname, BOOL rename_op) dev = (uint32)sbuf.st_dev; inode = (uint32)sbuf.st_ino; - lock_share_entry(cnum, dev, inode, &token); - num_share_modes = get_share_modes(cnum, token, dev, inode, &old_shares); + lock_share_entry(conn, dev, inode, &token); + num_share_modes = get_share_modes(conn, token, dev, inode, &old_shares); /* * Check if the share modes will give us access. @@ -1707,7 +1697,7 @@ batch oplocked file %s, dev = %x, inode = %x\n", fname, dev, inode)); dev = %x, inode = %x\n", share_entry->op_type, fname, dev, inode)); /* Oplock break.... */ - unlock_share_entry(cnum, dev, inode, token); + unlock_share_entry(conn, dev, inode, token); if(request_oplock_break(share_entry, dev, inode) == False) { free((char *)old_shares); @@ -1715,7 +1705,7 @@ dev = %x, inode = %x\n", share_entry->op_type, fname, dev, inode)); dev = %x, inode = %x\n", old_shares[i].op_type, fname, dev, inode)); return False; } - lock_share_entry(cnum, dev, inode, &token); + lock_share_entry(conn, dev, inode, &token); broke_oplock = True; break; } @@ -1731,7 +1721,7 @@ dev = %x, inode = %x\n", old_shares[i].op_type, fname, dev, inode)); if(broke_oplock) { free((char *)old_shares); - num_share_modes = get_share_modes(cnum, token, dev, inode, &old_shares); + num_share_modes = get_share_modes(conn, token, dev, inode, &old_shares); } } while(broke_oplock); } @@ -1744,7 +1734,7 @@ dev = %x, inode = %x\n", old_shares[i].op_type, fname, dev, inode)); free_and_exit: - unlock_share_entry(cnum, dev, inode, token); + unlock_share_entry(conn, dev, inode, token); if(old_shares != NULL) free((char *)old_shares); return(ret); @@ -1755,17 +1745,17 @@ free_and_exit: Helper for open_file_shared. Truncate a file after checking locking; close file if locked. **************************************************************************/ -static void truncate_unless_locked(int fnum, int cnum, int token, +static void truncate_unless_locked(int fnum, connection_struct *conn, int token, BOOL *share_locked) { files_struct *fsp = &Files[fnum]; if (fsp->can_write){ - if (is_locked(fnum,cnum,0x3FFFFFFF,0,F_WRLCK)){ + if (is_locked(fnum,conn,0x3FFFFFFF,0,F_WRLCK)){ /* If share modes are in force for this connection we have the share entry locked. Unlock it before closing. */ - if (*share_locked && lp_share_modes(SNUM(cnum))) - unlock_share_entry( cnum, fsp->fd_ptr->dev, + if (*share_locked && lp_share_modes(SNUM(conn))) + unlock_share_entry( conn, fsp->fd_ptr->dev, fsp->fd_ptr->inode, token); close_file(fnum,False); /* Share mode no longer locked. */ @@ -1823,7 +1813,7 @@ int check_share_mode( share_mode_entry *share, int deny_mode, char *fname, /**************************************************************************** open a file with a share mode ****************************************************************************/ -void open_file_shared(int fnum,int cnum,char *fname,int share_mode,int ofun, +void open_file_shared(int fnum,connection_struct *conn,char *fname,int share_mode,int ofun, int mode,int oplock_request, int *Access,int *action) { files_struct *fs_p = &Files[fnum]; @@ -1894,7 +1884,7 @@ void open_file_shared(int fnum,int cnum,char *fname,int share_mode,int ofun, #endif /* O_SYNC */ if (flags != O_RDONLY && file_existed && - (!CAN_WRITE(cnum) || IS_DOS_READONLY(dos_mode(cnum,fname,&sbuf)))) + (!CAN_WRITE(conn) || IS_DOS_READONLY(dos_mode(conn,fname,&sbuf)))) { if (!fcbopen) { @@ -1913,7 +1903,7 @@ void open_file_shared(int fnum,int cnum,char *fname,int share_mode,int ofun, if (deny_mode == DENY_FCB) deny_mode = DENY_DOS; - if (lp_share_modes(SNUM(cnum))) + if (lp_share_modes(SNUM(conn))) { int i; share_mode_entry *old_shares = 0; @@ -1922,9 +1912,9 @@ void open_file_shared(int fnum,int cnum,char *fname,int share_mode,int ofun, { dev = (uint32)sbuf.st_dev; inode = (uint32)sbuf.st_ino; - lock_share_entry(cnum, dev, inode, &token); + lock_share_entry(conn, dev, inode, &token); share_locked = True; - num_share_modes = get_share_modes(cnum, token, dev, inode, &old_shares); + num_share_modes = get_share_modes(conn, token, dev, inode, &old_shares); } /* @@ -1957,7 +1947,7 @@ void open_file_shared(int fnum,int cnum,char *fname,int share_mode,int ofun, dev = %x, inode = %x\n", share_entry->op_type, fname, dev, inode)); /* Oplock break.... */ - unlock_share_entry(cnum, dev, inode, token); + unlock_share_entry(conn, dev, inode, token); if(request_oplock_break(share_entry, dev, inode) == False) { free((char *)old_shares); @@ -1968,7 +1958,7 @@ dev = %x, inode = %x\n", old_shares[i].op_type, fname, dev, inode)); unix_ERR_code = ERRbadshare; return; } - lock_share_entry(cnum, dev, inode, &token); + lock_share_entry(conn, dev, inode, &token); broke_oplock = True; break; } @@ -1978,7 +1968,7 @@ dev = %x, inode = %x\n", old_shares[i].op_type, fname, dev, inode)); if(check_share_mode(share_entry, deny_mode, fname, fcbopen, &flags) == False) { free((char *)old_shares); - unlock_share_entry(cnum, dev, inode, token); + unlock_share_entry(conn, dev, inode, token); errno = EACCES; unix_ERR_class = ERRDOS; unix_ERR_code = ERRbadshare; @@ -1990,7 +1980,7 @@ dev = %x, inode = %x\n", old_shares[i].op_type, fname, dev, inode)); if(broke_oplock) { free((char *)old_shares); - num_share_modes = get_share_modes(cnum, token, dev, inode, &old_shares); + num_share_modes = get_share_modes(conn, token, dev, inode, &old_shares); } } while(broke_oplock); } @@ -2002,23 +1992,23 @@ dev = %x, inode = %x\n", old_shares[i].op_type, fname, dev, inode)); DEBUG(4,("calling open_file with flags=0x%X flags2=0x%X mode=0%o\n", flags,flags2,mode)); - open_file(fnum,cnum,fname,flags|(flags2&~(O_TRUNC)),mode,file_existed ? &sbuf : 0); + open_file(fnum,conn,fname,flags|(flags2&~(O_TRUNC)),mode,file_existed ? &sbuf : 0); if (!fs_p->open && flags==O_RDWR && errno!=ENOENT && fcbopen) { flags = O_RDONLY; - open_file(fnum,cnum,fname,flags,mode,file_existed ? &sbuf : 0 ); + open_file(fnum,conn,fname,flags,mode,file_existed ? &sbuf : 0 ); } if (fs_p->open) { int open_mode=0; - if((share_locked == False) && lp_share_modes(SNUM(cnum))) + if((share_locked == False) && lp_share_modes(SNUM(conn))) { /* We created the file - thus we must now lock the share entry before creating it. */ dev = fs_p->fd_ptr->dev; inode = fs_p->fd_ptr->inode; - lock_share_entry(cnum, dev, inode, &token); + lock_share_entry(conn, dev, inode, &token); share_locked = True; } @@ -2050,7 +2040,7 @@ dev = %x, inode = %x\n", old_shares[i].op_type, fname, dev, inode)); truncate can fail due to locking and have to close the file (which expects the share_mode_entry to be there). */ - if (lp_share_modes(SNUM(cnum))) + if (lp_share_modes(SNUM(conn))) { uint16 port = 0; /* JRA. Currently this only services Exlcusive and batch @@ -2058,8 +2048,8 @@ dev = %x, inode = %x\n", old_shares[i].op_type, fname, dev, inode)); be extended to level II oplocks (multiple reader oplocks). */ - if(oplock_request && (num_share_modes == 0) && lp_oplocks(SNUM(cnum)) && - !IS_VETO_OPLOCK_PATH(cnum,fname)) + if(oplock_request && (num_share_modes == 0) && lp_oplocks(SNUM(conn)) && + !IS_VETO_OPLOCK_PATH(conn,fname)) { fs_p->granted_oplock = True; fs_p->sent_oplock_break = False; @@ -2079,11 +2069,11 @@ dev = %x, inode = %x\n", oplock_request, fname, dev, inode)); } if ((flags2&O_TRUNC) && file_existed) - truncate_unless_locked(fnum,cnum,token,&share_locked); + truncate_unless_locked(fnum,conn,token,&share_locked); } - if (share_locked && lp_share_modes(SNUM(cnum))) - unlock_share_entry( cnum, dev, inode, token); + if (share_locked && lp_share_modes(SNUM(conn))) + unlock_share_entry( conn, dev, inode, token); } /**************************************************************************** @@ -2094,7 +2084,7 @@ int seek_file(int fnum,uint32 pos) uint32 offset = 0; files_struct *fsp = &Files[fnum]; - if (fsp->print_file && POSTSCRIPT(fsp->cnum)) + if (fsp->print_file && lp_postscript(fsp->conn->service)) offset = 3; fsp->pos = (int)(lseek(fsp->fd_ptr->fd,pos+offset,SEEK_SET) - offset); @@ -2170,9 +2160,9 @@ int write_file(int fnum,char *data,int n) struct stat st; fsp->modified = True; if (fstat(fsp->fd_ptr->fd,&st) == 0) { - int dosmode = dos_mode(fsp->cnum,fsp->name,&st); - if (MAP_ARCHIVE(fsp->cnum) && !IS_DOS_ARCHIVE(dosmode)) { - dos_chmod(fsp->cnum,fsp->name,dosmode | aARCH,&st); + int dosmode = dos_mode(fsp->conn,fsp->fsp_name,&st); + if (MAP_ARCHIVE(fsp->conn) && !IS_DOS_ARCHIVE(dosmode)) { + dos_chmod(fsp->conn,fsp->fsp_name,dosmode | aARCH,&st); } } } @@ -2184,44 +2174,42 @@ int write_file(int fnum,char *data,int n) /**************************************************************************** load parameters specific to a connection/service ****************************************************************************/ -BOOL become_service(int cnum,BOOL do_chdir) +BOOL become_service(connection_struct *conn,BOOL do_chdir) { - extern char magic_char; - static int last_cnum = -1; - int snum; + extern char magic_char; + static connection_struct *last_conn; + int snum; - if (!OPEN_CNUM(cnum)) - { - last_cnum = -1; - return(False); - } + if (!conn || !conn->open) { + last_conn = NULL; + return(False); + } - Connections[cnum].lastused = smb_last_time; + conn->lastused = smb_last_time; - snum = SNUM(cnum); + snum = SNUM(conn); - if (do_chdir && - ChDir(Connections[cnum].connectpath) != 0 && - ChDir(Connections[cnum].origpath) != 0) - { - DEBUG( 0, ( "chdir (%s) failed cnum=%d\n", - Connections[cnum].connectpath, cnum ) ); - return(False); - } + if (do_chdir && + ChDir(conn->connectpath) != 0 && + ChDir(conn->origpath) != 0) { + DEBUG(0,("chdir (%s) failed\n", + conn->connectpath)); + return(False); + } - if (cnum == last_cnum) - return(True); + if (conn == last_conn) + return(True); - last_cnum = cnum; + last_conn = conn; - case_default = lp_defaultcase(snum); - case_preserve = lp_preservecase(snum); - short_case_preserve = lp_shortpreservecase(snum); - case_mangle = lp_casemangle(snum); - case_sensitive = lp_casesensitive(snum); - magic_char = lp_magicchar(snum); - use_mangled_map = (*lp_mangled_map(snum) ? True:False); - return(True); + case_default = lp_defaultcase(snum); + case_preserve = lp_preservecase(snum); + short_case_preserve = lp_shortpreservecase(snum); + case_mangle = lp_casemangle(snum); + case_sensitive = lp_casesensitive(snum); + magic_char = lp_magicchar(snum); + use_mangled_map = (*lp_mangled_map(snum) ? True:False); + return(True); } @@ -2906,7 +2894,7 @@ BOOL oplock_break(uint32 dev, uint32 inode, struct timeval *tval) int fnum; time_t start_time; BOOL shutdown_server = False; - int saved_cnum; + connection_struct *saved_conn; int saved_vuid; pstring saved_dir; @@ -2957,7 +2945,7 @@ BOOL oplock_break(uint32 dev, uint32 inode, struct timeval *tval) { if( DEBUGLVL( 0 ) ) { - dbgtext( "oplock_break: file %s (fnum = %d, ", fsp->name, fnum ); + dbgtext( "oplock_break: file %s (fnum = %d, ", fsp->fsp_name, fnum ); dbgtext( "dev = %x, inode = %x) has no oplock.\n", dev, inode ); dbgtext( "Allowing break to succeed regardless.\n" ); } @@ -2970,7 +2958,7 @@ BOOL oplock_break(uint32 dev, uint32 inode, struct timeval *tval) if( DEBUGLVL( 0 ) ) { dbgtext( "oplock_break: ERROR: oplock_break already sent for " ); - dbgtext( "file %s (fnum = %d, ", fsp->name, fnum ); + dbgtext( "file %s (fnum = %d, ", fsp->fsp_name, fnum ); dbgtext( "dev = %x, inode = %x)\n", dev, inode ); } @@ -3008,7 +2996,7 @@ BOOL oplock_break(uint32 dev, uint32 inode, struct timeval *tval) set_message(outbuf,8,0,True); SCVAL(outbuf,smb_com,SMBlockingX); - SSVAL(outbuf,smb_tid,fsp->cnum); + SSVAL(outbuf,smb_tid,fsp->conn->cnum); SSVAL(outbuf,smb_pid,0xFFFF); SSVAL(outbuf,smb_uid,0); SSVAL(outbuf,smb_mid,0xFFFF); @@ -3037,7 +3025,7 @@ BOOL oplock_break(uint32 dev, uint32 inode, struct timeval *tval) * Save the information we need to re-become the * user, then unbecome the user whilst we're doing this. */ - saved_cnum = fsp->cnum; + saved_conn = fsp->conn; saved_vuid = current_user.vuid; GetWd(saved_dir); unbecome_user(); @@ -3060,7 +3048,7 @@ BOOL oplock_break(uint32 dev, uint32 inode, struct timeval *tval) DEBUG( 0, ( "oplock_break: receive_smb timed out after %d seconds.\n", OPLOCK_BREAK_TIMEOUT ) ); - DEBUGADD( 0, ( "oplock_break failed for file %s ", fsp->name ) ); + DEBUGADD( 0, ( "oplock_break failed for file %s ", fsp->fsp_name ) ); DEBUGADD( 0, ( "(fnum = %d, dev = %x, inode = %x).\n", fnum, dev, inode)); shutdown_server = True; break; @@ -3087,7 +3075,7 @@ BOOL oplock_break(uint32 dev, uint32 inode, struct timeval *tval) { dbgtext( "oplock_break: no break received from client " ); dbgtext( "within %d seconds.\n", OPLOCK_BREAK_TIMEOUT ); - dbgtext( "oplock_break failed for file %s ", fsp->name ); + dbgtext( "oplock_break failed for file %s ", fsp->fsp_name ); dbgtext( "(fnum = %d, dev = %x, inode = %x).\n", fnum, dev, inode ); } shutdown_server = True; @@ -3099,7 +3087,7 @@ BOOL oplock_break(uint32 dev, uint32 inode, struct timeval *tval) * Go back to being the user who requested the oplock * break. */ - if(!become_user(&Connections[saved_cnum], saved_cnum, saved_vuid)) + if(!become_user(saved_conn, saved_vuid)) { DEBUG( 0, ( "oplock_break: unable to re-become user!" ) ); DEBUGADD( 0, ( "Shutting down server\n" ) ); @@ -3322,7 +3310,7 @@ should be %d\n", pid, share_entry->op_port, oplock_port)); time_left -= (time(NULL) - start_time); } - DEBUG( 3, ( "%s request_oplock_break: broke oplock.\n" ) ); + DEBUG(3,("request_oplock_break: broke oplock.\n")); return True; } @@ -3365,11 +3353,13 @@ check if a snum is in use ****************************************************************************/ BOOL snum_used(int snum) { - int i; - for (i=0;i<MAX_CONNECTIONS;i++) - if (OPEN_CNUM(i) && (SNUM(i) == snum)) - return(True); - return(False); + int i; + for (i=0;i<MAX_CONNECTIONS;i++) { + if (Connections[i].open && (Connections[i].service == snum)) { + return(True); + } + } + return(False); } /**************************************************************************** @@ -3377,50 +3367,50 @@ BOOL snum_used(int snum) **************************************************************************/ BOOL reload_services(BOOL test) { - BOOL ret; + BOOL ret; + + if (lp_loaded()) { + pstring fname; + pstrcpy(fname,lp_configfile()); + if (file_exist(fname,NULL) && !strcsequal(fname,servicesf)) { + pstrcpy(servicesf,fname); + test = False; + } + } - if (lp_loaded()) - { - pstring fname; - pstrcpy(fname,lp_configfile()); - if (file_exist(fname,NULL) && !strcsequal(fname,servicesf)) - { - pstrcpy(servicesf,fname); - test = False; - } - } + reopen_logs(); - reopen_logs(); + if (test && !lp_file_list_changed()) + return(True); - if (test && !lp_file_list_changed()) - return(True); + lp_killunused(snum_used); - lp_killunused(snum_used); + ret = lp_load(servicesf,False,False,True); - ret = lp_load(servicesf,False,False,True); + load_printers(); - /* perhaps the config filename is now set */ - if (!test) - reload_services(True); + /* perhaps the config filename is now set */ + if (!test) + reload_services(True); - reopen_logs(); + reopen_logs(); - load_interfaces(); + load_interfaces(); - { - extern int Client; - if (Client != -1) { - set_socket_options(Client,"SO_KEEPALIVE"); - set_socket_options(Client,user_socket_options); - } - } + { + extern int Client; + if (Client != -1) { + set_socket_options(Client,"SO_KEEPALIVE"); + set_socket_options(Client,user_socket_options); + } + } - reset_mangled_cache(); + reset_mangled_cache(); - /* this forces service parameters to be flushed */ - become_service(-1,True); + /* this forces service parameters to be flushed */ + become_service(NULL,True); - return(ret); + return(ret); } @@ -3446,330 +3436,354 @@ static int sig_hup(void) return(0); } - /**************************************************************************** - make a connection to a service + find first available connection slot, starting from a random position. +The randomisation stops problems with the server dieing and clients +thinking the server is still available. ****************************************************************************/ -int make_connection(char *service,char *user,char *password, int pwlen, char *dev,uint16 vuid) +static connection_struct *find_free_connection(int hash) { - int cnum; - int snum; - struct passwd *pass = NULL; - connection_struct *pcon; - BOOL guest = False; - BOOL force = False; - extern int Client; + int i; + BOOL used=False; + hash = (hash % (MAX_CONNECTIONS-2))+1; - strlower(service); + again: - snum = find_service(service); - if (snum < 0) - { - extern int Client; - if (strequal(service,"IPC$")) - { - DEBUG( 3, ( "refusing IPC connection\n" ) ); - return( -3 ); + for (i=hash+1;i!=hash;) { + if (!Connections[i].open && Connections[i].used == used) { + DEBUG(3,("found free connection number %d\n",i)); + memset(&Connections[i], 0, sizeof(&Connections[i])); + Connections[i].cnum = i; + return &Connections[i]; + } + i++; + if (i == MAX_CONNECTIONS) { + i = 1; + } } - DEBUG( 0, ( "%s (%s) couldn't find service %s\n", - remote_machine, client_addr(Client), service ) ); - return(-2); - } - - if (strequal(service,HOMES_NAME)) - { - if (*user && Get_Pwnam(user,True)) - return(make_connection(user,user,password,pwlen,dev,vuid)); - - if(lp_security() != SEC_SHARE) - { - if (validated_username(vuid)) - { - pstrcpy(user,validated_username(vuid)); - return(make_connection(user,user,password,pwlen,dev,vuid)); - } - } - else - { - /* - * Security = share. Try with sesssetup_user as the username. - */ - if(*sesssetup_user) - { - pstrcpy(user,sesssetup_user); - return(make_connection(user,user,password,pwlen,dev,vuid)); - } - } - } + if (!used) { + used = !used; + goto again; + } - if (!lp_snum_ok(snum) || - !check_access(Client, lp_hostsallow(snum), lp_hostsdeny(snum))) { - return(-4); - } + DEBUG(1,("ERROR! Out of connection structures\n")); - /* you can only connect to the IPC$ service as an ipc device */ - if (strequal(service,"IPC$")) - pstrcpy(dev,"IPC"); + return NULL; +} - if (*dev == '?' || !*dev) - { - if (lp_print_ok(snum)) - pstrcpy(dev,"LPT1:"); - else - pstrcpy(dev,"A:"); - } - /* if the request is as a printer and you can't print then refuse */ - strupper(dev); - if (!lp_print_ok(snum) && (strncmp(dev,"LPT",3) == 0)) { - DEBUG(1,("Attempt to connect to non-printer as a printer\n")); - return(-6); - } +/**************************************************************************** + make a connection to a service +****************************************************************************/ +connection_struct *make_connection(char *service,char *user,char *password, int pwlen, char *dev,uint16 vuid, int *ecode) +{ + int snum; + struct passwd *pass = NULL; + BOOL guest = False; + BOOL force = False; + extern int Client; + connection_struct *conn; + + strlower(service); + + snum = find_service(service); + if (snum < 0) { + extern int Client; + if (strequal(service,"IPC$")) { + DEBUG(3,("refusing IPC connection\n")); + *ecode = ERRnoipc; + return NULL; + } - /* lowercase the user name */ - strlower(user); + DEBUG(0,("%s (%s) couldn't find service %s\n", + remote_machine, client_addr(Client), service)); + *ecode = ERRinvnetname; + return NULL; + } - /* add it as a possible user name */ - add_session_user(service); + if (strequal(service,HOMES_NAME)) { + if (*user && Get_Pwnam(user,True)) + return(make_connection(user,user,password, + pwlen,dev,vuid,ecode)); + + if(lp_security() != SEC_SHARE) { + if (validated_username(vuid)) { + pstrcpy(user,validated_username(vuid)); + return(make_connection(user,user,password,pwlen,dev,vuid,ecode)); + } + } else { + /* Security = share. Try with sesssetup_user + * as the username. */ + if(*sesssetup_user) { + pstrcpy(user,sesssetup_user); + return(make_connection(user,user,password,pwlen,dev,vuid,ecode)); + } + } + } - /* shall we let them in? */ - if (!authorise_login(snum,user,password,pwlen,&guest,&force,vuid)) - { - DEBUG( 2, ( "Invalid username/password for %s\n", service ) ); - return(-1); - } - - cnum = find_free_connection( str_checksum(service) + str_checksum(user) ); - if (cnum < 0) - { - DEBUG( 0, ( "Couldn't find free connection.\n" ) ); - return(-1); - } + if (!lp_snum_ok(snum) || + !check_access(Client, + lp_hostsallow(snum), lp_hostsdeny(snum))) { + *ecode = ERRaccess; + return NULL; + } - pcon = &Connections[cnum]; - bzero((char *)pcon,sizeof(*pcon)); + /* you can only connect to the IPC$ service as an ipc device */ + if (strequal(service,"IPC$")) + pstrcpy(dev,"IPC"); + + if (*dev == '?' || !*dev) { + if (lp_print_ok(snum)) { + pstrcpy(dev,"LPT1:"); + } else { + pstrcpy(dev,"A:"); + } + } - /* find out some info about the user */ - pass = Get_Pwnam(user,True); + /* if the request is as a printer and you can't print then refuse */ + strupper(dev); + if (!lp_print_ok(snum) && (strncmp(dev,"LPT",3) == 0)) { + DEBUG(1,("Attempt to connect to non-printer as a printer\n")); + *ecode = ERRinvdevice; + return NULL; + } - if (pass == NULL) - { - DEBUG( 0, ( "Couldn't find account %s\n", user ) ); - return(-7); - } + /* lowercase the user name */ + strlower(user); - pcon->read_only = lp_readonly(snum); + /* add it as a possible user name */ + add_session_user(service); - { - pstring list; - StrnCpy(list,lp_readlist(snum),sizeof(pstring)-1); - string_sub(list,"%S",service); + /* shall we let them in? */ + if (!authorise_login(snum,user,password,pwlen,&guest,&force,vuid)) { + DEBUG( 2, ( "Invalid username/password for %s\n", service ) ); + *ecode = ERRbadpw; + return NULL; + } + + conn = find_free_connection(str_checksum(service) + str_checksum(user)); + if (!conn) { + DEBUG(0,("Couldn't find free connection.\n")); + *ecode = ERRnoresource; + return NULL; + } - if (user_in_list(user,list)) - pcon->read_only = True; + /* find out some info about the user */ + pass = Get_Pwnam(user,True); - StrnCpy(list,lp_writelist(snum),sizeof(pstring)-1); - string_sub(list,"%S",service); + if (pass == NULL) { + DEBUG(0,( "Couldn't find account %s\n",user)); + *ecode = ERRbaduid; + return NULL; + } - if (user_in_list(user,list)) - pcon->read_only = False; - } + conn->read_only = lp_readonly(snum); - /* admin user check */ + { + pstring list; + StrnCpy(list,lp_readlist(snum),sizeof(pstring)-1); + string_sub(list,"%S",service); + + if (user_in_list(user,list)) + conn->read_only = True; + + StrnCpy(list,lp_writelist(snum),sizeof(pstring)-1); + string_sub(list,"%S",service); + + if (user_in_list(user,list)) + conn->read_only = False; + } - /* JRA - original code denied admin user if the share was - marked read_only. Changed as I don't think this is needed, - but old code left in case there is a problem here. - */ - if (user_in_list(user,lp_admin_users(snum)) + /* admin user check */ + + /* JRA - original code denied admin user if the share was + marked read_only. Changed as I don't think this is needed, + but old code left in case there is a problem here. + */ + if (user_in_list(user,lp_admin_users(snum)) #if 0 - && !pcon->read_only) -#else - ) + && !conn->read_only #endif - { - pcon->admin_user = True; - DEBUG(0,("%s logged in as admin user (root privileges)\n",user)); - } - else - pcon->admin_user = False; + ) { + conn->admin_user = True; + DEBUG(0,("%s logged in as admin user (root privileges)\n",user)); + } else { + conn->admin_user = False; + } - pcon->force_user = force; - pcon->vuid = vuid; - pcon->uid = pass->pw_uid; - pcon->gid = pass->pw_gid; - pcon->num_files_open = 0; - pcon->lastused = time(NULL); - pcon->service = snum; - pcon->used = True; - pcon->printer = (strncmp(dev,"LPT",3) == 0); - pcon->ipc = (strncmp(dev,"IPC",3) == 0); - pcon->dirptr = NULL; - pcon->veto_list = NULL; - pcon->hide_list = NULL; - pcon->veto_oplock_list = NULL; - string_set(&pcon->dirpath,""); - string_set(&pcon->user,user); - + conn->force_user = force; + conn->vuid = vuid; + conn->uid = pass->pw_uid; + conn->gid = pass->pw_gid; + conn->num_files_open = 0; + conn->lastused = time(NULL); + conn->service = snum; + conn->used = True; + conn->printer = (strncmp(dev,"LPT",3) == 0); + conn->ipc = (strncmp(dev,"IPC",3) == 0); + conn->dirptr = NULL; + conn->veto_list = NULL; + conn->hide_list = NULL; + conn->veto_oplock_list = NULL; + string_set(&conn->dirpath,""); + string_set(&conn->user,user); + #ifdef HAVE_GETGRNAM - if (*lp_force_group(snum)) - { - struct group *gptr; - pstring gname; - - StrnCpy(gname,lp_force_group(snum),sizeof(pstring)-1); - /* default service may be a group name */ - string_sub(gname,"%S",service); - gptr = (struct group *)getgrnam(gname); - - if (gptr) - { - pcon->gid = gptr->gr_gid; - DEBUG(3,("Forced group %s\n",gname)); + if (*lp_force_group(snum)) { + struct group *gptr; + pstring gname; + + StrnCpy(gname,lp_force_group(snum),sizeof(pstring)-1); + /* default service may be a group name */ + string_sub(gname,"%S",service); + gptr = (struct group *)getgrnam(gname); + + if (gptr) { + conn->gid = gptr->gr_gid; + DEBUG(3,("Forced group %s\n",gname)); + } else { + DEBUG(1,("Couldn't find group %s\n",gname)); + } } - else - DEBUG(1,("Couldn't find group %s\n",gname)); - } #endif - - if (*lp_force_user(snum)) - { - struct passwd *pass2; - fstring fuser; - fstrcpy(fuser,lp_force_user(snum)); - pass2 = (struct passwd *)Get_Pwnam(fuser,True); - if (pass2) - { - pcon->uid = pass2->pw_uid; - string_set(&pcon->user,fuser); - fstrcpy(user,fuser); - pcon->force_user = True; - DEBUG(3,("Forced user %s\n",fuser)); + + if (*lp_force_user(snum)) { + struct passwd *pass2; + fstring fuser; + fstrcpy(fuser,lp_force_user(snum)); + pass2 = (struct passwd *)Get_Pwnam(fuser,True); + if (pass2) { + conn->uid = pass2->pw_uid; + string_set(&conn->user,fuser); + fstrcpy(user,fuser); + conn->force_user = True; + DEBUG(3,("Forced user %s\n",fuser)); + } else { + DEBUG(1,("Couldn't find user %s\n",fuser)); + } } - else - DEBUG(1,("Couldn't find user %s\n",fuser)); - } - { - pstring s; - pstrcpy(s,lp_pathname(snum)); - standard_sub(cnum,s); - string_set(&pcon->connectpath,s); - DEBUG(3,("Connect path is %s\n",s)); - } - - /* groups stuff added by ih */ - pcon->ngroups = 0; - pcon->groups = NULL; - - if (!IS_IPC(cnum)) - { - /* Find all the groups this uid is in and store them. Used by become_user() */ - setup_groups(pcon->user,pcon->uid,pcon->gid, - &pcon->ngroups,&pcon->groups); - - /* check number of connections */ - if (!claim_connection(cnum, - lp_servicename(SNUM(cnum)), - lp_max_connections(SNUM(cnum)),False)) { - DEBUG(1,("too many connections - rejected\n")); - return(-8); - } - - if (lp_status(SNUM(cnum))) - claim_connection(cnum,"STATUS.",MAXSTATUS,False); - } /* IS_IPC */ - - pcon->open = True; - - /* execute any "root preexec = " line */ - if (*lp_rootpreexec(SNUM(cnum))) - { - pstring cmd; - pstrcpy(cmd,lp_rootpreexec(SNUM(cnum))); - standard_sub(cnum,cmd); - DEBUG(5,("cmd=%s\n",cmd)); - smbrun(cmd,NULL,False); - } - - if (!become_user(&Connections[cnum], cnum,pcon->vuid)) - { - DEBUG(0,("Can't become connected user!\n")); - pcon->open = False; - if (!IS_IPC(cnum)) { - yield_connection(cnum, - lp_servicename(SNUM(cnum)), - lp_max_connections(SNUM(cnum))); - if (lp_status(SNUM(cnum))) yield_connection(cnum,"STATUS.",MAXSTATUS); - } - return(-1); - } - - if (ChDir(pcon->connectpath) != 0) - { - DEBUG(0,("Can't change directory to %s (%s)\n", - pcon->connectpath,strerror(errno))); - pcon->open = False; - unbecome_user(); - if (!IS_IPC(cnum)) { - yield_connection(cnum, - lp_servicename(SNUM(cnum)), - lp_max_connections(SNUM(cnum))); - if (lp_status(SNUM(cnum))) yield_connection(cnum,"STATUS.",MAXSTATUS); - } - return(-5); - } - - string_set(&pcon->origpath,pcon->connectpath); + pstring s; + pstrcpy(s,lp_pathname(snum)); + standard_sub(conn,s); + string_set(&conn->connectpath,s); + DEBUG(3,("Connect path is %s\n",s)); + } + /* groups stuff added by ih */ + conn->ngroups = 0; + conn->groups = NULL; + + if (!IS_IPC(conn)) { + /* Find all the groups this uid is in and + store them. Used by become_user() */ + setup_groups(conn->user,conn->uid,conn->gid, + &conn->ngroups,&conn->groups); + + /* check number of connections */ + if (!claim_connection(conn, + lp_servicename(SNUM(conn)), + lp_max_connections(SNUM(conn)), + False)) { + DEBUG(1,("too many connections - rejected\n")); + *ecode = ERRnoresource; + return NULL; + } + + if (lp_status(SNUM(conn))) + claim_connection(conn,"STATUS.", + MAXSTATUS,False); + } /* IS_IPC */ + + conn->open = True; + + /* execute any "root preexec = " line */ + if (*lp_rootpreexec(SNUM(conn))) { + pstring cmd; + pstrcpy(cmd,lp_rootpreexec(SNUM(conn))); + standard_sub(conn,cmd); + DEBUG(5,("cmd=%s\n",cmd)); + smbrun(cmd,NULL,False); + } + + if (!become_user(conn, conn->vuid)) { + DEBUG(0,("Can't become connected user!\n")); + conn->open = False; + if (!IS_IPC(conn)) { + yield_connection(conn, + lp_servicename(SNUM(conn)), + lp_max_connections(SNUM(conn))); + if (lp_status(SNUM(conn))) { + yield_connection(conn,"STATUS.",MAXSTATUS); + } + } + *ecode = ERRbadpw; + return NULL; + } + + if (ChDir(conn->connectpath) != 0) { + DEBUG(0,("Can't change directory to %s (%s)\n", + conn->connectpath,strerror(errno))); + conn->open = False; + unbecome_user(); + if (!IS_IPC(conn)) { + yield_connection(conn, + lp_servicename(SNUM(conn)), + lp_max_connections(SNUM(conn))); + if (lp_status(SNUM(conn))) + yield_connection(conn,"STATUS.",MAXSTATUS); + } + *ecode = ERRinvnetname; + return NULL; + } + + string_set(&conn->origpath,conn->connectpath); + #if SOFTLINK_OPTIMISATION - /* resolve any soft links early */ - { - pstring s; - pstrcpy(s,pcon->connectpath); - GetWd(s); - string_set(&pcon->connectpath,s); - ChDir(pcon->connectpath); - } + /* resolve any soft links early */ + { + pstring s; + pstrcpy(s,conn->connectpath); + GetWd(s); + string_set(&conn->connectpath,s); + ChDir(conn->connectpath); + } #endif - - num_connections_open++; - add_session_user(user); - - /* execute any "preexec = " line */ - if (*lp_preexec(SNUM(cnum))) - { - pstring cmd; - pstrcpy(cmd,lp_preexec(SNUM(cnum))); - standard_sub(cnum,cmd); - smbrun(cmd,NULL,False); - } - - /* we've finished with the sensitive stuff */ - unbecome_user(); - - /* Add veto/hide lists */ - if (!IS_IPC(cnum) && !IS_PRINT(cnum)) - { - set_namearray( &pcon->veto_list, lp_veto_files(SNUM(cnum))); - set_namearray( &pcon->hide_list, lp_hide_files(SNUM(cnum))); - set_namearray( &pcon->veto_oplock_list, lp_veto_oplocks(SNUM(cnum))); - } - - if( DEBUGLVL( IS_IPC(cnum) ? 3 : 1 ) ) - { - extern int Client; - - dbgtext( "%s (%s) ", remote_machine, client_addr(Client) ); - dbgtext( "connect to service %s ", lp_servicename(SNUM(cnum)) ); - dbgtext( "as user %s ", user ); - dbgtext( "(uid=%d, gid=%d) ", pcon->uid, pcon->gid ); - dbgtext( "(pid %d)\n", (int)getpid() ); - } - - return(cnum); + + num_connections_open++; + add_session_user(user); + + /* execute any "preexec = " line */ + if (*lp_preexec(SNUM(conn))) { + pstring cmd; + pstrcpy(cmd,lp_preexec(SNUM(conn))); + standard_sub(conn,cmd); + smbrun(cmd,NULL,False); + } + + /* we've finished with the sensitive stuff */ + unbecome_user(); + + /* Add veto/hide lists */ + if (!IS_IPC(conn) && !IS_PRINT(conn)) { + set_namearray( &conn->veto_list, lp_veto_files(SNUM(conn))); + set_namearray( &conn->hide_list, lp_hide_files(SNUM(conn))); + set_namearray( &conn->veto_oplock_list, lp_veto_oplocks(SNUM(conn))); + } + + if( DEBUGLVL( IS_IPC(conn) ? 3 : 1 ) ) { + extern int Client; + + dbgtext( "%s (%s) ", remote_machine, client_addr(Client) ); + dbgtext( "connect to service %s ", lp_servicename(SNUM(conn)) ); + dbgtext( "as user %s ", user ); + dbgtext( "(uid=%d, gid=%d) ", conn->uid, conn->gid ); + dbgtext( "(pid %d)\n", (int)getpid() ); + } + + return(conn); } /**************************************************************************** @@ -3783,7 +3797,7 @@ int make_connection(char *service,char *user,char *password, int pwlen, char *de static BOOL attempt_close_oplocked_file(files_struct *fsp) { - DEBUG(5,("attempt_close_oplocked_file: checking file %s.\n", fsp->name)); + DEBUG(5,("attempt_close_oplocked_file: checking file %s.\n", fsp->fsp_name)); if (fsp->open && fsp->granted_oplock && !fsp->sent_oplock_break) { @@ -3867,41 +3881,6 @@ int find_free_file(void ) return(-1); } -/**************************************************************************** - find first available connection slot, starting from a random position. -The randomisation stops problems with the server dieing and clients -thinking the server is still available. -****************************************************************************/ -static int find_free_connection(int hash ) -{ - int i; - BOOL used=False; - hash = (hash % (MAX_CONNECTIONS-2))+1; - - again: - - for (i=hash+1;i!=hash;) - { - if (!Connections[i].open && Connections[i].used == used) - { - DEBUG(3,("found free connection number %d\n",i)); - return(i); - } - i++; - if (i == MAX_CONNECTIONS) - i = 1; - } - - if (!used) - { - used = !used; - goto again; - } - - DEBUG(1,("ERROR! Out of connection structures\n")); - return(-1); -} - /**************************************************************************** reply for the core protocol @@ -4183,7 +4162,9 @@ struct { /**************************************************************************** reply to a negprot ****************************************************************************/ -static int reply_negprot(char *inbuf,char *outbuf, int dum_size, int dum_buffsize) +static int reply_negprot(connection_struct *conn, + char *inbuf,char *outbuf, int dum_size, + int dum_buffsize) { int outsize = set_message(outbuf,1,0,True); int Index=0; @@ -4290,11 +4271,11 @@ static int reply_negprot(char *inbuf,char *outbuf, int dum_size, int dum_buffsiz /**************************************************************************** close all open files for a connection ****************************************************************************/ -static void close_open_files(int cnum) +static void close_open_files(connection_struct *conn) { int i; for (i=0;i<MAX_FNUMS;i++) - if( Files[i].cnum == cnum && Files[i].open) { + if (Files[i].conn == conn && Files[i].open) { if(Files[i].is_directory) close_directory(i); else @@ -4307,69 +4288,66 @@ static void close_open_files(int cnum) /**************************************************************************** close a cnum ****************************************************************************/ -void close_cnum(int cnum, uint16 vuid) +void close_cnum(connection_struct *conn, uint16 vuid) { - extern int Client; - DirCacheFlush(SNUM(cnum)); + extern int Client; + DirCacheFlush(SNUM(conn)); - unbecome_user(); + unbecome_user(); - if (!OPEN_CNUM(cnum)) - { - DEBUG(0,("Can't close cnum %d\n",cnum)); - return; - } + if (!conn->open) { + DEBUG(0,("cnum not open\n")); + return; + } - DEBUG( IS_IPC(cnum)?3:1, ( "%s (%s) closed connection to service %s\n", - remote_machine,client_addr(Client), - lp_servicename(SNUM(cnum)) ) ); + DEBUG(IS_IPC(conn)?3:1, ("%s (%s) closed connection to service %s\n", + remote_machine,client_addr(Client), + lp_servicename(SNUM(conn)))); - yield_connection(cnum, - lp_servicename(SNUM(cnum)), - lp_max_connections(SNUM(cnum))); + yield_connection(conn, + lp_servicename(SNUM(conn)), + lp_max_connections(SNUM(conn))); - if (lp_status(SNUM(cnum))) - yield_connection(cnum,"STATUS.",MAXSTATUS); + if (lp_status(SNUM(conn))) + yield_connection(conn,"STATUS.",MAXSTATUS); - close_open_files(cnum); - dptr_closecnum(cnum); + close_open_files(conn); + dptr_closecnum(conn); - /* execute any "postexec = " line */ - if (*lp_postexec(SNUM(cnum)) && become_user(&Connections[cnum], cnum,vuid)) - { - pstring cmd; - pstrcpy(cmd,lp_postexec(SNUM(cnum))); - standard_sub(cnum,cmd); - smbrun(cmd,NULL,False); - unbecome_user(); - } - - unbecome_user(); - /* execute any "root postexec = " line */ - if (*lp_rootpostexec(SNUM(cnum))) - { - pstring cmd; - pstrcpy(cmd,lp_rootpostexec(SNUM(cnum))); - standard_sub(cnum,cmd); - smbrun(cmd,NULL,False); - } - - Connections[cnum].open = False; - num_connections_open--; - if (Connections[cnum].ngroups && Connections[cnum].groups) - { - free(Connections[cnum].groups); - Connections[cnum].groups = NULL; - Connections[cnum].ngroups = 0; - } + /* execute any "postexec = " line */ + if (*lp_postexec(SNUM(conn)) && + become_user(conn, vuid)) { + pstring cmd; + pstrcpy(cmd,lp_postexec(SNUM(conn))); + standard_sub(conn,cmd); + smbrun(cmd,NULL,False); + unbecome_user(); + } - free_namearray(Connections[cnum].veto_list); - free_namearray(Connections[cnum].hide_list); - free_namearray(Connections[cnum].veto_oplock_list); + unbecome_user(); + /* execute any "root postexec = " line */ + if (*lp_rootpostexec(SNUM(conn))) { + pstring cmd; + pstrcpy(cmd,lp_rootpostexec(SNUM(conn))); + standard_sub(conn,cmd); + smbrun(cmd,NULL,False); + } + + conn->open = False; + num_connections_open--; + if (conn->ngroups && conn->groups) { + free(conn->groups); + conn->groups = NULL; + conn->ngroups = 0; + } - string_set(&Connections[cnum].user,""); - string_set(&Connections[cnum].dirpath,""); - string_set(&Connections[cnum].connectpath,""); + free_namearray(conn->veto_list); + free_namearray(conn->hide_list); + free_namearray(conn->veto_oplock_list); + + string_set(&conn->user,""); + string_set(&conn->dirpath,""); + string_set(&conn->connectpath,""); } @@ -4406,6 +4384,7 @@ static BOOL dump_core(void) DEBUG(0,("Dumping core in %s\n",dname)); + abort(); return(True); } #endif @@ -4425,7 +4404,7 @@ void exit_server(char *reason) DEBUG(2,("Closing connections\n")); for (i=0;i<MAX_CONNECTIONS;i++) if (Connections[i].open) - close_cnum(i,(uint16)-1); + close_cnum(&Connections[i],(uint16)-1); #ifdef WITH_DFS if (dcelogin_atmost_once) { dfs_unlogin(); @@ -4450,42 +4429,6 @@ void exit_server(char *reason) exit(0); } -/**************************************************************************** -do some standard substitutions in a string -****************************************************************************/ -void standard_sub(int cnum,char *str) -{ - if (VALID_CNUM(cnum)) { - char *p, *s, *home; - - for ( s=str ; (p=strchr(s, '%')) != NULL ; s=p ) { - switch (*(p+1)) { - case 'H' : if ((home = get_home_dir(Connections[cnum].user))!=NULL) - string_sub(p,"%H",home); - else - p += 2; - break; - case 'P' : string_sub(p,"%P",Connections[cnum].connectpath); break; - case 'S' : string_sub(p,"%S",lp_servicename(Connections[cnum].service)); break; - case 'g' : string_sub(p,"%g",gidtoname(Connections[cnum].gid)); break; - case 'u' : string_sub(p,"%u",Connections[cnum].user); break; - /* - * Patch from jkf@soton.ac.uk - * Left the %N (NIS server name) in standard_sub_basic as it - * is a feature for logon servers, hence uses the username. - * The %p (NIS server path) code is here as it is used - * instead of the default "path =" string in [homes] and so - * needs the service name, not the username. - */ - case 'p' : string_sub(p,"%p",automount_path(lp_servicename(Connections[cnum].service))); break; - case '\0' : p++; break; /* don't run off the end of the string */ - default : p+=2; break; - } - } - } - standard_sub_basic(str); -} - /* These flags determine some of the permissions required to do an operation @@ -4509,7 +4452,7 @@ struct smb_message_struct { int code; char *name; - int (*fn)(char *, char *, int, int); + int (*fn)(connection_struct *conn, char *, char *, int, int); int flags; #if PROFILING unsigned long time; @@ -4556,7 +4499,7 @@ struct smb_message_struct {SMBctemp,"SMBctemp",reply_ctemp,AS_USER | QUEUE_IN_OPLOCK }, {SMBsplopen,"SMBsplopen",reply_printopen,AS_USER | QUEUE_IN_OPLOCK }, {SMBsplclose,"SMBsplclose",reply_printclose,AS_USER}, - {SMBsplretq,"SMBsplretq",reply_printqueue,AS_USER|AS_GUEST}, + {SMBsplretq,"SMBsplretq",reply_printqueue,AS_USER}, {SMBsplwr,"SMBsplwr",reply_printwrite,AS_USER}, {SMBlock,"SMBlock",reply_lock,AS_USER}, {SMBunlock,"SMBunlock",reply_unlock,AS_USER}, @@ -4624,19 +4567,19 @@ return a string containing the function name of a SMB command ****************************************************************************/ char *smb_fn_name(int type) { - static char *unknown_name = "SMBunknown"; - static int num_smb_messages = - sizeof(smb_messages) / sizeof(struct smb_message_struct); - int match; + static char *unknown_name = "SMBunknown"; + static int num_smb_messages = + sizeof(smb_messages) / sizeof(struct smb_message_struct); + int match; - for (match=0;match<num_smb_messages;match++) - if (smb_messages[match].code == type) - break; + for (match=0;match<num_smb_messages;match++) + if (smb_messages[match].code == type) + break; - if (match == num_smb_messages) - return(unknown_name); + if (match == num_smb_messages) + return(unknown_name); - return(smb_messages[match].name); + return(smb_messages[match].name); } @@ -4706,6 +4649,12 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize static uint16 last_session_tag = UID_FIELD_INVALID; /* In share mode security we must ignore the vuid. */ uint16 session_tag = (lp_security() == SEC_SHARE) ? UID_FIELD_INVALID : SVAL(inbuf,smb_uid); + connection_struct *conn = NULL; + + if (VALID_CNUM(cnum) && Connections[cnum].open) { + conn = &Connections[cnum]; + } + /* Ensure this value is replaced in the incoming packet. */ SSVAL(inbuf,smb_uid,session_tag); @@ -4718,7 +4667,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize * move it unless you know what you're doing... :-). * JRA. */ - if(session_tag != last_session_tag ) { + if (session_tag != last_session_tag) { user_struct *vuser = NULL; last_session_tag = session_tag; @@ -4733,7 +4682,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize unbecome_user(); /* does this protocol need to be run as the connected user? */ - if ((flags & AS_USER) && !become_user(&Connections[cnum], cnum,session_tag)) { + if ((flags & AS_USER) && !become_user(conn,session_tag)) { if (flags & AS_GUEST) flags &= ~AS_USER; else @@ -4746,16 +4695,19 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize flags &= ~AS_GUEST; /* does it need write permission? */ - if ((flags & NEED_WRITE) && !CAN_WRITE(cnum)) + if ((flags & NEED_WRITE) && !CAN_WRITE(conn)) return(ERROR(ERRSRV,ERRaccess)); /* ipc services are limited */ - if (IS_IPC(cnum) && (flags & AS_USER) && !(flags & CAN_IPC)) + if (IS_IPC(conn) && (flags & AS_USER) && !(flags & CAN_IPC)) { return(ERROR(ERRSRV,ERRaccess)); + } /* load service specific parameters */ - if (OPEN_CNUM(cnum) && !become_service(cnum,(flags & AS_USER)?True:False)) + if (OPEN_CNUM(conn) && + !become_service(conn,(flags & AS_USER)?True:False)) { return(ERROR(ERRSRV,ERRaccess)); + } /* does this protocol need to be run as guest? */ if ((flags & AS_GUEST) && @@ -4766,7 +4718,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize last_inbuf = inbuf; - outsize = smb_messages[match].fn(inbuf,outbuf,size,bufsize); + outsize = smb_messages[match].fn(conn, inbuf,outbuf,size,bufsize); } else { @@ -5072,22 +5024,21 @@ static void process(void) } /* check for connection timeouts */ - for (i=0;i<MAX_CONNECTIONS;i++) - if (Connections[i].open) - { - /* close dirptrs on connections that are idle */ - if ((t-Connections[i].lastused)>DPTR_IDLE_TIMEOUT) - dptr_idlecnum(i); - - if (Connections[i].num_files_open > 0 || - (t-Connections[i].lastused)<deadtime) - allidle = False; - } + for (i=0;i<MAX_CONNECTIONS;i++) { + if (Connections[i].open) { + /* close dirptrs on connections that are idle */ + if ((t-Connections[i].lastused)>DPTR_IDLE_TIMEOUT) + dptr_idlecnum(&Connections[i]); + + if (Connections[i].num_files_open > 0 || + (t-Connections[i].lastused)<deadtime) + allidle = False; + } + } - if (allidle && num_connections_open>0) - { - DEBUG( 2, ( "Closing idle connection 2.\n" ) ); - return; + if (allidle && num_connections_open>0) { + DEBUG(2,("Closing idle connection 2.\n")); + return; } if(global_machine_pasword_needs_changing) @@ -5189,7 +5140,7 @@ static void init_structs(void ) for (i=0;i<MAX_FNUMS;i++) { Files[i].open = False; - string_init(&Files[i].name,""); + string_init(&Files[i].fsp_name,""); } for (i=0;i<MAX_OPEN_FILES;i++) diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c index fc119307cd..07f0316c22 100644 --- a/source3/smbd/trans2.c +++ b/source3/smbd/trans2.c @@ -26,7 +26,6 @@ extern int DEBUGLEVEL; extern int Protocol; -extern connection_struct Connections[]; extern files_struct Files[]; extern BOOL case_sensitive; extern int Client; @@ -42,7 +41,7 @@ extern int global_oplock_break; HACK ! Always assumes smb_setup field is zero. ****************************************************************************/ static int send_trans2_replies(char *outbuf, int bufsize, char *params, - int paramsize, char *pdata, int datasize) + int paramsize, char *pdata, int datasize) { /* As we are using a protocol > LANMAN1 then the max_send variable must have been set in the sessetupX call. @@ -182,8 +181,9 @@ static int send_trans2_replies(char *outbuf, int bufsize, char *params, /**************************************************************************** reply to a TRANSACT2_OPEN ****************************************************************************/ -static int call_trans2open(char *inbuf, char *outbuf, int bufsize, int cnum, - char **pparams, char **ppdata) +static int call_trans2open(connection_struct *conn, char *inbuf, char *outbuf, + int bufsize, + char **pparams, char **ppdata) { char *params = *pparams; int16 open_mode = SVAL(params, 2); @@ -211,12 +211,12 @@ static int call_trans2open(char *inbuf, char *outbuf, int bufsize, int cnum, StrnCpy(fname,pname,namelen); - DEBUG(3,("trans2open %s cnum=%d mode=%d attr=%d ofun=%d size=%d\n", - fname,cnum,open_mode, open_attr, open_ofun, open_size)); + DEBUG(3,("trans2open %s mode=%d attr=%d ofun=%d size=%d\n", + fname,open_mode, open_attr, open_ofun, open_size)); /* XXXX we need to handle passed times, sattr and flags */ - unix_convert(fname,cnum,0,&bad_path); + unix_convert(fname,conn,0,&bad_path); fnum = find_free_file(); if (fnum < 0) @@ -224,7 +224,7 @@ static int call_trans2open(char *inbuf, char *outbuf, int bufsize, int cnum, fsp = &Files[fnum]; - if (!check_name(fname,cnum)) + if (!check_name(fname,conn)) { if((errno == ENOENT) && bad_path) { @@ -235,9 +235,9 @@ static int call_trans2open(char *inbuf, char *outbuf, int bufsize, int cnum, return(UNIXERROR(ERRDOS,ERRnoaccess)); } - unixmode = unix_mode(cnum,open_attr | aARCH); + unixmode = unix_mode(conn,open_attr | aARCH); - open_file_shared(fnum,cnum,fname,open_mode,open_ofun,unixmode, + open_file_shared(fnum,conn,fname,open_mode,open_ofun,unixmode, oplock_request, &rmode,&smb_action); if (!fsp->open) @@ -257,7 +257,7 @@ static int call_trans2open(char *inbuf, char *outbuf, int bufsize, int cnum, } size = sbuf.st_size; - fmode = dos_mode(cnum,fname,&sbuf); + fmode = dos_mode(conn,fname,&sbuf); mtime = sbuf.st_mtime; inode = sbuf.st_ino; if (fmode & aDIR) { @@ -277,7 +277,7 @@ static int call_trans2open(char *inbuf, char *outbuf, int bufsize, int cnum, SIVAL(params,8, size); SSVAL(params,12,rmode); - if (oplock_request && lp_fake_oplocks(SNUM(cnum))) { + if (oplock_request && lp_fake_oplocks(SNUM(conn))) { smb_action |= EXTENDED_OPLOCK_GRANTED; } @@ -293,7 +293,8 @@ static int call_trans2open(char *inbuf, char *outbuf, int bufsize, int cnum, /**************************************************************************** get a level dependent lanman2 dir entry. ****************************************************************************/ -static int get_lanman2_dir_entry(int cnum,char *path_mask,int dirtype,int info_level, +static int get_lanman2_dir_entry(connection_struct *conn, + char *path_mask,int dirtype,int info_level, int requires_resume_key, BOOL dont_descend,char **ppdata, char *base_data, int space_remaining, @@ -314,17 +315,17 @@ static int get_lanman2_dir_entry(int cnum,char *path_mask,int dirtype,int info_l uint32 size=0,len; uint32 mdate=0, adate=0, cdate=0; char *nameptr; - BOOL isrootdir = (strequal(Connections[cnum].dirpath,"./") || - strequal(Connections[cnum].dirpath,".") || - strequal(Connections[cnum].dirpath,"/")); + BOOL isrootdir = (strequal(conn->dirpath,"./") || + strequal(conn->dirpath,".") || + strequal(conn->dirpath,"/")); BOOL was_8_3; int nt_extmode; /* Used for NT connections instead of mode */ - BOOL needslash = ( Connections[cnum].dirpath[strlen(Connections[cnum].dirpath) -1] != '/'); + BOOL needslash = ( conn->dirpath[strlen(conn->dirpath) -1] != '/'); *fname = 0; *out_of_space = False; - if (!Connections[cnum].dirptr) + if (!conn->dirptr) return(False); p = strrchr(path_mask,'/'); @@ -341,8 +342,8 @@ static int get_lanman2_dir_entry(int cnum,char *path_mask,int dirtype,int info_l while (!found) { /* Needed if we run out of space */ - prev_dirpos = TellDir(Connections[cnum].dirptr); - dname = ReadDirName(Connections[cnum].dirptr); + prev_dirpos = TellDir(conn->dirptr); + dname = ReadDirName(conn->dirptr); /* * Due to bugs in NT client redirectors we are not using @@ -354,7 +355,7 @@ static int get_lanman2_dir_entry(int cnum,char *path_mask,int dirtype,int info_l reskey = 0; DEBUG(8,("get_lanman2_dir_entry:readdir on dirptr 0x%x now at offset %d\n", - Connections[cnum].dirptr,TellDir(Connections[cnum].dirptr))); + (unsigned)conn->dirptr,TellDir(conn->dirptr))); if (!dname) return(False); @@ -372,7 +373,7 @@ static int get_lanman2_dir_entry(int cnum,char *path_mask,int dirtype,int info_l if (isrootdir && isdots) continue; - pstrcpy(pathreal,Connections[cnum].dirpath); + pstrcpy(pathreal,conn->dirpath); if(needslash) pstrcat(pathreal,"/"); pstrcat(pathreal,dname); @@ -382,9 +383,9 @@ static int get_lanman2_dir_entry(int cnum,char *path_mask,int dirtype,int info_l continue; } - mode = dos_mode(cnum,pathreal,&sbuf); + mode = dos_mode(conn,pathreal,&sbuf); - if (!dir_check_ftype(cnum,mode,&sbuf,dirtype)) { + if (!dir_check_ftype(conn,mode,&sbuf,dirtype)) { DEBUG(5,("[%s] attribs didn't match %x\n",fname,dirtype)); continue; } @@ -392,7 +393,7 @@ static int get_lanman2_dir_entry(int cnum,char *path_mask,int dirtype,int info_l size = sbuf.st_size; mdate = sbuf.st_mtime; adate = sbuf.st_atime; - cdate = get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(cnum))); + cdate = get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(conn))); if(mode & aDIR) size = 0; @@ -402,7 +403,7 @@ static int get_lanman2_dir_entry(int cnum,char *path_mask,int dirtype,int info_l } } - name_map_mangle(fname,False,SNUM(cnum)); + name_map_mangle(fname,False,SNUM(conn)); p = pdata; nameptr = p; @@ -497,7 +498,7 @@ static int get_lanman2_dir_entry(int cnum,char *path_mask,int dirtype,int info_l SIVAL(p,0,0); p += 4; if (!was_8_3) { pstrcpy(p+2,fname); - if (!name_map_mangle(p+2,True,SNUM(cnum))) + if (!name_map_mangle(p+2,True,SNUM(conn))) (p+2)[12] = 0; } else *(p+2) = 0; @@ -562,7 +563,7 @@ static int get_lanman2_dir_entry(int cnum,char *path_mask,int dirtype,int info_l if (PTR_DIFF(p,pdata) > space_remaining) { /* Move the dirptr back to prev_dirpos */ - SeekDir(Connections[cnum].dirptr, prev_dirpos); + SeekDir(conn->dirptr, prev_dirpos); *out_of_space = True; DEBUG(9,("get_lanman2_dir_entry: out of space\n")); return False; /* Not finished - just out of space */ @@ -605,8 +606,9 @@ void mask_convert( char *mask) /**************************************************************************** reply to a TRANS2_FINDFIRST ****************************************************************************/ -static int call_trans2findfirst(char *inbuf, char *outbuf, int bufsize, int cnum, - char **pparams, char **ppdata) +static int call_trans2findfirst(connection_struct *conn, + char *inbuf, char *outbuf, int bufsize, + char **pparams, char **ppdata) { /* We must be careful here that we don't return more than the allowed number of data bytes. If this means returning fewer than @@ -661,8 +663,8 @@ static int call_trans2findfirst(char *inbuf, char *outbuf, int bufsize, int cnum DEBUG(5,("path=%s\n",directory)); - unix_convert(directory,cnum,0,&bad_path); - if(!check_name(directory,cnum)) { + unix_convert(directory,conn,0,&bad_path); + if(!check_name(directory,conn)) { if((errno == ENOENT) && bad_path) { unix_ERR_class = ERRDOS; @@ -703,7 +705,7 @@ static int call_trans2findfirst(char *inbuf, char *outbuf, int bufsize, int cnum if(params == NULL) return(ERROR(ERRDOS,ERRnomem)); - dptr_num = dptr_create(cnum,directory, True ,SVAL(inbuf,smb_pid)); + dptr_num = dptr_create(conn,directory, True ,SVAL(inbuf,smb_pid)); if (dptr_num < 0) return(ERROR(ERRDOS,ERRbadfile)); @@ -742,8 +744,8 @@ static int call_trans2findfirst(char *inbuf, char *outbuf, int bufsize, int cnum a different TRANS2 call. */ DEBUG(8,("dirpath=<%s> dontdescend=<%s>\n", - Connections[cnum].dirpath,lp_dontdescend(SNUM(cnum)))); - if (in_list(Connections[cnum].dirpath,lp_dontdescend(SNUM(cnum)),case_sensitive)) + conn->dirpath,lp_dontdescend(SNUM(conn)))); + if (in_list(conn->dirpath,lp_dontdescend(SNUM(conn)),case_sensitive)) dont_descend = True; p = pdata; @@ -763,7 +765,7 @@ static int call_trans2findfirst(char *inbuf, char *outbuf, int bufsize, int cnum else { finished = - !get_lanman2_dir_entry(cnum,mask,dirtype,info_level, + !get_lanman2_dir_entry(conn,mask,dirtype,info_level, requires_resume_key,dont_descend, &p,pdata,space_remaining, &out_of_space, &last_name_off); @@ -807,9 +809,9 @@ static int call_trans2findfirst(char *inbuf, char *outbuf, int bufsize, int cnum if ((! *directory) && dptr_path(dptr_num)) slprintf(directory,sizeof(directory)-1, "(%s)",dptr_path(dptr_num)); - DEBUG( 4, ( "%s mask=%s directory=%s cnum=%d dirtype=%d numentries=%d\n", + DEBUG( 4, ( "%s mask=%s directory=%s dirtype=%d numentries=%d\n", smb_fn_name(CVAL(inbuf,smb_com)), - mask, directory, cnum, dirtype, numentries ) ); + mask, directory, dirtype, numentries ) ); return(-1); } @@ -818,8 +820,10 @@ static int call_trans2findfirst(char *inbuf, char *outbuf, int bufsize, int cnum /**************************************************************************** reply to a TRANS2_FINDNEXT ****************************************************************************/ -static int call_trans2findnext(char *inbuf, char *outbuf, int length, int bufsize, - int cnum, char **pparams, char **ppdata) +static int call_trans2findnext(connection_struct *conn, + char *inbuf, char *outbuf, + int length, int bufsize, + char **pparams, char **ppdata) { /* We must be careful here that we don't return more than the allowed number of data bytes. If this means returning fewer than @@ -885,10 +889,10 @@ resume_key = %d resume name = %s continue=%d level = %d\n", return(ERROR(ERRDOS,ERRnomem)); /* Check that the dptr is valid */ - if(!(Connections[cnum].dirptr = dptr_fetch_lanman2(dptr_num))) + if(!(conn->dirptr = dptr_fetch_lanman2(dptr_num))) return(ERROR(ERRDOS,ERRnofiles)); - string_set(&Connections[cnum].dirpath,dptr_path(dptr_num)); + string_set(&conn->dirpath,dptr_path(dptr_num)); /* Get the wildcard mask from the dptr */ if((p = dptr_wcard(dptr_num))== NULL) { @@ -896,21 +900,21 @@ resume_key = %d resume name = %s continue=%d level = %d\n", return (ERROR(ERRDOS,ERRnofiles)); } pstrcpy(mask, p); - pstrcpy(directory,Connections[cnum].dirpath); + pstrcpy(directory,conn->dirpath); /* Get the attr mask from the dptr */ dirtype = dptr_attr(dptr_num); DEBUG(3,("dptr_num is %d, mask = %s, attr = %x, dirptr=(0x%X,%d)\n", dptr_num, mask, dirtype, - Connections[cnum].dirptr, - TellDir(Connections[cnum].dirptr))); + (unsigned)conn->dirptr, + TellDir(conn->dirptr))); /* We don't need to check for VOL here as this is returned by a different TRANS2 call. */ - DEBUG(8,("dirpath=<%s> dontdescend=<%s>\n",Connections[cnum].dirpath,lp_dontdescend(SNUM(cnum)))); - if (in_list(Connections[cnum].dirpath,lp_dontdescend(SNUM(cnum)),case_sensitive)) + DEBUG(8,("dirpath=<%s> dontdescend=<%s>\n",conn->dirpath,lp_dontdescend(SNUM(conn)))); + if (in_list(conn->dirpath,lp_dontdescend(SNUM(conn)),case_sensitive)) dont_descend = True; p = pdata; @@ -937,7 +941,7 @@ resume_key = %d resume name = %s continue=%d level = %d\n", int current_pos, start_pos; char *dname; - void *dirptr = Connections[cnum].dirptr; + void *dirptr = conn->dirptr; start_pos = TellDir(dirptr); for(current_pos = start_pos; current_pos >= 0; current_pos--) { @@ -953,7 +957,7 @@ resume_key = %d resume name = %s continue=%d level = %d\n", * here. */ - name_map_mangle( dname, False, SNUM(cnum)); + name_map_mangle( dname, False, SNUM(conn)); if(dname && strcsequal( resume_name, dname)) { @@ -980,7 +984,7 @@ resume_key = %d resume name = %s continue=%d level = %d\n", * here. */ - name_map_mangle( dname, False, SNUM(cnum)); + name_map_mangle( dname, False, SNUM(conn)); if(strcsequal( resume_name, dname)) { @@ -1004,7 +1008,7 @@ resume_key = %d resume name = %s continue=%d level = %d\n", else { finished = - !get_lanman2_dir_entry(cnum,mask,dirtype,info_level, + !get_lanman2_dir_entry(conn,mask,dirtype,info_level, requires_resume_key,dont_descend, &p,pdata,space_remaining, &out_of_space, &last_name_off); @@ -1038,9 +1042,9 @@ resume_key = %d resume name = %s continue=%d level = %d\n", if ((! *directory) && dptr_path(dptr_num)) slprintf(directory,sizeof(directory)-1, "(%s)",dptr_path(dptr_num)); - DEBUG( 3, ( "%s mask=%s directory=%s cnum=%d dirtype=%d numentries=%d\n", + DEBUG( 3, ( "%s mask=%s directory=%s dirtype=%d numentries=%d\n", smb_fn_name(CVAL(inbuf,smb_com)), - mask, directory, cnum, dirtype, numentries ) ); + mask, directory, dirtype, numentries ) ); return(-1); } @@ -1048,18 +1052,20 @@ resume_key = %d resume name = %s continue=%d level = %d\n", /**************************************************************************** reply to a TRANS2_QFSINFO (query filesystem info) ****************************************************************************/ -static int call_trans2qfsinfo(char *inbuf, char *outbuf, int length, int bufsize, - int cnum, char **pparams, char **ppdata) +static int call_trans2qfsinfo(connection_struct *conn, + char *inbuf, char *outbuf, + int length, int bufsize, + char **pparams, char **ppdata) { char *pdata = *ppdata; char *params = *pparams; uint16 info_level = SVAL(params,0); int data_len; struct stat st; - char *vname = volume_label(SNUM(cnum)); - int snum = SNUM(cnum); + char *vname = volume_label(SNUM(conn)); + int snum = SNUM(conn); - DEBUG(3,("call_trans2qfsinfo: cnum = %d, level = %d\n", cnum, info_level)); + DEBUG(3,("call_trans2qfsinfo: level = %d\n", info_level)); if(sys_stat(".",&st)!=0) { DEBUG(2,("call_trans2qfsinfo: stat of . failed (%s)\n", strerror(errno))); @@ -1081,7 +1087,7 @@ static int call_trans2qfsinfo(char *inbuf, char *outbuf, int length, int bufsize SIVAL(pdata,l1_cUnitAvail,dfree); SSVAL(pdata,l1_cbSector,512); DEBUG(5,("call_trans2qfsinfo : bsize=%d, id=%x, cSectorUnit=%d, cUnit=%d, cUnitAvail=%d, cbSector=%d\n", - bsize, st.st_dev, bsize/512, dsize, dfree, 512)); + bsize, (unsigned)st.st_dev, bsize/512, dsize, dfree, 512)); break; } case 2: @@ -1096,7 +1102,8 @@ static int call_trans2qfsinfo(char *inbuf, char *outbuf, int length, int bufsize SIVAL(pdata,0,str_checksum(lp_servicename(snum)) ^ (str_checksum(local_machine)<<16) ); SCVAL(pdata,l2_vol_cch,volname_len); StrnCpy(pdata+l2_vol_szVolLabel,vname,volname_len); - DEBUG(5,("call_trans2qfsinfo : time = %x, namelen = %d, name = %s\n",st.st_ctime, volname_len, + DEBUG(5,("call_trans2qfsinfo : time = %x, namelen = %d, name = %s\n", + (unsigned)st.st_ctime, volname_len, pdata+l2_vol_szVolLabel)); break; } @@ -1159,15 +1166,17 @@ static int call_trans2qfsinfo(char *inbuf, char *outbuf, int length, int bufsize /**************************************************************************** reply to a TRANS2_SETFSINFO (set filesystem info) ****************************************************************************/ -static int call_trans2setfsinfo(char *inbuf, char *outbuf, int length, int bufsize, - int cnum, char **pparams, char **ppdata) +static int call_trans2setfsinfo(connection_struct *conn, + char *inbuf, char *outbuf, int length, + int bufsize, + char **pparams, char **ppdata) { /* Just say yes we did it - there is nothing that can be set here so it doesn't matter. */ int outsize; DEBUG(3,("call_trans2setfsinfo\n")); - if (!CAN_WRITE(cnum)) + if (!CAN_WRITE(conn)) return(ERROR(ERRSRV,ERRaccess)); outsize = set_message(outbuf,10,0,True); @@ -1180,8 +1189,9 @@ static int call_trans2setfsinfo(char *inbuf, char *outbuf, int length, int bufsi file name or file id). ****************************************************************************/ -static int call_trans2qfilepathinfo(char *inbuf, char *outbuf, int length, - int bufsize,int cnum, +static int call_trans2qfilepathinfo(connection_struct *conn, + char *inbuf, char *outbuf, int length, + int bufsize, char **pparams,char **ppdata, int total_data) { @@ -1203,10 +1213,10 @@ static int call_trans2qfilepathinfo(char *inbuf, char *outbuf, int length, int16 fnum = SVALS(params,0); info_level = SVAL(params,2); - CHECK_FNUM(fnum,cnum); + CHECK_FNUM(fnum,conn); CHECK_ERROR(fnum); - fname = Files[fnum].name; + fname = Files[fnum].fsp_name; if (fstat(Files[fnum].fd_ptr->fd,&sbuf) != 0) { DEBUG(3,("fstat of fnum %d failed (%s)\n",fnum, strerror(errno))); return(UNIXERROR(ERRDOS,ERRbadfid)); @@ -1217,8 +1227,8 @@ static int call_trans2qfilepathinfo(char *inbuf, char *outbuf, int length, info_level = SVAL(params,0); fname = &fname1[0]; pstrcpy(fname,¶ms[6]); - unix_convert(fname,cnum,0,&bad_path); - if (!check_name(fname,cnum) || sys_stat(fname,&sbuf)) { + unix_convert(fname,conn,0,&bad_path); + if (!check_name(fname,conn) || sys_stat(fname,&sbuf)) { DEBUG(3,("fileinfo of %s failed (%s)\n",fname,strerror(errno))); if((errno == ENOENT) && bad_path) { @@ -1240,7 +1250,7 @@ static int call_trans2qfilepathinfo(char *inbuf, char *outbuf, int length, else p++; l = strlen(p); - mode = dos_mode(cnum,fname,&sbuf); + mode = dos_mode(conn,fname,&sbuf); size = sbuf.st_size; if (mode & aDIR) size = 0; @@ -1261,7 +1271,7 @@ static int call_trans2qfilepathinfo(char *inbuf, char *outbuf, int length, case SMB_INFO_STANDARD: case SMB_INFO_QUERY_EA_SIZE: data_size = (info_level==1?22:26); - put_dos_date2(pdata,l1_fdateCreation,get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(cnum)))); + put_dos_date2(pdata,l1_fdateCreation,get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(conn)))); put_dos_date2(pdata,l1_fdateLastAccess,sbuf.st_atime); put_dos_date2(pdata,l1_fdateLastWrite,sbuf.st_mtime); /* write time */ SIVAL(pdata,l1_cbFile,size); @@ -1272,7 +1282,7 @@ static int call_trans2qfilepathinfo(char *inbuf, char *outbuf, int length, case SMB_INFO_QUERY_EAS_FROM_LIST: data_size = 24; - put_dos_date2(pdata,0,get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(cnum)))); + put_dos_date2(pdata,0,get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(conn)))); put_dos_date2(pdata,4,sbuf.st_atime); put_dos_date2(pdata,8,sbuf.st_mtime); SIVAL(pdata,12,size); @@ -1290,7 +1300,7 @@ static int call_trans2qfilepathinfo(char *inbuf, char *outbuf, int length, case SMB_QUERY_FILE_BASIC_INFO: data_size = 36; /* w95 returns 40 bytes not 36 - why ?. */ - put_long_date(pdata,get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(cnum)))); + put_long_date(pdata,get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(conn)))); put_long_date(pdata+8,sbuf.st_atime); put_long_date(pdata+16,sbuf.st_mtime); /* write time */ put_long_date(pdata+24,sbuf.st_mtime); /* change time */ @@ -1298,7 +1308,7 @@ static int call_trans2qfilepathinfo(char *inbuf, char *outbuf, int length, DEBUG(5,("SMB_QFBI - ")); { - time_t create_time = get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(cnum))); + time_t create_time = get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(conn))); DEBUG(5,("create: %s ", ctime(&create_time))); } DEBUG(5,("access: %s ", ctime(&sbuf.st_atime))); @@ -1329,7 +1339,7 @@ static int call_trans2qfilepathinfo(char *inbuf, char *outbuf, int length, /* Mangle if not already 8.3 */ if(!is_8_3(short_name, True)) { - if(!name_map_mangle(short_name,True,SNUM(cnum))) + if(!name_map_mangle(short_name,True,SNUM(conn))) *short_name = '\0'; } strupper(short_name); @@ -1353,7 +1363,7 @@ static int call_trans2qfilepathinfo(char *inbuf, char *outbuf, int length, break; case SMB_QUERY_FILE_ALL_INFO: - put_long_date(pdata,get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(cnum)))); + put_long_date(pdata,get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(conn)))); put_long_date(pdata+8,sbuf.st_atime); put_long_date(pdata+16,sbuf.st_mtime); /* write time */ put_long_date(pdata+24,sbuf.st_mtime); /* change time */ @@ -1403,8 +1413,9 @@ static int call_trans2qfilepathinfo(char *inbuf, char *outbuf, int length, /**************************************************************************** reply to a TRANS2_SETFILEINFO (set file info by fileid) ****************************************************************************/ -static int call_trans2setfilepathinfo(char *inbuf, char *outbuf, int length, - int bufsize, int cnum, char **pparams, +static int call_trans2setfilepathinfo(connection_struct *conn, + char *inbuf, char *outbuf, int length, + int bufsize, char **pparams, char **ppdata, int total_data) { char *params = *pparams; @@ -1420,17 +1431,17 @@ static int call_trans2setfilepathinfo(char *inbuf, char *outbuf, int length, int fd = -1; BOOL bad_path = False; - if (!CAN_WRITE(cnum)) + if (!CAN_WRITE(conn)) return(ERROR(ERRSRV,ERRaccess)); if (tran_call == TRANSACT2_SETFILEINFO) { int16 fnum = SVALS(params,0); info_level = SVAL(params,2); - CHECK_FNUM(fnum,cnum); + CHECK_FNUM(fnum,conn); CHECK_ERROR(fnum); - fname = Files[fnum].name; + fname = Files[fnum].fsp_name; fd = Files[fnum].fd_ptr->fd; if(fstat(fd,&st)!=0) { @@ -1442,8 +1453,8 @@ static int call_trans2setfilepathinfo(char *inbuf, char *outbuf, int length, info_level = SVAL(params,0); fname = fname1; pstrcpy(fname,¶ms[6]); - unix_convert(fname,cnum,0,&bad_path); - if(!check_name(fname, cnum)) + unix_convert(fname,conn,0,&bad_path); + if(!check_name(fname, conn)) { if((errno == ENOENT) && bad_path) { @@ -1475,7 +1486,7 @@ static int call_trans2setfilepathinfo(char *inbuf, char *outbuf, int length, size = st.st_size; tvs.modtime = st.st_mtime; tvs.actime = st.st_atime; - mode = dos_mode(cnum,fname,&st); + mode = dos_mode(conn,fname,&st); if (total_data > 0 && IVAL(pdata,0) == total_data) { /* uggh, EAs for OS2 */ @@ -1572,14 +1583,14 @@ static int call_trans2setfilepathinfo(char *inbuf, char *outbuf, int length, */ if (st.st_mtime != tvs.modtime || st.st_atime != tvs.actime) { - if(file_utime(cnum, fname, &tvs)!=0) + if(file_utime(conn, fname, &tvs)!=0) { return(ERROR(ERRDOS,ERRnoaccess)); } } /* check the mode isn't different, before changing it */ - if (mode != dos_mode(cnum, fname, &st) && dos_chmod(cnum, fname, mode, NULL)) + if (mode != dos_mode(conn, fname, &st) && dos_chmod(conn, fname, mode, NULL)) { DEBUG(2,("chmod of %s failed (%s)\n", fname, strerror(errno))); return(ERROR(ERRDOS,ERRnoaccess)); @@ -1613,24 +1624,25 @@ static int call_trans2setfilepathinfo(char *inbuf, char *outbuf, int length, /**************************************************************************** reply to a TRANS2_MKDIR (make directory with extended attributes). ****************************************************************************/ -static int call_trans2mkdir(char *inbuf, char *outbuf, int length, int bufsize, - int cnum, char **pparams, char **ppdata) +static int call_trans2mkdir(connection_struct *conn, + char *inbuf, char *outbuf, int length, int bufsize, + char **pparams, char **ppdata) { char *params = *pparams; pstring directory; int ret = -1; BOOL bad_path = False; - if (!CAN_WRITE(cnum)) + if (!CAN_WRITE(conn)) return(ERROR(ERRSRV,ERRaccess)); pstrcpy(directory, ¶ms[4]); DEBUG(3,("call_trans2mkdir : name = %s\n", directory)); - unix_convert(directory,cnum,0,&bad_path); - if (check_name(directory,cnum)) - ret = sys_mkdir(directory,unix_mode(cnum,aDIR)); + unix_convert(directory,conn,0,&bad_path); + if (check_name(directory,conn)) + ret = sys_mkdir(directory,unix_mode(conn,aDIR)); if(ret < 0) { @@ -1659,8 +1671,10 @@ static int call_trans2mkdir(char *inbuf, char *outbuf, int length, int bufsize, reply to a TRANS2_FINDNOTIFYFIRST (start monitoring a directory for changes) We don't actually do this - we just send a null response. ****************************************************************************/ -static int call_trans2findnotifyfirst(char *inbuf, char *outbuf, int length, int bufsize, - int cnum, char **pparams, char **ppdata) +static int call_trans2findnotifyfirst(connection_struct *conn, + char *inbuf, char *outbuf, + int length, int bufsize, + char **pparams, char **ppdata) { static uint16 fnf_handle = 257; char *params = *pparams; @@ -1700,8 +1714,10 @@ static int call_trans2findnotifyfirst(char *inbuf, char *outbuf, int length, int reply to a TRANS2_FINDNOTIFYNEXT (continue monitoring a directory for changes). Currently this does nothing. ****************************************************************************/ -static int call_trans2findnotifynext(char *inbuf, char *outbuf, int length, int bufsize, - int cnum, char **pparams, char **ppdata) +static int call_trans2findnotifynext(connection_struct *conn, + char *inbuf, char *outbuf, + int length, int bufsize, + char **pparams, char **ppdata) { char *params = *pparams; @@ -1723,236 +1739,255 @@ static int call_trans2findnotifynext(char *inbuf, char *outbuf, int length, int /**************************************************************************** reply to a SMBfindclose (stop trans2 directory search) ****************************************************************************/ -int reply_findclose(char *inbuf,char *outbuf,int length,int bufsize) +int reply_findclose(connection_struct *conn, + char *inbuf,char *outbuf,int length,int bufsize) { - int cnum; - int outsize = 0; - int16 dptr_num=SVALS(inbuf,smb_vwv0); + int outsize = 0; + int16 dptr_num=SVALS(inbuf,smb_vwv0); - cnum = SVAL(inbuf,smb_tid); + DEBUG(3,("reply_findclose, dptr_num = %d\n", dptr_num)); - DEBUG(3,("reply_findclose, cnum = %d, dptr_num = %d\n", cnum, dptr_num)); + dptr_close(dptr_num); - dptr_close(dptr_num); + outsize = set_message(outbuf,0,0,True); - outsize = set_message(outbuf,0,0,True); + DEBUG(3,("SMBfindclose dptr_num = %d\n", dptr_num)); - DEBUG( 3, ( "SMBfindclose cnum=%d, dptr_num = %d\n", cnum, dptr_num ) ); - - return(outsize); + return(outsize); } /**************************************************************************** reply to a SMBfindnclose (stop FINDNOTIFYFIRST directory search) ****************************************************************************/ -int reply_findnclose(char *inbuf,char *outbuf,int length,int bufsize) +int reply_findnclose(connection_struct *conn, + char *inbuf,char *outbuf,int length,int bufsize) { - int cnum; - int outsize = 0; - int dptr_num= -1; - - cnum = SVAL(inbuf,smb_tid); - dptr_num = SVAL(inbuf,smb_vwv0); + int outsize = 0; + int dptr_num= -1; + + dptr_num = SVAL(inbuf,smb_vwv0); - DEBUG(3,("reply_findnclose, cnum = %d, dptr_num = %d\n", cnum, dptr_num)); + DEBUG(3,("reply_findnclose, dptr_num = %d\n", dptr_num)); - /* We never give out valid handles for a - findnotifyfirst - so any dptr_num is ok here. - Just ignore it. */ + /* We never give out valid handles for a + findnotifyfirst - so any dptr_num is ok here. + Just ignore it. */ - outsize = set_message(outbuf,0,0,True); + outsize = set_message(outbuf,0,0,True); - DEBUG( 3, ( "SMB_findnclose cnum=%d, dptr_num = %d\n", cnum, dptr_num ) ); + DEBUG(3,("SMB_findnclose dptr_num = %d\n", dptr_num)); - return(outsize); + return(outsize); } /**************************************************************************** reply to a SMBtranss2 - just ignore it! ****************************************************************************/ -int reply_transs2(char *inbuf,char *outbuf,int length,int bufsize) +int reply_transs2(connection_struct *conn, + char *inbuf,char *outbuf,int length,int bufsize) { - DEBUG(4,("Ignoring transs2 of length %d\n",length)); - return(-1); + DEBUG(4,("Ignoring transs2 of length %d\n",length)); + return(-1); } /**************************************************************************** reply to a SMBtrans2 ****************************************************************************/ -int reply_trans2(char *inbuf,char *outbuf,int length,int bufsize) +int reply_trans2(connection_struct *conn, + char *inbuf,char *outbuf,int length,int bufsize) { - int outsize = 0; - int cnum = SVAL(inbuf,smb_tid); - unsigned int total_params = SVAL(inbuf, smb_tpscnt); - unsigned int total_data =SVAL(inbuf, smb_tdscnt); + int outsize = 0; + unsigned int total_params = SVAL(inbuf, smb_tpscnt); + unsigned int total_data =SVAL(inbuf, smb_tdscnt); #if 0 - unsigned int max_param_reply = SVAL(inbuf, smb_mprcnt); - unsigned int max_data_reply = SVAL(inbuf, smb_mdrcnt); - unsigned int max_setup_fields = SVAL(inbuf, smb_msrcnt); - BOOL close_tid = BITSETW(inbuf+smb_flags,0); - BOOL no_final_response = BITSETW(inbuf+smb_flags,1); - int32 timeout = IVALS(inbuf,smb_timeout); + unsigned int max_param_reply = SVAL(inbuf, smb_mprcnt); + unsigned int max_data_reply = SVAL(inbuf, smb_mdrcnt); + unsigned int max_setup_fields = SVAL(inbuf, smb_msrcnt); + BOOL close_tid = BITSETW(inbuf+smb_flags,0); + BOOL no_final_response = BITSETW(inbuf+smb_flags,1); + int32 timeout = IVALS(inbuf,smb_timeout); #endif - unsigned int suwcnt = SVAL(inbuf, smb_suwcnt); - unsigned int tran_call = SVAL(inbuf, smb_setup0); - char *params = NULL, *data = NULL; - int num_params, num_params_sofar, num_data, num_data_sofar; - - if(global_oplock_break && (tran_call == TRANSACT2_OPEN)) - { - /* - * Queue this open message as we are the process of an oplock break. - */ - - DEBUG( 2, ( "reply_trans2: queueing message trans2open due to being " ) ); - DEBUGADD( 2, ( "in oplock break state.\n" ) ); + unsigned int suwcnt = SVAL(inbuf, smb_suwcnt); + unsigned int tran_call = SVAL(inbuf, smb_setup0); + char *params = NULL, *data = NULL; + int num_params, num_params_sofar, num_data, num_data_sofar; - push_oplock_pending_smb_message( inbuf, length); - return -1; - } + if(global_oplock_break && (tran_call == TRANSACT2_OPEN)) { + /* Queue this open message as we are the process of an + * oplock break. */ - outsize = set_message(outbuf,0,0,True); + DEBUG(2,("reply_trans2: queueing message trans2open due to being ")); + DEBUGADD(2,( "in oplock break state.\n")); - /* All trans2 messages we handle have smb_sucnt == 1 - ensure this - is so as a sanity check */ - if(suwcnt != 1 ) - { - DEBUG(2,("Invalid smb_sucnt in trans2 call\n")); - return(ERROR(ERRSRV,ERRerror)); - } + push_oplock_pending_smb_message(inbuf, length); + return -1; + } + + outsize = set_message(outbuf,0,0,True); + + /* All trans2 messages we handle have smb_sucnt == 1 - ensure this + is so as a sanity check */ + if (suwcnt != 1) { + DEBUG(2,("Invalid smb_sucnt in trans2 call\n")); + return(ERROR(ERRSRV,ERRerror)); + } - /* Allocate the space for the maximum needed parameters and data */ - if (total_params > 0) - params = (char *)malloc(total_params); - if (total_data > 0) - data = (char *)malloc(total_data); + /* Allocate the space for the maximum needed parameters and data */ + if (total_params > 0) + params = (char *)malloc(total_params); + if (total_data > 0) + data = (char *)malloc(total_data); - if ((total_params && !params) || (total_data && !data)) - { - DEBUG(2,("Out of memory in reply_trans2\n")); - return(ERROR(ERRDOS,ERRnomem)); - } - - /* Copy the param and data bytes sent with this request into - the params buffer */ - num_params = num_params_sofar = SVAL(inbuf,smb_pscnt); - num_data = num_data_sofar = SVAL(inbuf, smb_dscnt); - - if (num_params > total_params || num_data > total_data) - exit_server("invalid params in reply_trans2"); - - if(params) - memcpy( params, smb_base(inbuf) + SVAL(inbuf, smb_psoff), num_params); - if(data) - memcpy( data, smb_base(inbuf) + SVAL(inbuf, smb_dsoff), num_data); - - if(num_data_sofar < total_data || num_params_sofar < total_params) - { - /* We need to send an interim response then receive the rest - of the parameter/data bytes */ - outsize = set_message(outbuf,0,0,True); - send_smb(Client,outbuf); - - while( num_data_sofar < total_data || num_params_sofar < total_params) - { - BOOL ret; - - ret = receive_next_smb(Client,oplock_sock,inbuf,bufsize, - SMB_SECONDARY_WAIT); + if ((total_params && !params) || (total_data && !data)) { + DEBUG(2,("Out of memory in reply_trans2\n")); + return(ERROR(ERRDOS,ERRnomem)); + } - if((ret && (CVAL(inbuf, smb_com) != SMBtranss2)) || !ret) - { - outsize = set_message(outbuf,0,0,True); - if(ret) - DEBUG(0,("reply_trans2: Invalid secondary trans2 packet\n")); - else - DEBUG(0,("reply_trans2: %s in getting secondary trans2 response.\n", - (smb_read_error == READ_ERROR) ? "error" : "timeout" )); - if(params) - free(params); - if(data) - free(data); - return(ERROR(ERRSRV,ERRerror)); - } + /* Copy the param and data bytes sent with this request into + the params buffer */ + num_params = num_params_sofar = SVAL(inbuf,smb_pscnt); + num_data = num_data_sofar = SVAL(inbuf, smb_dscnt); + + if (num_params > total_params || num_data > total_data) + exit_server("invalid params in reply_trans2"); + + if(params) + memcpy( params, smb_base(inbuf) + SVAL(inbuf, smb_psoff), num_params); + if(data) + memcpy( data, smb_base(inbuf) + SVAL(inbuf, smb_dsoff), num_data); + + if(num_data_sofar < total_data || num_params_sofar < total_params) { + /* We need to send an interim response then receive the rest + of the parameter/data bytes */ + outsize = set_message(outbuf,0,0,True); + send_smb(Client,outbuf); + + while (num_data_sofar < total_data || + num_params_sofar < total_params) { + BOOL ret; + + ret = receive_next_smb(Client,oplock_sock,inbuf,bufsize, + SMB_SECONDARY_WAIT); + + if ((ret && + (CVAL(inbuf, smb_com) != SMBtranss2)) || !ret) { + outsize = set_message(outbuf,0,0,True); + if(ret) + DEBUG(0,("reply_trans2: Invalid secondary trans2 packet\n")); + else + DEBUG(0,("reply_trans2: %s in getting secondary trans2 response.\n", + (smb_read_error == READ_ERROR) ? "error" : "timeout" )); + if(params) + free(params); + if(data) + free(data); + return(ERROR(ERRSRV,ERRerror)); + } - /* Revise total_params and total_data in case they have changed downwards */ - total_params = SVAL(inbuf, smb_tpscnt); - total_data = SVAL(inbuf, smb_tdscnt); - num_params_sofar += (num_params = SVAL(inbuf,smb_spscnt)); - num_data_sofar += ( num_data = SVAL(inbuf, smb_sdscnt)); - if (num_params_sofar > total_params || num_data_sofar > total_data) - exit_server("data overflow in trans2"); - - memcpy( ¶ms[ SVAL(inbuf, smb_spsdisp)], - smb_base(inbuf) + SVAL(inbuf, smb_spsoff), num_params); - memcpy( &data[SVAL(inbuf, smb_sdsdisp)], - smb_base(inbuf)+ SVAL(inbuf, smb_sdsoff), num_data); + /* Revise total_params and total_data in case + they have changed downwards */ + total_params = SVAL(inbuf, smb_tpscnt); + total_data = SVAL(inbuf, smb_tdscnt); + num_params_sofar += (num_params = SVAL(inbuf,smb_spscnt)); + num_data_sofar += ( num_data = SVAL(inbuf, smb_sdscnt)); + if (num_params_sofar > total_params || num_data_sofar > total_data) + exit_server("data overflow in trans2"); + + memcpy( ¶ms[ SVAL(inbuf, smb_spsdisp)], + smb_base(inbuf) + SVAL(inbuf, smb_spsoff), num_params); + memcpy( &data[SVAL(inbuf, smb_sdsdisp)], + smb_base(inbuf)+ SVAL(inbuf, smb_sdsoff), num_data); + } + } + + if (Protocol >= PROTOCOL_NT1) { + uint16 flg2 = SVAL(outbuf,smb_flg2); + SSVAL(outbuf,smb_flg2,flg2 | 0x40); /* IS_LONG_NAME */ } - } - - if (Protocol >= PROTOCOL_NT1) { - uint16 flg2 = SVAL(outbuf,smb_flg2); - SSVAL(outbuf,smb_flg2,flg2 | 0x40); /* IS_LONG_NAME */ - } - - /* Now we must call the relevant TRANS2 function */ - switch(tran_call) - { - case TRANSACT2_OPEN: - outsize = call_trans2open(inbuf, outbuf, bufsize, cnum, ¶ms, &data); - break; - case TRANSACT2_FINDFIRST: - outsize = call_trans2findfirst(inbuf, outbuf, bufsize, cnum, ¶ms, &data); - break; - case TRANSACT2_FINDNEXT: - outsize = call_trans2findnext(inbuf, outbuf, length, bufsize, cnum, ¶ms, &data); - break; - case TRANSACT2_QFSINFO: - outsize = call_trans2qfsinfo(inbuf, outbuf, length, bufsize, cnum, ¶ms, &data); - break; - case TRANSACT2_SETFSINFO: - outsize = call_trans2setfsinfo(inbuf, outbuf, length, bufsize, cnum, ¶ms, &data); - break; - case TRANSACT2_QPATHINFO: - case TRANSACT2_QFILEINFO: - outsize = call_trans2qfilepathinfo(inbuf, outbuf, length, bufsize, cnum, ¶ms, &data, total_data); - break; - case TRANSACT2_SETPATHINFO: - case TRANSACT2_SETFILEINFO: - outsize = call_trans2setfilepathinfo(inbuf, outbuf, length, bufsize, cnum, ¶ms, &data, total_data); - break; - case TRANSACT2_FINDNOTIFYFIRST: - outsize = call_trans2findnotifyfirst(inbuf, outbuf, length, bufsize, cnum, ¶ms, &data); - break; - case TRANSACT2_FINDNOTIFYNEXT: - outsize = call_trans2findnotifynext(inbuf, outbuf, length, bufsize, cnum, ¶ms, &data); - break; - case TRANSACT2_MKDIR: - outsize = call_trans2mkdir(inbuf, outbuf, length, bufsize, cnum, ¶ms, &data); - break; - default: - /* Error in request */ - DEBUG( 2, ( "Unknown request %d in trans2 call\n", tran_call ) ); - if(params) - free(params); - if(data) - free(data); - return (ERROR(ERRSRV,ERRerror)); - } - /* As we do not know how many data packets will need to be - returned here the various call_trans2xxxx calls - must send their own. Thus a call_trans2xxx routine only - returns a value other than -1 when it wants to send - an error packet. - */ - - if(params) - free(params); - if(data) - free(data); - return outsize; /* If a correct response was needed the call_trans2xxx - calls have already sent it. If outsize != -1 then it is - returning an error packet. */ + /* Now we must call the relevant TRANS2 function */ + switch(tran_call) { + case TRANSACT2_OPEN: + outsize = call_trans2open(conn, + inbuf, outbuf, bufsize, + ¶ms, &data); + break; + + case TRANSACT2_FINDFIRST: + outsize = call_trans2findfirst(conn, inbuf, outbuf, + bufsize, ¶ms, &data); + break; + + case TRANSACT2_FINDNEXT: + outsize = call_trans2findnext(conn, inbuf, outbuf, + length, bufsize, + ¶ms, &data); + break; + + case TRANSACT2_QFSINFO: + outsize = call_trans2qfsinfo(conn, inbuf, outbuf, + length, bufsize, ¶ms, + &data); + break; + + case TRANSACT2_SETFSINFO: + outsize = call_trans2setfsinfo(conn, inbuf, outbuf, + length, bufsize, + ¶ms, &data); + break; + + case TRANSACT2_QPATHINFO: + case TRANSACT2_QFILEINFO: + outsize = call_trans2qfilepathinfo(conn, inbuf, outbuf, + length, bufsize, + ¶ms, &data, total_data); + break; + case TRANSACT2_SETPATHINFO: + case TRANSACT2_SETFILEINFO: + outsize = call_trans2setfilepathinfo(conn, inbuf, outbuf, + length, bufsize, + ¶ms, &data, + total_data); + break; + + case TRANSACT2_FINDNOTIFYFIRST: + outsize = call_trans2findnotifyfirst(conn, inbuf, outbuf, + length, bufsize, + ¶ms, &data); + break; + + case TRANSACT2_FINDNOTIFYNEXT: + outsize = call_trans2findnotifynext(conn, inbuf, outbuf, + length, bufsize, + ¶ms, &data); + break; + case TRANSACT2_MKDIR: + outsize = call_trans2mkdir(conn, inbuf, outbuf, length, + bufsize, ¶ms, &data); + break; + default: + /* Error in request */ + DEBUG(2,("Unknown request %d in trans2 call\n", tran_call)); + if(params) + free(params); + if(data) + free(data); + return (ERROR(ERRSRV,ERRerror)); + } + + /* As we do not know how many data packets will need to be + returned here the various call_trans2xxxx calls + must send their own. Thus a call_trans2xxx routine only + returns a value other than -1 when it wants to send + an error packet. + */ + + if(params) + free(params); + if(data) + free(data); + return outsize; /* If a correct response was needed the + call_trans2xxx calls have already sent + it. If outsize != -1 then it is returning */ } diff --git a/source3/smbd/uid.c b/source3/smbd/uid.c index 9e669c301b..1276eeaaac 100644 --- a/source3/smbd/uid.c +++ b/source3/smbd/uid.c @@ -27,7 +27,7 @@ static int initial_uid; static int initial_gid; /* what user is current? */ -struct current_user current_user; +extern struct current_user current_user; pstring OriginalDir; @@ -51,7 +51,7 @@ void init_uid(void) initial_uid = geteuid(); initial_gid = getegid(); - current_user.cnum = -1; + current_user.conn = NULL; current_user.vuid = UID_FIELD_INVALID; ChDir(OriginalDir); @@ -180,7 +180,7 @@ BOOL become_guest(void) DEBUG(1,("Failed to become guest. Invalid guest account?\n")); } - current_user.cnum = -2; + current_user.conn = NULL; current_user.vuid = UID_FIELD_INVALID; return(ret); @@ -210,90 +210,89 @@ static BOOL check_user_ok(connection_struct *conn, user_struct *vuser,int snum) /**************************************************************************** become the user of a connection number ****************************************************************************/ -BOOL become_user(connection_struct *conn, int cnum, uint16 vuid) +BOOL become_user(connection_struct *conn, uint16 vuid) { - user_struct *vuser = get_valid_user_struct(vuid); - int snum,gid; - int uid; - - /* - * We need a separate check in security=share mode due to vuid - * always being UID_FIELD_INVALID. If we don't do this then - * in share mode security we are *always* changing uid's between - * SMB's - this hurts performance - Badly. - */ - - if((lp_security() == SEC_SHARE) && (current_user.cnum == cnum) && - (current_user.uid == conn->uid)) { - DEBUG(4,("Skipping become_user - already user\n")); - return(True); - } else if ((current_user.cnum == cnum) && (vuser != 0) && (current_user.vuid == vuid) && - (current_user.uid == vuser->uid)) { - DEBUG(4,("Skipping become_user - already user\n")); - return(True); - } - - unbecome_user(); - - if (!(VALID_CNUM(cnum) && conn->open)) { - DEBUG(2,("Connection %d not open\n",cnum)); - return(False); - } - - snum = conn->service; + user_struct *vuser = get_valid_user_struct(vuid); + int snum,gid; + int uid; + + /* + * We need a separate check in security=share mode due to vuid + * always being UID_FIELD_INVALID. If we don't do this then + * in share mode security we are *always* changing uid's between + * SMB's - this hurts performance - Badly. + */ + + if((lp_security() == SEC_SHARE) && (current_user.conn == conn) && + (current_user.uid == conn->uid)) { + DEBUG(4,("Skipping become_user - already user\n")); + return(True); + } else if ((current_user.conn == conn) && + (vuser != 0) && (current_user.vuid == vuid) && + (current_user.uid == vuser->uid)) { + DEBUG(4,("Skipping become_user - already user\n")); + return(True); + } - if((vuser != NULL) && !check_user_ok(conn, vuser, snum)) - return False; + unbecome_user(); - if (conn->force_user || - lp_security() == SEC_SHARE || - !(vuser) || (vuser->guest) - ) - { - uid = conn->uid; - gid = conn->gid; - current_user.groups = conn->groups; - current_user.ngroups = conn->ngroups; - } - else - { - if (!vuser) { - DEBUG(2,("Invalid vuid used %d\n",vuid)); - return(False); - } - uid = vuser->uid; - if(!*lp_force_group(snum)) - gid = vuser->gid; - else - gid = conn->gid; - current_user.ngroups = vuser->n_groups; - current_user.groups = vuser->groups; - } + if (!(conn && conn->open)) { + DEBUG(2,("Connection not open\n")); + return(False); + } - if (initial_uid == 0) - { - if (!become_gid(gid)) return(False); + snum = SNUM(conn); + + if((vuser != NULL) && !check_user_ok(conn, vuser, snum)) + return False; + + if (conn->force_user || + lp_security() == SEC_SHARE || + !(vuser) || (vuser->guest)) { + uid = conn->uid; + gid = conn->gid; + current_user.groups = conn->groups; + current_user.ngroups = conn->ngroups; + } else { + if (!vuser) { + DEBUG(2,("Invalid vuid used %d\n",vuid)); + return(False); + } + uid = vuser->uid; + if(!*lp_force_group(snum)) { + gid = vuser->gid; + } else { + gid = conn->gid; + } + current_user.ngroups = vuser->n_groups; + current_user.groups = vuser->groups; + } + + if (initial_uid == 0) { + if (!become_gid(gid)) return(False); #ifdef HAVE_SETGROUPS - if (!(VALID_CNUM(cnum) && conn->ipc)) { - /* groups stuff added by ih/wreu */ - if (current_user.ngroups > 0) - if (setgroups(current_user.ngroups,current_user.groups)<0) - DEBUG(0,("setgroups call failed!\n")); - } + if (!(conn && conn->ipc)) { + /* groups stuff added by ih/wreu */ + if (current_user.ngroups > 0) + if (setgroups(current_user.ngroups, + current_user.groups)<0) { + DEBUG(0,("setgroups call failed!\n")); + } + } #endif - if (!conn->admin_user && !become_uid(uid)) - return(False); - } - - current_user.cnum = cnum; - current_user.vuid = vuid; + if (!conn->admin_user && !become_uid(uid)) + return(False); + } + + current_user.conn = conn; + current_user.vuid = vuid; - DEBUG(5,("become_user uid=(%d,%d) gid=(%d,%d)\n", - getuid(),geteuid(),getgid(),getegid())); + DEBUG(5,("become_user uid=(%d,%d) gid=(%d,%d)\n", + getuid(),geteuid(),getgid(),getegid())); - return(True); + return(True); } /**************************************************************************** @@ -301,7 +300,7 @@ BOOL become_user(connection_struct *conn, int cnum, uint16 vuid) ****************************************************************************/ BOOL unbecome_user(void ) { - if (current_user.cnum == -1) + if (!current_user.conn) return(False); ChDir(OriginalDir); @@ -343,158 +342,12 @@ BOOL unbecome_user(void ) DEBUG(5,("unbecome_user now uid=(%d,%d) gid=(%d,%d)\n", getuid(),geteuid(),getgid(),getegid())); - current_user.cnum = -1; + current_user.conn = NULL; current_user.vuid = UID_FIELD_INVALID; return(True); } - -/**************************************************************************** -This is a utility function of smbrun(). It must be called only from -the child as it may leave the caller in a privilaged state. -****************************************************************************/ -static BOOL setup_stdout_file(char *outfile,BOOL shared) -{ - int fd; - struct stat st; - mode_t mode = S_IWUSR|S_IRUSR|S_IRGRP|S_IROTH; - int flags = O_RDWR|O_CREAT|O_TRUNC|O_EXCL; - - close(1); - - if (shared) { - /* become root - unprivilaged users can't delete these files */ -#ifdef HAVE_SETRESUID - setresgid(0,0,0); - setresuid(0,0,0); -#else - setuid(0); - seteuid(0); -#endif - } - - if(stat(outfile, &st) == 0) { - /* Check we're not deleting a device file. */ - if(st.st_mode & S_IFREG) - unlink(outfile); - else - flags = O_RDWR; - } - /* now create the file */ - fd = open(outfile,flags,mode); - - if (fd == -1) return False; - - if (fd != 1) { - if (dup2(fd,1) != 0) { - DEBUG(2,("Failed to create stdout file descriptor\n")); - close(fd); - return False; - } - close(fd); - } - return True; -} - - -/**************************************************************************** -run a command being careful about uid/gid handling and putting the output in -outfile (or discard it if outfile is NULL). - -if shared is True then ensure the file will be writeable by all users -but created such that its owned by root. This overcomes a security hole. - -if shared is not set then open the file with O_EXCL set -****************************************************************************/ -int smbrun(char *cmd,char *outfile,BOOL shared) -{ - int fd,pid; - int uid = current_user.uid; - int gid = current_user.gid; - -#ifndef HAVE_EXECL - int ret; - pstring syscmd; - char *path = lp_smbrun(); - - /* in the old method we use system() to execute smbrun which then - executes the command (using system() again!). This involves lots - of shell launches and is very slow. It also suffers from a - potential security hole */ - if (!file_exist(path,NULL)) - { - DEBUG(0,("SMBRUN ERROR: Can't find %s. Installation problem?\n",path)); - return(1); - } - - slprintf(syscmd,sizeof(syscmd)-1,"%s %d %d \"(%s 2>&1) > %s\"", - path,uid,gid,cmd, - outfile?outfile:"/dev/null"); - - DEBUG(5,("smbrun - running %s ",syscmd)); - ret = system(syscmd); - DEBUG(5,("gave %d\n",ret)); - return(ret); -#else - /* in this newer method we will exec /bin/sh with the correct - arguments, after first setting stdout to point at the file */ - - if ((pid=fork())) { - int status=0; - /* the parent just waits for the child to exit */ - if (sys_waitpid(pid,&status,0) != pid) { - DEBUG(2,("waitpid(%d) : %s\n",pid,strerror(errno))); - return -1; - } - return status; - } - - - /* we are in the child. we exec /bin/sh to do the work for us. we - don't directly exec the command we want because it may be a - pipeline or anything else the config file specifies */ - - /* point our stdout at the file we want output to go into */ - if (outfile && !setup_stdout_file(outfile,shared)) { - exit(80); - } - - /* now completely lose our privilages. This is a fairly paranoid - way of doing it, but it does work on all systems that I know of */ -#ifdef HAVE_SETRESUID - setresgid(0,0,0); - setresuid(0,0,0); - setresgid(gid,gid,gid); - setresuid(uid,uid,uid); -#else - setuid(0); - seteuid(0); - setgid(gid); - setegid(gid); - setuid(uid); - seteuid(uid); -#endif - - if (getuid() != uid || geteuid() != uid || - getgid() != gid || getegid() != gid) { - /* we failed to lose our privilages - do not execute the command */ - exit(81); /* we can't print stuff at this stage, instead use exit codes - for debugging */ - } - - /* close all other file descriptors, leaving only 0, 1 and 2. 0 and - 2 point to /dev/null from the startup code */ - for (fd=3;fd<256;fd++) close(fd); - - execl("/bin/sh","sh","-c",cmd,NULL); - - /* not reached */ - exit(82); -#endif - return 1; -} - static struct current_user current_user_saved; static int become_root_depth; static pstring become_root_dir; diff --git a/source3/utils/status.c b/source3/utils/status.c index 225f1712fe..848f87623e 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -61,9 +61,7 @@ int locks_only = 0; /* Added by RJS */ /* we need these because we link to locking*.o */ void become_root(BOOL save_dir) {} void unbecome_root(BOOL restore_dir) {} -connection_struct Connections[MAX_CONNECTIONS]; files_struct Files[MAX_OPEN_FILES]; -struct current_user current_user; /* added by OH */ diff --git a/source3/web/swat.c b/source3/web/swat.c index 78c1fa4f19..7c7a2ef205 100644 --- a/source3/web/swat.c +++ b/source3/web/swat.c @@ -36,9 +36,7 @@ static pstring servicesf = CONFIGFILE; void unbecome_root(BOOL restore_dir) {} /* We need this because we link to password.o */ BOOL change_oem_password(struct smb_passwd *smbpw, char *new_passwd, BOOL override) {return False;} -connection_struct Connections[MAX_CONNECTIONS]; files_struct Files[MAX_OPEN_FILES]; -struct current_user current_user; static int enum_index(int value, struct enum_list *enumlist) { |