00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <string.h>
00012 #include <unistd.h>
00013 #include <stdlib.h>
00014 #include <grass/gis.h>
00015 #include <grass/glocale.h>
00016
00017 #include <sys/types.h>
00018 #include <sys/stat.h>
00019
00020 #ifdef __MINGW32__
00021 # define mkdir(name, mode) ((mkdir) (name))
00022 #endif
00023
00024 int G__make_mapset_element (char *p_element)
00025 {
00026 char command[1024];
00027 char *path;
00028 char *p;
00029 char *G_mapset();
00030 char *element;
00031
00032 element = p_element;
00033 if (*element == 0)
00034 return 0;
00035 strcpy (path = command, "mkdir ");
00036 while (*path)
00037 path++;
00038
00039 G__file_name (p = path, "", "", G_mapset());
00040 while (*p)
00041 p++;
00042
00043 --p;
00044 if (*p++ != '/')
00045 {
00046 *p++ = '/' ;
00047 *p = 0;
00048 }
00049
00050
00051 while (1)
00052 {
00053 if (*element == '/' || *element == 0)
00054 {
00055 *p = 0;
00056
00057 if (access (path, 0) != 0)
00058 {
00059 mkdir(path, 0777);
00060 }
00061
00062 if (access (path, 0) != 0)
00063 {
00064 system (command);
00065 }
00066 if (access (path, 0) != 0)
00067 {
00068 char err[1024];
00069 sprintf (err, _("can't make mapset element %s (%s)"), p_element, path);
00070 G_fatal_error (err);
00071 exit(1);
00072 }
00073 if (*element == 0)
00074 return 1;
00075 }
00076 *p++ = *element++;
00077 }
00078 }
00079
00080
00081
00082
00083
00084
00085
00086
00087 int G__mapset_permissions (char *mapset)
00088 {
00089 char path[2000];
00090 struct stat info;
00091
00092 G__file_name (path,"","",mapset);
00093
00094 if (stat (path, &info) != 0)
00095 return -1;
00096
00097 #ifndef __MINGW32__
00098 if (info.st_uid != getuid())
00099 return 0;
00100 if (info.st_uid != geteuid())
00101 return 0;
00102 #endif
00103
00104 return 1;
00105 }
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 int G__mapset_permissions2 ( char * gisdbase, char * location, char *mapset )
00117 {
00118 char path[2000];
00119 struct stat info;
00120
00121 sprintf ( path, "%s/%s/%s", gisdbase, location, mapset );
00122
00123 if (stat (path, &info) != 0)
00124 return -1;
00125
00126 #ifndef __MINGW32__
00127 if (info.st_uid != getuid())
00128 return 0;
00129 if (info.st_uid != geteuid())
00130 return 0;
00131 #endif
00132
00133 return 1;
00134 }
00135