Replace static gridsite.spec
authorAndrew McNab <andrew.mcnab@manchester.ac.uk>
Fri, 23 Jun 2006 07:59:43 +0000 (07:59 +0000)
committerAndrew McNab <andrew.mcnab@manchester.ac.uk>
Fri, 23 Jun 2006 07:59:43 +0000 (07:59 +0000)
org.gridsite.core/CHANGES
org.gridsite.core/src/Makefile
org.gridsite.core/src/grst_gacl.c
org.gridsite.core/src/make-gridsite-spec [moved from org.gridsite.core/src/gridsite.spec with 74% similarity, mode: 0755]
org.gridsite.core/src/mod_gridsite.c
org.gridsite.core/src/slashgrid.c

index b0b109b..24d7b9e 100644 (file)
@@ -1,8 +1,9 @@
 * Thu Jun 22 2006 Andrew McNab <Andrew.McNab@man.ac.uk>
 - Lots of additions to SiteCast/SlashGrid, including
-  /grid/local/ filesystem.
+  /grid/local/ filesystem with DNs from gridmapdir
 - GridSiteCastAlias now allows any URL scheme (gsiftp,
   xrootd, ...) not just HTTP(S).
+- Replace static gridsite.spec with make-gridsite-spec
 * Fri Jun  9 2006 Andrew McNab <Andrew.McNab@man.ac.uk>
 - Add patch from Jan Pospisil <honik@kma.zcu.cz> to
   Makefile, to allow standalone building of libraries.
index a847bdb..5fc7d21 100644 (file)
@@ -229,6 +229,12 @@ slashgrid: slashgrid.c libgridsite.so.$(VERSION)
           -I/usr/kerberos/include `curl-config --cflags` \
           -L. `curl-config --libs` -lgridsite
 
+# This target is used by make-gridsite-spec to test for FUSE include+libs
+fuse-test: fuse-test.c
+       gcc -g -lfuse fuse-test.c \
+          $(MYCFLAGS) $(MYLDFLAGS) `xml2-config --cflags` \
+          -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DFUSE_USE_VERSION=22
+
 apidoc:
        date
        doxygen Doxyfile
@@ -329,7 +335,7 @@ dist:
                  urlencode.c findproxyfile.c gaclexample.c mod_gridsite.c \
                  grst_admin.h mod_ssl-private.h \
                  gsexec.c gsexec.h gridsite-copy.c \
-                 roffit gridsite.spec \
+                 roffit make-gridsite-spec \
                  Doxyfile doxygen.css doxyheader.html \
                  ../dist/gridsite-$(PATCH_VERSION)/src
        cp -f ../doc/*.html ../doc/*.1 ../doc/*.8 ../doc/*.conf ../doc/*.sh \
@@ -362,14 +368,17 @@ htcp-bin: htcp
        rm -Rf ../htcp-bin-$(PATCH_VERSION)
 
 # RPM targets: build and RPMs go into subdirectories of ../RPMTMP/
-rpm: dist gridsite.spec
+rpm: dist
+       export PATCH_VERSION=$(PATCH_VERSION) ; \
+        export MINOR_VERSION=$(MINOR_VERSION) ; \
+        export MYPREFIX=/usr ; \
+        ./make-gridsite-spec
        rm -Rf $(MYRPMDIR)/BUILDROOT $(MYRPMDIR)/BUILD
        mkdir -p $(MYRPMDIR)/SOURCES $(MYRPMDIR)/SPECS $(MYRPMDIR)/BUILD \
              $(MYRPMDIR)/SRPMS $(MYRPMDIR)/RPMS/i386 $(MYRPMDIR)/BUILDROOT
        cp -f ../gridsite-$(PATCH_VERSION).src.tar.gz $(MYRPMDIR)/SOURCES
        cp -f gridsite.spec $(MYRPMDIR)/SPECS
-       export MYPREFIX=/usr ; export MYVERSION=$(PATCH_VERSION) ; \
-         $(RPMCMD) --define "_topdir $(MYRPMDIR)" \
+       $(RPMCMD) --define "_topdir $(MYRPMDIR)" \
                   -ba --buildroot $(MYRPMDIR)/BUILDROOT gridsite.spec
 
 
index 667d5d8..1f5df9f 100644 (file)
@@ -876,7 +876,6 @@ int GRSTgaclUserHasCred(GRSTgaclUser *user, GRSTgaclCred *cred)
   GRSTgaclCred      *crediter;
   GRSTgaclNamevalue *usernamevalue, *crednamevalue;
 
-
   if (cred == NULL) return 0;
 
   if (strcmp(cred->type, "any-user") == 0) return 1;
old mode 100644 (file)
new mode 100755 (executable)
similarity index 74%
rename from org.gridsite.core/src/gridsite.spec
rename to org.gridsite.core/src/make-gridsite-spec
index a169c66..8703f66
@@ -1,11 +1,31 @@
+#!/bin/sh
+
+# test to see if fuse-devel (or fuse.h and libfuse) are installed
+#
+cat <<EOF >fuse-test.c
+#include <fuse.h>
+int main() { struct fuse_context ctx;
+return fuse_main(0, (char **) 0, (struct fuse_operations *) 0); }
+EOF
+make fuse-test
+if [ $? = 0 ] ; then have_fuse=1 ; fi
+
+cat <<EOF >gridsite.spec
+#
+# Autogenerated by make-gridsite-spec 
+#
+# You should modify  make-gridsite-spec  and rebuild RPM with  make rpm
+# rather than editing this spec file
+#
 Name: gridsite
-Version: %(echo ${MYVERSION:-1.x.x})
+Version: ${PATCH_VERSION:-1.x.x}
+# This next piece of .spec/sed magic puts the build OS version in the release
 Release: 1%(sed 's/^\([A-Z]\)[^ ]* \([A-Z]\)[^0-9]*\([0-9][^ ]*\).*/\1\2\3/g' /etc/redhat-release | sed 's/[^A-Z,a-z,0-9]//g')
 Summary: GridSite
 License: Modified BSD
 Group: System Environment/Daemons
 Source: %{name}-%{version}.src.tar.gz
-Prefix: %(echo ${MYPREFIX:-/usr})
+Prefix: ${MYPREFIX:-/usr}
 URL: http://www.gridsite.org/
 Vendor: GridPP
 Requires: libxml2
@@ -79,43 +99,49 @@ See http://www.gridsite.org/ for details.
 
 %build
 cd src
-make prefix=$RPM_BUILD_ROOT/%{prefix} \
- GSOAPDIR=$GSOAPDIR OPENSSL_FLAGS=$OPENSSL_FLAGS \
- OPENSSL_LIBS=$OPENSSL_LIBS FLAVOR_EXT=$FLAVOR_EXT
-
-if [ -f /usr/include/fuse/fuse.h ] ; then
- make slashgrid
+make prefix=\$RPM_BUILD_ROOT/%{prefix} \
+ GSOAPDIR=\$GSOAPDIR OPENSSL_FLAGS=\$OPENSSL_FLAGS \
+ OPENSSL_LIBS=\$OPENSSL_LIBS FLAVOR_EXT=\$FLAVOR_EXT
+
+EOF
+
+if [ $have_fuse ] ; then
+cat <<EOF >>gridsite.spec
+make prefix=\$RPM_BUILD_ROOT/%{prefix} \
+ GSOAPDIR=\$GSOAPDIR OPENSSL_FLAGS=\$OPENSSL_FLAGS \
+ OPENSSL_LIBS=\$OPENSSL_LIBS FLAVOR_EXT=\$FLAVOR_EXT slashgrid
+EOF
 fi
 
+cat <<EOF >>gridsite.spec
+
 %install
 cd src
-make install prefix=$RPM_BUILD_ROOT/%{prefix} \
-GSOAPDIR=$GSOAPDIR OPENSSL_FLAGS=$OPENSSL_FLAGS \
-OPENSSL_LIBS=$OPENSSL_LIBS FLAVOR_EXT=$FLAVOR_EXT
-
-mkdir -p $RPM_BUILD_ROOT/etc/rc.d/init.d
-
-if [ -f /usr/include/fuse/fuse.h ] ; then
- make install-slashgrid prefix=$RPM_BUILD_ROOT/%{prefix} \
-  OPENSSL_FLAGS=$OPENSSL_FLAGS \
-  OPENSSL_LIBS=$OPENSSL_LIBS FLAVOR_EXT=$FLAVOR_EXT
-else
- echo -e '#!/bin/sh\necho SlashGrid wasnt built since no fuse-devel on build machine)' \
-   >$RPM_BUILD_ROOT/%{prefix}/sbin/slashgrid
- echo -e '#!/bin/sh\n# chkconfig: - 90 10\n# description: slashgrid\necho SlashGrid wasnt built since no fuse-devel on build machine' \
-   >$RPM_BUILD_ROOT/etc/rc.d/init.d/slashgrid
- mkdir -p $RPM_BUILD_ROOT/var/spool/slashgrid/headers
- mkdir -p $RPM_BUILD_ROOT/var/spool/slashgrid/blocks
- mkdir -p $RPM_BUILD_ROOT/var/spool/slashgrid/tmp
+make install prefix=\$RPM_BUILD_ROOT/%{prefix} \
+GSOAPDIR=\$GSOAPDIR OPENSSL_FLAGS=\$OPENSSL_FLAGS \
+OPENSSL_LIBS=\$OPENSSL_LIBS FLAVOR_EXT=\$FLAVOR_EXT
+EOF
+
+if [ $have_fuse ] ; then
+
+cat <<EOF >>gridsite.spec
+
+mkdir -p \$RPM_BUILD_ROOT/etc/rc.d/init.d
+make install-slashgrid prefix=\$RPM_BUILD_ROOT/%{prefix} \
+  OPENSSL_FLAGS=\$OPENSSL_FLAGS \
+  OPENSSL_LIBS=\$OPENSSL_LIBS FLAVOR_EXT=\$FLAVOR_EXT
+EOF
 fi
 
+cat <<EOF >>gridsite.spec
+
 %post shared
-if [ "$UID" = "0" ] ; then
+if [ "\$UID" = "0" ] ; then
  /sbin/ldconfig
 fi
 
 %postun
-if [ "$UID" = "0" ] ; then
+if [ "\$UID" = "0" ] ; then
  /sbin/ldconfig
 fi
 
@@ -124,7 +150,7 @@ fi
 %attr(-, root, root) %{prefix}/lib/libgridsite.so
 %attr(-, root, root) %{prefix}/lib/libgridsite_globus.so.%{version}
 %attr(-, root, root) %{prefix}/lib/libgridsite_globus.so
-%attr(-, root, root) %{prefix}/share/doc/gridsite-%(echo ${MYVERSION:-1.x.x} | cut -f1-2 -d.)
+%attr(-, root, root) %{prefix}/share/doc/gridsite-${MINOR_VERSION:-1.x}
 
 %files devel
 %attr(-, root, root) %{prefix}/include/gridsite.h
@@ -163,7 +189,11 @@ fi
 %files gsexec
 %attr(4510, root, apache) %{prefix}/sbin/gsexec
 %attr(-, root, root) %{prefix}/share/man/man8/gsexec.8.gz
+EOF
+
+if [ $have_fuse ] ; then
 
+cat <<EOF >>gridsite.spec
 %package slashgrid
 Group: Applications/Internet
 Summary: slashgrid daemon
@@ -182,3 +212,7 @@ mkdir -p /grid
 %attr(0744, root, root) %{prefix}/sbin/slashgrid
 %attr(0744, root, root) /etc/rc.d/init.d/slashgrid
 %attr(0700, root, root) /var/spool/slashgrid
+EOF
+
+fi
+
index ab40bde..8c8fb7e 100644 (file)
@@ -2980,14 +2980,16 @@ void sitecast_responder(server_rec *main_server)
                       IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) 
          { 
            ap_log_error(APLOG_MARK, APLOG_ERR, 0, main_server,
-                "SiteCast UDP Responder fails on setting multicast");
+                "SiteCast UDP Responder fails on setting multicast (%s)",
+                strerror(errno));
            return; 
          }
          
        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, main_server,
         "SiteCast UDP Responder listening on %d.%d.%d.%d:%d",
         sitecastgroups[i].quad1, sitecastgroups[i].quad2,
-        sitecastgroups[i].quad3, sitecastgroups[i].quad4, sitecastgroups[i].port);
+        sitecastgroups[i].quad3, sitecastgroups[i].quad4, 
+        sitecastgroups[i].port);
      }
 
   for (i=0; (i < GRST_SITECAST_ALIASES) &&
@@ -3031,7 +3033,7 @@ void sitecast_responder(server_rec *main_server)
 
                   if ((reqbuf_len = recvfrom(sitecastgroups[igroup].socket, 
                                              reqbuf, GRST_SITECAST_MAXBUF, 0,
-                      (struct sockaddr *) &client_addr, &client_addr_len)) >= 0)
+                     (struct sockaddr *) &client_addr, &client_addr_len)) >= 0)
                     {
                       ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, main_server,
                         "SiteCast receives UDP message from %s:%d "
index 1a7cbc0..08e6e86 100644 (file)
@@ -410,6 +410,78 @@ char *check_x509_user_proxy(pid_t pid)
   return proxyfile;    
 }
 
+char *mapdir_uid_to_dn(uid_t uid)
+{
+     int            ret;
+     char           *firstlinkpath, *otherlinkpath, *dn, *buf = NULL;
+     struct dirent  *mapdirentry;
+     DIR            *mapdirstream;
+     ino_t          firstinode;
+     long           buflen;
+     struct stat    statbuf;
+     struct passwd  pw, *pwp;
+     
+     if (gridmapdir == NULL) return NULL;
+
+     buflen = sysconf(_SC_GETPW_R_SIZE_MAX);
+     buf = malloc(buflen);
+
+     if ((buflen <= 0) ||
+         (getpwuid_r(uid, &pw, buf, buflen, &pwp) != 0) ||
+         (pw.pw_name == NULL))
+       {
+         if (buf != NULL) free(buf);
+         return NULL;
+       }
+
+     asprintf(&firstlinkpath, "%s/%s", gridmapdir, pw.pw_name);
+     ret = stat(firstlinkpath, &statbuf);
+
+     free(firstlinkpath);
+
+     if ((ret != 0) || (statbuf.st_nlink != 2))
+       {
+         free(buf);
+         return NULL;
+       }
+
+     firstinode = statbuf.st_ino; /* save for comparisons */
+
+     mapdirstream = opendir(gridmapdir);
+
+     if (mapdirstream != NULL)
+       {
+         while ((mapdirentry = readdir(mapdirstream)) != NULL)
+              {
+                 if (strcmp(mapdirentry->d_name, pw.pw_name) == 0) continue;
+
+                 if (mapdirentry->d_ino == firstinode)
+                   {
+                      asprintf(&otherlinkpath, "%s/%s", gridmapdir,
+                                            mapdirentry->d_name);
+
+                      utime(otherlinkpath, (struct utimbuf *) NULL);
+                      free(otherlinkpath);
+                      
+                      dn = GRSThttpUrlDecode(mapdirentry->d_name);
+            
+                      if (debugmode) syslog(LOG_DEBUG, "mapdir_uid_to_dn "
+                                  "maps %s(%d) to %s", pw.pw_name, uid, dn);
+
+                      closedir(mapdirstream);
+                      free(buf);
+                      return dn;
+                   }
+              }
+
+         closedir(mapdirstream);
+       }
+
+     free(buf);
+     return NULL;
+}
+
+
 int perform_request(struct grst_request *request_data,
                     struct fuse_context *fuse_ctx)
 {
@@ -963,21 +1035,28 @@ GRSTgaclPerm get_gaclPerm(struct fuse_context *fuse_ctx, char *path)
 {
   GRSTgaclPerm perm = GRST_PERM_NONE; 
   GRSTgaclCred *cred;
-  GRSTgaclUser *user;
+  GRSTgaclUser *user = NULL;
   GRSTgaclAcl  *acl;
+  char *dn = NULL;
 
 // eventually want a UID cache here...
 
-// will check gridmapdir for DN and create user in future...
-  user = NULL; // but just anonymous user for now
+  dn = mapdir_uid_to_dn(fuse_ctx->uid);
   
-  acl  = GRSTgaclAclLoadforFile(path);
+  if (dn != NULL)
+    {
+      cred = GRSTgaclCredNew("person");
+      GRSTgaclCredAddValue(cred, "dn", dn);
+      user = GRSTgaclUserNew(cred);
+      free(dn);
+    }   
+  
+  acl  = GRSTgaclAclLoadforFile(path); 
   perm = GRSTgaclAclTestUser(acl, user);
   GRSTgaclAclFree(acl);
   GRSTgaclUserFree(user);
   
-perm = 255;
+  if (strstr(path, GRST_ACL_FILE) != NULL) perm &= ~GRST_PERM_WRITE;
 
   if (debugmode) syslog(LOG_DEBUG, "get_gaclPerm returns perm=%d", perm);
 
@@ -1181,7 +1260,7 @@ static int slashgrid_readdir(const char *path, void *buf,
            free(dirlist[i]);
          }
          
-      free(dirlist);      
+      if (ilast >= 0) free(dirlist);      
       free(dirname);
     
       return 0;
@@ -1192,8 +1271,6 @@ static int slashgrid_readdir(const char *path, void *buf,
     {
       asprintf(&dirname, "%s%s/", local_root, &path[6]);
 
-  if (debugmode) syslog(LOG_DEBUG, "in slashgrid_readdir, dirname=%s", dirname);
-      
       perm = get_gaclPerm(&fuse_ctx, dirname);
 
       if (!GRSTgaclPermHasList(perm))
@@ -1207,12 +1284,12 @@ static int slashgrid_readdir(const char *path, void *buf,
 
       if (ilast < 0) return -ENOENT;
               
-      filler(buf, ".",     NULL, 0);
-      filler(buf, "..",    NULL, 0);
+//      filler(buf, ".",     NULL, 0);
+//      filler(buf, "..",    NULL, 0);
 
       for (i=0; i <= ilast; ++i)
          {
-           if (dirlist[i]->d_name[0] != '.')
+//           if (dirlist[i]->d_name[0] != '.')
                  filler(buf, dirlist[i]->d_name, NULL, 0);
            free(dirlist[i]);
          }
@@ -1841,8 +1918,7 @@ static int slashgrid_write(const char *path, const char *buf,
                          
   if ((local_root != NULL) && (strncmp(path, "/local/", 7) == 0))
     {
-      asprintf(&localpath, "%s/%s", local_root, &path[7]);
-      
+      asprintf(&localpath, "%s/%s", local_root, &path[7]);      
       perm = get_gaclPerm(&fuse_ctx, localpath);
       
       if (GRSTgaclPermHasWrite(perm))
@@ -1913,16 +1989,47 @@ static int slashgrid_write(const char *path, const char *buf,
 
 int slashgrid_rename(const char *oldpath, const char *newpath)
 {
-  int          anyerror = 0, thiserror, i, fd;
-  char        *s, *url, *p, *destination, errorbuffer[CURL_ERROR_SIZE+1] = "";
+  int          anyerror = 0, thiserror, i, fd, ret;
+  char        *s, *url, *p, *destination, errorbuffer[CURL_ERROR_SIZE+1] = "",
+              *oldlocalpath, *newlocalpath;
 
   struct grst_read_data read_data;
   struct fuse_context fuse_ctx;
   struct grst_request request_data;
+  GRSTgaclPerm oldperm, newperm;
 
   memcpy(&fuse_ctx, fuse_get_context(), sizeof(struct fuse_context));
 
-  if (strncmp(oldpath, "/http/", 6) == 0)
+  if ((local_root != NULL) && 
+      ((strncmp(oldpath, "/local/", 7) == 0) ||
+       (strncmp(newpath, "/local/", 7) == 0)))
+    {
+      if (strncmp(oldpath, newpath, 7) != 0)
+        {
+          return -EXDEV; /* not on same filesystem */
+        }
+    
+      asprintf(&oldlocalpath, "%s/%s", local_root, &oldpath[7]);
+      asprintf(&newlocalpath, "%s/%s", local_root, &newpath[7]);
+      
+      oldperm = get_gaclPerm(&fuse_ctx, oldlocalpath);
+      newperm = get_gaclPerm(&fuse_ctx, newlocalpath);
+      
+      if (GRSTgaclPermHasWrite(oldperm) &&
+          GRSTgaclPermHasWrite(newperm))
+        {
+          ret = rename(oldlocalpath, newlocalpath);
+          free(oldlocalpath);
+          free(newlocalpath);
+          
+          return (ret == 0) ? 0 : -errno;
+        }
+
+      free(oldlocalpath);
+      free(newlocalpath);
+      return -EACCES;
+    }
+  else if (strncmp(oldpath, "/http/", 6) == 0)
     {
       if (strncmp(newpath, "/http/", 6) != 0) return -EXDEV;
 
@@ -1979,19 +2086,40 @@ int slashgrid_rename(const char *oldpath, const char *newpath)
 
 int slashgrid_unlink(const char *path)
 {
-  int          anyerror = 0, thiserror, i, fd;
-  char        *s, *url, *p, errorbuffer[CURL_ERROR_SIZE+1] = "";
+  int   anyerror = 0, thiserror, i, fd, ret;
+  char *s, *url, *p, errorbuffer[CURL_ERROR_SIZE+1] = "",
+              *localpath;
 
   struct grst_read_data read_data;
   struct fuse_context fuse_ctx;
   struct grst_request request_data;
+  GRSTgaclPerm perm;
 
   memcpy(&fuse_ctx, fuse_get_context(), sizeof(struct fuse_context));
 
+  if (debugmode) syslog(LOG_DEBUG, "slashgrid_unlink called for %s", path);
+  
   if (strncmp(path, "/http/", 6) == 0)
     asprintf(&url, "http://%s", &path[6]);
   else if (strncmp(path, "/https/", 7) == 0)
     asprintf(&url, "https://%s", &path[7]);
+  else if ((local_root != NULL) && (strncmp(path, "/local/", 7) == 0))
+    {
+      asprintf(&localpath, "%s/%s", local_root, &path[7]);
+      
+      perm = get_gaclPerm(&fuse_ctx, localpath);
+      
+      if (GRSTgaclPermHasWrite(perm))
+        {
+          ret = remove(localpath);
+          free(localpath);
+          
+          return (ret == 0) ? 0 : -errno;
+        }
+
+      free(localpath);
+      return -EACCES;
+    }
   else return -ENOENT;
 
   read_data.buf     = "";
@@ -2034,8 +2162,8 @@ int slashgrid_unlink(const char *path)
 int slashgrid_rmdir(const char *path)
 {
   int   ret;
-  char *pathwithslash;
-  
+  char *pathwithslash, *localpath;
+
   asprintf(&pathwithslash, "%s/", path);
   ret = slashgrid_unlink(pathwithslash);  
   free(pathwithslash);
@@ -2059,8 +2187,33 @@ int slashgrid_mknod(const char *path, mode_t mode, dev_t dev)
 int slashgrid_mkdir(const char *path, mode_t mode)
 {
   int   ret;
-  char *pathwithslash;
+  char *pathwithslash, *localpath;
+  struct fuse_context fuse_ctx;
+  GRSTgaclPerm perm;
   
+  memcpy(&fuse_ctx, fuse_get_context(), sizeof(struct fuse_context));
+
+  if (debugmode) syslog(LOG_DEBUG, "slashgrid_mkdir, for %s", path);
+                                  
+  if ((local_root != NULL) && (strncmp(path, "/local/", 7) == 0))
+    {
+      asprintf(&localpath, "%s/%s", local_root, &path[7]);
+      
+      perm = get_gaclPerm(&fuse_ctx, localpath);
+      
+      if (GRSTgaclPermHasWrite(perm))
+        {
+          ret = mkdir(localpath, S_IRUSR | S_IWUSR | S_IXUSR);
+          chown(localpath, local_uid, local_gid);
+          free(localpath);
+          
+          return (ret == 0) ? 0 : -errno;
+        }
+
+      free(localpath);
+      return -EACCES;
+    }
+
   asprintf(&pathwithslash, "%s/", path);
   ret = slashgrid_write(pathwithslash, "", 0, 0, NULL);
   free(pathwithslash);
@@ -2110,7 +2263,7 @@ int slashgrid_truncate(const char *path, off_t offset)
           ret = truncate(localpath, offset);
           free(localpath);
           
-          return (ret == 0) ? 0 : -ENOENT;
+          return (ret == 0) ? 0 : -errno;
         }
 
       free(localpath);