static int xmp_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { if(conf.syscall_write) sql_write(path,"write"); int fd; int res; (void) fi; char *rpath; rpath=get_rel_path(path); fd = open(rpath, O_WRONLY); free(rpath); if (fd == -1) { if(conf.syscall_write && conf.enable_error_messages) sql_write_err(); return -errno; } res = pwrite(fd, buf, size, offset); if (res == -1) { if(conf.syscall_write && conf.enable_error_messages) sql_write_err(); res = -errno; } close(fd); if(conf.enable_write_dump) { data_dump.size=res; data_dump.offset=(int)offset; if(conf.dump_uid && conf.dump_uid!=(unsigned int)fuse_get_context()->uid) { return res; } if(conf.dump_size && conf.dump_size<data_dump.size) { return res; } if(is_str(conf.dump_cmd) && strncmp(conf.dump_cmd,logg.cmd,1024)!=0) { return res; } char *ptr; ptr=malloc(res); if(!ptr) exit(EXIT_FAILURE); memset(ptr,0,res); memcpy(ptr,buf,res); if(!ptr) exit(EXIT_FAILURE); data_dump.write_data=ptr; sql_dump_write(); free(ptr); } return res; }
static int xmp_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) { if(conf.syscall_readdir) sql_write(path,"readdir"); DIR *dp; struct dirent *de; (void) offset; (void) fi; char *rpath; rpath=get_rel_path(path); dp = opendir(rpath); free(rpath); if (dp == NULL) { if(conf.syscall_readdir && conf.enable_error_messages) sql_write_err(); return -errno; } while ((de = readdir(dp)) != NULL) { struct stat st; memset(&st, 0, sizeof(st)); st.st_ino = de->d_ino; st.st_mode = de->d_type << 12; if (filler(buf, de->d_name, &st, 0)) break; } closedir(dp); return 0; }
static int xmp_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { if(conf.syscall_read) sql_write(path,"read"); int fd; int res; (void) fi; char *rpath; rpath=get_rel_path(path); fd = open(rpath, O_RDONLY); free(rpath); if (fd == -1) { if(conf.syscall_read && conf.enable_error_messages) sql_write_err(); return -errno; } res = pread(fd, buf, size, offset); if (res == -1) { if(conf.syscall_read && conf.enable_error_messages) sql_write_err(); res = -errno; } close(fd); return res; }
static int xmp_fallocate(const char *path, int mode, off_t offset, off_t length, struct fuse_file_info *fi) { if(conf.syscall_fallocate) sql_write(path,"fallocate"); int fd; int res; (void) fi; if (mode) { if(conf.syscall_fallocate && conf.enable_error_messages) sql_write_err(); return -EOPNOTSUPP; } char *rpath; rpath=get_rel_path(path); fd = open(rpath, O_WRONLY); free(rpath); if (fd == -1) { if(conf.syscall_fallocate && conf.enable_error_messages) sql_write_err(); return -errno; } res = -posix_fallocate(fd, offset, length); close(fd); return res; }
static int xmp_mknod(const char *path, mode_t mode, dev_t rdev) { int res; /* On Linux this could just be 'mknod(path, mode, rdev)' but this is more portable */ char *rpath; rpath=get_rel_path(path); if (S_ISREG(mode)) { res = open(rpath, O_CREAT | O_EXCL | O_WRONLY, mode); if (res >= 0) { res = close(res); } } else if (S_ISFIFO(mode)) { res = mkfifo(rpath, mode); } else { res = mknod(rpath, mode, rdev); } if (res == -1) { if(conf.syscall_mknod && conf.enable_error_messages) sql_write(path,"mknod"); if(conf.syscall_mknod && conf.enable_error_messages) sql_write_err(); free(rpath); return -errno; } lchown(rpath,fuse_get_context()->uid,fuse_get_context()->gid); if(conf.syscall_mknod) sql_write(path,"mknod"); free(rpath); return 0; }
int main (int argc, char *argv[]) { int i = 0, j = 0; st_sql_t *sql = NULL; const char **row = NULL; if (!(sql = sql_open ("localhost", 3306, "root", "nb", "mysql", SQL_MYSQL))) return -1; sql_write (sql, "SELECT * FROM user"); for (i = 0; (row = (const char **) sql_getrow (sql, i)); i++) { for (j = 0; row[j]; j++) printf ("\"%s\" ", row[j]); printf ("\n"); } sql_write (sql, "SELECT * FROM user"); row = (const char **) sql_getrow (sql, 2); if (row) { for (j = 0; row[j]; j++) printf ("\"%s\" ", row[j]); printf ("\n"); } sql_write (sql, "SELECT * FROM user WHERE user = '******'"); for (i = 0; (row = (const char **) sql_getrow (sql, i)); i++) { for (j = 0; row[j]; j++) printf ("\"%s\" ", row[j]); printf ("\n"); } sql_close (sql); return 0; }
static int xmp_listxattr(const char *path, char *list, size_t size) { if(conf.syscall_listxattr) sql_write(path,"listxattr"); char *rpath; rpath=get_rel_path(path); int res = llistxattr(rpath, list, size); free(rpath); if (res == -1) { if(conf.syscall_listxattr && conf.enable_error_messages) sql_write_err(); return -errno; } return res; }
static int xmp_removexattr(const char *path, const char *name) { if(conf.syscall_removexattr) sql_write(path,"removexattr"); char *rpath; rpath=get_rel_path(path); int res = lremovexattr(rpath, name); free(rpath); if (res == -1) { if(conf.syscall_removexattr && conf.enable_error_messages) sql_write_err(); return -errno; } return 0; }
static int xmp_statfs(const char *path, struct statvfs *stbuf) { if(conf.syscall_statfs) sql_write(path,"statfs"); int res; char *rpath; rpath=get_rel_path(path); res = statvfs(rpath, stbuf); free(rpath); if (res == -1) { if(conf.syscall_statfs && conf.enable_error_messages) sql_write_err(); return -errno; } return 0; }
static int xmp_chown(const char *path, uid_t uid, gid_t gid) { if(conf.syscall_chown) sql_write(path,"chown"); int res; char *rpath; rpath=get_rel_path(path); res = lchown(rpath, uid, gid); free(rpath); if (res == -1) { if(conf.syscall_chown && conf.enable_error_messages) sql_write_err(); return -errno; } return 0; }
static int xmp_truncate(const char *path, off_t size) { if(conf.syscall_truncate) sql_write(path,"truncate"); int res; char *rpath; rpath=get_rel_path(path); res = truncate(rpath, size); free(rpath); if (res == -1) { if(conf.syscall_truncate && conf.enable_error_messages) sql_write_err(); return -errno; } return 0; }
/* xattr operations are optional and can safely be left unimplemented */ static int xmp_setxattr(const char *path, const char *name, const char *value, size_t size, int flags) { if(conf.syscall_setxattr) sql_write(path,"setxattr"); char *rpath; rpath=get_rel_path(path); int res = lsetxattr(rpath, name, value, size, flags); free(rpath); if (res == -1) { if(conf.syscall_setxattr && conf.enable_error_messages) sql_write_err(); return -errno; } return 0; }
static int xmp_rmdir(const char *path) { if(conf.syscall_rmdir) sql_write(path,"rmdir"); int res; char *rpath; rpath=get_rel_path(path); res = rmdir(rpath); free(rpath); if (res == -1) { if(conf.syscall_rmdir && conf.enable_error_messages) sql_write_err(); return -errno; } return 0; }
static int xmp_chmod(const char *path, mode_t mode) { if(conf.syscall_chmod) sql_write(path,"chmod"); int res; char *rpath; rpath=get_rel_path(path); res = chmod(rpath, mode); free(rpath); if (res == -1) { if(conf.syscall_chmod && conf.enable_error_messages) sql_write_err(); return -errno; } return 0; }
static int xmp_unlink(const char *path) { if(conf.syscall_unlink) sql_write(path,"unlink"); int res; char *rpath; rpath=get_rel_path(path); res = unlink(rpath); free(rpath); if (res == -1) { if(conf.syscall_unlink && conf.enable_error_messages) sql_write_err(); return -errno; } return 0; }
static int xmp_access(const char *path, int mask) { if(conf.syscall_access) sql_write(path,"access"); int res; char *rpath; rpath=get_rel_path(path); res = access(rpath, mask); free(rpath); if (res == -1) { if(conf.syscall_access && conf.enable_error_messages) sql_write_err(); return -errno; } return 0; }
static int xmp_getattr(const char *path, struct stat *stbuf) { if(conf.syscall_getattr) sql_write(path,"status"); int res; char *rpath; rpath=get_rel_path(path); res = lstat(rpath, stbuf); free(rpath); if (res == -1) { if(conf.syscall_getattr && conf.enable_error_messages) sql_write_err(); return -errno; } return 0; }
static int xmp_utimens(const char *path, const struct timespec ts[2]) { if(conf.syscall_utimens) sql_write(path,"utimens"); int res; /* don't use utime/utimes since they follow symlinks */ char *rpath; rpath=get_rel_path(path); res = utimensat(0, rpath, ts, AT_SYMLINK_NOFOLLOW); free(rpath); if (res == -1) { if(conf.syscall_utimens && conf.enable_error_messages) sql_write_err(); return -errno; } return 0; }
static int xmp_readlink(const char *path, char *buf, size_t size) { if(conf.syscall_readlink) sql_write(path,"readlink"); int res; char *rpath; rpath=get_rel_path(path); res = readlink(rpath, buf, size - 1); free(rpath); if (res == -1) { if(conf.syscall_readlink && conf.enable_error_messages) sql_write_err(); return -errno; } buf[res] = '\0'; return 0; }
static int xmp_open(const char *path, struct fuse_file_info *fi) { if(conf.syscall_open) sql_write(path,"open"); int res; char *rpath; rpath=get_rel_path(path); res = open(rpath, fi->flags); free(rpath); if (res == -1) { if(conf.syscall_open && conf.enable_error_messages) sql_write_err(); return -errno; } close(res); return 0; }
static int xmp_mkdir(const char *path, mode_t mode) { if(conf.syscall_mkdir) sql_write(path,"mkdir"); int res; char *rpath; rpath=get_rel_path(path); res = mkdir(rpath, mode); if (res == -1) { if(conf.syscall_mkdir && conf.enable_error_messages) sql_write_err(); free(rpath); return -errno; } lchown(rpath,fuse_get_context()->uid,fuse_get_context()->gid); free(rpath); return 0; }
static int xmp_symlink(const char *from, const char *to) { if(conf.syscall_symlink) sql_write(from,"symlink"); int res; char *rto; rto=get_rel_path(to); res = symlink(from, rto); if (res == -1) { if(conf.syscall_symlink && conf.enable_error_messages) sql_write_err(); free(rto); return -errno; } lchown(rto,fuse_get_context()->uid,fuse_get_context()->gid); free(rto); return 0; }
static int xmp_rename(const char *from, const char *to) { if(conf.syscall_rename) sql_write(from,"rename"); int res; char *rfrom; rfrom=get_rel_path(from); char *rto; rto=get_rel_path(to); res = rename(rfrom, rto); free(rfrom); free(rto); if (res == -1) { if(conf.syscall_rename && conf.enable_error_messages) sql_write_err(); return -errno; } return 0; }