smbd/fake_file.c

説明を見る。
00001 /* 
00002    Unix SMB/CIFS implementation.
00003    FAKE FILE suppport, for faking up special files windows want access to
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 #include "includes.h"
00022 
00023 extern struct current_user current_user;
00024 
00025 static FAKE_FILE fake_files[] = {
00026 #ifdef WITH_QUOTAS
00027         {FAKE_FILE_NAME_QUOTA_UNIX,     FAKE_FILE_TYPE_QUOTA,   init_quota_handle,      destroy_quota_handle},
00028 #endif /* WITH_QUOTAS */
00029         {NULL,                          FAKE_FILE_TYPE_NONE,    NULL,                   NULL }
00030 };
00031 
00032 /****************************************************************************
00033  Create a fake file handle
00034 ****************************************************************************/
00035 
00036 static struct _FAKE_FILE_HANDLE *init_fake_file_handle(enum FAKE_FILE_TYPE type)
00037 {
00038         TALLOC_CTX *mem_ctx = NULL;
00039         FAKE_FILE_HANDLE *fh = NULL;
00040         int i;
00041 
00042         for (i=0;fake_files[i].name!=NULL;i++) {
00043                 if (fake_files[i].type==type) {
00044                         DEBUG(5,("init_fake_file_handle: for [%s]\n",fake_files[i].name));
00045 
00046                         if ((mem_ctx=talloc_init("fake_file_handle"))==NULL) {
00047                                 DEBUG(0,("talloc_init(fake_file_handle) failed.\n"));
00048                                 return NULL;    
00049                         }
00050 
00051                         if ((fh =TALLOC_ZERO_P(mem_ctx, FAKE_FILE_HANDLE))==NULL) {
00052                                 DEBUG(0,("TALLOC_ZERO() failed.\n"));
00053                                 talloc_destroy(mem_ctx);
00054                                 return NULL;
00055                         }
00056 
00057                         fh->type = type;
00058                         fh->mem_ctx = mem_ctx;
00059 
00060                         if (fake_files[i].init_pd) {
00061                                 fh->pd = fake_files[i].init_pd(fh->mem_ctx);
00062                         }
00063 
00064                         fh->free_pd = fake_files[i].free_pd;
00065 
00066                         return fh;
00067                 }
00068         }
00069 
00070         return NULL;    
00071 }
00072 
00073 /****************************************************************************
00074  Does this name match a fake filename ?
00075 ****************************************************************************/
00076 
00077 enum FAKE_FILE_TYPE is_fake_file(const char *fname)
00078 {
00079 #ifdef HAVE_SYS_QUOTAS
00080         int i;
00081 #endif
00082 
00083         if (!fname) {
00084                 return FAKE_FILE_TYPE_NONE;
00085         }
00086 
00087 #ifdef HAVE_SYS_QUOTAS
00088         for (i=0;fake_files[i].name!=NULL;i++) {
00089                 if (strncmp(fname,fake_files[i].name,strlen(fake_files[i].name))==0) {
00090                         DEBUG(5,("is_fake_file: [%s] is a fake file\n",fname));
00091                         return fake_files[i].type;
00092                 }
00093         }
00094 #endif
00095 
00096         return FAKE_FILE_TYPE_NONE;
00097 }
00098 
00099 
00100 /****************************************************************************
00101  Open a fake quota file with a share mode.
00102 ****************************************************************************/
00103 
00104 NTSTATUS open_fake_file(connection_struct *conn,
00105                                 enum FAKE_FILE_TYPE fake_file_type,
00106                                 const char *fname,
00107                                 uint32 access_mask,
00108                                 files_struct **result)
00109 {
00110         files_struct *fsp = NULL;
00111         NTSTATUS status;
00112 
00113         /* access check */
00114         if (current_user.ut.uid != 0) {
00115                 DEBUG(1,("open_fake_file_shared: access_denied to service[%s] file[%s] user[%s]\n",
00116                         lp_servicename(SNUM(conn)),fname,conn->user));
00117                 return NT_STATUS_ACCESS_DENIED;
00118 
00119         }
00120 
00121         status = file_new(conn, &fsp);
00122         if(!NT_STATUS_IS_OK(status)) {
00123                 return status;
00124         }
00125 
00126         DEBUG(5,("open_fake_file_shared: fname = %s, FID = %d, access_mask = 0x%x\n",
00127                 fname, fsp->fnum, (unsigned int)access_mask));
00128 
00129         fsp->conn = conn;
00130         fsp->fh->fd = -1;
00131         fsp->vuid = current_user.vuid;
00132         fsp->fh->pos = -1;
00133         fsp->can_lock = False; /* Should this be true ? - No, JRA */
00134         fsp->access_mask = access_mask;
00135         string_set(&fsp->fsp_name,fname);
00136         
00137         fsp->fake_file_handle = init_fake_file_handle(fake_file_type);
00138         
00139         if (fsp->fake_file_handle==NULL) {
00140                 file_free(fsp);
00141                 return NT_STATUS_NO_MEMORY;
00142         }
00143 
00144         conn->num_files_open++;
00145         *result = fsp;
00146         return NT_STATUS_OK;
00147 }
00148 
00149 void destroy_fake_file_handle(FAKE_FILE_HANDLE **fh)
00150 {
00151         if (!fh||!(*fh)) {
00152                 return;
00153         }
00154 
00155         if ((*fh)->free_pd) {
00156                 (*fh)->free_pd(&(*fh)->pd);             
00157         }
00158 
00159         talloc_destroy((*fh)->mem_ctx);
00160         (*fh) = NULL;
00161 }
00162 
00163 NTSTATUS close_fake_file(files_struct *fsp)
00164 {
00165         file_free(fsp);
00166         return NT_STATUS_OK;
00167 }

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