📄 filestat.c
字号:
/* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2000-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */#include <aclapi.h>#include "apr_private.h"#include "win32/fileio.h"#include "apr_file_io.h"#include "apr_general.h"#include "apr_strings.h"#include "apr_errno.h"#include "apr_time.h"#include <sys/stat.h>#include "atime.h"#include "misc.h"static apr_status_t free_localheap(void *heap) { LocalFree(heap); return APR_SUCCESS;}static apr_gid_t worldid = NULL;static void free_world(void){ if (worldid) { FreeSid(worldid); worldid = NULL; }}/* Left bit shifts from World scope to given scope */typedef enum prot_scope_e { prot_scope_world = 0, prot_scope_group = 4, prot_scope_user = 8} prot_scope_e;static apr_fileperms_t convert_prot(ACCESS_MASK acc, prot_scope_e scope){ /* These choices are based on the single filesystem bit that controls * the given behavior. They are -not- recommended for any set protection * function, such a function should -set- use GENERIC_READ/WRITE/EXECUTE */ apr_fileperms_t prot; if (acc & FILE_EXECUTE) prot |= APR_WEXECUTE; if (acc & FILE_WRITE_DATA) prot |= APR_WWRITE; if (acc & FILE_READ_DATA) prot |= APR_WREAD; return (prot << scope);}static void resolve_prot(apr_finfo_t *finfo, apr_int32_t wanted, PACL dacl){ TRUSTEE ident = {NULL, NO_MULTIPLE_TRUSTEE, TRUSTEE_IS_SID}; ACCESS_MASK acc; if ((wanted & APR_FINFO_WPROT) && !worldid) { SID_IDENTIFIER_AUTHORITY SIDAuth = SECURITY_WORLD_SID_AUTHORITY; if (AllocateAndInitializeSid(&SIDAuth, 1, SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, &worldid)) atexit(free_world); else worldid = NULL; } if ((wanted & APR_FINFO_UPROT) && (finfo->valid & APR_FINFO_USER)) { ident.TrusteeType = TRUSTEE_IS_USER; ident.ptstrName = finfo->user; if (GetEffectiveRightsFromAcl(dacl, &ident, &acc) == ERROR_SUCCESS) { finfo->protection |= convert_prot(acc, prot_scope_user); finfo->valid |= APR_FINFO_UPROT; } } if ((wanted & APR_FINFO_GPROT) && (finfo->valid & APR_FINFO_GROUP)) { ident.TrusteeType = TRUSTEE_IS_GROUP; ident.ptstrName = finfo->group; if (GetEffectiveRightsFromAcl(dacl, &ident, &acc) == ERROR_SUCCESS) { finfo->protection |= convert_prot(acc, prot_scope_group); finfo->valid |= APR_FINFO_GPROT; } } if ((wanted & APR_FINFO_WPROT) && (worldid)) { ident.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP; ident.ptstrName = worldid; if (GetEffectiveRightsFromAcl(dacl, &ident, &acc) == ERROR_SUCCESS) { finfo->protection |= convert_prot(acc, prot_scope_world); finfo->valid |= APR_FINFO_WPROT; } }}static int resolve_ident(apr_finfo_t *finfo, const char *fname, apr_int32_t wanted, apr_pool_t *cont){ apr_file_t *thefile = NULL; apr_status_t rv; /* * NT5 (W2K) only supports symlinks in the same manner as mount points. * This code should eventually take that into account, for now treat * every reparse point as a symlink... * * We must open the file with READ_CONTROL if we plan to retrieve the * user, group or permissions. */ if ((rv = apr_file_open(&thefile, fname, ((wanted & APR_FINFO_LINK) ? APR_OPENLINK : 0) | ((wanted & (APR_FINFO_PROT | APR_FINFO_OWNER)) ? APR_READCONTROL : 0), APR_OS_DEFAULT, cont)) == APR_SUCCESS) { rv = apr_file_info_get(finfo, wanted, thefile); finfo->filehand = NULL; apr_file_close(thefile); } else if (APR_STATUS_IS_EACCES(rv) && (wanted & (APR_FINFO_PROT | APR_FINFO_OWNER))) { /* We have a backup plan. Perhaps we couldn't grab READ_CONTROL? * proceed without asking for that permission... */ if ((rv = apr_file_open(&thefile, fname, ((wanted & APR_FINFO_LINK) ? APR_OPENLINK : 0), APR_OS_DEFAULT, cont)) == APR_SUCCESS) { rv = apr_file_info_get(finfo, wanted & ~(APR_FINFO_PROT | APR_FINFO_OWNER), thefile); finfo->filehand = NULL; apr_file_close(thefile); } } if (rv != APR_SUCCESS && rv != APR_INCOMPLETE) return (rv); /* We picked up this case above and had opened the link's properties */ if (wanted & APR_FINFO_LINK) finfo->valid |= APR_FINFO_LINK; finfo->fname = thefile->fname; return rv;}apr_status_t more_finfo(apr_finfo_t *finfo, const void *ufile, apr_int32_t wanted, int whatfile, apr_oslevel_e os_level){ PSID user = NULL, grp = NULL; PACL dacl = NULL; apr_status_t rv; if (os_level < APR_WIN_NT) { /* Read, write execute for owner. In the Win9x environment, any * readable file is executable (well, not entirely 100% true, but * still looking for some cheap logic that would help us here.) */ if (finfo->protection & APR_FREADONLY) { finfo->protection |= APR_WREAD | APR_WEXECUTE; } else { finfo->protection |= APR_WREAD | APR_WEXECUTE | APR_WWRITE; } finfo->protection |= (finfo->protection << prot_scope_group) | (finfo->protection << prot_scope_user); finfo->valid |= APR_FINFO_UPROT | APR_FINFO_GPROT | APR_FINFO_WPROT; } else if (wanted & (APR_FINFO_PROT | APR_FINFO_OWNER)) { /* On NT this request is incredibly expensive, but accurate. */ SECURITY_INFORMATION sinf = 0; PSECURITY_DESCRIPTOR pdesc = NULL; if (wanted & (APR_FINFO_USER | APR_FINFO_UPROT)) sinf |= OWNER_SECURITY_INFORMATION; if (wanted & (APR_FINFO_GROUP | APR_FINFO_GPROT)) sinf |= GROUP_SECURITY_INFORMATION; if (wanted & APR_FINFO_PROT) sinf |= DACL_SECURITY_INFORMATION; if (whatfile == MORE_OF_WFSPEC) rv = GetNamedSecurityInfoW((apr_wchar_t*)ufile, SE_FILE_OBJECT, sinf, ((wanted & APR_FINFO_USER) ? &user : NULL), ((wanted & APR_FINFO_GROUP) ? &grp : NULL), ((wanted & APR_FINFO_PROT) ? &dacl : NULL), NULL, &pdesc); else if (whatfile == MORE_OF_FSPEC) rv = GetNamedSecurityInfoA((char*)ufile, SE_FILE_OBJECT, sinf, ((wanted & APR_FINFO_USER) ? &user : NULL), ((wanted & APR_FINFO_GROUP) ? &grp : NULL), ((wanted & APR_FINFO_PROT) ? &dacl : NULL), NULL, &pdesc); else if (whatfile == MORE_OF_HANDLE) rv = GetSecurityInfo((HANDLE)ufile, SE_FILE_OBJECT, sinf, ((wanted & APR_FINFO_USER) ? &user : NULL), ((wanted & APR_FINFO_GROUP) ? &grp : NULL),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -