static int get_directory_owner(const char *path, char *owner) { char aclpath[CHIRP_PATH_MAX]; char tmp[CHIRP_LINE_MAX]; char *r; CHIRP_FILE *file; int result; sprintf(aclpath, "%s/.__acl", path); file = cfs_fopen(aclpath, "r"); if(!file) return -1; r = cfs_fgets(tmp, sizeof(tmp), file); if(!r) return -1; result = sscanf(tmp, "%[^ \t\n]", owner); cfs_fclose(file); if(result == 1) { return 0; } else { return -1; } }
int chirp_acl_read(CHIRP_FILE * aclfile, char *subject, int *flags) { char acl[CHIRP_LINE_MAX]; char tmp[CHIRP_LINE_MAX]; while(cfs_fgets(acl, sizeof(acl), aclfile)) { if(sscanf(acl, "%[^ ] %[rwldpvax()]", subject, tmp) == 2) { *flags = chirp_acl_text_to_flags(tmp); return 1; } else { continue; } } return 0; }
char *cfs_fgets(char *s, int n, CHIRP_FILE * file) { char *current = s; INT64_T i, empty = file->f.cfile.read_n == 0; if(file->type == LOCAL) return fgets(s, n, file->f.lfile); for(i = 0; i < file->f.cfile.read_n; i++) if(i + 2 >= n || file->f.cfile.read[i] == '\n') { /* we got data now */ memcpy(s, file->f.cfile.read, i + 1); s[i + 1] = '\0'; memmove(file->f.cfile.read, file->f.cfile.read + i + 1, (file->f.cfile.read_n -= i + 1)); return s; } memcpy(current, file->f.cfile.read, i); current += i; n -= i; file->f.cfile.read_n = 0; i = cfs->pread(file->f.cfile.fd, file->f.cfile.read, CHIRP_FILESYSTEM_BUFFER - 1, file->f.cfile.offset); if(i == -1) { file->f.cfile.error = errno; return 0; } else if(i == 0 && empty) { return NULL; } else if(i == 0) { return s; } file->f.cfile.read_n += i; file->f.cfile.offset += i; if(cfs_fgets(current, n, file) == NULL) /* some error */ return NULL; else return s; }