00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021
00022 #include <sys/types.h>
00023 #include <sys/stat.h>
00024
00025 #include <errno.h>
00026
00027 #include "errno2result.h"
00028
00029
00030
00031
00032
00033 #include "../fsaccess.c"
00034
00035 isc_result_t
00036 isc_fsaccess_set(const char *path, isc_fsaccess_t access) {
00037 struct stat statb;
00038 mode_t mode;
00039 isc_boolean_t is_dir = ISC_FALSE;
00040 isc_fsaccess_t bits;
00041 isc_result_t result;
00042
00043 if (stat(path, &statb) != 0)
00044 return (isc__errno2result(errno));
00045
00046 if ((statb.st_mode & S_IFDIR) != 0)
00047 is_dir = ISC_TRUE;
00048 else if ((statb.st_mode & S_IFREG) == 0)
00049 return (ISC_R_INVALIDFILE);
00050
00051 result = check_bad_bits(access, is_dir);
00052 if (result != ISC_R_SUCCESS)
00053 return (result);
00054
00055
00056
00057
00058 mode = 0;
00059
00060 #define SET_AND_CLEAR1(modebit) \
00061 if ((access & bits) != 0) { \
00062 mode |= modebit; \
00063 access &= ~bits; \
00064 }
00065 #define SET_AND_CLEAR(user, group, other) \
00066 SET_AND_CLEAR1(user); \
00067 bits <<= STEP; \
00068 SET_AND_CLEAR1(group); \
00069 bits <<= STEP; \
00070 SET_AND_CLEAR1(other);
00071
00072 bits = ISC_FSACCESS_READ | ISC_FSACCESS_LISTDIRECTORY;
00073
00074 SET_AND_CLEAR(S_IRUSR, S_IRGRP, S_IROTH);
00075
00076 bits = ISC_FSACCESS_WRITE |
00077 ISC_FSACCESS_CREATECHILD |
00078 ISC_FSACCESS_DELETECHILD;
00079
00080 SET_AND_CLEAR(S_IWUSR, S_IWGRP, S_IWOTH);
00081
00082 bits = ISC_FSACCESS_EXECUTE |
00083 ISC_FSACCESS_ACCESSCHILD;
00084
00085 SET_AND_CLEAR(S_IXUSR, S_IXGRP, S_IXOTH);
00086
00087 INSIST(access == 0);
00088
00089 if (chmod(path, mode) < 0)
00090 return (isc__errno2result(errno));
00091
00092 return (ISC_R_SUCCESS);
00093 }