[Cvs-nserver-commits] CVS: cvs-nserver/acl dir-acl.c,1.1.2.21,1.1.2.22 dir-acl.h,1.1.2.11,1.1.2.12
Brought to you by:
tyranny
From: Alexey M. <ty...@us...> - 2002-06-09 11:42:57
|
Update of /cvsroot/cvs-nserver/cvs-nserver/acl In directory usw-pr-cvs1:/tmp/cvs-serv12159 Modified Files: Tag: NCLI-1-11-1 dir-acl.c dir-acl.h Log Message: Rename internal_get_dir_acl() to add_dir_acl_topdirs(); refactor; plug memory leaks; better error handling; document Index: dir-acl.c =================================================================== RCS file: /cvsroot/cvs-nserver/cvs-nserver/acl/Attic/dir-acl.c,v retrieving revision 1.1.2.21 retrieving revision 1.1.2.22 diff -u -d -r1.1.2.21 -r1.1.2.22 --- dir-acl.c 9 Jun 2002 00:36:49 -0000 1.1.2.21 +++ dir-acl.c 9 Jun 2002 11:42:55 -0000 1.1.2.22 @@ -128,9 +128,8 @@ return current_default_dir_perm; } -static DIR_ACL *create_and_load_dir_acl (char *dir); -static DIR_ACL *internal_get_dir_acl (char *dir, char *branch, - struct DIR_ACL *the_dir_acl); +static struct DIR_ACL *create_and_load_dir_acl (char *dir); +static struct DIR_ACL *add_dir_acl_topdirs (char *dir, struct DIR_ACL *the_dir_acl); struct DIR_ACL * @@ -143,15 +142,16 @@ if (strncmp(dir, current_toplevel_directory, strlen(current_toplevel_directory)) != 0) goto out; - dir_copy = strdup(dir); - if (dir_copy == NULL) - goto err; - dir_acl = create_and_load_dir_acl(dir); if (!dir_acl) goto err; - if (!internal_get_dir_acl(dir_copy, branch, dir_acl)) + /* add_dir_acl_topdirs() will modify its first argument */ + dir_copy = strdup(dir); + if (dir_copy == NULL) + goto err; + + if (!add_dir_acl_topdirs(dir_copy, dir_acl)) goto err; out: @@ -195,15 +195,30 @@ } -static DIR_ACL * -internal_get_dir_acl (char *dir, char *branch, struct DIR_ACL *the_dir_acl) +/*! \fn struct DIR_ACL* add_dir_acl_topdirs (char* dir, struct DIR_ACL* the_dir_acl) + + \brief Adds parent directories of specified directory to \c the_dir_acl->top_dirs + + \param dir Full path to the directory that corresponds to \c + the_dir_acl. This argument will be modified inplace, so it should be + temporary \c strdup()'ed copy. + + \param the_dir_acl \c "struct DIR_ACL", whose \c top_dirs field will + be filled with DIR_ACL's for parent directories. + + \retval the_dir_acl if all was Ok. + + \retval NULL if memory allocation failed or \c + create_and_load_dir_acl() returned error. + +*/ + +static struct DIR_ACL * +add_dir_acl_topdirs (char *dir, struct DIR_ACL *the_dir_acl) { int toplevel_len = strlen(current_toplevel_directory); char *last_component; - if (the_dir_acl == NULL) - return NULL; - /* FIXME: somehow the parent directory gets added twice. It is harmless, but needs investigation */ @@ -211,17 +226,25 @@ if (last_component == NULL) { /* we are processing the top dir */ struct DIR_ACL *topdir_acl = create_and_load_dir_acl(dir); + if (!topdir_acl) + return NULL; - add_dir_to_path(the_dir_acl, topdir_acl); + if (!add_dir_to_path(the_dir_acl, topdir_acl)) + return NULL; } else { /* we need to strip the last component and try to get its top dir */ struct DIR_ACL *this_dir_acl; *last_component = '\0'; this_dir_acl = create_and_load_dir_acl(dir); - add_dir_to_path(the_dir_acl, this_dir_acl); + if (!this_dir_acl) + return NULL; - internal_get_dir_acl(dir, branch, the_dir_acl); + if (!add_dir_to_path(the_dir_acl, this_dir_acl)) + return NULL; + + if (!add_dir_acl_topdirs(dir, the_dir_acl)) + return NULL; *last_component = '/'; } @@ -264,10 +287,16 @@ void destroy_dir_acl (struct DIR_ACL* dir_acl) { + int i; + if (!dir_acl) return; free_stringbuf(dir_acl->dirname); + free_user_acls(dir_acl->user_acls); + for (i = 0; i < dir_acl->top_dirs_count; i++) { + destroy_dir_acl(dir_acl->top_dirs[i]); + } free(dir_acl->top_dirs); free(dir_acl); } @@ -278,7 +307,7 @@ /*! \fn struct DIR_ACL* create_and_load_dir_acl (char* dir) - \brief Creates struct DIR_ACL for specified directory and loads its + \brief Creates \c "struct DIR_ACL" for specified directory and loads its access control list. \param dir Full path to a directory @@ -288,8 +317,8 @@ \retval NULL if: - memory allocation failed; - specified directory does not exist (\c errno is set to \c ENOENT); - - too long line in the DIRACL file (\c errno is set to \c E2BIG); - - invalid line format in the DIRACL file (\c errno is set to \c EINVAL); + - too long line in the \c DIRACL file (\c errno is set to \c E2BIG); + - invalid line format in the \c DIRACL file (\c errno is set to \c EINVAL); */ @@ -597,7 +626,7 @@ static int -internal_store_dir_acl (int fd, DIR_ACL *dir_acl) +internal_store_dir_acl (int fd, struct DIR_ACL *dir_acl) { int retval = -1; struct stringbuf *line = NULL; @@ -635,7 +664,7 @@ } static int -internal_store_default_file_acl (FILE *acl_file, DIR_ACL *dir_acl) +internal_store_default_file_acl (FILE *acl_file, struct DIR_ACL *dir_acl) { struct DEFAULT_FILE_ACL *dfa = dir_acl->default_file_acl; @@ -773,7 +802,7 @@ static struct DEFAULT_FILE_ACL * -get_default_file_acl (DIR_ACL *dir_acl, char *branch) +get_default_file_acl (struct DIR_ACL *dir_acl, char *branch) { struct DEFAULT_FILE_ACL *current = dir_acl->default_file_acl; @@ -788,7 +817,7 @@ } struct USER_ACL * -get_default_file_user_acl (DIR_ACL *dir_acl, char *branch) +get_default_file_user_acl (struct DIR_ACL *dir_acl, char *branch) { struct DEFAULT_FILE_ACL *dfa = get_default_file_acl(dir_acl, branch); if (dfa == NULL) @@ -798,7 +827,7 @@ } int -set_default_file_acl (DIR_ACL *dir_acl, char *branch, char *username, int perm) +set_default_file_acl (struct DIR_ACL *dir_acl, char *branch, char *username, int perm) { struct DEFAULT_FILE_ACL *dfa; struct USER_ACL *new_acls; Index: dir-acl.h =================================================================== RCS file: /cvsroot/cvs-nserver/cvs-nserver/acl/Attic/dir-acl.h,v retrieving revision 1.1.2.11 retrieving revision 1.1.2.12 diff -u -d -r1.1.2.11 -r1.1.2.12 --- dir-acl.h 9 Jun 2002 00:36:49 -0000 1.1.2.11 +++ dir-acl.h 9 Jun 2002 11:42:55 -0000 1.1.2.12 @@ -97,6 +97,8 @@ int branch_acls_loaded; }; +typedef struct DIR_ACL DIR_ACL; + enum DIR_PERM { dir_perm_none = 0x00, dir_perm_access = 0x01, @@ -105,8 +107,6 @@ dir_perm_all = dir_perm_access | dir_perm_modify }; -typedef struct DIR_ACL DIR_ACL; - typedef int dir_permission; void set_toplevel_directory(char *toplevel_dir); @@ -131,8 +131,8 @@ int store_dir_acl (struct DIR_ACL *dir_acl); -int set_default_file_acl (DIR_ACL *dir_acl, char *branch, char *username, int perm); +int set_default_file_acl (struct DIR_ACL *dir_acl, char *branch, char *username, int perm); -struct USER_ACL *get_default_file_user_acl(DIR_ACL *dir_acl, char *branch); +struct USER_ACL *get_default_file_user_acl(struct DIR_ACL *dir_acl, char *branch); #endif /* DIR_ACL_H */ |