main.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /****************************************************************************
  2. *
  3. * MODULE: g.access
  4. * AUTHOR(S): Michael Shapiro CERL (original contributor)
  5. * Markus Neteler <neteler itc.it>
  6. * Bernhard Reiter <bernhard intevation.de>,
  7. * Glynn Clements <glynn gclements.plus.com>,
  8. * Hamish Bowman <hamish_nospam yahoo.com>, Radim Blazek <radim.blazek gmail.com>
  9. * PURPOSE:
  10. * COPYRIGHT: (C) 1999-2006 by the GRASS Development Team
  11. *
  12. * This program is free software under the GNU General Public
  13. * License (>=v2). Read the file COPYING that comes with GRASS
  14. * for details.
  15. *
  16. *****************************************************************************/
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <unistd.h>
  20. #include <grass/gis.h>
  21. #include <grass/glocale.h>
  22. #include "local_proto.h"
  23. int
  24. main (int argc, char *argv[])
  25. {
  26. char path[1024];
  27. int perms; /* full mapset permissions */
  28. int group, other; /* bool. want group/other permission */
  29. struct Option *group_opt, *other_opt;
  30. struct GModule *module;
  31. /* init the GRASS library */
  32. G_gisinit(argv[0]);
  33. module = G_define_module();
  34. module->keywords = _("general");
  35. module->description =
  36. _("Controls access to the current mapset for other users on the system.");
  37. group_opt = G_define_option();
  38. group_opt->key = "group";
  39. group_opt->type = TYPE_STRING;
  40. group_opt->required = NO;
  41. group_opt->options = "grant,revoke";
  42. group_opt->description = _("Access for group");
  43. other_opt = G_define_option();
  44. other_opt->key = "other";
  45. other_opt->type = TYPE_STRING;
  46. other_opt->required = NO;
  47. other_opt->options = "grant,revoke";
  48. other_opt->description = _("Access for others");
  49. if (G_parser(argc, argv) < 0)
  50. exit(EXIT_FAILURE);
  51. /* get the unix file name for the mapset directory */
  52. G__file_name (path, "", "", G_mapset());
  53. /* this part is until PERMANENT no longer holds DEFAULT_WIND and MYNAME */
  54. if (strcmp (G_mapset(), "PERMANENT") == 0)
  55. G_fatal_error(
  56. _("Access to the PERMANENT mapset must be open, nothing changed"));
  57. /* get the current permissions */
  58. if(get_perms (path, &perms, &group, &other) < 0)
  59. G_fatal_error(_("Unable to determine mapset permssions"));
  60. if ( group_opt->answer ) {
  61. if ( group_opt->answer[0] == 'g' )
  62. group = 1;
  63. else
  64. group = 0;
  65. }
  66. if ( other_opt->answer ) {
  67. if ( other_opt->answer[0] == 'g' )
  68. other = 1;
  69. else
  70. other = 0;
  71. }
  72. set_perms (path, perms, group, other);
  73. exit(EXIT_SUCCESS);
  74. }