modules/vfs_default_quota.c

説明を見る。
00001 /* 
00002  * Store default Quotas in a specified quota record
00003  *
00004  * Copyright (C) Stefan (metze) Metzmacher 2003
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *  
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *  
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 /*
00022  * This module allows the default quota values,
00023  * in the windows explorer GUI, to be stored on a samba server.
00024  * The problem is that linux filesystems only store quotas
00025  * for users and groups, but no default quotas.
00026  *
00027  * Samba returns NO_LIMIT as the default quotas by default
00028  * and refuses to update them.
00029  *
00030  * With this module you can store the default quotas that are reported to
00031  * a windows client, in the quota record of a user. By default the root user
00032  * is taken because quota limits for root are typically not enforced.
00033  *
00034  * This module takes 2 parametric parameters in smb.conf:
00035  * (the default prefix for them is 'default_quota',
00036  *  it can be overwrittem when you load the module in
00037  *  the 'vfs objects' parameter like this:
00038  *  vfs objects = default_quota:myprefix)
00039  * 
00040  * "<myprefix>:uid" parameter takes a integer argument,
00041  *     it specifies the uid of the quota record, that will be taken for
00042  *     storing the default USER-quotas.
00043  *
00044  *     - default value: '0' (for root user)
00045  *     - e.g.: default_quota:uid = 65534
00046  *
00047  * "<myprefix>:uid nolimit" parameter takes a boolean argument,
00048  *     it specifies if we should report the stored default quota values,
00049  *     also for the user record, or if you should just report NO_LIMIT
00050  *     to the windows client for the user specified by the "<prefix>:uid" parameter.
00051  *     
00052  *     - default value: yes (that means to report NO_LIMIT)
00053  *     - e.g.: default_quota:uid nolimit = no
00054  * 
00055  * "<myprefix>:gid" parameter takes a integer argument,
00056  *     it's just like "<prefix>:uid" but for group quotas.
00057  *     (NOTE: group quotas are not supported from the windows explorer!)
00058  *
00059  *     - default value: '0' (for root group)
00060  *     - e.g.: default_quota:gid = 65534
00061  *
00062  * "<myprefix>:gid nolimit" parameter takes a boolean argument,
00063  *     it's just like "<prefix>:uid nolimit" but for group quotas.
00064  *     (NOTE: group quotas are not supported from the windows explorer!)
00065  *     
00066  *     - default value: yes (that means to report NO_LIMIT)
00067  *     - e.g.: default_quota:uid nolimit = no
00068  *
00069  */
00070 
00071 #include "includes.h"
00072 
00073 #undef DBGC_CLASS
00074 #define DBGC_CLASS DBGC_QUOTA
00075 
00076 #define DEFAULT_QUOTA_NAME "default_quota"
00077 
00078 #define DEFAULT_QUOTA_UID_DEFAULT               0
00079 #define DEFAULT_QUOTA_UID_NOLIMIT_DEFAULT       True
00080 #define DEFAULT_QUOTA_GID_DEFAULT               0
00081 #define DEFAULT_QUOTA_GID_NOLIMIT_DEFAULT       True
00082 
00083 #define DEFAULT_QUOTA_UID(handle) \
00084         (uid_t)lp_parm_int(SNUM((handle)->conn),DEFAULT_QUOTA_NAME,"uid",DEFAULT_QUOTA_UID_DEFAULT)
00085 
00086 #define DEFAULT_QUOTA_UID_NOLIMIT(handle) \
00087         lp_parm_bool(SNUM((handle)->conn),DEFAULT_QUOTA_NAME,"uid nolimit",DEFAULT_QUOTA_UID_NOLIMIT_DEFAULT)
00088 
00089 #define DEFAULT_QUOTA_GID(handle) \
00090         (gid_t)lp_parm_int(SNUM((handle)->conn),DEFAULT_QUOTA_NAME,"gid",DEFAULT_QUOTA_GID_DEFAULT)
00091 
00092 #define DEFAULT_QUOTA_GID_NOLIMIT(handle) \
00093         lp_parm_bool(SNUM((handle)->conn),DEFAULT_QUOTA_NAME,"gid nolimit",DEFAULT_QUOTA_GID_NOLIMIT_DEFAULT)
00094 
00095 static int default_quota_get_quota(vfs_handle_struct *handle, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dq)
00096 {
00097         int ret = -1;
00098 
00099         if ((ret=SMB_VFS_NEXT_GET_QUOTA(handle, qtype, id, dq))!=0) {
00100                 return ret;
00101         }
00102 
00103         switch (qtype) {
00104                 case SMB_USER_QUOTA_TYPE:
00105                         /* we use id.uid == 0 for default quotas */
00106                         if ((id.uid==DEFAULT_QUOTA_UID(handle)) &&
00107                                 DEFAULT_QUOTA_UID_NOLIMIT(handle)) {
00108                                 SMB_QUOTAS_SET_NO_LIMIT(dq);
00109                         }
00110                         break;
00111 #ifdef HAVE_GROUP_QUOTA
00112                 case SMB_GROUP_QUOTA_TYPE:
00113                         /* we use id.gid == 0 for default quotas */
00114                         if ((id.gid==DEFAULT_QUOTA_GID(handle)) &&
00115                                 DEFAULT_QUOTA_GID_NOLIMIT(handle)) {
00116                                 SMB_QUOTAS_SET_NO_LIMIT(dq);
00117                         }
00118                         break;
00119 #endif /* HAVE_GROUP_QUOTA */
00120                 case SMB_USER_FS_QUOTA_TYPE:
00121                         {
00122                                 unid_t qid;
00123                                 uint32 qflags = dq->qflags;
00124                                 qid.uid = DEFAULT_QUOTA_UID(handle);
00125                                 SMB_VFS_NEXT_GET_QUOTA(handle, SMB_USER_QUOTA_TYPE, qid, dq);
00126                                 dq->qflags = qflags;
00127                         }
00128                         break;
00129 #ifdef HAVE_GROUP_QUOTA
00130                 case SMB_GROUP_FS_QUOTA_TYPE:
00131                         {
00132                                 unid_t qid;
00133                                 uint32 qflags = dq->qflags;
00134                                 qid.gid = DEFAULT_QUOTA_GID(handle);
00135                                 SMB_VFS_NEXT_GET_QUOTA(handle, SMB_GROUP_QUOTA_TYPE, qid, dq);
00136                                 dq->qflags = qflags;
00137                         }
00138                         break;
00139 #endif /* HAVE_GROUP_QUOTA */
00140                 default:
00141                         errno = ENOSYS;
00142                         return -1;
00143                         break;
00144         }
00145 
00146         return ret;
00147 }
00148 
00149 static int default_quota_set_quota(vfs_handle_struct *handle, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dq)
00150 {
00151         int ret = -1;
00152 
00153         switch (qtype) {
00154                 case SMB_USER_QUOTA_TYPE:
00155                         /* we use id.uid == 0 for default quotas */
00156                         if ((id.uid==DEFAULT_QUOTA_UID(handle)) &&
00157                                 DEFAULT_QUOTA_UID_NOLIMIT(handle)) {
00158                                 return -1;
00159                         }
00160                         break;
00161 #ifdef HAVE_GROUP_QUOTA
00162                 case SMB_GROUP_QUOTA_TYPE:
00163                         /* we use id.gid == 0 for default quotas */
00164                         if ((id.gid==DEFAULT_QUOTA_GID(handle)) &&
00165                                 DEFAULT_QUOTA_GID_NOLIMIT(handle)) {
00166                                 return -1;
00167                         }
00168                         break;
00169 #endif /* HAVE_GROUP_QUOTA */
00170                 case SMB_USER_FS_QUOTA_TYPE:
00171                         break;
00172 #ifdef HAVE_GROUP_QUOTA
00173                 case SMB_GROUP_FS_QUOTA_TYPE:
00174                         break;
00175 #endif /* HAVE_GROUP_QUOTA */
00176                 default:
00177                         errno = ENOSYS;
00178                         return -1;
00179                         break;
00180         }
00181 
00182         if ((ret=SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, dq))!=0) {
00183                 return ret;
00184         }
00185 
00186         switch (qtype) {
00187                 case SMB_USER_QUOTA_TYPE:
00188                         break;
00189 #ifdef HAVE_GROUP_QUOTA
00190                 case SMB_GROUP_QUOTA_TYPE:
00191                         break;
00192 #endif /* HAVE_GROUP_QUOTA */
00193                 case SMB_USER_FS_QUOTA_TYPE:
00194                         {
00195                                 unid_t qid;
00196                                 qid.uid = DEFAULT_QUOTA_UID(handle);
00197                                 ret = SMB_VFS_NEXT_SET_QUOTA(handle, SMB_USER_QUOTA_TYPE, qid, dq);
00198                         }
00199                         break;
00200 #ifdef HAVE_GROUP_QUOTA
00201                 case SMB_GROUP_FS_QUOTA_TYPE:
00202                         {
00203                                 unid_t qid;
00204                                 qid.gid = DEFAULT_QUOTA_GID(handle);
00205                                 ret = SMB_VFS_NEXT_SET_QUOTA(handle, SMB_GROUP_QUOTA_TYPE, qid, dq);
00206                         }
00207                         break;
00208 #endif /* HAVE_GROUP_QUOTA */
00209                 default:
00210                         errno = ENOSYS;
00211                         return -1;
00212                         break;
00213         }
00214 
00215         return ret;
00216 }
00217 
00218 /* VFS operations structure */
00219 
00220 static vfs_op_tuple default_quota_ops[] = {     
00221         {SMB_VFS_OP(default_quota_get_quota),   SMB_VFS_OP_GET_QUOTA,   SMB_VFS_LAYER_TRANSPARENT},
00222         {SMB_VFS_OP(default_quota_set_quota),   SMB_VFS_OP_SET_QUOTA,   SMB_VFS_LAYER_TRANSPARENT},
00223 
00224         {SMB_VFS_OP(NULL),                      SMB_VFS_OP_NOOP,        SMB_VFS_LAYER_NOOP}
00225 };
00226 
00227 NTSTATUS vfs_default_quota_init(void);
00228 NTSTATUS vfs_default_quota_init(void)
00229 {
00230         return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, DEFAULT_QUOTA_NAME, default_quota_ops);
00231 }

Sambaに対してSat Aug 29 21:23:07 2009に生成されました。  doxygen 1.4.7