main.c 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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: Controls access to the current mapset for other users on the system
  10. * COPYRIGHT: (C) 1999-2006, 2011 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[GPATH_MAX];
  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. G_add_keyword(_("map management"));
  35. G_add_keyword(_("permission"));
  36. module->label =
  37. _("Controls access to the current mapset for other users on the system.");
  38. module->description = _("If no option given, prints current status.");
  39. group_opt = G_define_option();
  40. group_opt->key = "group";
  41. group_opt->type = TYPE_STRING;
  42. group_opt->required = NO;
  43. group_opt->options = "grant,revoke";
  44. group_opt->description = _("Access for group");
  45. group_opt->guisection = _("Settings");
  46. other_opt = G_define_option();
  47. other_opt->key = "other";
  48. other_opt->type = TYPE_STRING;
  49. other_opt->required = NO;
  50. other_opt->options = "grant,revoke";
  51. other_opt->description = _("Access for others");
  52. other_opt->guisection = _("Settings");
  53. if (G_parser(argc, argv))
  54. exit(EXIT_FAILURE);
  55. #ifdef __MINGW32__
  56. G_fatal_error(_("UNIX filesystem access controls are not supported by MS-Windows"));
  57. #endif
  58. /* get the unix file name for the mapset directory */
  59. G_file_name(path, "", "", G_mapset());
  60. /* this part is until PERMANENT no longer holds DEFAULT_WIND and MYNAME */
  61. if (strcmp(G_mapset(), "PERMANENT") == 0)
  62. G_fatal_error(_("Access to the PERMANENT mapset must be open, nothing changed"));
  63. /* get the current permissions */
  64. if (get_perms(path, &perms, &group, &other) < 0)
  65. G_fatal_error(_("Unable to determine mapset permissions"));
  66. if (group_opt->answer) {
  67. if (group_opt->answer[0] == 'g')
  68. group = 1;
  69. else
  70. group = 0;
  71. }
  72. if (other_opt->answer) {
  73. if (other_opt->answer[0] == 'g')
  74. other = 1;
  75. else
  76. other = 0;
  77. }
  78. set_perms(path, perms, group, other);
  79. exit(EXIT_SUCCESS);
  80. }