Changeset 5451 for trunk/Ohana/src/libohana
- Timestamp:
- Oct 27, 2005, 7:10:17 PM (21 years ago)
- Location:
- trunk/Ohana/src/libohana
- Files:
-
- 2 edited
-
include/ohana.h (modified) (1 diff)
-
src/findexec.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/libohana/include/ohana.h
r5273 r5451 118 118 int mkdirhier PROTO((char *path)); 119 119 void make_backup PROTO((char *filename)); 120 int check_file_access PROTO((char *basefile, int backup, int verbose)); 120 121 121 122 /* in glockfile.c */ -
trunk/Ohana/src/libohana/src/findexec.c
r4810 r5451 25 25 } 26 26 27 /* pathname 28 27 /* check that file can be written to: 28 - dir exists 29 - dir permissions OK 30 - file permissions OK, 31 - file backup permission OK (optional) 32 */ 33 int check_file_access (char *basefile, int BACKUP, int VERBOSE) { 34 35 char *path, *filename; 36 struct stat filestat; 37 uid_t uid; 38 gid_t gid; 39 int status, cmode; 40 41 uid = getuid(); 42 gid = getgid(); 43 44 /* check permission to write to directory */ 45 path = pathname (basefile); 46 status = stat (path, &filestat); 47 if (status == -1) { 48 if (VERBOSE) fprintf (stderr, "directory %s does not exist, creating...\n", path); 49 cmode = S_IRWXU | S_IRWXG | S_IRWXO; 50 status = mkdir (path, cmode); 51 if (status == -1) { 52 if (VERBOSE) fprintf (stderr, "can't create %s\n", path); 53 return (FALSE); 54 } 55 } 56 status = stat (path, &filestat); 57 if (((uid == filestat.st_uid) && (filestat.st_mode & S_IRWXU)) || 58 ((gid == filestat.st_gid) && (filestat.st_mode & S_IRWXG)) || 59 (filestat.st_mode & S_IRWXO)) { 60 } else { 61 if (VERBOSE) fprintf (stderr, "can't write to %s\n", path); 62 return (FALSE); 63 } 64 free (path); 65 66 /* check permission to write to file */ 67 status = stat (basefile, &filestat); 68 if (status == 0) { /* file exists, are permissions OK? */ 69 if (((uid == filestat.st_uid) && (filestat.st_mode & S_IRUSR) && (filestat.st_mode & S_IWUSR)) || 70 ((gid == filestat.st_gid) && (filestat.st_mode & S_IRGRP) && (filestat.st_mode & S_IWGRP)) || 71 ((filestat.st_mode & S_IROTH) && (filestat.st_mode & S_IWOTH))) { 72 } else { 73 if (VERBOSE) fprintf (stderr, "can't write to %s\n", basefile); 74 return (FALSE); 75 } 76 } 77 78 /* check permission to write to backup file */ 79 if (BACKUP) { 80 ALLOCATE (filename, char, strlen(basefile) + 2); 81 sprintf (filename, "%s~", basefile); 82 status = stat (filename, &filestat); 83 if (status == 0) { /* file exists, are permissions OK? */ 84 if (((uid == filestat.st_uid) && (filestat.st_mode & S_IRUSR) && (filestat.st_mode & S_IWUSR)) || 85 ((gid == filestat.st_gid) && (filestat.st_mode & S_IRGRP) && (filestat.st_mode & S_IWGRP)) || 86 ((filestat.st_mode & S_IROTH) && (filestat.st_mode & S_IWOTH))) { 87 } else { 88 if (VERBOSE) fprintf (stderr, "can't write to %s\n", filename); 89 return (FALSE); 90 } 91 } 92 free (filename); 93 } 94 return (TRUE); 95 } 96 97 /* pathname: 29 98 given path/filename, returns path 30 99 given just filename, returns .
Note:
See TracChangeset
for help on using the changeset viewer.
