modules/vfs_audit.c

説明を見る。
00001 /* 
00002  * Auditing VFS module for samba.  Log selected file operations to syslog
00003  * facility.
00004  *
00005  * Copyright (C) Tim Potter                     1999-2000
00006  * Copyright (C) Alexander Bokovoy              2002
00007  * Copyright (C) Stefan (metze) Metzmacher      2002
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *  
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *  
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00022  */
00023 
00024 
00025 #include "includes.h"
00026 
00027 #undef DBGC_CLASS
00028 #define DBGC_CLASS DBGC_VFS
00029 
00030 /* Function prototypes */
00031 
00032 static int audit_connect(vfs_handle_struct *handle, const char *svc, const char *user);
00033 static void audit_disconnect(vfs_handle_struct *handle);
00034 static SMB_STRUCT_DIR *audit_opendir(vfs_handle_struct *handle, const char *fname, const char *mask, uint32 attr);
00035 static int audit_mkdir(vfs_handle_struct *handle, const char *path, mode_t mode);
00036 static int audit_rmdir(vfs_handle_struct *handle, const char *path);
00037 static int audit_open(vfs_handle_struct *handle, const char *fname, files_struct *fsp, int flags, mode_t mode);
00038 static int audit_close(vfs_handle_struct *handle, files_struct *fsp, int fd);
00039 static int audit_rename(vfs_handle_struct *handle, const char *oldname, const char *newname);
00040 static int audit_unlink(vfs_handle_struct *handle, const char *path);
00041 static int audit_chmod(vfs_handle_struct *handle, const char *path, mode_t mode);
00042 static int audit_chmod_acl(vfs_handle_struct *handle, const char *name, mode_t mode);
00043 static int audit_fchmod(vfs_handle_struct *handle, files_struct *fsp, int fd, mode_t mode);
00044 static int audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp, int fd, mode_t mode);
00045 
00046 /* VFS operations */
00047 
00048 static vfs_op_tuple audit_op_tuples[] = {
00049     
00050         /* Disk operations */
00051 
00052         {SMB_VFS_OP(audit_connect),     SMB_VFS_OP_CONNECT,     SMB_VFS_LAYER_LOGGER},
00053         {SMB_VFS_OP(audit_disconnect),  SMB_VFS_OP_DISCONNECT,  SMB_VFS_LAYER_LOGGER},
00054 
00055         /* Directory operations */
00056 
00057         {SMB_VFS_OP(audit_opendir),     SMB_VFS_OP_OPENDIR,     SMB_VFS_LAYER_LOGGER},
00058         {SMB_VFS_OP(audit_mkdir),               SMB_VFS_OP_MKDIR,       SMB_VFS_LAYER_LOGGER},
00059         {SMB_VFS_OP(audit_rmdir),               SMB_VFS_OP_RMDIR,       SMB_VFS_LAYER_LOGGER},
00060 
00061         /* File operations */
00062 
00063         {SMB_VFS_OP(audit_open),                SMB_VFS_OP_OPEN,        SMB_VFS_LAYER_LOGGER},
00064         {SMB_VFS_OP(audit_close),               SMB_VFS_OP_CLOSE,       SMB_VFS_LAYER_LOGGER},
00065         {SMB_VFS_OP(audit_rename),              SMB_VFS_OP_RENAME,      SMB_VFS_LAYER_LOGGER},
00066         {SMB_VFS_OP(audit_unlink),              SMB_VFS_OP_UNLINK,      SMB_VFS_LAYER_LOGGER},
00067         {SMB_VFS_OP(audit_chmod),               SMB_VFS_OP_CHMOD,       SMB_VFS_LAYER_LOGGER},
00068         {SMB_VFS_OP(audit_fchmod),              SMB_VFS_OP_FCHMOD,      SMB_VFS_LAYER_LOGGER},
00069         {SMB_VFS_OP(audit_chmod_acl),   SMB_VFS_OP_CHMOD_ACL,   SMB_VFS_LAYER_LOGGER},
00070         {SMB_VFS_OP(audit_fchmod_acl),  SMB_VFS_OP_FCHMOD_ACL,  SMB_VFS_LAYER_LOGGER},
00071         
00072         /* Finish VFS operations definition */
00073         
00074         {SMB_VFS_OP(NULL),                      SMB_VFS_OP_NOOP,        SMB_VFS_LAYER_NOOP}
00075 };
00076 
00077 
00078 static int audit_syslog_facility(vfs_handle_struct *handle)
00079 {
00080         static const struct enum_list enum_log_facilities[] = {
00081                 { LOG_USER, "USER" },
00082                 { LOG_LOCAL0, "LOCAL0" },
00083                 { LOG_LOCAL1, "LOCAL1" },
00084                 { LOG_LOCAL2, "LOCAL2" },
00085                 { LOG_LOCAL3, "LOCAL3" },
00086                 { LOG_LOCAL4, "LOCAL4" },
00087                 { LOG_LOCAL5, "LOCAL5" },
00088                 { LOG_LOCAL6, "LOCAL6" },
00089                 { LOG_LOCAL7, "LOCAL7" }
00090         };
00091 
00092         int facility;
00093 
00094         facility = lp_parm_enum(SNUM(handle->conn), "audit", "facility", enum_log_facilities, LOG_USER);
00095 
00096         return facility;
00097 }
00098 
00099 
00100 static int audit_syslog_priority(vfs_handle_struct *handle)
00101 {
00102         static const struct enum_list enum_log_priorities[] = {
00103                 { LOG_EMERG, "EMERG" },
00104                 { LOG_ALERT, "ALERT" },
00105                 { LOG_CRIT, "CRIT" },
00106                 { LOG_ERR, "ERR" },
00107                 { LOG_WARNING, "WARNING" },
00108                 { LOG_NOTICE, "NOTICE" },
00109                 { LOG_INFO, "INFO" },
00110                 { LOG_DEBUG, "DEBUG" }
00111         };
00112 
00113         int priority;
00114 
00115         priority = lp_parm_enum(SNUM(handle->conn), "audit", "priority", enum_log_priorities, LOG_NOTICE);
00116 
00117         return priority;
00118 }
00119 
00120 /* Implementation of vfs_ops.  Pass everything on to the default
00121    operation but log event first. */
00122 
00123 static int audit_connect(vfs_handle_struct *handle, const char *svc, const char *user)
00124 {
00125         int result;
00126         
00127         openlog("smbd_audit", LOG_PID, audit_syslog_facility(handle));
00128 
00129         syslog(audit_syslog_priority(handle), "connect to service %s by user %s\n", 
00130                svc, user);
00131 
00132         result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
00133 
00134         return result;
00135 }
00136 
00137 static void audit_disconnect(vfs_handle_struct *handle)
00138 {
00139         syslog(audit_syslog_priority(handle), "disconnected\n");
00140         SMB_VFS_NEXT_DISCONNECT(handle);
00141 
00142         return;
00143 }
00144 
00145 static SMB_STRUCT_DIR *audit_opendir(vfs_handle_struct *handle, const char *fname, const char *mask, uint32 attr)
00146 {
00147         SMB_STRUCT_DIR *result;
00148         
00149         result = SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr);
00150 
00151         syslog(audit_syslog_priority(handle), "opendir %s %s%s\n",
00152                fname,
00153                (result == NULL) ? "failed: " : "",
00154                (result == NULL) ? strerror(errno) : "");
00155 
00156         return result;
00157 }
00158 
00159 static int audit_mkdir(vfs_handle_struct *handle, const char *path, mode_t mode)
00160 {
00161         int result;
00162         
00163         result = SMB_VFS_NEXT_MKDIR(handle, path, mode);
00164         
00165         syslog(audit_syslog_priority(handle), "mkdir %s %s%s\n", 
00166                path,
00167                (result < 0) ? "failed: " : "",
00168                (result < 0) ? strerror(errno) : "");
00169 
00170         return result;
00171 }
00172 
00173 static int audit_rmdir(vfs_handle_struct *handle, const char *path)
00174 {
00175         int result;
00176 
00177         result = SMB_VFS_NEXT_RMDIR(handle, path);
00178 
00179         syslog(audit_syslog_priority(handle), "rmdir %s %s%s\n", 
00180                path, 
00181                (result < 0) ? "failed: " : "",
00182                (result < 0) ? strerror(errno) : "");
00183 
00184         return result;
00185 }
00186 
00187 static int audit_open(vfs_handle_struct *handle, const char *fname, files_struct *fsp, int flags, mode_t mode)
00188 {
00189         int result;
00190 
00191         result = SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode);
00192 
00193         syslog(audit_syslog_priority(handle), "open %s (fd %d) %s%s%s\n", 
00194                fname, result,
00195                ((flags & O_WRONLY) || (flags & O_RDWR)) ? "for writing " : "", 
00196                (result < 0) ? "failed: " : "",
00197                (result < 0) ? strerror(errno) : "");
00198 
00199         return result;
00200 }
00201 
00202 static int audit_close(vfs_handle_struct *handle, files_struct *fsp, int fd)
00203 {
00204         int result;
00205 
00206         result = SMB_VFS_NEXT_CLOSE(handle, fsp, fd);
00207 
00208         syslog(audit_syslog_priority(handle), "close fd %d %s%s\n",
00209                fd,
00210                (result < 0) ? "failed: " : "",
00211                (result < 0) ? strerror(errno) : "");
00212 
00213         return result;
00214 }
00215 
00216 static int audit_rename(vfs_handle_struct *handle, const char *oldname, const char *newname)
00217 {
00218         int result;
00219 
00220         result = SMB_VFS_NEXT_RENAME(handle, oldname, newname);
00221 
00222         syslog(audit_syslog_priority(handle), "rename %s -> %s %s%s\n",
00223                oldname, newname,
00224                (result < 0) ? "failed: " : "",
00225                (result < 0) ? strerror(errno) : "");
00226 
00227         return result;    
00228 }
00229 
00230 static int audit_unlink(vfs_handle_struct *handle, const char *path)
00231 {
00232         int result;
00233 
00234         result = SMB_VFS_NEXT_UNLINK(handle, path);
00235 
00236         syslog(audit_syslog_priority(handle), "unlink %s %s%s\n",
00237                path,
00238                (result < 0) ? "failed: " : "",
00239                (result < 0) ? strerror(errno) : "");
00240 
00241         return result;
00242 }
00243 
00244 static int audit_chmod(vfs_handle_struct *handle, const char *path, mode_t mode)
00245 {
00246         int result;
00247 
00248         result = SMB_VFS_NEXT_CHMOD(handle, path, mode);
00249 
00250         syslog(audit_syslog_priority(handle), "chmod %s mode 0x%x %s%s\n",
00251                path, mode,
00252                (result < 0) ? "failed: " : "",
00253                (result < 0) ? strerror(errno) : "");
00254 
00255         return result;
00256 }
00257 
00258 static int audit_chmod_acl(vfs_handle_struct *handle, const char *path, mode_t mode)
00259 {
00260         int result;
00261 
00262         result = SMB_VFS_NEXT_CHMOD_ACL(handle, path, mode);
00263 
00264         syslog(audit_syslog_priority(handle), "chmod_acl %s mode 0x%x %s%s\n",
00265                path, mode,
00266                (result < 0) ? "failed: " : "",
00267                (result < 0) ? strerror(errno) : "");
00268 
00269         return result;
00270 }
00271 
00272 static int audit_fchmod(vfs_handle_struct *handle, files_struct *fsp, int fd, mode_t mode)
00273 {
00274         int result;
00275 
00276         result = SMB_VFS_NEXT_FCHMOD(handle, fsp, fd, mode);
00277 
00278         syslog(audit_syslog_priority(handle), "fchmod %s mode 0x%x %s%s\n",
00279                fsp->fsp_name, mode,
00280                (result < 0) ? "failed: " : "",
00281                (result < 0) ? strerror(errno) : "");
00282 
00283         return result;
00284 }
00285 
00286 static int audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp, int fd, mode_t mode)
00287 {
00288         int result;
00289 
00290         result = SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, fd, mode);
00291 
00292         syslog(audit_syslog_priority(handle), "fchmod_acl %s mode 0x%x %s%s\n",
00293                fsp->fsp_name, mode,
00294                (result < 0) ? "failed: " : "",
00295                (result < 0) ? strerror(errno) : "");
00296 
00297         return result;
00298 }
00299 
00300 NTSTATUS vfs_audit_init(void);
00301 NTSTATUS vfs_audit_init(void)
00302 {
00303         return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "audit", audit_op_tuples);
00304 }

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