home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / cvs-1.8.7-src.tgz / tar.out / fsf / cvs / src / admin.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  4KB  |  173 lines

  1. /*
  2.  * Copyright (c) 1992, Brian Berliner and Jeff Polk
  3.  * Copyright (c) 1989-1992, Brian Berliner
  4.  * 
  5.  * You may distribute under the terms of the GNU General Public License as
  6.  * specified in the README file that comes with the CVS 1.4 kit.
  7.  * 
  8.  * Administration
  9.  * 
  10.  * For now, this is basically a front end for rcs.  All options are passed
  11.  * directly on.
  12.  */
  13.  
  14. #include "cvs.h"
  15. #ifdef CVS_ADMIN_GROUP
  16. #include <grp.h>
  17. #endif
  18.  
  19. static Dtype admin_dirproc PROTO ((void *callerdat, char *dir,
  20.                    char *repos, char *update_dir,
  21.                    List *entries));
  22. static int admin_fileproc PROTO ((void *callerdat, struct file_info *finfo));
  23.  
  24. static const char *const admin_usage[] =
  25. {
  26.     "Usage: %s %s rcs-options files...\n",
  27.     NULL
  28. };
  29.  
  30. static int ac;
  31. static char **av;
  32.  
  33. int
  34. admin (argc, argv)
  35.     int argc;
  36.     char **argv;
  37. {
  38.     int err;
  39. #ifdef CVS_ADMIN_GROUP
  40.     struct group *grp;
  41. #endif
  42.     if (argc <= 1)
  43.     usage (admin_usage);
  44.  
  45. #ifdef CVS_ADMIN_GROUP
  46.     grp = getgrnam(CVS_ADMIN_GROUP);
  47.      /* skip usage right check if group CVS_ADMIN_GROUP does not exist */
  48.     if (grp != NULL)
  49.     {
  50.     char *me = getcaller();
  51.     char **grnam = grp->gr_mem;
  52.     int denied = 1;
  53.     
  54.     while (*grnam)
  55.     {
  56.         if (strcmp(*grnam, me) == 0) 
  57.         {
  58.         denied = 0;
  59.         break;
  60.         }
  61.         grnam++;
  62.     }
  63.  
  64.     if (denied)
  65.         error (1, 0, "usage is restricted to members of the group %s",
  66.            CVS_ADMIN_GROUP);
  67.     }
  68. #endif
  69.  
  70.     wrap_setup ();
  71.  
  72.     /* skip all optional arguments to see if we have any file names */
  73.     for (ac = 1; ac < argc; ac++)
  74.     if (argv[ac][0] != '-')
  75.         break;
  76.     argc -= ac;
  77.     av = argv + 1;
  78.     argv += ac;
  79.     ac--;
  80.     if (ac == 0 || argc == 0)
  81.     usage (admin_usage);
  82.  
  83. #ifdef CLIENT_SUPPORT
  84.     if (client_active)
  85.     {
  86.     int i;
  87.  
  88.     /* We're the client side.  Fire up the remote server.  */
  89.     start_server ();
  90.     
  91.     ign_setup ();
  92.  
  93.     for (i = 0; i <= ac; ++i)    /* XXX send -ko too with i = 0 */
  94.         send_arg (av[i]);
  95.  
  96.     send_file_names (argc, argv, SEND_EXPAND_WILD);
  97.     /* FIXME:  We shouldn't have to send current files, but I'm not sure
  98.        whether it works.  So send the files --
  99.        it's slower but it works.  */
  100.     send_files (argc, argv, 0, 0);
  101.     send_to_server ("admin\012", 0);
  102.         return get_responses_and_close ();
  103.     }
  104. #endif /* CLIENT_SUPPORT */
  105.  
  106.     /* start the recursion processor */
  107.     err = start_recursion (admin_fileproc, (FILESDONEPROC) NULL, admin_dirproc,
  108.                (DIRLEAVEPROC) NULL, NULL, argc, argv, 0,
  109.                W_LOCAL, 0, 1, (char *) NULL, 1);
  110.     return (err);
  111. }
  112.  
  113. /*
  114.  * Called to run "rcs" on a particular file.
  115.  */
  116. /* ARGSUSED */
  117. static int
  118. admin_fileproc (callerdat, finfo)
  119.     void *callerdat;
  120.     struct file_info *finfo;
  121. {
  122.     Vers_TS *vers;
  123.     char *version;
  124.     char **argv;
  125.     int argc;
  126.     int retcode = 0;
  127.     int status = 0;
  128.  
  129.     vers = Version_TS (finfo, NULL, NULL, NULL, 0, 0);
  130.  
  131.     version = vers->vn_user;
  132.     if (version == NULL)
  133.     goto exitfunc;
  134.     else if (strcmp (version, "0") == 0)
  135.     {
  136.     error (0, 0, "cannot admin newly added file `%s'", finfo->file);
  137.     goto exitfunc;
  138.     }
  139.  
  140.     run_setup ("%s%s -x,v/", Rcsbin, RCS);
  141.     for (argc = ac, argv = av; argc; argc--, argv++)
  142.     run_arg (*argv);
  143.     run_arg (vers->srcfile->path);
  144.     if ((retcode = run_exec (RUN_TTY, RUN_TTY, RUN_TTY, RUN_NORMAL)) != 0)
  145.     {
  146.     if (!quiet)
  147.         error (0, retcode == -1 ? errno : 0,
  148.            "%s failed for `%s'", RCS, finfo->file);
  149.     status = 1;
  150.     goto exitfunc;
  151.     }
  152.   exitfunc:
  153.     freevers_ts (&vers);
  154.     return status;
  155. }
  156.  
  157. /*
  158.  * Print a warm fuzzy message
  159.  */
  160. /* ARGSUSED */
  161. static Dtype
  162. admin_dirproc (callerdat, dir, repos, update_dir, entries)
  163.     void *callerdat;
  164.     char *dir;
  165.     char *repos;
  166.     char *update_dir;
  167.     List *entries;
  168. {
  169.     if (!quiet)
  170.     error (0, 0, "Administrating %s", update_dir);
  171.     return (R_PROCESS);
  172. }
  173.