/* * Intercept truncate() */ asmlinkage long my_sys_truncate(const char __user *path, long length) { long errno; int temp[4] = _NULL_BIT_; int len = length; int change_start; int change_end; int i; errno = orig_sys_truncate(path, length); if (errno < 0) { goto OUT; } change_start = len/Block_Size; if (change_start + _CHANGE_OFFSET_ > _CHANGE_MAX_) { change_start = _FILE_REST_; } else { change_start = change_start + _CHANGE_OFFSET_; } change_end = _FILE_REST_; for (i = change_start; i < change_end; i++) { set_bit(i, (void *)&temp); } set_bit(_FILE_MODIFY_BIT_ , (void *)&temp); process_file_name(path, temp); OUT: return errno; }
FILE *open_file(char *filename, char *old, size_t n, const char *mode, FILE *old_file) { /* * mode is something like "r" or "w" or "rb", as needed by fopen(), * and old_file is NULL normally, but can be a (FILE *) to indicate * the use of freopen rather than fopen. */ FILE *ff; process_file_name(filename, old, n); ce_print("Filename given as: "); ce_print(old); ce_print("\nConverted to: "); ce_print(filename); ce_print("\n"); if (*filename == 0) return NULL; #ifdef NO_BINARY_FOPEN /* * On some Unix implementations (I mean DECs version on its MIPS workstations * and on the microvax I tried) the library does not support "rb" and "wb" * modes, so I work around that here. Explicit selection of binary file * access will be needed on some non-Unix operating systems, but should * never be relevant under Unix, hence my choice of a flag for the conditional * compilation here. */ if (mode[0] == 'w') { if (mode[1] == '+') mode = "w+"; else mode = "w"; } else if (mode[1] == '+') mode = "r+"; else mode = "r"; /* That ought to patch it up */ #endif if (old_file == NULL) ff = fopen(filename, mode); else { fclose(old_file); ff = fopen(filename, mode); } /* * In suitable cases when the first attempt to open the file fails I * will try creating any necessary directories and then try again. */ if (ff==NULL && *mode=='w') { char *p = filename; while (*p != 0) { int ch = *p; if (ch == '/' || ch == '\\') { *p = 0; // Cmkdir(filename); CAN NOT DO THIS YET *p = ch; } p++; } if (old_file == NULL) ff = fopen(filename, mode); else { fclose(old_file); ff = fopen(filename, mode); } } return ff; }
int file_readable(char *filename, char *old, size_t n) { FILE *ff; process_file_name(filename, old, n); ff = fopen(filename, "r"); if (ff == NULL) return 0; fclose(ff); return 1; }
extern CSLbool file_exists(char *filename, char *old, size_t n, char *tt) { FILE *ff; process_file_name(filename, old, n); ff = fopen(filename, "r"); if (ff == NULL) return 0; fclose(ff); strcpy(tt, "Today"); return 1; }
/* * Intercept open() */ asmlinkage long my_sys_open(const char __user *filename, int flags, int mode) { long errno; int ret = 0; int temp[4] = _NULL_BIT_; ret = orig_sys_access(filename, _MY_MODE_); errno = orig_sys_open(filename, flags, mode); if (errno < 0) { goto OUT; } if (mode || O_EXCL) { set_bit(_FILE_CREATE_BIT_, (void *)&temp); process_file_name(filename, temp); goto OUT; } if (mode || O_CREAT) { if (ret < 0) { set_bit(_FILE_CREATE_BIT_, (void *)&temp); process_file_name(filename, temp); goto OUT; } } if (mode || O_TRUNC) { set_bit(_FILE_CREATE_BIT_, (void *)&temp); process_file_name(filename, temp); goto OUT; } OUT: return errno; }
/* * Intercept chmod() */ asmlinkage long my_sys_chmod(const char __user *filename, mode_t mode) { long errno; int temp[4] = _NULL_BIT_; errno = orig_sys_chmod(filename, mode); if (errno < 0) { goto OUT; } set_bit(_FILE_MODE_BIT_, (void *)&temp); process_file_name(filename, temp); OUT: return errno; }
/* * Intercept mkdir() */ asmlinkage long my_sys_mkdir(const char __user *pathname, umode_t mode) { long errno = 0; int temp[4] = _NULL_BIT_; errno = orig_sys_mkdir(pathname, mode); if (errno < 0) { goto OUT; } set_bit(_FILE_CREATE_BIT_, (void *)&temp); process_file_name(pathname, temp); OUT: return errno; }
/* * Intercept utimes() */ asmlinkage long my_sys_utimes(char __user *filename, struct timeval __user *times) { long errno; int temp[4] = _NULL_BIT_; errno = orig_sys_utimes(filename, times); if (errno < 0) { goto OUT; } set_bit(_FILE_TIME_BIT_, (void *)&temp); process_file_name(filename, temp); OUT: return errno; }
/* * Have overwritten chown32 as that is the one which is called * for this architecture */ asmlinkage long my_sys_chown(const char __user *filename, uid_t user, gid_t group) { long errno; int temp[4] = _NULL_BIT_; errno = orig_sys_chown(filename, user, group); if (errno < 0) { goto OUT; } set_bit(_FILE_OWNER_BIT_, (void *)&temp); process_file_name(filename, temp); OUT: return errno; }
/* * Intercept rename() */ asmlinkage long my_sys_rename(const char __user *oldname, const char __user *newname) { long errno; int temp[4] = _NULL_BIT_; errno = orig_sys_rename(oldname, newname); if (errno < 0) { goto OUT; } set_bit(_FILE_RENAME_BIT_, (void *)&temp); process_file_name(newname, temp); OUT: return errno; }
/* * Intercept utimensat() */ asmlinkage long my_sys_utimensat(int dfd, const char __user *filename, struct timespec __user *utimes, int flags) { long errno = -EINVAL; int temp[4] = _NULL_BIT_; errno = (*orig_sys_utimensat)(dfd, filename, utimes, flags); if (errno < 0) { goto OUT; } set_bit(_FILE_TIME_BIT_, (void *)&temp); process_file_name(filename, temp); OUT: return errno; }
char *get_truename(char *filename, char *old, size_t n) { process_file_name(filename, old, n); return filename; }
int directoryp(char *filename, char *old, size_t n) { process_file_name(filename, old, n); return 0; }
int file_writeable(char *filename, char *old, size_t n) { process_file_name(filename, old, n); return 1; }