[Cvs-nserver-commits] CVS: cvs-nserver/acl check_dir_acl.c,1.1.2.9,1.1.2.10 dir-acl.c,1.1.2.20,1.1.2
Brought to you by:
tyranny
From: Alexey M. <ty...@us...> - 2002-06-09 00:36:55
|
Update of /cvsroot/cvs-nserver/cvs-nserver/acl In directory usw-pr-cvs1:/tmp/cvs-serv5678 Modified Files: Tag: NCLI-1-11-1 check_dir_acl.c dir-acl.c dir-acl.h Log Message: Refactor; plug memory leaks; fix error handling Index: check_dir_acl.c =================================================================== RCS file: /cvsroot/cvs-nserver/cvs-nserver/acl/Attic/check_dir_acl.c,v retrieving revision 1.1.2.9 retrieving revision 1.1.2.10 diff -u -d -r1.1.2.9 -r1.1.2.10 --- check_dir_acl.c 7 Jun 2002 13:18:36 -0000 1.1.2.9 +++ check_dir_acl.c 9 Jun 2002 00:36:49 -0000 1.1.2.10 @@ -64,6 +64,8 @@ topdir_acl = get_dir_acl("./nosuchdir", "trunk"); assert(topdir_acl == NULL); assert(errno == ENOENT); + + destroy_dir_acl(topdir_acl); } @@ -87,6 +89,8 @@ /* set default dir permissions back to all */ set_default_dir_perm(dir_perm_all); + + destroy_dir_acl(topdir_acl); } static void @@ -116,6 +120,8 @@ set_default_dir_perm(dir_perm_all); assert(dir_permission_granted(topdir_acl, "mike", dir_perm_access)); assert(dir_permission_granted(topdir_acl, "mike", dir_perm_modify)); + + destroy_dir_acl(topdir_acl); } static void @@ -133,6 +139,7 @@ perror("Storing dir ACL"); exit(1); } + destroy_dir_acl(topdir_acl); topdir_acl = get_dir_acl("./test-acl", "trunk"); assert(topdir_acl); @@ -163,12 +170,14 @@ perror("Storing dir ACL"); exit(1); } + destroy_dir_acl(topdir_acl); topdir_acl = get_dir_acl("./test-acl", "trunk"); assert(topdir_acl); assert(!dir_permission_granted(topdir_acl, "bob", dir_perm_access)); assert(!dir_permission_granted(topdir_acl, "bob", dir_perm_modify)); + destroy_dir_acl(topdir_acl); } int Index: dir-acl.c =================================================================== RCS file: /cvsroot/cvs-nserver/cvs-nserver/acl/Attic/dir-acl.c,v retrieving revision 1.1.2.20 retrieving revision 1.1.2.21 diff -u -d -r1.1.2.20 -r1.1.2.21 --- dir-acl.c 9 Jun 2002 00:12:39 -0000 1.1.2.20 +++ dir-acl.c 9 Jun 2002 00:36:49 -0000 1.1.2.21 @@ -132,19 +132,37 @@ static DIR_ACL *internal_get_dir_acl (char *dir, char *branch, struct DIR_ACL *the_dir_acl); -DIR_ACL * + +struct DIR_ACL * get_dir_acl (char *dir, char *branch) { - struct DIR_ACL *dir_acl = create_and_load_dir_acl(dir); - char *dir_copy = strdup(dir); + struct DIR_ACL *dir_acl = NULL; + char *dir_copy = NULL; + + /* check that requested directory derives from top-level directory */ + if (strncmp(dir, current_toplevel_directory, strlen(current_toplevel_directory)) != 0) + goto out; + + dir_copy = strdup(dir); if (dir_copy == NULL) - return NULL; + goto err; - internal_get_dir_acl(dir_copy, branch, dir_acl); + dir_acl = create_and_load_dir_acl(dir); + if (!dir_acl) + goto err; + if (!internal_get_dir_acl(dir_copy, branch, dir_acl)) + goto err; + + out: free(dir_copy); return dir_acl; + + err: + destroy_dir_acl(dir_acl); + dir_acl = NULL; + goto out; } @@ -183,10 +201,6 @@ int toplevel_len = strlen(current_toplevel_directory); char *last_component; - /* check that requested directory derives from top-level directory */ - if (strncmp(dir, current_toplevel_directory, toplevel_len) != 0) - return NULL; - if (the_dir_acl == NULL) return NULL; @@ -237,22 +251,24 @@ return NULL; dir_acl->dirname = new_stringbuf(dir); - if (dir_acl->dirname == NULL) { - free(dir_acl); - return NULL; - } + if (!dir_acl->dirname) + goto err; return dir_acl; + err: + destroy_dir_acl(dir_acl); + return NULL; } -static void +void destroy_dir_acl (struct DIR_ACL* dir_acl) { if (!dir_acl) return; free_stringbuf(dir_acl->dirname); + free(dir_acl->top_dirs); free(dir_acl); } @@ -680,6 +696,7 @@ retval = 0; out: + free_stringbuf(filename); free_stringbuf(tmpfilename); return retval; Index: dir-acl.h =================================================================== RCS file: /cvsroot/cvs-nserver/cvs-nserver/acl/Attic/dir-acl.h,v retrieving revision 1.1.2.10 retrieving revision 1.1.2.11 diff -u -d -r1.1.2.10 -r1.1.2.11 --- dir-acl.h 8 Jun 2002 23:30:01 -0000 1.1.2.10 +++ dir-acl.h 9 Jun 2002 00:36:49 -0000 1.1.2.11 @@ -114,7 +114,9 @@ void set_default_dir_perm (enum DIR_PERM new_perm); enum DIR_PERM get_default_dir_perm (void); -DIR_ACL *get_dir_acl(char *dir, char *branch); +struct DIR_ACL *get_dir_acl(char *dir, char *branch); +void destroy_dir_acl (struct DIR_ACL* dir_acl); + int load_branch_acls(struct DIR_ACL *dir_acl); int store_branch_acls (struct DIR_ACL *dir_acl); |