[Cvs-nserver-commits] CVS: cvs-nserver/src ls.c,1.1.2.13,1.1.2.14 lsmodules.c,1.1.2.7,1.1.2.8
Brought to you by:
tyranny
From: Alexey M. <mo...@us...> - 2002-06-13 13:43:01
|
Update of /cvsroot/cvs-nserver/cvs-nserver/src In directory usw-pr-cvs1:/tmp/cvs-serv17477 Modified Files: Tag: NCLI-1-11-1 ls.c lsmodules.c Log Message: Code cleanups and small bugfixes for lsmodules.c Index: ls.c =================================================================== RCS file: /cvsroot/cvs-nserver/cvs-nserver/src/Attic/ls.c,v retrieving revision 1.1.2.13 retrieving revision 1.1.2.14 diff -u -d -r1.1.2.13 -r1.1.2.14 --- ls.c 4 Jun 2002 08:02:44 -0000 1.1.2.13 +++ ls.c 13 Jun 2002 13:42:49 -0000 1.1.2.14 @@ -10,6 +10,8 @@ General Public License for more details. Copyright (c) Alexey Mahotkin <al...@hs...> 2001 + Alexey Morozov <mo...@no...>, + Novosoft, Inc. 2002 "ls" subcommand gives a listing of specified directory in repository @@ -20,8 +22,6 @@ #include "ls.h" -#include "stringbuf.h" - #include "cvs.h" #include "acl.h" #include "recurse.h" @@ -45,7 +45,6 @@ static int deep = 0; static struct DIR_ACL *dir_acl = NULL; - /* ARGSUSED */ static Dtype ls_dirproc (callerdat, dir, repository, update_dir, entries) @@ -77,21 +76,7 @@ cvs_output("D/", 2); cvs_output(update_dir,0); cvs_output("//",2); - if (perm == dir_perm_none) { - cvs_output("none",0); - } else { - int need_comma = 0; - if (perm & dir_perm_access) { - cvs_output("access",0); - need_comma = 1; - } - if (perm & dir_perm_modify) { - if (need_comma) - cvs_output(",modify",0); - else - cvs_output("modify",0); - } - } + cvs_output(dir_permissions_string(perm),0); cvs_output("\n", 1); #ifdef SERVER_SUPPORT @@ -116,7 +101,6 @@ return 0; } - int ls_fileproc (void *callerdat, struct file_info *finfo) { @@ -128,7 +112,6 @@ struct BRANCH_ACL *branch_acl; struct BRANCH_ACE *branch_ace; char timestamp[32]; - int ts_len; int single_file; char *xbranch = (tagname) ? tagname : "trunk"; int perm; @@ -136,8 +119,11 @@ #ifdef SERVER_SUPPORT if (dir_acl == NULL) { - if ((dir_acl = get_dir_acl(finfo->repository,xbranch)) == NULL) - error(1, 0, "Error getting directory ACL for %s: %s", finfo->repository, strerror(errno)); + if ((dir_acl = get_dir_acl(finfo->repository,xbranch)) == NULL) { + error(0, errno, + "Error getting directory ACL for %s", finfo->repository); + return 1; + } single_file = 1; } #endif @@ -185,22 +171,7 @@ perm = branch_perm_all; #endif - if (perm == branch_perm_none) { - cvs_output("none",0); - } else { - int need_comma = 0; - if (perm & branch_perm_checkout) { - cvs_output("checkout",0); - need_comma = 1; - } - if (perm & branch_perm_checkin) { - if (need_comma) - cvs_output(",checkin",0); - else - cvs_output("checkin",0); - } - } - + cvs_output(branch_permissions_string(perm),0); cvs_output("/",1); @@ -228,7 +199,6 @@ server_side_ls (int argc, char **argv) { int err = 0; - int i; err += ls_proc (argc , argv, (char *) NULL, (char *) NULL, (char *) NULL, 0, (char *) NULL,(char *) NULL); Index: lsmodules.c =================================================================== RCS file: /cvsroot/cvs-nserver/cvs-nserver/src/Attic/lsmodules.c,v retrieving revision 1.1.2.7 retrieving revision 1.1.2.8 diff -u -d -r1.1.2.7 -r1.1.2.8 --- lsmodules.c 4 Jun 2002 08:02:44 -0000 1.1.2.7 +++ lsmodules.c 13 Jun 2002 13:42:49 -0000 1.1.2.8 @@ -8,7 +8,6 @@ #include "acl.h" #include "cvs.h" #include "lsmodules.h" -#include "stringbuf.h" #include "recurse.h" static const char *const lsmodules_usage[] = @@ -34,29 +33,15 @@ static void lsmodules_print(const char *module, int perm) { -#if 1 - cvs_output("D/", 2); -#endif if (mod_list != ALL_MOD_LIST && perm == dir_perm_none) return; +#if 1 + cvs_output("D/", 2); +#endif cvs_output(module,0); cvs_output("//",2); - if (perm == dir_perm_none) { - cvs_output("none",0); - } else { - int need_comma = 0; - if (perm & dir_perm_access) { - cvs_output("access",0); - need_comma = 1; - } - if (perm & dir_perm_modify) { - if (need_comma) - cvs_output(",modify",0); - else - cvs_output("modify",0); - } - } + cvs_output(dir_permissions_string(perm), 0); cvs_output("\n", 1); } @@ -74,8 +59,10 @@ int perm; char *xbranch = (tagname) ? tagname : "trunk"; struct DIR_ACL *dir_acl = NULL; - if ((dir_acl = get_dir_acl(repository,xbranch)) == NULL) - error(1, 0, "Error getting directory ACL for %s: %s", repository, strerror(errno)); + if ((dir_acl = get_dir_acl(repository,xbranch)) == NULL) { + error(0, errno, "Error getting directory ACL for %s", repository); + return R_SKIP_ALL; + } perm = dir_permission_granted(dir_acl,CVS_Username,dir_perm_all); #else int perm = dir_perm_all; @@ -86,8 +73,7 @@ /* prevent unprivileged user from checking if a particular * directory even exists */ - error(1, 0, "could not read RCS file for %s",update_dir); - /* just in case */ + error(0, 0, "could not read RCS file for %s",update_dir); return R_SKIP_ALL; } deep++; @@ -110,18 +96,34 @@ char *msg; { struct DIR_ACL *dir_acl = NULL; + char fullpath[PATH_MAX + 1]; char *xbranch = (tagname) ? tagname : "trunk"; int perm; - + int err = 0; /* The module can be either regular or alias. In either case - * argv[0] is directory name related to the current directory (hopefully, - * repository. So first we retrieve its DIRACL and check if it allows us - * to go further (has dir_perm_access) */ + * argv[0] is directory name related to the current directory + * (hopefully, repository). So first we retrieve its DIRACL and + * check if it allows us to go further (has dir_perm_access) */ - if ((dir_acl = get_dir_acl(argv[0],xbranch)) == NULL) - error(1, 0, "Error getting directory ACL for %s/%s: %s", - current_parsed_root->directory, argv[0], strerror(errno)); + if ((strlen(current_parsed_root->directory) + strlen(argv[0]) + 2) > PATH_MAX) { + error(0, 0, "Repository path %s/%s exceeds PATH_MAX", + current_parsed_root->directory, argv[0]); + return 1; + } + + strcpy(fullpath, current_parsed_root->directory); + strcat(fullpath, "/"); + strcat(fullpath, argv[0]); + + /* Unfortunately libcvsacl requires absolute dir names... I don't + know why Alex decided so... */ + if ((dir_acl = get_dir_acl(fullpath,xbranch)) == NULL) { + error(0, errno, "Error getting directory ACL for %s", fullpath); + return 1; + } + perm = dir_permission_granted(dir_acl,CVS_Username,dir_perm_all); + if (! (perm & dir_perm_access)) return 0; if (argc == 1) { @@ -131,7 +133,6 @@ module_dir_perm |= perm; return 0; } - if (mwhere != NULL) { int i; /* Hmm looks like a regular module, not alias. @@ -141,41 +142,58 @@ * and then check every item ACLs */ struct stat stbuf; char curdir[PATH_MAX+1]; - if (getcwd(curdir,PATH_MAX)==NULL) - error(1, 0, "unable to get current directory: %s", - strerror(errno)); - if (CVS_CHDIR(argv[0])!=0) - error(1, 0, "unable to change working directory to %s/%s: %s", - current_parsed_root->directory, argv[0], strerror(errno)); + if (getcwd(curdir,PATH_MAX)==NULL) { + error(0, errno, "Error getting current directory"); + return 1; + } + if (CVS_CHDIR(fullpath)!=0) { + CVS_CHDIR(curdir); + error(0, errno, + "Error changing working directory to %s", fullpath); + return 1; + } for(i=1;i<argc;i++) { - if (CVS_STAT(argv[i],&stbuf)==-1) - continue; /* some elements may refer to non-existing objects */ - if (S_ISDIR(stbuf.st_mode)) { + if (CVS_STAT(argv[i],&stbuf)!=-1 && S_ISDIR(stbuf.st_mode)) { struct DIR_ACL *sd_acl; - if ((sd_acl = get_dir_acl(argv[i],xbranch)) == NULL) - error(1, 0, "unable to get DIR ACL for %s/%s/%s: %s", - current_parsed_root->directory, - argv[0],argv[i],strerror(errno)); - module_dir_perm |= dir_permission_granted(sd_acl,CVS_Username, - dir_perm_all); + char itempath[PATH_MAX + 1]; + if ((strlen(fullpath) + strlen(argv[i]) + 1) > PATH_MAX) { + error(0, 0, "Path %s/%s exceeds PATH_MAX", fullpath, argv[i]); + err++; + continue; + } + strcpy(itempath, fullpath); + strcat(itempath, "/"); + strcat(itempath, argv[i]); + if ((sd_acl = get_dir_acl(itempath,xbranch)) == NULL) { + error(0, errno, "Error getting Dir ACL for %s", itempath); + err++; + continue; + } + module_dir_perm |= + dir_permission_granted(sd_acl,CVS_Username,dir_perm_all); /* should we somehow cleanup sd_acl structure?? */ } else { - /* Well, the file is a specific part of the module. So + /* Well, argv[i] either not or it's not a dir. + * We consider this case as a file case. So * if a user can checkout it, it means she has access * to the module. If she can checkin the file, she's * able to modify the module */ struct BRANCH_ACL *branch_acl; struct BRANCH_ACE *branch_ace; - if ((branch_acl = get_branch_acl(dir_acl,xbranch)) == NULL) - error(1, 0, "Error getting branch ACL for %s/%s: %s", - current_parsed_root->directory, argv[0], - strerror(errno)); + if ((branch_acl = get_branch_acl(dir_acl,xbranch)) == NULL) { + error(0, errno, "Error getting Branch ACL for %s", + fullpath); + err++; + continue; + } - if ((branch_ace = get_file_on_branch_ace(branch_acl, argv[i])) == NULL) - error(1, 0, "Error getting file ACE for %s/%s/%s: %s", - current_parsed_root->directory,argv[0], argv[i], - strerror(errno)); + if ((branch_ace = get_file_on_branch_ace(branch_acl, argv[i])) == NULL) { + error(0, errno, "Error getting File ACE for %s/%s", + fullpath, argv[i]); + err++; + continue; + } perm = branch_permission_granted(branch_ace, CVS_Username, branch_perm_all); if (perm & branch_perm_checkout) @@ -184,19 +202,23 @@ module_dir_perm |= dir_perm_modify; } } + CVS_CHDIR(curdir); } else if (argc > 1 && argv[1] && *argv[1]) { /* Well, it's an alias. if argv[1] presents it's a file * (not dir) inside argv[0] */ struct BRANCH_ACL *branch_acl; struct BRANCH_ACE *branch_ace; - if ((branch_acl = get_branch_acl(dir_acl,xbranch)) == NULL) - error(1, 0, "Error getting branch ACL for %s/%s: %s", - current_parsed_root->directory, argv[0], strerror(errno)); - - if ((branch_ace = get_file_on_branch_ace(branch_acl, argv[1])) == NULL) - error(1, 0, "Error getting file ACE for %s/%s/%s: %s", - current_parsed_root->directory,argv[0], argv[1], - strerror(errno)); + if ((branch_acl = get_branch_acl(dir_acl,xbranch)) == NULL) { + error(0, errno, "Error getting branch ACL for %s", fullpath); + return 1; + } + + if ((branch_ace = get_file_on_branch_ace(branch_acl, argv[1])) == NULL) { + error(0, errno, "Error getting file ACE for %s/%s", + fullpath, argv[1]); + return 1; + } + perm = branch_permission_granted(branch_ace, CVS_Username, branch_perm_all); if (perm & branch_perm_checkout) @@ -204,7 +226,7 @@ if (perm & branch_perm_checkin) module_dir_perm |= dir_perm_modify; } - return 0; + return err; } extern int ls_fileproc(void *callerdat, struct file_info *finfo); @@ -216,8 +238,11 @@ const int argc = 1; const int which = W_REPOS | W_ATTIC; deep = 0; - if (CVS_CHDIR(current_parsed_root->directory) < 0) + if (CVS_CHDIR(current_parsed_root->directory) < 0) { + error(0, errno, "Error changing working directory to %s", + current_parsed_root->directory); return 1; + } return start_recursion (ls_fileproc, (FILESDONEPROC) NULL, lsmodules_dirproc, (DIRLEAVEPROC) NULL, (void *) NULL, argc , argv, 0, which, 0, 1,"", 1); @@ -238,8 +263,10 @@ * only one opened instance of the DB. But this may change in future * releases so be careful... */ #if 0 - if (!(db1 = open_module ())) - error (1, 0, "failed to open the modules file"); + if (!(db1 = open_module ())) { + error (0, errno, "failed to open the modules file"); + return 1; + } #else # define db1 db #endif |