main.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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_b 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 main(int argc, char *argv[])
  24. {
  25. char path[1024];
  26. int perms; /* full mapset permissions */
  27. int group, other; /* bool. want group/other permission */
  28. struct Option *group_opt, *other_opt;
  29. struct GModule *module;
  30. /* init the GRASS library */
  31. G_gisinit(argv[0]);
  32. module = G_define_module();
  33. G_add_keyword(_("general"));
  34. module->description =
  35. _("Controls access to the current mapset for other users on the system.");
  36. group_opt = G_define_option();
  37. group_opt->key = "group";
  38. group_opt->type = TYPE_STRING;
  39. group_opt->required = NO;
  40. group_opt->options = "grant,revoke";
  41. group_opt->description = _("Access for group");
  42. other_opt = G_define_option();
  43. other_opt->key = "other";
  44. other_opt->type = TYPE_STRING;
  45. other_opt->required = NO;
  46. other_opt->options = "grant,revoke";
  47. other_opt->description = _("Access for others");
  48. if (G_parser(argc, argv))
  49. exit(EXIT_FAILURE);
  50. /* get the unix file name for the mapset directory */
  51. G__file_name(path, "", "", G_mapset());
  52. /* this part is until PERMANENT no longer holds DEFAULT_WIND and MYNAME */
  53. if (strcmp(G_mapset(), "PERMANENT") == 0)
  54. G_fatal_error(_("Access to the PERMANENT mapset must be open, nothing changed"));
  55. /* get the current permissions */
  56. if (get_perms(path, &perms, &group, &other) < 0)
  57. G_fatal_error(_("Unable to determine mapset permissions"));
  58. if (group_opt->answer) {
  59. if (group_opt->answer[0] == 'g')
  60. group = 1;
  61. else
  62. group = 0;
  63. }
  64. if (other_opt->answer) {
  65. if (other_opt->answer[0] == 'g')
  66. other = 1;
  67. else
  68. other = 0;
  69. }
  70. set_perms(path, perms, group, other);
  71. exit(EXIT_SUCCESS);
  72. }