Add NT quota support. Patch from Stefan (metze) Metzemacher
authorAlexander Bokovoy <ab@samba.org>
Mon, 12 May 2003 01:20:17 +0000 (01:20 +0000)
committerAlexander Bokovoy <ab@samba.org>
Mon, 12 May 2003 01:20:17 +0000 (01:20 +0000)
1. Allows to change quota settings for shared mount points from Win2K and WinXP from Explorer properties tab
2. Disabled by default and when requested, will be probed and enabled only on Linux where it works
3. Was tested for approx. two weeks now on Linux by two independent QA teams, have not found any bugs so far
Documentation to follow
(This used to be commit 4bf022ce9e45be85609426762ba2644ac2031326)

21 files changed:
source3/Makefile.in
source3/aclocal.m4
source3/configure.in
source3/include/nterr.h
source3/include/ntioctl.h
source3/include/smb.h
source3/include/smbprofile.h
source3/include/sysquotas.h
source3/lib/sysquotas.c [new file with mode: 0644]
source3/lib/util.c
source3/lib/util_str.c
source3/libsmb/nterr.c
source3/param/loadparm.c
source3/smbd/dfree.c
source3/smbd/fake_file.c [new file with mode: 0644]
source3/smbd/files.c
source3/smbd/ntquotas.c [new file with mode: 0644]
source3/smbd/nttrans.c
source3/smbd/quotas.c
source3/smbd/trans2.c
source3/smbd/vfs-wrap.c

index c96508c8439fdef8e6d69807a214a618adb80738..492d73d4b7a8bf2a838e4caf52ea4b0d1ddfcd99 100644 (file)
@@ -141,8 +141,6 @@ SHLIBS = @SHLIB_PROGS@ @LIBSMBCLIENT@
 
 SCRIPTS = $(srcdir)/script/smbtar $(builddir)/script/findsmb
 
-QUOTAOBJS=@QUOTAOBJS@
-
 VFS_MODULES = @VFS_MODULES@
 PDB_MODULES = @PDB_MODULES@
 RPC_MODULES = @RPC_MODULES@
@@ -330,14 +328,15 @@ SMBD_OBJ_SRV = smbd/files.o smbd/chgpasswd.o smbd/connection.o \
                smbd/posix_acls.o lib/sysacls.o lib/server_mutex.o \
               smbd/process.o smbd/service.o smbd/error.o \
               printing/printfsp.o lib/util_seaccess.o \
-               smbd/build_options.o \
-              smbd/change_trust_pw.o \
+               smbd/build_options.o lib/sysquotas.o \
+              smbd/change_trust_pw.o smbd/fake_file.o \
+              smbd/quotas.o smbd/ntquotas.o \
               $(MANGLE_OBJ) @VFS_STATIC@
 
 SMBD_OBJ_BASE = $(PARAM_OBJ) $(SMBD_OBJ_SRV) $(MSDFS_OBJ) $(LIBSMB_OBJ) \
                $(RPC_SERVER_OBJ) $(RPC_PARSE_OBJ) $(SECRETS_OBJ) $(UBIQX_OBJ) \
                $(LOCKING_OBJ) $(PASSDB_OBJ) $(PRINTING_OBJ) $(PROFILE_OBJ) \
-               $(LIB_OBJ) $(PRINTBACKEND_OBJ) $(QUOTAOBJS) $(OPLOCK_OBJ) \
+               $(LIB_OBJ) $(PRINTBACKEND_OBJ) $(OPLOCK_OBJ) \
                $(NOTIFY_OBJ) $(GROUPDB_OBJ) $(AUTH_OBJ) \
                $(LIBMSRPC_OBJ) $(LIBMSRPC_SERVER_OBJ) \
                $(LIBADS_OBJ) $(KRBCLIENT_OBJ) $(LIBADS_SERVER_OBJ) \
@@ -543,7 +542,7 @@ PROTO_OBJ = $(SMBD_OBJ_MAIN) \
            $(RPC_PIPE_OBJ) $(RPC_PARSE_OBJ) $(KRBCLIENT_OBJ) \
            $(AUTH_OBJ) $(PARAM_OBJ) $(LOCKING_OBJ) $(SECRETS_OBJ) \
            $(PRINTING_OBJ) $(PRINTBACKEND_OBJ) $(OPLOCK_OBJ) $(NOTIFY_OBJ) \
-           $(QUOTAOBJS) $(PASSDB_OBJ) $(GROUPDB_OBJ) $(MSDFS_OBJ) \
+           $(PASSDB_OBJ) $(GROUPDB_OBJ) $(MSDFS_OBJ) \
            $(READLINE_OBJ) $(PROFILE_OBJ) $(LIBADS_OBJ) $(LIBADS_SERVER_OBJ) \
            $(LIB_SMBD_OBJ) $(SAM_OBJ) $(REGISTRY_OBJ) $(POPT_LIB_OBJ) \
            $(RPC_LSA_OBJ) $(RPC_NETLOG_OBJ) $(RPC_SAMR_OBJ) $(RPC_REG_OBJ) \
index f470e2e8b0e0f1cbc083bfe35b05d1f6427f6056..dd1ae8df72bcf205f966b8c1e1e2eb7d93abac3b 100644 (file)
@@ -678,3 +678,29 @@ dnl AC_DISABLE_STATIC - set the default static flag to --disable-static
 AC_DEFUN([AC_DISABLE_STATIC],
 [AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
 AC_ENABLE_STATIC(no)])
+
+dnl AC_TRY_RUN_STRICT(PROGRAM,CFLAGS,CPPFLAGS,LDFLAGS,
+dnl            [ACTION-IF-TRUE],[ACTION-IF-FALSE],
+dnl            [ACTION-IF-CROSS-COMPILING = RUNTIME-ERROR])
+AC_DEFUN( [AC_TRY_RUN_STRICT],
+[
+       old_CFLAGS="$CFLAGS";
+       CFLAGS="$2";
+       export CFLAGS;
+       old_CPPFLAGS="$CPPFLAGS";
+       CPPFLAGS="$3";
+       export CPPFLAGS;
+       old_LDFLAGS="$LDFLAGS";
+       LDFLAGS="$4";
+       export LDFLAGS;
+       AC_TRY_RUN([$1],[$5],[$6],[$7]);
+       CFLAGS="$old_CFLAGS";
+       old_CFLAGS="";
+       export CFLAGS;
+       CPPFLAGS="$old_CPPFLAGS";
+       old_CPPFLAGS="";
+       export CPPFLAGS;
+       LDFLAGS="$old_LDFLAGS";
+       old_LDFLAGS="";
+       export LDFLAGS;
+])
index ba9b485df29031b593b4e1cbe9713c1f0fbb8b8e..0f6a9fa27c24360eff200bea340c7122786d79ad 100644 (file)
@@ -224,6 +224,30 @@ else
 fi
 AC_SUBST(BROKEN_CC)
 
+dnl Check if the C compiler understands -Werror
+AC_CACHE_CHECK([that the C compiler understands -Werror],samba_cv_HAVE_Werror, [
+ AC_TRY_RUN_STRICT([
+  int main(void)
+  {
+       return 0;
+  }],[-Werror],[$CPPFLAGS],[$LDFLAGS],
+  samba_cv_HAVE_Werror=yes,samba_cv_HAVE_Werror=no,samba_cv_HAVE_Werror=cross)])
+if test x"$samba_cv_HAVE_Werror" = x"yes"; then
+   Werror_FLAGS="-Werror"
+else 
+dnl Check if the C compiler understands -w2
+AC_CACHE_CHECK([that the C compiler understands -w2],samba_cv_HAVE_w2, [
+ AC_TRY_RUN_STRICT([
+  int main(void)
+  {
+       return 0;
+  }],[-w2],[$CPPFLAGS],[$LDFLAGS],
+  samba_cv_HAVE_w2=yes,samba_cv_HAVE_w2=no,samba_cv_HAVE_w2=cross)])
+if test x"$samba_cv_HAVE_w2" = x"yes"; then
+   Werror_FLAGS="-w2"
+fi
+fi
+
 dnl Check if the C compiler understands volatile (it should, being ANSI).
 AC_CACHE_CHECK([that the C compiler understands volatile],samba_cv_volatile, [
     AC_TRY_COMPILE([#include <sys/types.h>],[volatile int i = 0],
@@ -232,6 +256,21 @@ if test x"$samba_cv_volatile" = x"yes"; then
    AC_DEFINE(HAVE_VOLATILE, 1, [Whether the C compiler understands volatile])
 fi
 
+UNAME_S=`uname -s`
+AC_MSG_CHECKING(uname -s)
+AC_MSG_RESULT(${UNAME_S})
+
+UNAME_R=`uname -r`
+AC_MSG_CHECKING(uname -r)
+AC_MSG_RESULT(${UNAME_R})
+
+UNAME_M=`uname -m`
+AC_MSG_CHECKING(uname -m)
+AC_MSG_RESULT(${UNAME_M})
+
+UNAME_P=`uname -p`
+AC_MSG_CHECKING(uname -p)
+AC_MSG_RESULT(${UNAME_P})
 
 AC_CANONICAL_SYSTEM
 
@@ -517,13 +556,6 @@ AC_CHECK_HEADERS(sys/acl.h sys/cdefs.h glob.h)
 # For experimental utmp support (lastlog on some BSD-like systems)
 AC_CHECK_HEADERS(utmp.h utmpx.h lastlog.h)
  
-# For quotas on Veritas VxFS filesystems
-AC_CHECK_HEADERS(sys/fs/vx_quota.h)
-
-# For quotas on Linux XFS filesystems
-AC_CHECK_HEADERS(linux/xqm.h)
-AC_CHECK_HEADERS(xfs/xqm.h)
-
 AC_CHECK_SIZEOF(int,cross)
 AC_CHECK_SIZEOF(long,cross)
 AC_CHECK_SIZEOF(short,cross)
@@ -2525,44 +2557,230 @@ AC_ARG_WITH(profiling-data,
 
 #################################################
 # check for experimental disk-quotas support
-QUOTAOBJS=smbd/noquotas.o
 
-AC_MSG_CHECKING(whether to support disk-quotas)
+samba_cv_TRY_QUOTAS=no
+AC_MSG_CHECKING(whether to try disk-quotas support)
 AC_ARG_WITH(quotas,
-[  --with-quotas           Include experimental disk-quota support (default=no)],
+[  --with-quotas           Include disk-quota support (default=no)],
+[ case "$withval" in
+  no)
+    AC_MSG_RESULT(no)
+    samba_cv_TRY_QUOTAS=no
+    ;;
+  *)
+    AC_MSG_RESULT(yes)
+    ;;
+  esac ],
+  AC_MSG_RESULT(yes)
+)
+
+samba_cv_TRY_SYS_QUOTAS=auto
+AC_MSG_CHECKING(whether to try the new lib/sysquotas.c interface)
+AC_ARG_WITH(sys-quotas,
+[  --with-sys-quotas       Include lib/sysquotas.c support (default=auto)],
 [ case "$withval" in
   yes)
     AC_MSG_RESULT(yes)
-    case "$host_os" in
-      *linux*)
-        # Check for kernel 2.4.x quota braindamage...
-        AC_CACHE_CHECK([for linux 2.4.x quota braindamage..],samba_cv_linux_2_4_quota_braindamage, [
-        AC_TRY_COMPILE([#include <stdio.h>
-#include <sys/types.h>
-#include <asm/types.h>
-#include <linux/quota.h>
-#include <mntent.h>
-#include <linux/unistd.h>],[struct mem_dqblk D;],
-      samba_cv_linux_2_4_quota_braindamage=yes,samba_cv_linux_2_4_quota_braindamage=no)])
-if test x"$samba_cv_linux_2_4_quota_braindamage" = x"yes"; then
-        AC_DEFINE(LINUX_QUOTAS_2,1,[linux 2.4.x quota braindamage])
-else
-        AC_DEFINE(LINUX_QUOTAS_1,1,[linux quotas])
-fi
-        ;;
-      *)
-        ;;
-    esac
-    QUOTAOBJS=smbd/quotas.o
-    AC_DEFINE(WITH_QUOTAS,1,[Whether to include experimental quota support])
+    samba_cv_TRY_QUOTAS=yes
+    samba_cv_TRY_SYS_QUOTAS=yes
     ;;
-  *)
+  no)
     AC_MSG_RESULT(no)
+    samba_cv_TRY_SYS_QUOTAS=no
+    ;;
+  *)
+    AC_MSG_RESULT(auto)
     ;;
   esac ],
-  AC_MSG_RESULT(no)
+  AC_MSG_RESULT(auto)
 )
-AC_SUBST(QUOTAOBJS)
+
+if test x"$samba_cv_TRY_SYS_QUOTAS" = x"auto"; then
+AC_MSG_CHECKING(whether to try the lib/sysquotas.c interface on ${host_os})
+  case "$host_os" in
+       *linux*)
+           AC_MSG_RESULT(yes)
+           samba_cv_TRY_SYS_QUOTAS=yes
+           ;;
+       *)
+           AC_MSG_RESULT(no)
+           samba_cv_TRY_SYS_QUOTAS=no
+           ;;
+  esac
+fi
+
+#############################################
+# only check for quota stuff if --with-quotas
+if test x"$samba_cv_TRY_QUOTAS" = x"yes"; then
+
+# For quotas on Veritas VxFS filesystems
+AC_CHECK_HEADERS(sys/fs/vx_quota.h)
+
+# For sys/quota.h and linux/quota.h
+AC_CHECK_HEADERS(sys/quota.h)
+AC_CHECK_HEADERS(asm/types.h linux/quota.h)
+
+# For quotas on Linux XFS filesystems
+AC_CHECK_HEADERS(linux/xqm.h linux/xfs_fs.h)
+AC_CHECK_HEADERS(xfs/libxfs.h xfs/xqm.h xfs/xfs_fs.h)
+# For linux > 2.5.56 
+AC_CHECK_HEADERS(linux/dqblk_xfs.h)
+
+# if we have struct if_dqblk in <linux/quota.h> we should use it
+AC_CACHE_CHECK([for struct if_dqblk in <linux/quota.h>],samba_cv_HAVE_STRUCT_IF_DQBLK, [
+AC_TRY_COMPILE([
+#include "confdefs.h"
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_ASM_TYPES_H
+#include <asm/types.h>
+#endif
+#include <linux/quota.h>
+],[struct if_dqblk D;],
+samba_cv_HAVE_STRUCT_IF_DQBLK=yes,samba_cv_HAVE_STRUCT_IF_DQBLK=no)])
+if test "$samba_cv_HAVE_STRUCT_IF_DQBLK"x = "yes"x; then
+       AC_DEFINE(HAVE_STRUCT_IF_DQBLK,1,[struct if_dqblk])
+fi
+
+# if we have struct mem_dqblk in <linux/quota.h> we should use it
+AC_CACHE_CHECK([for struct mem_dqblk in <linux/quota.h>],samba_cv_HAVE_STRUCT_MEM_DQBLK, [
+AC_TRY_COMPILE([
+#include "confdefs.h"
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_ASM_TYPES_H
+#include <asm/types.h>
+#endif
+#include <linux/quota.h>
+],[struct mem_dqblk D;],
+samba_cv_HAVE_STRUCT_MEM_DQBLK=yes,samba_cv_HAVE_STRUCT_MEM_DQBLK=no)])
+if test "$samba_cv_HAVE_STRUCT_MEM_DQBLK"x = "yes"x; then
+       AC_DEFINE(HAVE_STRUCT_MEM_DQBLK,1,[struct mem_dqblk])
+fi
+
+# if we have struct dqblk .dqb_fsoftlimit instead of .dqb_isoftlimit on IRIX 
+AC_CACHE_CHECK([if struct dqblk has .dqb_fsoftlimit],samba_cv_HAVE_DQB_FSOFTLIMIT, [
+AC_TRY_COMPILE([
+#include "confdefs.h"
+#ifdef HAVE_SYS_QUOTA_H
+#include <sys/quota.h>
+#endif
+],[
+struct dqblk D;
+D.dqb_fsoftlimit = 0;],
+samba_cv_HAVE_DQB_FSOFTLIMIT=yes,samba_cv_HAVE_DQB_FSOFTLIMIT=no)])
+if test "$samba_cv_HAVE_DQB_FSOFTLIMIT"x = "yes"x; then
+       AC_DEFINE(HAVE_DQB_FSOFTLIMIT,1,[struct dqblk .dqb_fsoftlimit])
+fi
+
+##################
+# look for a working quota system
+samba_cv_SYSQUOTA_FOUND=no;
+
+if test x"$samba_cv_SYSQUOTA_FOUND" != x"yes"; then
+AC_CACHE_CHECK([for long quotactl(int cmd, char *special, qid_t id, caddr_t addr)],samba_cv_HAVE_QUOTACTL_4A,[
+AC_TRY_RUN_STRICT([
+#define HAVE_QUOTACTL_4A 1
+#define AUTOCONF_TEST 1
+#include "confdefs.h"
+#include "${srcdir-.}/lib/sysquotas.c"],[$Werror_FLAGS],[$CPPFLAGS],[$LDFLAGS],
+           samba_cv_HAVE_QUOTACTL_4A=yes,samba_cv_HAVE_QUOTACTL_4A=no,samba_cv_HAVE_QUOTACTL_4A=cross)])
+if test x"$samba_cv_HAVE_QUOTACTL_4A" = x"yes"; then
+    samba_cv_SYSQUOTA_FOUND=yes;AC_DEFINE(HAVE_QUOTACTL_4A,1,[Whether long quotactl(int cmd, char *special, qid_t id, caddr_t addr) is available])
+fi
+fi
+
+if test x"$samba_cv_SYSQUOTA_FOUND" != x"yes"; then
+AC_CACHE_CHECK([for int quotactl(const char *path, int cmd, int id, char *addr)],samba_cv_HAVE_QUOTACTL_4B,[
+AC_TRY_RUN_STRICT([
+#define HAVE_QUOTACTL_4B 1
+#define AUTOCONF_TEST 1
+#include "confdefs.h"
+#include "${srcdir-.}/lib/sysquotas.c"],[$Werror_FLAGS],[$CPPFLAGS],[$LDFLAGS],
+           samba_cv_HAVE_QUOTACTL_4B=yes,samba_cv_HAVE_QUOTACTL_4B=no,samba_cv_HAVE_QUOTACTL_4B=cross)])
+if test x"$samba_cv_HAVE_QUOTACTL_4B" = x"yes"; then
+    echo "int quotactl(const char *path, int cmd, int id, char *addr) is not reworked for the new sys_quota api"
+#    samba_cv_SYSQUOTA_FOUND=yes;AC_DEFINE(HAVE_QUOTACTL_4B,1,[Whether int quotactl(const char *path, int cmd, int id, char *addr) is available])
+fi
+fi
+
+if test x"$samba_cv_SYSQUOTA_FOUND" != x"yes"; then
+AC_CACHE_CHECK([for CRAY int quotactl (char *spec, int request, char *arg)],samba_cv_HAVE_QUOTACTL_3,[
+AC_TRY_RUN_STRICT([
+#define HAVE_QUOTACTL_3 1
+#define AUTOCONF_TEST 1
+#include "confdefs.h"
+#include "${srcdir-.}/lib/sysquotas.c"],[$Werror_FLAGS],[$CPPFLAGS],[$LDFLAGS],
+           samba_cv_HAVE_QUOTACTL_3=yes,samba_cv_HAVE_QUOTACTL_3=no,samba_cv_HAVE_QUOTACTL_3=cross)])
+if test x"$samba_cv_HAVE_QUOTACTL_3" = x"yes"; then
+    echo "CRAY int quotactl (char *spec, int request, char *arg) is NOT reworked for the sys_quota api"
+#    samba_cv_SYSQUOTA_FOUND=yes;AC_DEFINE(HAVE_QUOTACTL_3,1,[Whether CRAY int quotactl (char *spec, int request, char *arg); is available])
+fi
+fi
+
+#################################################
+# check for mntent.h and struct mntent
+AC_CHECK_HEADERS(mntent.h)
+#################################################
+# check for setmntent,getmntent,endmntent
+AC_CHECK_FUNCS(setmntent getmntent endmntent)
+
+#################################################
+# check for devnm.h and struct mntent
+AC_CHECK_HEADERS(devnm.h)
+#################################################
+# check for devnm
+AC_CHECK_FUNCS(devnm)
+
+
+if test x"$samba_cv_SYSQUOTA_FOUND" = x"yes"; then
+AC_CACHE_CHECK([whether the sys_quota interface works],samba_cv_SYSQUOTA_WORKS,[
+SAVE_CPPFLAGS="$CPPFLAGS"
+CPPFLAGS="$CPPFLAGS -I${srcdir-.}/ -I. -I${srcdir-.}/include -I${srcdir-.}/ubiqx -I${srcdir-.}/popt  -I${srcdir-.}/smbwrapper -I${srcdir-.}/nsswitch"
+AC_TRY_COMPILE([
+#include "confdefs.h"
+#define NO_PROTO_H 1
+#define NO_CONFIG_H 1
+#define HAVE_SYS_QUOTAS 1
+#include "${srcdir-.}/lib/sysquotas.c"
+],[],samba_cv_SYSQUOTA_WORKS=yes,samba_cv_SYSQUOTA_WORKS=no)
+CPPFLAGS="$SAVE_CPPFLAGS"
+])
+if test x"$samba_cv_SYSQUOTA_WORKS" = x"yes"; then
+AC_MSG_CHECKING(whether to use the new lib/sysquotas.c interface)
+    if test x"$samba_cv_TRY_SYS_QUOTAS" = x"yes"; then 
+       AC_DEFINE(WITH_QUOTAS,1,[Whether to use disk quota support])
+       AC_DEFINE(HAVE_SYS_QUOTAS,1,[Whether the new lib/sysquotas.c interface can be used])
+       samba_cv_WE_USE_SYS_QUOTAS=yes
+       AC_MSG_RESULT(yes)
+    else
+        AC_MSG_RESULT(no)
+    fi
+fi
+fi
+
+AC_CACHE_CHECK([whether the old quota support works],samba_cv_QUOTA_WORKS,[
+SAVE_CPPFLAGS="$CPPFLAGS"
+CPPFLAGS="$CPPFLAGS -I${srcdir-.}/ -I. -I${srcdir-.}/include -I${srcdir-.}/ubiqx -I${srcdir-.}/popt  -I${srcdir-.}/smbwrapper -I${srcdir-.}/nsswitch"
+AC_TRY_COMPILE([
+#include "confdefs.h"
+#define NO_PROTO_H 1
+#define NO_CONFIG_H 1
+#include "${srcdir-.}/smbd/quotas.c"
+],[],samba_cv_QUOTA_WORKS=yes,samba_cv_QUOTA_WORKS=no)
+CPPFLAGS="$SAVE_CPPFLAGS"
+])
+if test x"$samba_cv_QUOTA_WORKS" = x"yes"; then
+    if test x"$samba_cv_WE_USE_SYS_QUOTAS" != x"yes"; then
+       AC_DEFINE(WITH_QUOTAS,1,[Whether to use disk quota support])
+    fi
+fi
+
+####################
+# End of quota check
+fi
 
 #################################################
 # check for experimental utmp accounting
index dcc26d98848972401d7ad5d52d98914420a9587f..19c70cffcc9160fdd1b29c08304eeda6efe1baba 100644 (file)
 #define NT_STATUS_TOO_MANY_LINKS NT_STATUS(0xC0000000 | 0x0265)
 #define NT_STATUS_QUOTA_LIST_INCONSISTENT NT_STATUS(0xC0000000 | 0x0266)
 #define NT_STATUS_FILE_IS_OFFLINE NT_STATUS(0xC0000000 | 0x0267)
+#define NT_STATUS_NOT_A_REPARSE_POINT NT_STATUS(0xC0000000 | 0x0275)
 #define NT_STATUS_NO_SUCH_JOB NT_STATUS(0xC0000000 | 0xEDE) /* scheduler */
 
 #endif /* _NTERR_H */
index 4749842ddc5f65fedb9f859fa71710819a845379..17791fde18f13b8ba2353106bf7783dad73ce462 100644 (file)
   we only need the sparse flag
 */
 
-#define NTIOCTL_SET_SPARSE 0x900c4
+
+/* IOCTL information */
+/* List of ioctl function codes that look to be of interest to remote clients like this. */
+/* Need to do some experimentation to make sure they all work remotely.                  */
+/* Some of the following such as the encryption/compression ones would be                */
+/* invoked from tools via a specialized hook into the VFS rather than via the            */
+/* standard vfs entry points */
+#define FSCTL_REQUEST_OPLOCK_LEVEL_1 0x00090000
+#define FSCTL_REQUEST_OPLOCK_LEVEL_2 0x00090004
+#define FSCTL_REQUEST_BATCH_OPLOCK   0x00090008
+#define FSCTL_LOCK_VOLUME            0x00090018
+#define FSCTL_UNLOCK_VOLUME          0x0009001C
+#define FSCTL_GET_COMPRESSION        0x0009003C
+#define FSCTL_SET_COMPRESSION        0x0009C040
+#define FSCTL_REQUEST_FILTER_OPLOCK  0x0009008C
+#define FSCTL_FIND_FILES_BY_SID             0x0009008F
+#define FSCTL_FILESYS_GET_STATISTICS 0x00090090
+#define FSCTL_SET_REPARSE_POINT      0x000900A4
+#define FSCTL_GET_REPARSE_POINT      0x000900A8
+#define FSCTL_DELETE_REPARSE_POINT   0x000900AC
+#define FSCTL_0x000900C0            0x000900C0
+#define FSCTL_SET_SPARSE             0x000900C4
+#define FSCTL_SET_ZERO_DATA          0x000900C8
+#define FSCTL_SET_ENCRYPTION         0x000900D7
+#define FSCTL_ENCRYPTION_FSCTL_IO    0x000900DB
+#define FSCTL_WRITE_RAW_ENCRYPTED    0x000900DF
+#define FSCTL_READ_RAW_ENCRYPTED     0x000900E3
+#define FSCTL_SIS_COPYFILE           0x00090100
+#define FSCTL_SIS_LINK_FILES         0x0009C104
+
+#if 0
+#define FSCTL_SECURITY_ID_CHECK
+#define FSCTL_DISMOUNT_VOLUME
+#define FSCTL_GET_NTFS_FILE_RECORD
+#define FSCTL_ALLOW_EXTENDED_DASD_IO
+#define FSCTL_RECALL_FILE
+#define FSCTL_QUERY_ALLOCATED_RANGES
+
+#endif
+
+#define IO_REPARSE_TAG_MOUNT_POINT   0xA0000003
+#define IO_REPARSE_TAG_HSM           0xC0000004
+#define IO_REPARSE_TAG_SIS           0x80000007
index fc5c50323049898d5e7410e98f7d7c9fcea7a1a9..bba5d5cd52177434c67f67b81db2203b9c1944e8 100644 (file)
@@ -243,6 +243,7 @@ typedef struct nttime_info
 /* SID Types */
 enum SID_NAME_USE
 {
+       SID_NAME_USE_NONE = 0,
        SID_NAME_USER    = 1, /* user */
        SID_NAME_DOM_GRP,     /* domain group */
        SID_NAME_DOMAIN,      /* domain sid */
@@ -403,6 +404,7 @@ typedef struct files_struct
        BOOL is_stat;
        BOOL directory_delete_on_close;
        char *fsp_name;
+       FAKE_FILE_HANDLE *fake_file_handle;
 } files_struct;
 
 #include "ntquotas.h"
index e501de8c0e2566a8127c0540b4415a35044c6912..a64c2ce69ececb603d0bfaddbfe3d56585c470f6 100644 (file)
@@ -108,6 +108,10 @@ struct profile_stats {
        unsigned syscall_mknod_time;
        unsigned syscall_realpath_count;
        unsigned syscall_realpath_time;
+       unsigned syscall_get_quota_count;
+       unsigned syscall_get_quota_time;
+       unsigned syscall_set_quota_count;
+       unsigned syscall_set_quota_time;
 /* stat cache counters */
        unsigned statcache_lookups;
        unsigned statcache_misses;
@@ -326,6 +330,10 @@ struct profile_stats {
        unsigned NT_transact_rename_time;
        unsigned NT_transact_query_security_desc_count;
        unsigned NT_transact_query_security_desc_time;
+       unsigned NT_transact_get_user_quota_count;
+       unsigned NT_transact_get_user_quota_time;
+       unsigned NT_transact_set_user_quota_count;
+       unsigned NT_transact_set_user_quota_time;
 /* These are ACL manipulation calls */
        unsigned get_nt_acl_count;
        unsigned get_nt_acl_time;
index 9513110a6acb100a09fecae13a07c8ec507c28a5..46a265ed179bde4ebc305988de5829ebab06e46b 100644 (file)
 /* 
-   Unix SMB/CIFS implementation.
-   SYS QUOTA code constants
-   Copyright (C) Stefan (metze) Metzmacher     2003
-   
-   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.
+    Unix SMB/CIFS implementation.
+    SYS QUOTA code constants
+    Copyright (C) Stefan (metze) Metzmacher    2003
+    
+    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.
 */
-
 #ifndef _SYSQUOTAS_H
 #define _SYSQUOTAS_H
+#ifdef HAVE_SYS_QUOTAS
+
+/* Sometimes we need this on linux for linux/quota.h */
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
+#ifdef HAVE_ASM_TYPES_H
+#include <asm/types.h>
+#endif
+
+/*
+ * This shouldn't be neccessary - it should be /usr/include/sys/quota.h
+ * Unfortunately, RH7.1 ships with a different quota system using struct mem_dqblk
+ * rather than the struct dqblk defined in /usr/include/sys/quota.h.
+ * This means we must include linux/quota.h to have a hope of working on
+ * RH7.1 systems. And it also means this breaks if the kernel is upgraded
+ * to a Linus 2.4.x (where x > the minor number shipped with RH7.1) until
+ * Linus synchronises with the AC patches. Sometimes I *hate* Linux :-). JRA.
+ */
+#ifdef HAVE_LINUX_QUOTA_H
+#include <linux/quota.h>
+#elif defined(HAVE_SYS_QUOTA_H)
+#include <sys/quota.h>
+#endif
+
+#if defined(HAVE_STRUCT_IF_DQBLK)
+# define SYS_DQBLK if_dqblk
+# define dqb_curblocks dqb_curspace/bsize
+#elif defined(HAVE_STRUCT_MEM_DQBLK)
+# define SYS_DQBLK mem_dqblk
+# define dqb_curblocks dqb_curspace/bsize
+#else /* STRUCT_DQBLK */
+# define SYS_DQBLK dqblk
+#endif
+
+#ifndef Q_SETQLIM
+#define Q_SETQLIM Q_SETQUOTA
+#endif
+
+/*********************************************
+ check for XFS QUOTA MANAGER 
+ *********************************************/
+/* on linux */
+#ifdef HAVE_LINUX_XQM_H
+# include <linux/xqm.h>
+# define HAVE_XFS_QUOTA
+#else
+# ifdef HAVE_XFS_XQM_H
+#  include <xfs/xqm.h>
+#  define HAVE_XFS_QUOTA
+# else
+#  ifdef HAVE_LINUX_DQBLK_XFS_H
+#   include <linux/dqblk_xfs.h>
+#   define HAVE_XFS_QUOTA
+#  endif 
+# endif
+#endif
+/* on IRIX */
+#ifdef Q_XGETQUOTA
+# ifndef HAVE_XFS_QUOTA
+#  define HAVE_XFS_QUOTA
+#  ifndef Q_XQUOTAON
+#   define Q_XQUOTAON Q_QUOTAON
+#  endif /* Q_XQUOTAON */
+#  ifndef Q_XQUOTAOFF
+#   define Q_XQUOTAOFF Q_QUOTAOFF
+#  endif /* Q_XQUOTAOFF */
+#  ifndef Q_XGETQSTAT
+#   define Q_XGETQSTAT Q_GETQSTAT
+#  endif /* Q_XGETQSTAT */
+# endif /* HAVE_XFS_QUOTA */
+#endif /* Q_XGETQUOTA */
+
+#ifdef HAVE_XFS_QUOTA
+/* Linux has BBSIZE in <linux/xfs_fs.h>
+ * or <xfs/xfs_fs.h>
+ * IRIX has BBSIZE in <sys/param.h>
+ */
+#ifdef HAVE_LINUX_XFS_FS_H
+#include <linux/xfs_fs.h>
+#elif defined(HAVE_XFS_XFS_FS_H)
+#include <xfs/xfs_fs.h>
+#endif /* *_XFS_FS_H */
+
+#ifndef BBSHIFT
+#define        BBSHIFT         9
+#endif /* BBSHIFT */
+#ifndef BBSIZE
+#define        BBSIZE          (1<<BBSHIFT)
+#endif /* BBSIZE */
+
+#endif /* HAVE_XFS_QUOTA */
+
+#ifdef LINUX
+# ifndef QUOTABLOCK_SIZE
+#  define QUOTABLOCK_SIZE 1024
+# endif
+/* end LINUX */
+#elif defined(IRIX6)
+# ifndef QUOTABLOCK_SIZE
+#  define QUOTABLOCK_SIZE BBSIZE
+# endif
+/* end IRIX6 */
+#else /* HPUP,... */
+# ifndef QUOTABLOCK_SIZE
+#  define QUOTABLOCK_SIZE DEV_BSIZE
+# endif
+#endif /* HPUP,... */
+
+#if !defined(QUOTAFILENAME) && defined(QFILENAME)
+#define QUOTAFILENAME QFILENAME
+#endif
+
+#ifdef INITQFNAMES
+#define USERQUOTAFILE_EXTENSION ".user"
+#else
+#define USERQUOTAFILE_EXTENSION ""
+#endif
+
+/* this check should be before the QCMD fake! */
+#if defined(QCMD)&&defined(GRPQUOTA)
+#define HAVE_GROUP_QUOTA
+#endif
+
+/* on some systems we have to fake this up ...*/
+#ifndef QCMD
+#define QCMD(cmd,type) (cmd)
+#endif /* QCMD */
+
+
+#ifdef HAVE_DQB_FSOFTLIMIT
+#define dqb_isoftlimit dqb_fsoftlimit
+#define dqb_ihardlimit dqb_fhardlimit
+#define dqb_curinodes  dqb_curfiles
+#endif
+
+/* maybe we can add a configure test for HAVE_CADDR_T,
+ * but it's not needed
+ */
+#ifdef HAVE_CADDR_T
+#define CADDR_T caddr_t
+#else /* CADDR_T */
+#define CADDR_T void*
+#endif /* CADDR_T */
+
+#if defined(HAVE_MNTENT_H)&&defined(HAVE_SETMNTENT)&&defined(HAVE_GETMNTENT)&&defined(HAVE_ENDMNTENT)
+#include <mntent.h>
+#define HAVE_MNTENT 1
+/*#endif defined(HAVE_MNTENT_H)&&defined(HAVE_SETMNTENT)&&defined(HAVE_GETMNTENT)&&defined(HAVE_ENDMNTENT) */
+#elif defined(HAVE_DEVNM_H)&&defined(HAVE_DEVNM)
+#include <devnm.h>
+#endif /* defined(HAVE_DEVNM_H)&&defined(HAVE_DEVNM) */
 
+#endif /* HAVE_SYS_QUOTAS */
 
 /**************************************************
  Some stuff for the sys_quota api.
diff --git a/source3/lib/sysquotas.c b/source3/lib/sysquotas.c
new file mode 100644 (file)
index 0000000..ba58e87
--- /dev/null
@@ -0,0 +1,956 @@
+/* 
+   Unix SMB/CIFS implementation.
+   System QUOTA function wrappers
+   Copyright (C) Stefan (metze) Metzmacher     2003
+   
+   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.
+*/
+
+
+#ifndef AUTOCONF_TEST
+
+#include "includes.h"
+
+
+#if defined(HAVE_QUOTACTL_4A) 
+/* long quotactl(int cmd, char *special, qid_t id, caddr_t addr) */
+/* this is used by: linux,HPUX,IRIX */
+
+/****************************************************************************
+ Abstract out the old and new Linux quota get calls.
+****************************************************************************/
+static int sys_get_vfs_quota(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp)
+{
+       int ret = -1;
+       uint32 qflags = 0;
+       struct SYS_DQBLK D;
+       SMB_BIG_UINT bsize = (SMB_BIG_UINT)QUOTABLOCK_SIZE;
+
+       if (!path||!bdev||!dp)
+               smb_panic("sys_get_vfs_quota: called with NULL pointer");
+
+       ZERO_STRUCT(D);
+       ZERO_STRUCT(*dp);
+       dp->qtype = qtype;
+
+       switch (qtype) {
+               case SMB_USER_QUOTA_TYPE:
+                       /* we use id.uid == 0 for default quotas */
+                       if (id.uid == 0) {
+                               ret = 0;
+                               break;
+                       }
+       
+                       if ((ret = quotactl(QCMD(Q_GETQUOTA,USRQUOTA), bdev, id.uid, (CADDR_T)&D))) {
+                               return ret;
+                       }
+
+                       if ((D.dqb_curblocks==0)&&
+                               (D.dqb_bsoftlimit==0)&&
+                               (D.dqb_bhardlimit==0)) {
+                               /* the upper layer functions don't want empty quota records...*/
+                               return -1;
+                       }
+
+                       break;
+#ifdef HAVE_GROUP_QUOTA
+               case SMB_GROUP_QUOTA_TYPE:
+                       if ((ret = quotactl(QCMD(Q_GETQUOTA,GRPQUOTA), bdev, id.gid, (CADDR_T)&D))) {
+                               return ret;
+                       }
+
+                       if ((D.dqb_curblocks==0)&&
+                               (D.dqb_bsoftlimit==0)&&
+                               (D.dqb_bhardlimit==0)) {
+                               /* the upper layer functions don't want empty quota records...*/
+                               return -1;
+                       }
+
+                       break;
+#endif /* HAVE_GROUP_QUOTA */
+               case SMB_USER_FS_QUOTA_TYPE:
+                       id.uid = getuid();
+
+                       if ((ret = quotactl(QCMD(Q_GETQUOTA,USRQUOTA), bdev, id.uid, (CADDR_T)&D))==0) {
+                               qflags |= QUOTAS_DENY_DISK;
+                       }
+
+                       /* get the default quotas stored in the root's (uid =0) record */
+                       if ((ret = quotactl(QCMD(Q_GETQUOTA,USRQUOTA), bdev, 0, (CADDR_T)&D))) {
+                               return ret;
+                       }
+
+                       ret = 0;
+                       break;
+               default:
+                       errno = ENOSYS;
+                       return -1;
+       }
+
+       dp->bsize = bsize;
+       dp->softlimit = (SMB_BIG_UINT)D.dqb_bsoftlimit;
+       dp->hardlimit = (SMB_BIG_UINT)D.dqb_bhardlimit;
+       dp->ihardlimit = (SMB_BIG_UINT)D.dqb_ihardlimit;
+       dp->isoftlimit = (SMB_BIG_UINT)D.dqb_isoftlimit;
+       dp->curinodes = (SMB_BIG_UINT)D.dqb_curinodes;
+       dp->curblocks = (SMB_BIG_UINT)D.dqb_curblocks;
+
+
+       dp->qflags = qflags;
+
+       return ret;
+}
+
+/****************************************************************************
+ Abstract out the old and new Linux quota set calls.
+****************************************************************************/
+
+static int sys_set_vfs_quota(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp)
+{
+       int ret = -1;
+       uint32 qflags = 0;
+       struct SYS_DQBLK D;
+       SMB_BIG_UINT bsize = (SMB_BIG_UINT)QUOTABLOCK_SIZE;
+
+       if (!path||!bdev||!dp)
+               smb_panic("sys_set_vfs_quota: called with NULL pointer");
+
+       ZERO_STRUCT(D);
+
+       if (bsize == dp->bsize) {
+               D.dqb_bsoftlimit = dp->softlimit;
+               D.dqb_bhardlimit = dp->hardlimit;
+               D.dqb_ihardlimit = dp->ihardlimit;
+               D.dqb_isoftlimit = dp->isoftlimit;
+       } else {
+               D.dqb_bsoftlimit = (dp->softlimit*dp->bsize)/bsize;
+               D.dqb_bhardlimit = (dp->hardlimit*dp->bsize)/bsize;
+               D.dqb_ihardlimit = (dp->ihardlimit*dp->bsize)/bsize;
+               D.dqb_isoftlimit = (dp->isoftlimit*dp->bsize)/bsize;
+       }
+
+       qflags = dp->qflags;
+
+       switch (qtype) {
+               case SMB_USER_QUOTA_TYPE:
+                       /* we use id.uid == 0 for default quotas */
+                       if (id.uid>0) {
+                               ret = quotactl(QCMD(Q_SETQLIM,USRQUOTA), bdev, id.uid, (CADDR_T)&D);
+                       }
+                       break;
+#ifdef HAVE_GROUP_QUOTA
+               case SMB_GROUP_QUOTA_TYPE:
+                       ret = quotactl(QCMD(Q_SETQLIM,GRPQUOTA), bdev, id.gid, (CADDR_T)&D);
+                       break;
+#endif /* HAVE_GROUP_QUOTA */
+               case SMB_USER_FS_QUOTA_TYPE:
+                       /* this stuff didn't work as it should:
+                        * switching on/off quota via quotactl()
+                        * didn't work!
+                        * So we only set the default limits
+                        * --metze
+                        * 
+                        * On HPUX we didn't have the mount path,
+                        * we need to fix sys_path_to_bdev()
+                        *
+                        */
+#if 0
+                       uid = getuid();
+
+                       ret = quotactl(QCMD(Q_GETQUOTA,USRQUOTA), bdev, uid, (CADDR_T)&D);
+
+                       if ((qflags&QUOTAS_DENY_DISK)||(qflags&QUOTAS_ENABLED)) {
+                               if (ret == 0) {
+                                       char *quota_file = NULL;
+                                       
+                                       asprintf(&quota_file,"/%s/%s%s",path, QUOTAFILENAME,USERQUOTAFILE_EXTENSION);
+                                       if (quota_file == NULL) {
+                                               DEBUG(0,("asprintf() failed!\n"));
+                                               errno = ENOMEM;
+                                               return -1;
+                                       }
+                                       
+                                       ret = quotactl(QCMD(Q_QUOTAON,USRQUOTA), bdev, -1,(CADDR_T)quota_file);
+                               } else {
+                                       ret = 0;        
+                               }
+                       } else {
+                               if (ret != 0) {
+                                       /* turn off */
+                                       ret = quotactl(QCMD(Q_QUOTAOFF,USRQUOTA), bdev, -1, (CADDR_T)0);        
+                               } else {
+                                       ret = 0;
+                               }               
+                       }
+
+                       DEBUG(0,("vfs_fs_quota: ret(%d) errno(%d)[%s] uid(%d) bdev[%s]\n",
+                               ret,errno,strerror(errno),uid,bdev));
+#endif
+                               
+                       /* we use uid == 0 for default quotas */
+                       ret = quotactl(QCMD(Q_SETQLIM,USRQUOTA), bdev, 0, (CADDR_T)&D);
+                       
+                       break;
+
+               default:
+                       errno = ENOSYS;
+                       return -1;
+       }
+
+       return ret;
+}
+
+/*#endif HAVE_QUOTACTL_4A */
+#elif defined(HAVE_QUOTACTL_4B)
+
+#error HAVE_QUOTACTL_4B not implemeted
+
+/*#endif HAVE_QUOTACTL_4B */
+#elif defined(HAVE_QUOTACTL_3)
+
+#error HAVE_QUOTACTL_3 not implemented
+
+/* #endif  HAVE_QUOTACTL_3 */
+#else /* NO_QUOTACTL_USED */
+
+static int sys_get_vfs_quota(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp)
+{
+       int ret = -1;
+
+       if (!path||!bdev||!dp)
+               smb_panic("sys_get_vfs_quota: called with NULL pointer");
+               
+       errno = ENOSYS;
+
+       return ret;
+}
+
+static int sys_set_vfs_quota(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp)
+{
+       int ret = -1;
+
+       if (!path||!bdev||!dp)
+               smb_panic("sys_set_vfs_quota: called with NULL pointer");
+
+       errno = ENOSYS;
+
+       return ret;
+}
+
+#endif /* NO_QUOTACTL_USED */
+
+#ifdef HAVE_MNTENT
+static int sys_path_to_bdev(const char *path, char **mntpath, char **bdev, char **fs)
+{
+       int ret = -1;
+       SMB_STRUCT_STAT S;
+       FILE *fp;
+       struct mntent *mnt;
+       SMB_DEV_T devno;
+
+       /* find the block device file */
+
+       if (!path||!mntpath||!bdev||!fs)
+               smb_panic("sys_path_to_bdev: called with NULL pointer");
+
+       (*mntpath) = NULL;
+       (*bdev) = NULL;
+       (*fs) = NULL;
+       
+       if ( sys_stat(path, &S) == -1 )
+               return (-1);
+
+       devno = S.st_dev ;
+
+       fp = setmntent(MOUNTED,"r");
+  
+       while ((mnt = getmntent(fp))) {
+               if ( sys_stat(mnt->mnt_dir,&S) == -1 )
+                       continue ;
+
+               if (S.st_dev == devno) {
+                       (*mntpath) = strdup(mnt->mnt_dir);
+                       (*bdev) = strdup(mnt->mnt_fsname);
+                       (*fs)   = strdup(mnt->mnt_type);
+                       if ((*mntpath)&&(*bdev)&&(*fs)) {
+                               ret = 0;
+                       } else {
+                               SAFE_FREE(*mntpath);
+                               SAFE_FREE(*bdev);
+                               SAFE_FREE(*fs);
+                               ret = -1;
+                       }
+
+                       break;
+               }
+       }
+
+       endmntent(fp) ;
+
+       return ret;
+}
+/* #endif HAVE_MNTENT */
+#elif defined(HAVE_DEVNM)
+
+/* we have this on HPUX, ... */
+static int sys_path_to_bdev(const char *path, char **mntpath, char **bdev, char **fs)
+{
+       int ret = -1;
+       char dev_disk[256];
+       SMB_STRUCT_STAT S;
+
+       if (!path||!mntpath||!bdev||!fs)
+               smb_panic("sys_path_to_bdev: called with NULL pointer");
+
+       (*mntpath) = NULL;
+       (*bdev) = NULL;
+       (*fs) = NULL;
+       
+       /* find the block device file */
+
+       if ((ret=sys_stat(path, &S))!=0) {
+               return ret;
+       }
+       
+       if ((ret=devnm(S_IFBLK, S.st_dev, dev_disk, 256, 1))!=0) {
+               return ret;     
+       }
+
+       /* we should get the mntpath right...
+        * but I don't know how
+        * --metze
+        */
+       (*mntpath) = strdup(path);
+       (*bdev) = strdup(dev_disk);
+       if ((*mntpath)&&(*bdev)) {
+               ret = 0;
+       } else {
+               SAFE_FREE(*mntpath);
+               SAFE_FREE(*bdev);
+               ret = -1;
+       }       
+       
+       
+       return ret;     
+}
+
+/* #endif HAVE_DEVNM */
+#else
+/* we should fake this up...*/
+static int sys_path_to_bdev(const char *path, char **mntpath, char **bdev, char **fs)
+{
+       int ret = -1;
+
+       if (!path||!mntpath||!bdev||!fs)
+               smb_panic("sys_path_to_bdev: called with NULL pointer");
+
+       (*mntpath) = NULL;
+       (*bdev) = NULL;
+       (*fs) = NULL;
+       
+       (*mntpath) = strdup(path);
+       if (*mntpath) {
+               ret = 0;
+       } else {
+               SAFE_FREE(*mntpath);
+               ret = -1;
+       }
+
+       return ret;
+}
+#endif
+
+
+/*********************************************************
+ if we have XFS QUOTAS we should use them
+ *********************************************************/
+#ifdef HAVE_XFS_QUOTA
+/****************************************************************************
+ Abstract out the XFS Quota Manager quota get call.
+****************************************************************************/
+static int sys_get_xfs_quota(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp)
+{
+       int ret;
+       uint32 qflags = 0;
+       SMB_BIG_UINT bsize = (SMB_BIG_UINT)BBSIZE;
+       struct fs_disk_quota D;
+       struct fs_quota_stat F;
+       ZERO_STRUCT(D);
+       ZERO_STRUCT(F);
+
+       if (!bdev||!dp)
+               smb_panic("sys_get_xfs_quota: called with NULL pointer");
+               
+       ZERO_STRUCT(*dp);
+       dp->qtype = qtype;
+               
+       switch (qtype) {
+               case SMB_USER_QUOTA_TYPE:
+                       /* we use id.uid == 0 for default quotas */
+                       if (id.uid == 0) {
+                               ret = 0;
+                               break;
+                       }
+                       if ((ret=quotactl(QCMD(Q_XGETQUOTA,USRQUOTA), bdev, id.uid, (CADDR_T)&D)))
+                               return ret;
+                       break;
+#ifdef HAVE_GROUP_QUOTA
+               case SMB_GROUP_QUOTA_TYPE:
+                       if ((ret=quotactl(QCMD(Q_XGETQUOTA,GRPQUOTA), bdev, id.gid, (CADDR_T)&D)))
+                               return ret;
+                       break;
+#endif /* HAVE_GROUP_QUOTA */
+               case SMB_USER_FS_QUOTA_TYPE:
+                       /* TODO: get quota status from quotactl() ... */        
+                       if ((ret = quotactl(QCMD(Q_XGETQSTAT,USRQUOTA), bdev, -1, (CADDR_T)&F)))
+                               return ret;
+
+                       if (F.qs_flags & XFS_QUOTA_UDQ_ENFD) {
+                               qflags |= QUOTAS_DENY_DISK;
+                       }
+                       else if (F.qs_flags & XFS_QUOTA_UDQ_ACCT) {
+                               qflags |= QUOTAS_ENABLED;
+                       }
+
+                       /* we use uid == 0 for default quotas */
+                       if ((ret=quotactl(QCMD(Q_XGETQUOTA,USRQUOTA), bdev, 0, (CADDR_T)&D)))
+                               return ret;
+
+                       break;
+               default:
+                       errno = ENOSYS;
+                       return -1;
+       }
+
+       dp->bsize = bsize;
+       dp->softlimit = (SMB_BIG_UINT)D.d_blk_softlimit;
+       dp->hardlimit = (SMB_BIG_UINT)D.d_blk_hardlimit;
+       dp->ihardlimit = (SMB_BIG_UINT)D.d_ino_hardlimit;
+       dp->isoftlimit = (SMB_BIG_UINT)D.d_ino_softlimit;
+       dp->curinodes = (SMB_BIG_UINT)D.d_icount;
+       dp->curblocks = (SMB_BIG_UINT)D.d_bcount;
+       dp->qflags = qflags;
+
+       return ret;
+}
+
+/****************************************************************************
+ Abstract out the XFS Quota Manager quota set call.
+****************************************************************************/
+static int sys_set_xfs_quota(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp)
+{
+       int ret = -1;
+       uint32 qflags = 0;
+       SMB_BIG_UINT bsize = (SMB_BIG_UINT)BBSIZE;
+       struct fs_disk_quota D;
+       struct fs_quota_stat F;
+       int q_on = 0;
+       int q_off = 0;
+       ZERO_STRUCT(D);
+       ZERO_STRUCT(F);
+
+       if (!bdev||!dp)
+               smb_panic("sys_set_xfs_quota: called with NULL pointer");
+       
+       if (bsize == dp->bsize) {
+               D.d_blk_softlimit = dp->softlimit;
+               D.d_blk_hardlimit = dp->hardlimit;
+               D.d_ino_hardlimit = dp->ihardlimit;
+               D.d_ino_softlimit = dp->isoftlimit;
+       } else {
+               D.d_blk_softlimit = (dp->softlimit*dp->bsize)/bsize;
+               D.d_blk_hardlimit = (dp->hardlimit*dp->bsize)/bsize;
+               D.d_ino_hardlimit = (dp->ihardlimit*dp->bsize)/bsize;
+               D.d_ino_softlimit = (dp->isoftlimit*dp->bsize)/bsize;           
+       }
+
+       qflags = dp->qflags;
+
+       switch (qtype) {
+               case SMB_USER_QUOTA_TYPE:
+                       /* we use uid == 0 for default quotas */
+                       if (id.uid>0) {
+                               D.d_fieldmask |= FS_DQ_LIMIT_MASK;
+                               ret = quotactl(QCMD(Q_XSETQLIM,USRQUOTA), bdev, id.uid, (CADDR_T)&D);
+                       }
+                       break;
+#ifdef HAVE_GROUP_QUOTA
+               case SMB_GROUP_QUOTA_TYPE:
+                       D.d_fieldmask |= FS_DQ_LIMIT_MASK;
+                       ret = quotactl(QCMD(Q_XSETQLIM,GRPQUOTA), bdev, id.gid, (CADDR_T)&D);
+                       break;
+#endif /* HAVE_GROUP_QUOTA */
+               case SMB_USER_FS_QUOTA_TYPE:
+                       /* TODO */
+                       quotactl(QCMD(Q_XGETQSTAT,USRQUOTA), bdev, -1, (CADDR_T)&F);
+                       
+                       if (qflags & QUOTAS_DENY_DISK) {
+                               if (!(F.qs_flags & XFS_QUOTA_UDQ_ENFD))
+                                       q_on |= XFS_QUOTA_UDQ_ENFD;
+                               if (!(F.qs_flags & XFS_QUOTA_UDQ_ACCT))
+                                       q_on |= XFS_QUOTA_UDQ_ACCT;
+                               
+                               if (q_on != 0) {
+                                       ret = quotactl(QCMD(Q_XQUOTAON,USRQUOTA),bdev, -1, (CADDR_T)&q_on);
+                               }
+
+                       } else if (qflags & QUOTAS_ENABLED) {
+                               if (F.qs_flags & XFS_QUOTA_UDQ_ENFD)
+                                       q_off |= XFS_QUOTA_UDQ_ENFD;
+
+                               if (q_off != 0) {
+                                       ret = quotactl(QCMD(Q_XQUOTAOFF,USRQUOTA),bdev, -1, (CADDR_T)&q_off);
+                               }
+
+                               if (!(F.qs_flags & XFS_QUOTA_UDQ_ACCT))
+                                       q_on |= XFS_QUOTA_UDQ_ACCT;
+
+                               if (q_on != 0) {
+                                       ret = quotactl(QCMD(Q_XQUOTAON,USRQUOTA),bdev, -1, (CADDR_T)&q_on);
+                               }
+                       } else {
+#if 0
+                       /* Switch on XFS_QUOTA_UDQ_ACCT didn't work!
+                        * only swittching off XFS_QUOTA_UDQ_ACCT work
+                        */
+                               if (F.qs_flags & XFS_QUOTA_UDQ_ENFD)
+                                       q_off |= XFS_QUOTA_UDQ_ENFD;
+                               if (F.qs_flags & XFS_QUOTA_UDQ_ACCT)
+                                       q_off |= XFS_QUOTA_UDQ_ACCT;
+
+                               if (q_off !=0) {
+                                       ret = quotactl(QCMD(Q_XQUOTAOFF,USRQUOTA),bdev, -1, (CADDR_T)&q_off);
+                               }
+#endif
+                       }
+                       
+                       /* we use uid == 0 for default quotas */
+                       D.d_fieldmask |= FS_DQ_LIMIT_MASK;
+                       ret = quotactl(QCMD(Q_XSETQLIM,USRQUOTA), bdev, 0, (CADDR_T)&D);
+                       break;
+               default:
+                       errno = ENOSYS;
+                       return -1;
+       }
+
+       return ret;
+}
+#endif /* HAVE_XFS_QUOTA */
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/*********************************************************************
+ Now the list of all filesystem specific quota systems we have found
+**********************************************************************/
+static struct {
+       const char *name;
+       int (*get_quota)(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp);
+       int (*set_quota)(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp);
+} sys_quota_backends[] = {
+#ifdef HAVE_XFS_QUOTA
+       {"xfs", sys_get_xfs_quota,      sys_set_xfs_quota},
+#endif /* HAVE_XFS_QUOTA */
+       {NULL,  NULL,                   NULL}   
+};
+
+static int command_get_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp)
+{
+       const char *get_quota_command;
+       
+       get_quota_command = lp_get_quota_command();
+       if (get_quota_command && *get_quota_command) {
+               const char *p;
+               char *p2;
+               char **lines;
+               pstring syscmd;
+               int _id = -1;
+
+               switch(qtype) {
+                       case SMB_USER_QUOTA_TYPE:
+                       case SMB_USER_FS_QUOTA_TYPE:
+                               _id = id.uid;
+                               break;
+                       case SMB_GROUP_QUOTA_TYPE:
+                       case SMB_GROUP_FS_QUOTA_TYPE:
+                               _id = id.gid;
+                               break;
+                       default:
+                               DEBUG(0,("invalid quota type.\n"));
+                               return -1;
+               }
+
+               slprintf(syscmd, sizeof(syscmd)-1, 
+                       "%s \"%s\" %d %d", 
+                       get_quota_command, path, qtype, _id);
+
+               DEBUG (3, ("get_quota: Running command %s\n", syscmd));
+
+               lines = file_lines_pload(syscmd, NULL);
+               if (lines) {
+                       char *line = lines[0];
+
+                       DEBUG (3, ("Read output from get_quota, \"r%s\"\n", line));
+
+                       /* we need to deal with long long unsigned here, if supported */
+
+                       dp->qflags = (enum SMB_QUOTA_TYPE)strtoul(line, &p2, 10);
+                       p = p2;
+                       while (p && *p && isspace(*p))
+                               p++;
+                       if (p && *p)
+                               dp->curblocks = STR_TO_SMB_BIG_UINT(p, &p);
+                       else 
+                               goto invalid_param;
+                       while (p && *p && isspace(*p))
+                               p++;
+                       if (p && *p)
+                               dp->softlimit = STR_TO_SMB_BIG_UINT(p, &p);
+                       else
+                               goto invalid_param;
+                       while (p && *p && isspace(*p))
+                               p++;
+                       if (p && *p)
+                               dp->hardlimit = STR_TO_SMB_BIG_UINT(p, &p);
+                       else 
+                               goto invalid_param;
+                       while (p && *p && isspace(*p))
+                               p++;
+                       if (p && *p)
+                               dp->curinodes = STR_TO_SMB_BIG_UINT(p, &p);
+                       else
+                               goto invalid_param;
+                       while (p && *p && isspace(*p))
+                               p++;
+                       if (p && *p)
+                               dp->isoftlimit = STR_TO_SMB_BIG_UINT(p, &p);
+                       else
+                               goto invalid_param;
+                       while (p && *p && isspace(*p))
+                               p++;
+                       if (p && *p)
+                               dp->ihardlimit = STR_TO_SMB_BIG_UINT(p, &p);
+                       else
+                               goto invalid_param;     
+                       while (p && *p && isspace(*p))
+                               p++;
+                       if (p && *p)
+                               dp->bsize = STR_TO_SMB_BIG_UINT(p, NULL);
+                       else
+                               dp->bsize = 1024;
+                       file_lines_free(lines);
+                       DEBUG (3, ("Parsed output of get_quota, ...\n"));
+
+#ifdef LARGE_SMB_OFF_T
+                       DEBUGADD (5,( 
+                               "qflags:%u curblocks:%llu softlimit:%llu hardlimit:%llu\n"
+                               "curinodes:%llu isoftlimit:%llu ihardlimit:%llu bsize:%llu\n", 
+                               dp->qflags,(long long unsigned)dp->curblocks,
+                               (long long unsigned)dp->softlimit,(long long unsigned)dp->hardlimit,
+                               (long long unsigned)dp->curinodes,
+                               (long long unsigned)dp->isoftlimit,(long long unsigned)dp->ihardlimit,
+                               (long long unsigned)dp->bsize));
+#else /* LARGE_SMB_OFF_T */
+                       DEBUGADD (5,( 
+                               "qflags:%u curblocks:%lu softlimit:%lu hardlimit:%lu\n"
+                               "curinodes:%lu isoftlimit:%lu ihardlimit:%lu bsize:%lu\n", 
+                               dp->qflags,(long unsigned)dp->curblocks,
+                               (long unsigned)dp->softlimit,(long unsigned)dp->hardlimit,
+                               (long unsigned)dp->curinodes,
+                               (long unsigned)dp->isoftlimit,(long unsigned)dp->ihardlimit,
+                               (long unsigned)dp->bsize));
+#endif /* LARGE_SMB_OFF_T */
+                       return 0;
+               }
+
+               DEBUG (0, ("get_quota_command failed!\n"));
+               return -1;
+       }
+
+       errno = ENOSYS;
+       return -1;
+       
+invalid_param:
+       DEBUG(0,("The output of get_quota_command is invalid!\n"));
+       return -1;
+}
+
+static int command_set_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp)
+{
+       const char *set_quota_command;
+       
+       set_quota_command = lp_set_quota_command();
+       if (set_quota_command && *set_quota_command) {
+               char **lines;
+               pstring syscmd;
+               int _id = -1;
+
+               switch(qtype) {
+                       case SMB_USER_QUOTA_TYPE:
+                       case SMB_USER_FS_QUOTA_TYPE:
+                               _id = id.uid;
+                               break;
+                       case SMB_GROUP_QUOTA_TYPE:
+                       case SMB_GROUP_FS_QUOTA_TYPE:
+                               _id = id.gid;
+                               break;
+                       default:
+                               return -1;
+               }
+
+#ifdef LARGE_SMB_OFF_T
+               slprintf(syscmd, sizeof(syscmd)-1, 
+                       "%s \"%s\" %d %d "
+                       "%u %llu %llu "
+                       "%llu %llu %llu ", 
+                       set_quota_command, path, qtype, _id, dp->qflags,
+                       (long long unsigned)dp->softlimit,(long long unsigned)dp->hardlimit,
+                       (long long unsigned)dp->isoftlimit,(long long unsigned)dp->ihardlimit,
+                       (long long unsigned)dp->bsize);
+#else /* LARGE_SMB_OFF_T */
+               slprintf(syscmd, sizeof(syscmd)-1, 
+                       "%s \"%s\" %d %d "
+                       "%u %lu %lu "
+                       "%lu %lu %lu ", 
+                       set_quota_command, path, qtype, _id, dp->qflags,
+                       (long unsigned)dp->softlimit,(long unsigned)dp->hardlimit,
+                       (long unsigned)dp->isoftlimit,(long unsigned)dp->ihardlimit,
+                       (long unsigned)dp->bsize);
+#endif /* LARGE_SMB_OFF_T */
+
+
+
+               DEBUG (3, ("get_quota: Running command %s\n", syscmd));
+
+               lines = file_lines_pload(syscmd, NULL);
+               if (lines) {
+                       char *line = lines[0];
+
+                       DEBUG (3, ("Read output from set_quota, \"%s\"\n", line));
+
+                       file_lines_free(lines);
+                       
+                       return 0;
+               }
+               DEBUG (0, ("set_quota_command failed!\n"));
+               return -1;
+       }
+
+       errno = ENOSYS;
+       return -1;
+}
+
+int sys_get_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp)
+{
+       int ret = -1;
+       int i;
+       BOOL ready = False;
+       char *mntpath = NULL;
+       char *bdev = NULL;
+       char *fs = NULL;
+
+       if (!path||!dp)
+               smb_panic("sys_get_quota: called with NULL pointer");
+
+       if (command_get_quota(path, qtype, id, dp)==0) {        
+               return 0;
+       } else if (errno != ENOSYS) {
+               return -1;
+       }
+
+       if ((ret=sys_path_to_bdev(path,&mntpath,&bdev,&fs))!=0) {
+               return ret;
+       }
+
+       for (i=0;(fs && sys_quota_backends[i].name && sys_quota_backends[i].get_quota);i++) {
+               if (strcmp(fs,sys_quota_backends[i].name)==0) {
+                       ret = sys_quota_backends[i].get_quota(mntpath, bdev, qtype, id, dp);
+                       ready = True;
+                       break;  
+               }               
+       }
+
+       if (!ready) {
+               /* use the default vfs quota functions */
+               ret = sys_get_vfs_quota(mntpath, bdev, qtype, id, dp);
+       }
+
+       SAFE_FREE(mntpath);
+       SAFE_FREE(bdev);
+       SAFE_FREE(fs);
+
+       if ((ret!=0)&& (errno == EDQUOT)) {
+               return 0;
+       }
+
+       return ret;
+}
+
+int sys_set_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp)
+{
+       int ret = -1;
+       int i;
+       BOOL ready = False;
+       char *mntpath = NULL;
+       char *bdev = NULL;
+       char *fs = NULL;
+
+       /* find the block device file */
+
+       if (!path||!dp)
+               smb_panic("get_smb_quota: called with NULL pointer");
+
+       if (command_set_quota(path, qtype, id, dp)==0) {        
+               return 0;
+       } else if (errno != ENOSYS) {
+               return -1;
+       }
+
+       if ((ret=sys_path_to_bdev(path,&mntpath,&bdev,&fs))!=0) {
+               return ret;
+       }
+
+       for (i=0;(fs && sys_quota_backends[i].name && sys_quota_backends[i].set_quota);i++) {
+               if (strcmp(fs,sys_quota_backends[i].name)==0) {
+                       ret = sys_quota_backends[i].set_quota(mntpath, bdev, qtype, id, dp);
+                       ready = True;
+                       break;
+               }               
+       }
+
+       if (!ready) {
+               /* use the default vfs quota functions */
+               ret=sys_set_vfs_quota(mntpath, bdev, qtype, id, dp);
+       }
+
+       SAFE_FREE(mntpath);
+       SAFE_FREE(bdev);
+       SAFE_FREE(fs);
+
+       if ((ret!=0)&& (errno == EDQUOT)) {
+               return 0;
+       }
+
+       return ret;             
+}
+
+
+#else /* ! AUTOCONF_TEST */
+/* this is the autoconf driver to test witch quota system we should use */
+
+#if defined(HAVE_QUOTACTL_4A)
+/* long quotactl(int cmd, char *special, qid_t id, caddr_t addr) */
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
+#ifdef HAVE_ASM_TYPES_H
+#include <asm/types.h>
+#endif
+
+#if defined(HAVE_LINUX_QUOTA_H)
+# include <linux/quota.h>
+# if defined(HAVE_STRUCT_IF_DQBLK)
+#  define SYS_DQBLK if_dqblk
+# elif defined(HAVE_STRUCT_MEM_DQBLK)
+#  define SYS_DQBLK mem_dqblk
+# endif
+#elif defined(HAVE_SYS_QUOTA_H)
+# include <sys/quota.h>
+#endif
+
+#ifndef SYS_DQBLK
+#define SYS_DQBLK dqblk
+#endif
+
+ int autoconf_quota(void)
+{
+       int ret = -1;
+       struct SYS_DQBLK D;
+
+       ret = quotactl(Q_GETQUOTA,"/dev/hda1",0,(void *)&D);
+       
+       return ret;
+}
+
+#elif defined(HAVE_QUOTACTL_4B)
+/* int quotactl(const char *path, int cmd, int id, char *addr); */
+
+#ifdef HAVE_SYS_QUOTA_H
+#include <sys/quota.h>
+#else /* *BSD */
+#include <sys/types.h>
+#include <ufs/ufs/quota.h>
+#include <machine/param.h>
+#endif
+
+ int autoconf_quota(void)
+{
+       int ret = -1;
+       struct dqblk D;
+
+       ret = quotactl("/",Q_GETQUOTA,0,(char *) &D);
+
+       return ret;
+}
+
+#elif defined(HAVE_QUOTACTL_3)
+/* int quotactl (char *spec, int request, char *arg); */
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_QUOTA_H
+#include <sys/quota.h>
+#endif
+
+ int autoconf_quota(void)
+{
+       int ret = -1;
+       struct q_request request;
+
+       ret = quotactl("/", Q_GETQUOTA, &request);
+
+       return ret;
+}
+
+#elif defined(HAVE_QUOTACTL_2)
+
+#error HAVE_QUOTACTL_2 not implemented
+
+#else
+
+#error Unknow QUOTACTL prototype
+
+#endif
+
+ int main(void)
+{      
+       autoconf_quota();
+       return 0;
+}
+#endif /* AUTOCONF_TEST */
index e58f5274df5069a93b8621e916c14c94868e1d1f..4452de8b4bc8114cd4f4ffa0c6bdaed0dc0d93e4 100644 (file)
@@ -937,6 +937,19 @@ void *Realloc(void *p,size_t size)
        return(ret);
 }
 
+void *Realloc_zero(void *ptr, size_t size)
+{
+       void *tptr = NULL;
+               
+       tptr = Realloc(ptr, size);
+       if(tptr == NULL)
+               return NULL;
+
+       memset((char *)tptr,'\0',size);
+
+       return tptr;
+}
+
 /****************************************************************************
  Free memory, checks for NULL.
  Use directly SAFE_FREE()
index e561d15f61b64b1d196b8d43790f7509975e005f..87a8ea2eb19eb4965c8c7908fcca926a20c525ac 100644 (file)
@@ -1713,3 +1713,25 @@ char * base64_encode_data_blob(DATA_BLOB data)
     return result;
 }
 
+/* read a SMB_BIG_UINT from a string */
+SMB_BIG_UINT STR_TO_SMB_BIG_UINT(const char *nptr, const char **entptr)
+{
+
+       SMB_BIG_UINT val = -1;
+       const char *p = nptr;
+       
+       while (p && *p && isspace(*p))
+               p++;
+#ifdef LARGE_SMB_OFF_T
+       sscanf(p,"%llu",&val);  
+#else /* LARGE_SMB_OFF_T */
+       sscanf(p,"%lu",&val);
+#endif /* LARGE_SMB_OFF_T */
+       if (entptr) {
+               while (p && *p && isdigit(*p))
+                       p++;
+               *entptr = p;
+       }
+
+       return val;
+}
index e6047847ae883e36fa29589aae73d2711433cb01..166229ec6c4d58ab9560dc399c5fc5ae67cfaaaf 100644 (file)
@@ -533,6 +533,7 @@ static nt_err_code_struct nt_errs[] =
        { "NT_STATUS_TOO_MANY_LINKS", NT_STATUS_TOO_MANY_LINKS },
        { "NT_STATUS_QUOTA_LIST_INCONSISTENT", NT_STATUS_QUOTA_LIST_INCONSISTENT },
        { "NT_STATUS_FILE_IS_OFFLINE", NT_STATUS_FILE_IS_OFFLINE },
+       { "NT_STATUS_NOT_A_REPARSE_POINT", NT_STATUS_NOT_A_REPARSE_POINT },
         { "NT_STATUS_NO_MORE_ENTRIES", NT_STATUS_NO_MORE_ENTRIES },
        { "STATUS_MORE_ENTRIES", STATUS_MORE_ENTRIES },
        { "STATUS_SOME_UNMAPPED", STATUS_SOME_UNMAPPED },
index eee23a39b64a8adcb3ae2727aecd905864e438be..45c95d12586ee41d5c8f9573cc59f4f512aad613 100644 (file)
@@ -108,6 +108,8 @@ typedef struct
        char *szRootdir;
        char *szDefaultService;
        char *szDfree;
+       char *szGetQuota;
+       char *szSetQuota;
        char *szMsgCommand;
        char *szHostsEquiv;
        char *szServerString;
@@ -1060,6 +1062,8 @@ static struct parm_struct parm_table[] = {
        {"default", P_STRING, P_GLOBAL, &Globals.szDefaultService, NULL, NULL,  FLAG_DEVELOPER},
        {"message command", P_STRING, P_GLOBAL, &Globals.szMsgCommand, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
        {"dfree command", P_STRING, P_GLOBAL, &Globals.szDfree, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
+       {"get quota command", P_STRING, P_GLOBAL, &Globals.szGetQuota, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
+       {"set quota command", P_STRING, P_GLOBAL, &Globals.szSetQuota, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
        {"remote announce", P_STRING, P_GLOBAL, &Globals.szRemoteAnnounce, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
        {"remote browse sync", P_STRING, P_GLOBAL, &Globals.szRemoteBrowseSync, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
        {"socket address", P_STRING, P_GLOBAL, &Globals.szSocketAddress, NULL, NULL, FLAG_DEVELOPER},
@@ -1582,6 +1586,8 @@ FN_GLOBAL_STRING(lp_source_environment, &Globals.szSourceEnv)
 FN_GLOBAL_STRING(lp_defaultservice, &Globals.szDefaultService)
 FN_GLOBAL_STRING(lp_msg_command, &Globals.szMsgCommand)
 FN_GLOBAL_STRING(lp_dfree_command, &Globals.szDfree)
+FN_GLOBAL_STRING(lp_get_quota_command, &Globals.szGetQuota)
+FN_GLOBAL_STRING(lp_set_quota_command, &Globals.szSetQuota)
 FN_GLOBAL_STRING(lp_hosts_equiv, &Globals.szHostsEquiv)
 FN_GLOBAL_STRING(lp_auto_services, &Globals.szAutoServices)
 FN_GLOBAL_STRING(lp_passwd_program, &Globals.szPasswdProgram)
index 71b3f2bf7724dd15f89244b7a04790c54c3655a6..f93cdf3791e2cfbbb0bdde0e139cb61bb439b751 100644 (file)
@@ -80,7 +80,7 @@ static SMB_BIG_UINT disk_free(const char *path, BOOL small_query,
 
        dfree_command = lp_dfree_command();
        if (dfree_command && *dfree_command) {
-               char *p;
+               const char *p;
                char **lines;
                pstring syscmd;
 
@@ -93,15 +93,15 @@ static SMB_BIG_UINT disk_free(const char *path, BOOL small_query,
 
                        DEBUG (3, ("Read input from dfree, \"%s\"\n", line));
 
-                       *dsize = (SMB_BIG_UINT)strtoul(line, &p, 10);
-                       while (p && *p & isspace(*p))
+                       *dsize = STR_TO_SMB_BIG_UINT(line, &p);
+                       while (p && *p && isspace(*p))
                                p++;
                        if (p && *p)
-                               *dfree = (SMB_BIG_UINT)strtoul(p, &p, 10);
-                       while (p && *p & isspace(*p))
+                               *dfree = STR_TO_SMB_BIG_UINT(p, &p);
+                       while (p && *p && isspace(*p))
                                p++;
                        if (p && *p)
-                               *bsize = (SMB_BIG_UINT)strtoul(p, NULL, 10);
+                               *bsize = STR_TO_SMB_BIG_UINT(p, NULL);
                        else
                                *bsize = 1024;
                        file_lines_free(lines);
diff --git a/source3/smbd/fake_file.c b/source3/smbd/fake_file.c
new file mode 100644 (file)
index 0000000..86d78e0
--- /dev/null
@@ -0,0 +1,166 @@
+/* 
+   Unix SMB/CIFS implementation.
+   FAKE FILE suppport, for faking up special files windows want access to
+   Copyright (C) Stefan (metze) Metzmacher     2003
+   
+   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"
+
+/****************************************************************************
+ Open a file with a share mode.
+****************************************************************************/
+files_struct *open_fake_file_shared1(enum FAKE_FILE_TYPE fake_file_type, connection_struct *conn,char *fname,
+                               SMB_STRUCT_STAT *psbuf, 
+                               uint32 desired_access, 
+                               int share_mode,int ofun, mode_t mode,int oplock_request, 
+                               int *Access,int *action)
+{
+       extern struct current_user current_user;
+       int flags=0;
+       files_struct *fsp = NULL;
+
+       if (fake_file_type == 0) {
+               return open_file_shared1(conn,fname,psbuf,desired_access,
+                                       share_mode,ofun,mode,
+                                       oplock_request,Access,action);  
+       }
+
+       /* access check */
+       if (conn->admin_user != True) {
+               DEBUG(1,("access_denied to service[%s] file[%s] user[%s]\n",
+                       lp_servicename(SNUM(conn)),fname,conn->user));
+               errno = EACCES;
+               return NULL;
+       }
+
+       fsp = file_new(conn);
+       if(!fsp)
+               return NULL;
+
+       DEBUG(5,("open_fake_file_shared1: fname = %s, FID = %d, share_mode = %x, ofun = %x, mode = %o, oplock request = %d\n",
+               fname, fsp->fnum, share_mode, ofun, (int)mode,  oplock_request ));
+
+       if (!check_name(fname,conn)) {
+               file_free(fsp);
+               return NULL;
+       } 
+
+       fsp->fd = -1;
+       fsp->mode = psbuf->st_mode;
+       fsp->inode = psbuf->st_ino;
+       fsp->dev = psbuf->st_dev;
+       fsp->vuid = current_user.vuid;
+       fsp->size = psbuf->st_size;
+       fsp->pos = -1;
+       fsp->can_lock = True;
+       fsp->can_read = ((flags & O_WRONLY)==0);
+       fsp->can_write = ((flags & (O_WRONLY|O_RDWR))!=0);
+       fsp->share_mode = 0;
+       fsp->desired_access = desired_access;
+       fsp->print_file = False;
+       fsp->modified = False;
+       fsp->oplock_type = NO_OPLOCK;
+       fsp->sent_oplock_break = NO_BREAK_SENT;
+       fsp->is_directory = False;
+       fsp->is_stat = False;
+       fsp->directory_delete_on_close = False;
+       fsp->conn = conn;
+       string_set(&fsp->fsp_name,fname);
+       fsp->wcp = NULL; /* Write cache pointer. */
+       
+       fsp->fake_file_handle = init_fake_file_handle(fake_file_type);
+       
+       if (fsp->fake_file_handle==NULL) {
+               file_free(fsp);
+               return NULL;
+       }
+
+       conn->num_files_open++;
+       return fsp;
+}
+
+static FAKE_FILE fake_files[] = {
+#ifdef WITH_QUOTAS
+       {FAKE_FILE_NAME_QUOTA,  FAKE_FILE_TYPE_QUOTA,   init_quota_handle,      destroy_quota_handle},
+#endif /* WITH_QUOTAS */
+       {NULL,                  FAKE_FILE_TYPE_NONE,    NULL,                   NULL }
+};
+
+int is_fake_file(char *fname)
+{
+       int i;
+
+       if (!fname)
+               return 0;
+
+       for (i=0;fake_files[i].name!=NULL;i++) {
+               if (strncmp(fname,fake_files[i].name,strlen(fake_files[i].name))==0) {
+                       DEBUG(5,("is_fake_file: [%s] is a fake file\n",fname));
+                       return fake_files[i].type;
+               }
+       }
+
+       return FAKE_FILE_TYPE_NONE;
+}
+
+struct _FAKE_FILE_HANDLE *init_fake_file_handle(enum FAKE_FILE_TYPE type)
+{
+       TALLOC_CTX *mem_ctx = NULL;
+       FAKE_FILE_HANDLE *fh = NULL;
+       int i;
+
+       for (i=0;fake_files[i].name!=NULL;i++) {
+               if (fake_files[i].type==type) {
+                       DEBUG(5,("init_fake_file_handle: for [%s]\n",fake_files[i].name));
+
+                       if ((mem_ctx=talloc_init("fake_file_handle"))==NULL) {
+                               DEBUG(0,("talloc_init(fake_file_handle) failed.\n"));
+                               return NULL;    
+                       }
+
+                       if ((fh =(FAKE_FILE_HANDLE *)talloc_zero(mem_ctx, sizeof(FAKE_FILE_HANDLE)))==NULL) {
+                               DEBUG(0,("talloc_zero() failed.\n"));
+                               talloc_destroy(mem_ctx);
+                               return NULL;
+                       }
+
+                       fh->type = type;
+                       fh->mem_ctx = mem_ctx;
+
+                       if (fake_files[i].init_pd)
+                               fh->pd = fake_files[i].init_pd(fh->mem_ctx);
+
+                       fh->free_pd = fake_files[i].free_pd;
+
+                       return fh;
+               }
+       }
+
+       return NULL;    
+}
+
+void destroy_fake_file_handle(FAKE_FILE_HANDLE **fh)
+{
+       if (!fh||!(*fh))
+               return ;
+
+       if ((*fh)->free_pd)
+               (*fh)->free_pd(&(*fh)->pd);             
+
+       talloc_destroy((*fh)->mem_ctx);
+       (*fh) = NULL;
+}
index d926718c5d326581923929a6b62cb6ee09ec3b17..4d1409feac20e255dd1b77e6133ed5f4543b9515 100644 (file)
@@ -338,6 +338,10 @@ void file_free(files_struct *fsp)
 
        string_free(&fsp->fsp_name);
 
+       if (fsp->fake_file_handle) {
+               destroy_fake_file_handle(&fsp->fake_file_handle);
+       }
+
        bitmap_clear(file_bmap, fsp->fnum - FILE_HANDLE_OFFSET);
        files_used--;
 
diff --git a/source3/smbd/ntquotas.c b/source3/smbd/ntquotas.c
new file mode 100644 (file)
index 0000000..85e1e13
--- /dev/null
@@ -0,0 +1,259 @@
+/* 
+   Unix SMB/CIFS implementation.
+   NT QUOTA suppport
+   Copyright (C) Stefan (metze) Metzmacher     2003
+   
+   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"
+
+static SMB_BIG_UINT limit_nt2unix(SMB_BIG_UINT in, SMB_BIG_UINT bsize)
+{
+       SMB_BIG_UINT ret = (SMB_BIG_UINT)0;
+
+       ret =   (SMB_BIG_UINT)(in/bsize);
+       if (in>0 && ret==0) {
+               /* we have to make sure that a overflow didn't set NO_LIMIT */
+               ret = (SMB_BIG_UINT)1;
+       }
+
+       if (in == SMB_NTQUOTAS_NO_LIMIT)
+               ret = SMB_QUOTAS_NO_LIMIT;
+       else if (in == SMB_NTQUOTAS_NO_SPACE)
+               ret = SMB_QUOTAS_NO_SPACE;
+       else if (in == SMB_NTQUOTAS_NO_ENTRY)
+               ret = SMB_QUOTAS_NO_LIMIT;
+
+       return ret;
+}
+
+static SMB_BIG_UINT limit_unix2nt(SMB_BIG_UINT in, SMB_BIG_UINT bsize)
+{
+       SMB_BIG_UINT ret = (SMB_BIG_UINT)0;
+
+       ret = (SMB_BIG_UINT)(in*bsize);
+       
+       if (ret < in) {
+               /* we overflow */
+               ret = SMB_NTQUOTAS_NO_LIMIT;
+       }
+
+       if (in == SMB_QUOTAS_NO_LIMIT)
+               ret = SMB_NTQUOTAS_NO_LIMIT;
+
+       return ret;
+}
+
+static SMB_BIG_UINT limit_blk2inodes(SMB_BIG_UINT in)
+{
+       SMB_BIG_UINT ret = (SMB_BIG_UINT)0;
+       
+       ret = (SMB_BIG_UINT)(in/2);
+       
+       if (ret == 0 && in != 0)
+               ret = (SMB_BIG_UINT)1;
+
+       return ret;     
+}
+
+int vfs_get_ntquota(files_struct *fsp, enum SMB_QUOTA_TYPE qtype, DOM_SID *psid, SMB_NTQUOTA_STRUCT *qt)
+{
+       int ret;
+       SMB_DISK_QUOTA D;
+       unid_t id;
+       enum SID_NAME_USE sid_use = SID_NAME_USE_NONE;
+
+       ZERO_STRUCT(D);
+
+       if (!fsp||!fsp->conn||!qt)
+               return (-1);
+
+       ZERO_STRUCT(*qt);
+
+       id.uid = -1;
+
+       if (psid && !sid_to_uid(psid, &id.uid, &sid_use)) {
+               DEBUG(0,("sid_to_uid: failed, SID[%s]\n",
+                       sid_string_static(psid)));      
+       }
+
+       ret = VFS_GET_QUOTA(fsp->conn, qtype, id, &D);
+
+       if (psid)
+               qt->sid    = *psid;
+
+       if (ret!=0) {
+               return ret;
+       }
+               
+       qt->usedspace = (SMB_BIG_UINT)D.curblocks*D.bsize;
+       qt->softlim = limit_unix2nt(D.softlimit, D.bsize);
+       qt->hardlim = limit_unix2nt(D.hardlimit, D.bsize);
+       qt->qflags = D.qflags;
+
+       
+       return 0;
+}
+
+int vfs_set_ntquota(files_struct *fsp, enum SMB_QUOTA_TYPE qtype, DOM_SID *psid, SMB_NTQUOTA_STRUCT *qt)
+{
+       int ret;
+       SMB_DISK_QUOTA D;
+       unid_t id;
+       enum SID_NAME_USE sid_use = SID_NAME_USE_NONE;
+       ZERO_STRUCT(D);
+
+       if (!fsp||!fsp->conn||!qt)
+               return (-1);
+
+       id.uid = -1;
+
+       D.bsize     = (SMB_BIG_UINT)QUOTABLOCK_SIZE;
+       D.softlimit = limit_nt2unix(qt->softlim,D.bsize);
+       D.hardlimit = limit_nt2unix(qt->hardlim,D.bsize);
+       D.qflags     = qt->qflags;
+
+       D.isoftlimit = limit_blk2inodes(D.softlimit);
+       D.ihardlimit = limit_blk2inodes(D.hardlimit);
+
+       if (psid && !sid_to_uid(psid, &id.uid, &sid_use)) {
+               DEBUG(0,("sid_to_uid: failed, SID[%s]\n",
+                       sid_string_static(psid)));      
+       }
+
+       ret = VFS_SET_QUOTA(fsp->conn, qtype, id, &D);
+       
+       return ret;
+}
+
+static BOOL allready_in_quota_list(SMB_NTQUOTA_LIST *qt_list, uid_t uid)
+{
+       SMB_NTQUOTA_LIST *tmp_list = NULL;
+       
+       if (!qt_list)
+               return False;
+
+       for (tmp_list=qt_list;tmp_list!=NULL;tmp_list=tmp_list->next) {
+               if (tmp_list->uid == uid) {
+                       return True;    
+               }
+       }
+
+       return False;
+}
+
+int vfs_get_user_ntquota_list(files_struct *fsp, SMB_NTQUOTA_LIST **qt_list)
+{
+       struct passwd *usr;
+       TALLOC_CTX *mem_ctx = NULL;
+
+       if (!fsp||!fsp->conn||!qt_list)
+               return (-1);
+
+       *qt_list = NULL;
+
+       if ((mem_ctx=talloc_init("SMB_USER_QUOTA_LIST"))==NULL) {
+               DEBUG(0,("talloc_init() failed\n"));
+               return (-1);
+       }
+
+       sys_setpwent();
+       while ((usr = sys_getpwent()) != NULL) {
+               SMB_NTQUOTA_STRUCT tmp_qt;
+               SMB_NTQUOTA_LIST *tmp_list_ent;
+               DOM_SID sid;
+
+               ZERO_STRUCT(tmp_qt);
+
+               if (allready_in_quota_list((*qt_list),usr->pw_uid)) {
+                       DEBUG(5,("record for uid[%d] allready in the list\n",usr->pw_uid));
+                       continue;
+               }
+
+               if (uid_to_sid(&sid,usr->pw_uid)==NULL) {
+                       DEBUG(0,("uid_to_sid failed for %d\n",usr->pw_uid));
+                       continue;
+               }
+
+               if (vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &tmp_qt)!=0) {
+                       DEBUG(1,("no quota entry for sid[%s] path[%s]\n",
+                               sid_string_static(&sid),fsp->conn->connectpath));
+                       continue;
+               }
+
+               DEBUG(15,("quota entry for id[%s] path[%s]\n",
+                       sid_string_static(&sid),fsp->conn->connectpath));
+
+               if ((tmp_list_ent=(SMB_NTQUOTA_LIST *)talloc_zero(mem_ctx,sizeof(SMB_NTQUOTA_LIST)))==NULL) {
+                       DEBUG(0,("talloc_zero() failed\n"));
+                       *qt_list = NULL;
+                       talloc_destroy(mem_ctx);
+                       return (-1);
+               }
+
+               if ((tmp_list_ent->quotas=(SMB_NTQUOTA_STRUCT *)talloc_zero(mem_ctx,sizeof(SMB_NTQUOTA_STRUCT)))==NULL) {
+                       DEBUG(0,("talloc_zero() failed\n"));
+                       *qt_list = NULL;
+                       talloc_destroy(mem_ctx);
+                       return (-1);
+               }
+
+               tmp_list_ent->uid = usr->pw_uid;
+               memcpy(tmp_list_ent->quotas,&tmp_qt,sizeof(tmp_qt));
+               tmp_list_ent->mem_ctx = mem_ctx;
+
+               DLIST_ADD((*qt_list),tmp_list_ent);
+               
+       }
+       sys_endpwent();
+
+       return 0;
+}
+
+void *init_quota_handle(TALLOC_CTX *mem_ctx)
+{
+       SMB_NTQUOTA_HANDLE *qt_handle;
+
+       if (!mem_ctx)
+               return False;
+
+       qt_handle = (SMB_NTQUOTA_HANDLE *)talloc_zero(mem_ctx,sizeof(SMB_NTQUOTA_HANDLE));
+       if (qt_handle==NULL) {
+               DEBUG(0,("talloc_zero() failed\n"));
+               return NULL;
+       }
+
+       return (void *)qt_handle;       
+}
+
+void destroy_quota_handle(void **pqt_handle)
+{
+       SMB_NTQUOTA_HANDLE *qt_handle = NULL;
+       if (!pqt_handle||!(*pqt_handle))
+               return;
+       
+       qt_handle = (*pqt_handle);
+       
+       
+       if (qt_handle->quota_list)
+               free_ntquota_list(&qt_handle->quota_list);
+
+       qt_handle->quota_list = NULL;
+       qt_handle->tmp_list = NULL;
+       qt_handle = NULL;
+
+       return;
+}
index 38de5586ea9e7d3249a130748ee5c178d59fe0bb..c026ee9f58d055854f231ce65336ee35bf36a43a 100644 (file)
@@ -1,7 +1,8 @@
 /*
    Unix SMB/CIFS implementation.
    SMB NT transaction handling
-   Copyright (C) Jeremy Allison 1994-1998
+   Copyright (C) Jeremy Allison                        1994-1998
+   Copyright (C) Stefan (metze) Metzmacher     2003
 
    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
@@ -26,6 +27,7 @@ extern int global_oplock_break;
 extern BOOL case_sensitive;
 extern BOOL case_preserve;
 extern BOOL short_case_preserve;
+extern struct current_user current_user;
 
 static const char *known_nt_pipes[] = {
        "\\LANMAN",
@@ -53,6 +55,24 @@ struct generic_mapping file_generic_mapping = {
        FILE_GENERIC_ALL
 };
 
+char *nttrans_realloc(char **ptr, size_t size)
+{
+       char *tptr = NULL;
+       if (ptr==NULL)
+               smb_panic("nttrans_realloc() called with NULL ptr\n");
+               
+       tptr = Realloc_zero(*ptr, size);
+       if(tptr == NULL) {
+               *ptr = NULL;
+               return NULL;
+       }
+
+       *ptr = tptr;
+
+       return tptr;
+}
+
+
 /****************************************************************************
  Send the required number of replies back.
  We assume all fields other than the data fields are
@@ -542,6 +562,7 @@ int reply_ntcreate_and_X(connection_struct *conn,
 {  
        int result;
        pstring fname;
+       enum FAKE_FILE_TYPE fake_file_type = 0;
        uint32 flags = IVAL(inbuf,smb_ntcreate_Flags);
        uint32 desired_access = IVAL(inbuf,smb_ntcreate_DesiredAccess);
        uint32 file_attributes = IVAL(inbuf,smb_ntcreate_FileAttributes);
@@ -669,8 +690,21 @@ create_options = 0x%x root_dir_fid = 0x%x\n", flags, desired_access, file_attrib
                 */
 
                if( strchr_m(fname, ':')) {
-                       END_PROFILE(SMBntcreateX);
-                       return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
+                       
+                       if ((fake_file_type=is_fake_file(fname))!=0) {
+                               /*
+                                * here we go! support for changing the disk quotas --metze
+                                *
+                                * we need to fake up to open this MAGIC QUOTA file 
+                                * and return a valid FID
+                                *
+                                * w2k close this file directly after openening
+                                * xp also tries a QUERY_FILE_INFO on the file and then close it
+                                */
+                       } else {
+                               END_PROFILE(SMBntcreateX);
+                               return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
+                       }
                }
        }
        
@@ -746,12 +780,21 @@ create_options = 0x%x root_dir_fid = 0x%x\n", flags, desired_access, file_attrib
                 * before issuing an oplock break request to
                 * our client. JRA.  */
 
-               fsp = open_file_shared1(conn,fname,&sbuf,
+               if (fake_file_type==0) {
+                       fsp = open_file_shared1(conn,fname,&sbuf,
                                        desired_access,
                                        smb_open_mode,
                                        smb_ofun,unixmode, oplock_request,
                                        &rmode,&smb_action);
-
+               } else {
+                       /* to open a fake_file --metze */
+                       fsp = open_fake_file_shared1(fake_file_type,conn,fname,&sbuf,
+                                       desired_access,
+                                       smb_open_mode,
+                                       smb_ofun,unixmode, oplock_request,
+                                       &rmode,&smb_action);
+               }
+               
                if (!fsp) { 
                        /* We cheat here. There are two cases we
                         * care about. One is a directory rename,
@@ -944,14 +987,10 @@ static int do_nt_transact_create_pipe( connection_struct *conn,
                return ret;
        
        /* Realloc the size of parameters and data we will return */
-       params = Realloc(*ppparams, 69);
+       params = nttrans_realloc(ppparams, 69);
        if(params == NULL)
                return ERROR_DOS(ERRDOS,ERRnomem);
        
-       *ppparams = params;
-       
-       memset((char *)params,'\0',69);
-       
        p = params;
        SCVAL(p,0,NO_OPLOCK_RETURN);
        
@@ -1331,14 +1370,10 @@ static int call_nt_transact_create(connection_struct *conn,
        }
 
        /* Realloc the size of parameters and data we will return */
-       params = Realloc(*ppparams, 69);
+       params = nttrans_realloc(ppparams, 69);
        if(params == NULL)
                return ERROR_DOS(ERRDOS,ERRnomem);
 
-       *ppparams = params;
-
-       memset((char *)params,'\0',69);
-
        p = params;
        if (extended_oplock_granted)
                SCVAL(p,0, BATCH_OPLOCK_RETURN);
@@ -1543,12 +1578,10 @@ static int call_nt_transact_query_security_desc(connection_struct *conn,
 
        DEBUG(3,("call_nt_transact_query_security_desc: file = %s\n", fsp->fsp_name ));
 
-       params = Realloc(*ppparams, 4);
+       params = nttrans_realloc(ppparams, 4);
        if(params == NULL)
                return ERROR_DOS(ERRDOS,ERRnomem);
 
-       *ppparams = params;
-
        if ((mem_ctx = talloc_init("call_nt_transact_query_security_desc")) == NULL) {
                DEBUG(0,("call_nt_transact_query_security_desc: talloc_init failed.\n"));
                return ERROR_DOS(ERRDOS,ERRnomem);
@@ -1584,16 +1617,12 @@ static int call_nt_transact_query_security_desc(connection_struct *conn,
         * Allocate the data we will point this at.
         */
 
-       data = Realloc(*ppdata, sd_size);
+       data = nttrans_realloc(ppdata, sd_size);
        if(data == NULL) {
                talloc_destroy(mem_ctx);
                return ERROR_DOS(ERRDOS,ERRnomem);
        }
 
-       *ppdata = data;
-
-       memset(data, '\0', sd_size);
-
        /*
         * Init the parse struct we will marshall into.
         */
@@ -1686,6 +1715,7 @@ static int call_nt_transact_ioctl(connection_struct *conn,
 {
        unsigned fnum, control;
        static BOOL logged_message;
+       char *pdata = *ppdata;
 
        if (setup_count != 8) {
                DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count));
@@ -1695,28 +1725,479 @@ static int call_nt_transact_ioctl(connection_struct *conn,
        fnum = SVAL(*ppsetup, 4);
        control = IVAL(*ppsetup, 0);
 
-       DEBUG(6,("call_nt_transact_ioctl: fnum=%d control=0x%x\n", 
+       DEBUG(10,("call_nt_transact_ioctl: fnum=%d control=0x%08x\n", 
                 fnum, control));
 
        switch (control) {
-       case NTIOCTL_SET_SPARSE:
+       case FSCTL_SET_SPARSE:
                /* pretend this succeeded - tho strictly we should
                   mark the file sparse (if the local fs supports it)
                   so we can know if we need to pre-allocate or not */
+
+               DEBUG(10,("FSCTL_SET_SPARSE: fnum=%d control=0x%08x\n",fnum,control));
+               send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
+               return -1;
+       
+       case FSCTL_0x000900C0:
+               /* pretend this succeeded - don't know what this really is
+                  but works ok like this --metze
+                */
+
+               DEBUG(1,("FSCTL_GET_REPARSE_POINT: fnum=%d control=0x%08x\n",fnum,control));
                send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
                return -1;
 
+       case FSCTL_GET_REPARSE_POINT:
+               /* pretend this fail - my winXP does it like this
+                * --metze
+                */
+
+               DEBUG(1,("FSCTL_GET_REPARSE_POINT: fnum=%d control=0x%08x\n",fnum,control));
+               send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_NOT_A_REPARSE_POINT, NULL, 0, NULL, 0);
+               return -1;
+
+       case FSCTL_SET_REPARSE_POINT:
+               /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
+                * --metze
+                */
+
+               DEBUG(1,("FSCTL_SET_REPARSE_POINT: fnum=%d control=0x%08x\n",fnum,control));
+               send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_NOT_A_REPARSE_POINT, NULL, 0, NULL, 0);
+               return -1;
+                       
+       case FSCTL_FIND_FILES_BY_SID: /* I hope this name is right */
+       {
+               /* pretend this succeeded - 
+                * 
+                * we have to send back a list with all files owned by this SID
+                *
+                * but I have to check that --metze
+                */ 
+                  
+               DOM_SID sid;
+               uid_t uid;
+               enum SID_NAME_USE sid_use = 0;
+               size_t sid_len=SID_MAX_SIZE;
+               
+               DEBUG(1,("FSCTL_FIND_FILES_BY_SID: fnum=%d control=0x%08x\n",fnum,control));
+               
+               /* this is not the length of the sid :-( so unknown 4 bytes */
+               /*sid_len = IVAL(pdata,0);      
+               DEBUGADD(0,("sid_len: (%u)\n",sid_len));*/
+               
+               sid_parse(pdata+4,sid_len,&sid);
+               DEBUGADD(2,("SID: %s\n",sid_string_static(&sid)));
+
+               if (!sid_to_uid(&sid, &uid, &sid_use)
+                       ||sid_use!=SID_NAME_USER) {
+                       DEBUG(0,("sid_to_uid: failed, sid[%s] sid_use: %d\n",
+                               sid_string_static(&sid),sid_use));
+                       uid = (-1);
+               }
+               
+               /* we can take a look at the find source :-)
+                *
+                * find ./ -uid $uid  -name '*'   is what we need here
+                *
+                *
+                * and send 4bytes len and then NULL terminated unicode strings
+                * for each file
+                *
+                * but I don't know how to deal with the paged results
+                *
+                * we don't send all files at once
+                * and at the next we should *not* start from the beginning, 
+                * so we have to cache the result 
+                *
+                * --metze
+                */
+               
+               /* this works for now... */
+               send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
+               return -1;      
+       }       
        default:
                if (!logged_message) {
                        logged_message = True; /* Only print this once... */
-                       DEBUG(3,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
+                       DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
                                 control));
                }
        }
 
        return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
 }
-   
+
+
+/****************************************************************************
+ Reply to get user quota 
+****************************************************************************/
+
+static int call_nt_transact_get_user_quota(connection_struct *conn,
+                                               char *inbuf, char *outbuf, 
+                                               int length, int bufsize, 
+                                               char **ppsetup, int setup_count,
+                                               char **ppparams, int params_count,
+                                               char **ppdata, int data_count)
+{
+       NTSTATUS nt_status = NT_STATUS_OK;
+       uint32 max_data_count = IVAL(inbuf,smb_nt_MaxDataCount);
+       char *params = *ppparams;
+       char *pdata = *ppdata;
+       char *entry;
+       int data_len=0,param_len=0;
+       int qt_len=0;
+       int entry_len = 0;
+       files_struct *fsp = NULL;
+       uint16 level = 0;
+       size_t sid_len;
+       DOM_SID sid;
+       BOOL start_enum = True;
+       SMB_NTQUOTA_STRUCT qt;
+       SMB_NTQUOTA_LIST *tmp_list;
+       SMB_NTQUOTA_HANDLE *qt_handle = NULL;
+
+       ZERO_STRUCT(qt);
+
+       /* access check */
+       if (conn->admin_user != True) {
+               DEBUG(1,("set_user_quota: access_denied service [%s] user [%s]\n",
+                       lp_servicename(SNUM(conn)),conn->user));
+               return ERROR_DOS(ERRDOS,ERRnoaccess);
+       }
+
+       /*
+        * Ensure minimum number of parameters sent.
+        */
+
+       if (params_count < 4) {
+               DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",params_count));
+               return ERROR_DOS(ERRDOS,ERRinvalidparam);
+       }
+       
+       /* maybe we can check the quota_fnum */
+       fsp = file_fsp(params,0);
+       if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
+               DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
+               return ERROR_NT(NT_STATUS_INVALID_HANDLE);
+       }
+
+       /* the NULL pointer cheking for fsp->fake_file_handle->pd
+        * is done by CHECK_NTQUOTA_HANDLE_OK()
+        */
+       qt_handle = (SMB_NTQUOTA_HANDLE *)fsp->fake_file_handle->pd;
+
+       level = SVAL(params,2);
+       
+       /* unknown 12 bytes leading in params */ 
+       
+       switch (level) {
+               case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE:
+                       /* seems that we should continue with the enum here --metze */
+
+                       if (qt_handle->quota_list!=NULL && 
+                           qt_handle->tmp_list==NULL) {
+               
+                               /* free the list */
+                               free_ntquota_list(&(qt_handle->quota_list));
+
+                               /* Realloc the size of parameters and data we will return */
+                               param_len = 4;
+                               params = nttrans_realloc(ppparams, param_len);
+                               if(params == NULL)
+                                       return ERROR_DOS(ERRDOS,ERRnomem);
+
+                               data_len = 0;
+                               SIVAL(params,0,data_len);
+
+                               break;
+                       }
+
+                       start_enum = False;
+
+               case TRANSACT_GET_USER_QUOTA_LIST_START:
+
+                       if (qt_handle->quota_list==NULL &&
+                               qt_handle->tmp_list==NULL) {
+                               start_enum = True;
+                       }
+
+                       if (start_enum && vfs_get_user_ntquota_list(fsp,&(qt_handle->quota_list))!=0)
+                               return ERROR_DOS(ERRSRV,ERRerror);
+
+                       /* Realloc the size of parameters and data we will return */
+                       param_len = 4;
+                       params = nttrans_realloc(ppparams, param_len);
+                       if(params == NULL)
+                               return ERROR_DOS(ERRDOS,ERRnomem);
+
+                       /* we should not trust the value in max_data_count*/
+                       max_data_count = MIN(max_data_count,2048);
+                       
+                       pdata = nttrans_realloc(ppdata, max_data_count);/* should be max data count from client*/
+                       if(pdata == NULL)
+                               return ERROR_DOS(ERRDOS,ERRnomem);
+
+                       entry = pdata;
+
+
+                       /* set params Size of returned Quota Data 4 bytes*/
+                       /* but set it later when we know it */
+               
+                       /* for each entry push the data */
+
+                       if (start_enum) {
+                               qt_handle->tmp_list = qt_handle->quota_list;
+                       }
+
+                       tmp_list = qt_handle->tmp_list;
+
+                       for (;((tmp_list!=NULL)&&((qt_len +40+SID_MAX_SIZE)<max_data_count));
+                               tmp_list=tmp_list->next,entry+=entry_len,qt_len+=entry_len) {
+
+                               sid_len = sid_size(&tmp_list->quotas->sid);
+                               entry_len = 40 + sid_len;
+
+                               /* nextoffset entry 4 bytes */
+                               SIVAL(entry,0,entry_len);
+               
+                               /* then the len of the SID 4 bytes */
+                               SIVAL(entry,4,sid_len);
+                               
+                               /* unknown data 8 bytes SMB_BIG_UINT */
+                               SBIG_UINT(entry,8,(SMB_BIG_UINT)0); /* this is not 0 in windows...-metze*/
+                               
+                               /* the used disk space 8 bytes SMB_BIG_UINT */
+                               SBIG_UINT(entry,16,tmp_list->quotas->usedspace);
+                               
+                               /* the soft quotas 8 bytes SMB_BIG_UINT */
+                               SBIG_UINT(entry,24,tmp_list->quotas->softlim);
+                               
+                               /* the hard quotas 8 bytes SMB_BIG_UINT */
+                               SBIG_UINT(entry,32,tmp_list->quotas->hardlim);
+                               
+                               /* and now the SID */
+                               sid_linearize(entry+40, sid_len, &tmp_list->quotas->sid);
+                       }
+                       
+                       qt_handle->tmp_list = tmp_list;
+                       
+                       /* overwrite the offset of the last entry */
+                       SIVAL(entry-entry_len,0,0);
+
+                       data_len = 4+qt_len;
+                       /* overwrite the params quota_data_len */
+                       SIVAL(params,0,data_len);
+
+                       break;
+
+               case TRANSACT_GET_USER_QUOTA_FOR_SID:
+                       
+                       /* unknown 4 bytes IVAL(pdata,0) */     
+                       
+                       if (data_count < 8) {
+                               DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count,8));
+                               return ERROR_DOS(ERRDOS,ERRunknownlevel);                               
+                       }
+
+                       sid_len = IVAL(pdata,4);
+
+                       if (data_count < 8+sid_len) {
+                               DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count,8+sid_len));
+                               return ERROR_DOS(ERRDOS,ERRunknownlevel);                               
+                       }
+
+                       data_len = 4+40+sid_len;
+
+                       if (max_data_count < data_len) {
+                               DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
+                                       max_data_count, data_len));
+                               param_len = 4;
+                               SIVAL(params,0,data_len);
+                               data_len = 0;
+                               nt_status = NT_STATUS_BUFFER_TOO_SMALL;
+                               break;
+                       }
+
+                       sid_parse(pdata+8,sid_len,&sid);
+               
+
+                       if (vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
+                               ZERO_STRUCT(qt);
+                               /* 
+                                * we have to return zero's in all fields 
+                                * instead of returning an error here
+                                * --metze
+                                */
+                       }
+
+                       /* Realloc the size of parameters and data we will return */
+                       param_len = 4;
+                       params = nttrans_realloc(ppparams, param_len);
+                       if(params == NULL)
+                               return ERROR_DOS(ERRDOS,ERRnomem);
+
+                       pdata = nttrans_realloc(ppdata, data_len);
+                       if(pdata == NULL)
+                               return ERROR_DOS(ERRDOS,ERRnomem);
+
+                       entry = pdata;
+
+                       /* set params Size of returned Quota Data 4 bytes*/
+                       SIVAL(params,0,data_len);
+       
+                       /* nextoffset entry 4 bytes */
+                       SIVAL(entry,0,0);
+       
+                       /* then the len of the SID 4 bytes */
+                       SIVAL(entry,4,sid_len);
+                       
+                       /* unknown data 8 bytes SMB_BIG_UINT */
+                       SBIG_UINT(entry,8,(SMB_BIG_UINT)0); /* this is not 0 in windows...-mezte*/
+                       
+                       /* the used disk space 8 bytes SMB_BIG_UINT */
+                       SBIG_UINT(entry,16,qt.usedspace);
+                       
+                       /* the soft quotas 8 bytes SMB_BIG_UINT */
+                       SBIG_UINT(entry,24,qt.softlim);
+                       
+                       /* the hard quotas 8 bytes SMB_BIG_UINT */
+                       SBIG_UINT(entry,32,qt.hardlim);
+                       
+                       /* and now the SID */
+                       sid_linearize(entry+40, sid_len, &sid);
+
+                       break;
+
+               default:
+                       DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp->fnum,level));
+                       return ERROR_DOS(ERRSRV,ERRerror);
+                       break;
+       }
+
+       send_nt_replies(inbuf, outbuf, bufsize, nt_status, params, param_len, pdata, data_len);
+
+       return -1;
+}
+
+/****************************************************************************
+ Reply to set user quota
+****************************************************************************/
+
+static int call_nt_transact_set_user_quota(connection_struct *conn,
+                                               char *inbuf, char *outbuf, 
+                                               int length, int bufsize, 
+                                               char **ppsetup, int setup_count,
+                                               char **ppparams, int params_count,
+                                               char **ppdata, int data_count)
+{
+       char *params = *ppparams;
+       char *pdata = *ppdata;
+       int data_len=0,param_len=0;
+       SMB_NTQUOTA_STRUCT qt;
+       size_t sid_len;
+       DOM_SID sid;
+       files_struct *fsp = NULL;
+
+       ZERO_STRUCT(qt);
+
+       /* access check */
+       if (conn->admin_user != True) {
+               DEBUG(1,("set_user_quota: access_denied service [%s] user [%s]\n",
+                       lp_servicename(SNUM(conn)),conn->user));
+               return ERROR_DOS(ERRDOS,ERRnoaccess);
+       }
+
+       /*
+        * Ensure minimum number of parameters sent.
+        */
+
+       if (params_count < 2) {
+               DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",params_count));
+               return ERROR_DOS(ERRDOS,ERRinvalidparam);
+       }
+       
+       /* maybe we can check the quota_fnum */
+       fsp = file_fsp(params,0);
+       if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
+               DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
+               return ERROR_NT(NT_STATUS_INVALID_HANDLE);
+       }
+
+       if (data_count < 40) {
+               DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count,40));
+               return ERROR_DOS(ERRDOS,ERRunknownlevel);               
+       }
+
+       /* offset to next quota record.
+        * 4 bytes IVAL(pdata,0)
+        * unused here...
+        */
+
+       /* sid len */
+       sid_len = IVAL(pdata,4);
+
+       if (data_count < 40+sid_len) {
+               DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count,40+sid_len));
+               return ERROR_DOS(ERRDOS,ERRunknownlevel);               
+       }
+
+       /* unknown 8 bytes in pdata 
+        * maybe its the change time in NTTIME
+        */
+
+       /* the used space 8 bytes (SMB_BIG_UINT)*/
+       qt.usedspace = (SMB_BIG_UINT)IVAL(pdata,16);
+#ifdef LARGE_SMB_OFF_T
+       qt.usedspace |= (((SMB_BIG_UINT)IVAL(pdata,20)) << 32);
+#else /* LARGE_SMB_OFF_T */
+       if ((IVAL(pdata,20) != 0)&&
+               ((qt.usedspace != 0xFFFFFFFF)||
+               (IVAL(pdata,20)!=0xFFFFFFFF)))) {
+               /* more than 32 bits? */
+               return ERROR_DOS(ERRDOS,ERRunknownlevel);
+       }
+#endif /* LARGE_SMB_OFF_T */
+
+       /* the soft quotas 8 bytes (SMB_BIG_UINT)*/
+       qt.softlim = (SMB_BIG_UINT)IVAL(pdata,24);
+#ifdef LARGE_SMB_OFF_T
+       qt.softlim |= (((SMB_BIG_UINT)IVAL(pdata,28)) << 32);
+#else /* LARGE_SMB_OFF_T */
+       if ((IVAL(pdata,28) != 0)&&
+               ((qt.softlim != 0xFFFFFFFF)||
+               (IVAL(pdata,28)!=0xFFFFFFFF)))) {
+               /* more than 32 bits? */
+               return ERROR_DOS(ERRDOS,ERRunknownlevel);
+       }
+#endif /* LARGE_SMB_OFF_T */
+
+       /* the hard quotas 8 bytes (SMB_BIG_UINT)*/
+       qt.hardlim = (SMB_BIG_UINT)IVAL(pdata,32);
+#ifdef LARGE_SMB_OFF_T
+       qt.hardlim |= (((SMB_BIG_UINT)IVAL(pdata,36)) << 32);
+#else /* LARGE_SMB_OFF_T */
+       if ((IVAL(pdata,36) != 0)&&
+               ((qt.hardlim != 0xFFFFFFFF)||
+               (IVAL(pdata,36)!=0xFFFFFFFF)))) {
+               /* more than 32 bits? */
+               return ERROR_DOS(ERRDOS,ERRunknownlevel);
+       }
+#endif /* LARGE_SMB_OFF_T */
+       
+       sid_parse(pdata+40,sid_len,&sid);
+       DEBUGADD(8,("SID: %s\n",sid_string_static(&sid)));
+
+       /* 44 unknown bytes left... */
+
+       if (vfs_set_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
+               return ERROR_DOS(ERRSRV,ERRerror);      
+       }
+
+       send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, params, param_len, pdata, data_len);
+
+       return -1;
+}
+
 /****************************************************************************
  Reply to a SMBNTtrans.
 ****************************************************************************/
@@ -1960,6 +2441,24 @@ due to being in oplock break state.\n", (unsigned int)function_code ));
                                        &setup, &params, &data);
                        END_PROFILE_NESTED(NT_transact_query_security_desc);
                        break;
+               case NT_TRANSACT_GET_USER_QUOTA:
+                       START_PROFILE_NESTED(NT_transact_get_user_quota);
+                       outsize = call_nt_transact_get_user_quota(conn, inbuf, outbuf, 
+                                               length, bufsize,
+                                               &setup, setup_count,
+                                               &params, parameter_count, 
+                                               &data, data_count);
+                       END_PROFILE_NESTED(NT_transact_get_user_quota);
+                       break;
+               case NT_TRANSACT_SET_USER_QUOTA:
+                       START_PROFILE_NESTED(NT_transact_set_user_quota);
+                       outsize = call_nt_transact_set_user_quota(conn, inbuf, outbuf, 
+                                               length, bufsize, 
+                                               &setup, setup_count,
+                                               &params, parameter_count, 
+                                               &data, data_count);
+                       END_PROFILE_NESTED(NT_transact_set_user_quota);
+                       break;                                  
                default:
                        /* Error in request */
                        DEBUG(0,("reply_nttrans: Unknown request %d in nttrans call\n", function_code));
index 5b843bd09a6e996eb6bd89a6bdf205ccd5a21e33..0163120ee580d0c78652ed84a9457985432034ee 100644 (file)
 
 #include "includes.h"
 
+#ifndef HAVE_SYS_QUOTAS
+
+#ifdef WITH_QUOTAS
+
 #if defined(VXFS_QUOTA)
 
 /*
@@ -1112,3 +1116,108 @@ BOOL disk_quotas_vxfs(const pstring name, char *path, SMB_BIG_UINT *bsize, SMB_B
 #endif /* SUNOS5 || ... */
 
 #endif /* VXFS_QUOTA */
+
+#else /* WITH_QUOTAS */
+
+BOOL disk_quotas(const char *path,SMB_BIG_UINT *bsize,SMB_BIG_UINT *dfree,SMB_BIG_UINT *dsize)
+{
+  (*bsize) = 512; /* This value should be ignored */
+
+  /* And just to be sure we set some values that hopefully */
+  /* will be larger that any possible real-world value     */
+  (*dfree) = (SMB_BIG_UINT)-1;
+  (*dsize) = (SMB_BIG_UINT)-1;
+
+  /* As we have select not to use quotas, allways fail */
+  return False;
+}
+#endif /* WITH_QUOTAS */
+
+#else /* HAVE_SYS_QUOTAS */
+/* wrapper to the new sys_quota interface 
+   this file should be removed later
+   */
+BOOL disk_quotas(const char *path,SMB_BIG_UINT *bsize,SMB_BIG_UINT *dfree,SMB_BIG_UINT *dsize)
+{
+       int r;
+       SMB_DISK_QUOTA D;
+       unid_t id;
+
+       id.uid = geteuid();
+  
+       r=sys_get_quota(path, SMB_USER_QUOTA_TYPE, id, &D);
+
+       /* Use softlimit to determine disk space, except when it has been exceeded */
+       *bsize = D.bsize;
+       if (r == -1) {
+               if (errno == EDQUOT) {
+                       *dfree =0;
+                       *dsize =D.curblocks;
+                       return (True);
+               } else {
+                       goto try_group_quota;
+               }
+       }
+
+       /* Use softlimit to determine disk space, except when it has been exceeded */
+       if (
+               (D.softlimit && D.curblocks >= D.softlimit) ||
+               (D.hardlimit && D.curblocks >= D.hardlimit) ||
+               (D.isoftlimit && D.curinodes >= D.isoftlimit) ||
+               (D.ihardlimit && D.curinodes>=D.ihardlimit)
+       ) {
+               *dfree = 0;
+               *dsize = D.curblocks;
+       } else if (D.softlimit==0 && D.hardlimit==0) {
+               goto try_group_quota;
+       } else {
+               if (D.softlimit == 0)
+                       D.softlimit = D.hardlimit;
+               *dfree = D.softlimit - D.curblocks;
+               *dsize = D.softlimit;
+       }
+
+       return True;
+       
+try_group_quota:
+#ifdef HAVE_GROUP_QUOTA
+       id.gid = getegid();
+  
+       r=sys_get_quota(path, SMB_GROUP_QUOTA_TYPE, id, &D);
+
+       /* Use softlimit to determine disk space, except when it has been exceeded */
+       *bsize = D.bsize;
+       if (r == -1) {
+               if (errno == EDQUOT) {
+                       *dfree =0;
+                       *dsize =D.curblocks;
+                       return (True);
+               } else {
+                       return False;
+               }
+       }
+
+       /* Use softlimit to determine disk space, except when it has been exceeded */
+       if (
+               (D.softlimit && D.curblocks >= D.softlimit) ||
+               (D.hardlimit && D.curblocks >= D.hardlimit) ||
+               (D.isoftlimit && D.curinodes >= D.isoftlimit) ||
+               (D.ihardlimit && D.curinodes>=D.ihardlimit)
+       ) {
+               *dfree = 0;
+               *dsize = D.curblocks;
+       } else if (D.softlimit==0 && D.hardlimit==0) {
+               return False;
+       } else {
+               if (D.softlimit == 0)
+                       D.softlimit = D.hardlimit;
+               *dfree = D.softlimit - D.curblocks;
+               *dsize = D.softlimit;
+       }
+
+       return (True);
+#else /* HAVE_GROUP_QUOTA */
+       return False;
+#endif /* HAVE_GROUP_QUOTA */
+}
+#endif /* HAVE_SYS_QUOTAS */
index c9eef637d9598330bdee2c698f52e87d2d2b0459..ea530592793aa967c91edd9834860799f2a68088 100644 (file)
@@ -1,7 +1,8 @@
 /* 
    Unix SMB/CIFS implementation.
    SMB transaction2 handling
-   Copyright (C) Jeremy Allison 1994-2001
+   Copyright (C) Jeremy Allison                        1994-2001
+   Copyright (C) Stefan (metze) Metzmacher     2003
 
    Extensively modified by Andrew Tridgell, 1995
 
@@ -28,6 +29,7 @@ extern int smb_read_error;
 extern fstring local_machine;
 extern int global_oplock_break;
 extern uint32 global_client_caps;
+extern struct current_user current_user;
 
 #define get_file_size(sbuf) ((sbuf).st_size)
 
@@ -1368,7 +1370,9 @@ static int call_trans2qfsinfo(connection_struct *conn, char *inbuf, char *outbuf
                case SMB_FS_ATTRIBUTE_INFORMATION:
 
                        SIVAL(pdata,0,FILE_CASE_PRESERVED_NAMES|FILE_CASE_SENSITIVE_SEARCH|
-                               (lp_nt_acl_support(SNUM(conn)) ? FILE_PERSISTENT_ACLS : 0)); /* FS ATTRIBUTES */
+                               (lp_nt_acl_support(SNUM(conn)) ? FILE_PERSISTENT_ACLS : 0)|
+                               (HAVE_SYS_QUOTAS ? FILE_VOLUME_QUOTAS: 0)); /* FS ATTRIBUTES */
+
                        SIVAL(pdata,4,255); /* Max filename component length */
                        /* NOTE! the fstype must *not* be null terminated or win98 won't recognise it
                                and will think we can't do long filenames */
@@ -1470,6 +1474,76 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)bsize, (unsigned
                        SIVAL(pdata,4,0); /* characteristics */
                        break;
 
+               case SMB_FS_QUOTA_INFORMATION:
+               /* 
+                * what we have to send --metze:
+                *
+                * Unknown1:            24 NULL bytes
+                * Soft Quota Treshold: 8 bytes seems like SMB_BIG_UINT or so
+                * Hard Quota Limit:    8 bytes seems like SMB_BIG_UINT or so
+                * Quota Flags:         2 byte :
+                * Unknown3:            6 NULL bytes
+                *
+                * 48 bytes total
+                * 
+                * details for Quota Flags:
+                * 
+                * 0x0020 Log Limit: log if the user exceeds his Hard Quota
+                * 0x0010 Log Warn:  log if the user exceeds his Soft Quota
+                * 0x0002 Deny Disk: deny disk access when the user exceeds his Hard Quota
+                * 0x0001 Enable Quotas: enable quota for this fs
+                *
+                */
+               {
+                       /* we need to fake up a fsp here,
+                        * because its not send in this call
+                        */
+                       files_struct fsp;
+                       SMB_NTQUOTA_STRUCT quotas;
+                       
+                       ZERO_STRUCT(fsp);
+                       ZERO_STRUCT(quotas);
+                       
+                       fsp.conn = conn;
+                       fsp.fnum = -1;
+                       fsp.fd = -1;
+                       
+                       /* access check */
+                       if (conn->admin_user != True) {
+                               DEBUG(0,("set_user_quota: access_denied service [%s] user [%s]\n",
+                                       lp_servicename(SNUM(conn)),conn->user));
+                               return ERROR_DOS(ERRDOS,ERRnoaccess);
+                       }
+                       
+                       if (vfs_get_ntquota(&fsp, SMB_USER_FS_QUOTA_TYPE, NULL, &quotas)!=0) {
+                               DEBUG(0,("vfs_get_ntquota() failed for service [%s]\n",lp_servicename(SNUM(conn))));
+                               return ERROR_DOS(ERRSRV,ERRerror);
+                       }
+
+                       data_len = 48;
+
+                       DEBUG(10,("SMB_FS_QUOTA_INFORMATION: for service [%s]\n",lp_servicename(SNUM(conn))));          
+               
+                       /* Unknown1 24 NULL bytes*/
+                       SBIG_UINT(pdata,0,(SMB_BIG_UINT)0);
+                       SBIG_UINT(pdata,8,(SMB_BIG_UINT)0);
+                       SBIG_UINT(pdata,16,(SMB_BIG_UINT)0);
+               
+                       /* Default Soft Quota 8 bytes */
+                       SBIG_UINT(pdata,24,quotas.softlim);
+
+                       /* Default Hard Quota 8 bytes */
+                       SBIG_UINT(pdata,32,quotas.hardlim);
+       
+                       /* Quota flag 2 bytes */
+                       SSVAL(pdata,40,quotas.qflags);
+               
+                       /* Unknown3 6 NULL bytes */
+                       SSVAL(pdata,42,0);
+                       SIVAL(pdata,44,0);
+                       
+                       break;
+               }
                case SMB_FS_OBJECTID_INFORMATION:
                        data_len = 64;
                        break;
@@ -1519,14 +1593,104 @@ static int call_trans2setfsinfo(connection_struct *conn,
                                char *inbuf, char *outbuf, int length, int bufsize,
                                char **pparams, int total_params, char **ppdata, int total_data)
 {
-       /* Just say yes we did it - there is nothing that
-               can be set here so it doesn't matter. */
+       char *pdata = *ppdata;
+       char *params = *pparams;
+       files_struct *fsp = NULL;
+       uint16 info_level;
        int outsize;
-       DEBUG(3,("call_trans2setfsinfo\n"));
+       SMB_NTQUOTA_STRUCT quotas;
+       
+       ZERO_STRUCT(quotas);
 
-       if (!CAN_WRITE(conn))
+       DEBUG(10,("call_trans2setfsinfo: SET_FS_QUOTA: for service [%s]\n",lp_servicename(SNUM(conn))));
+
+       /* access check */
+       if ((conn->admin_user != True)||!CAN_WRITE(conn)) {
+               DEBUG(0,("set_user_quota: access_denied service [%s] user [%s]\n",
+                       lp_servicename(SNUM(conn)),conn->user));
                return ERROR_DOS(ERRSRV,ERRaccess);
+       }
+
+       /*  */
+       if (total_params < 4) {
+               DEBUG(0,("call_trans2setfsinfo: requires total_params(%d) >= 4 bytes!\n",
+                       total_params));
+               return ERROR_DOS(ERRDOS,ERRinvalidparam);
+       }
 
+       fsp = file_fsp(params,0);
+       if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
+               DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
+               return ERROR_NT(NT_STATUS_INVALID_HANDLE);
+       }
+
+       info_level = SVAL(params,2);
+
+       switch(info_level) {
+               case SMB_FS_QUOTA_INFORMATION:
+                       /* note: normaly there're 48 bytes,
+                        * but we didn't use the last 6 bytes for now 
+                        * --metze 
+                        */
+                       if (total_data < 42) {
+                               DEBUG(0,("call_trans2setfsinfo: SET_FS_QUOTA: requires total_data(%d) >= 42 bytes!\n",
+                                       total_data));
+                               return ERROR_DOS(ERRDOS,ERRunknownlevel);
+                       }
+                       
+                       /* unknown_1 24 NULL bytes in pdata*/
+               
+                       /* the soft quotas 8 bytes (SMB_BIG_UINT)*/
+                       quotas.softlim = (SMB_BIG_UINT)IVAL(pdata,24);
+#ifdef LARGE_SMB_OFF_T
+                       quotas.softlim |= (((SMB_BIG_UINT)IVAL(pdata,28)) << 32);
+#else /* LARGE_SMB_OFF_T */
+                       if ((IVAL(pdata,28) != 0)&&
+                               ((quotas.softlim != 0xFFFFFFFF)||
+                               (IVAL(pdata,28)!=0xFFFFFFFF)))) {
+                               /* more than 32 bits? */
+                               return ERROR_DOS(ERRDOS,ERRunknownlevel);
+                       }
+#endif /* LARGE_SMB_OFF_T */
+               
+                       /* the hard quotas 8 bytes (SMB_BIG_UINT)*/
+                       quotas.hardlim = (SMB_BIG_UINT)IVAL(pdata,32);
+#ifdef LARGE_SMB_OFF_T
+                       quotas.hardlim |= (((SMB_BIG_UINT)IVAL(pdata,36)) << 32);
+#else /* LARGE_SMB_OFF_T */
+                       if ((IVAL(pdata,36) != 0)&&
+                               ((quotas.hardlim != 0xFFFFFFFF)||
+                               (IVAL(pdata,36)!=0xFFFFFFFF)))) {
+                               /* more than 32 bits? */
+                               return ERROR_DOS(ERRDOS,ERRunknownlevel);
+                       }
+#endif /* LARGE_SMB_OFF_T */
+               
+                       /* quota_flags 2 bytes **/
+                       quotas.qflags = SVAL(pdata,40);
+               
+                       /* unknown_2 6 NULL bytes follow*/
+               
+                       /* now set the quotas */
+                       if (vfs_set_ntquota(fsp, SMB_USER_FS_QUOTA_TYPE, NULL, &quotas)!=0) {
+                               DEBUG(0,("vfs_set_ntquota() failed for service [%s]\n",lp_servicename(SNUM(conn))));
+                               return ERROR_DOS(ERRSRV,ERRerror);
+                       }
+                       
+                       break;
+               default:
+                       DEBUG(3,("call_trans2setfsinfo: unknown level (0x%X) not implemented yet.\n",
+                               info_level));
+                       return ERROR_DOS(ERRDOS,ERRunknownlevel);
+                       break;
+       }
+
+       /* 
+        * sending this reply works fine, 
+        * but I'm not sure it's the same 
+        * like windows do...
+        * --metze
+        */ 
        outsize = set_message(outbuf,10,0,True);
 
        return outsize;
@@ -1589,7 +1753,20 @@ static int call_trans2qfilepathinfo(connection_struct *conn,
 
                DEBUG(3,("call_trans2qfilepathinfo: TRANSACT2_QFILEINFO: level = %d\n", info_level));
 
-               if(fsp && (fsp->is_directory || fsp->fd == -1)) {
+               if(fsp && (fsp->fake_file_handle)) {
+                       /*
+                        * This is actually for the QUOTA_FAKE_FILE --metze
+                        */
+                                               
+                       pstrcpy(fname, fsp->fsp_name);
+                       unix_convert(fname,conn,0,&bad_path,&sbuf);
+                       if (!check_name(fname,conn)) {
+                               DEBUG(3,("call_trans2qfilepathinfo: fileinfo of %s failed for fake_file(%s)\n",fname,strerror(errno)));
+                               set_bad_path_error(errno, bad_path);
+                               return(UNIXERROR(ERRDOS,ERRbadpath));
+                       }
+                       
+               } else if(fsp && (fsp->is_directory || fsp->fd == -1)) {
                        /*
                         * This is actually a QFILEINFO on a directory
                         * handle (returned from an NT SMB). NT5.0 seems
@@ -2229,7 +2406,13 @@ static int call_trans2setfilepathinfo(connection_struct *conn,
        gid_t set_grp = (uid_t)SMB_GID_NO_CHANGE;
        mode_t unixmode = 0;
 
+       if (!params)
+               return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+
        if (tran_call == TRANSACT2_SETFILEINFO) {
+               if (total_params < 4)
+                       return(ERROR_DOS(ERRDOS,ERRinvalidparam));
+
                fsp = file_fsp(params,0);
                info_level = SVAL(params,2);    
 
index 4422666006df9c3827ea8b307c411d4193c09ea1..dd8aad117065279a6bbc4d232db0f82ef7a0f9e2 100644 (file)
@@ -749,14 +749,22 @@ int vfswrap_sys_acl_free_qualifier(vfs_handle_struct *handle, connection_struct
        return sys_acl_free_qualifier(qualifier, tagtype);
 }
 
-int vfswrap_get_quota(vfs_handle_struct *handle, connection_struct *conn, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt)
+int vfswrap_get_quota(struct vfs_handle_struct *handle, struct connection_struct *conn, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt)
 {
-       errno = ENOSYS;
-       return -1;      
+       int result;
+
+       START_PROFILE(syscall_get_quota);
+       result = sys_get_quota(conn->connectpath, qtype, id, qt);
+       END_PROFILE(syscall_get_quota);
+       return result;  
 }
 
-int vfswrap_set_quota(vfs_handle_struct *handle, connection_struct *conn, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt)
+int vfswrap_set_quota(struct vfs_handle_struct *handle, struct connection_struct *conn, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt)
 {
-       errno = ENOSYS;
-       return -1;
+       int result;
+
+       START_PROFILE(syscall_set_quota);
+       result = sys_set_quota(conn->connectpath, qtype, id, qt);
+       END_PROFILE(syscall_set_quota);
+       return result;  
 }