From 124632ba8a6546654cedcfbea8b8372b586f1cb9 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 16 May 2014 13:26:49 +0000 Subject: [PATCH] rewrote the pre-revprop-chagnge script in perl --- codepot/configure | 3 +- codepot/configure.ac | 1 + codepot/etc/Makefile.am | 7 +- codepot/etc/Makefile.in | 58 ++++++++++++---- codepot/etc/pre-revprop-change | 24 ------- codepot/etc/pre-revprop-change.in | 108 ++++++++++++++++++++++++++++++ 6 files changed, 160 insertions(+), 41 deletions(-) delete mode 100755 codepot/etc/pre-revprop-change create mode 100644 codepot/etc/pre-revprop-change.in diff --git a/codepot/configure b/codepot/configure index 3555a547..4c23831f 100755 --- a/codepot/configure +++ b/codepot/configure @@ -2544,7 +2544,7 @@ cachedir=$cachedir - ac_config_files="$ac_config_files Makefile codepot.spec etc/Makefile etc/codepot.ini etc/codepot.a2ldap etc/start-commit DEBIAN/Makefile DEBIAN/control DEBIAN/postinst DEBIAN/postrm src/config.php src/codepot/config/Makefile src/codepot/controllers/Makefile src/codepot/errors/Makefile src/codepot/helpers/Makefile src/codepot/hooks/Makefile src/codepot/language/english/Makefile src/codepot/language/indonesian/Makefile src/codepot/language/korean/Makefile src/codepot/language/Makefile src/codepot/libraries/Makefile src/codepot/models/Makefile src/codepot/views/Makefile src/codepot/Makefile src/css/images/Makefile src/css/Makefile src/js/prettify/Makefile src/js/Makefile src/system/cache/Makefile src/system/codeigniter/Makefile src/system/database/drivers/mssql/Makefile src/system/database/drivers/mysql/Makefile src/system/database/drivers/mysqli/Makefile src/system/database/drivers/oci8/Makefile src/system/database/drivers/odbc/Makefile src/system/database/drivers/postgre/Makefile src/system/database/drivers/sqlite/Makefile src/system/database/drivers/Makefile src/system/database/Makefile src/system/fonts/Makefile src/system/helpers/Makefile src/system/language/english/Makefile src/system/language/korean/Makefile src/system/language/Makefile src/system/libraries/Makefile src/system/logs/Makefile src/system/plugins/Makefile src/system/scaffolding/images/Makefile src/system/scaffolding/views/Makefile src/system/scaffolding/Makefile src/system/Makefile src/Makefile" + ac_config_files="$ac_config_files Makefile codepot.spec etc/Makefile etc/codepot.ini etc/codepot.a2ldap etc/start-commit etc/pre-revprop-change DEBIAN/Makefile DEBIAN/control DEBIAN/postinst DEBIAN/postrm src/config.php src/codepot/config/Makefile src/codepot/controllers/Makefile src/codepot/errors/Makefile src/codepot/helpers/Makefile src/codepot/hooks/Makefile src/codepot/language/english/Makefile src/codepot/language/indonesian/Makefile src/codepot/language/korean/Makefile src/codepot/language/Makefile src/codepot/libraries/Makefile src/codepot/models/Makefile src/codepot/views/Makefile src/codepot/Makefile src/css/images/Makefile src/css/Makefile src/js/prettify/Makefile src/js/Makefile src/system/cache/Makefile src/system/codeigniter/Makefile src/system/database/drivers/mssql/Makefile src/system/database/drivers/mysql/Makefile src/system/database/drivers/mysqli/Makefile src/system/database/drivers/oci8/Makefile src/system/database/drivers/odbc/Makefile src/system/database/drivers/postgre/Makefile src/system/database/drivers/sqlite/Makefile src/system/database/drivers/Makefile src/system/database/Makefile src/system/fonts/Makefile src/system/helpers/Makefile src/system/language/english/Makefile src/system/language/korean/Makefile src/system/language/Makefile src/system/libraries/Makefile src/system/logs/Makefile src/system/plugins/Makefile src/system/scaffolding/images/Makefile src/system/scaffolding/views/Makefile src/system/scaffolding/Makefile src/system/Makefile src/Makefile" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -3077,6 +3077,7 @@ do "etc/codepot.ini" ) CONFIG_FILES="$CONFIG_FILES etc/codepot.ini" ;; "etc/codepot.a2ldap" ) CONFIG_FILES="$CONFIG_FILES etc/codepot.a2ldap" ;; "etc/start-commit" ) CONFIG_FILES="$CONFIG_FILES etc/start-commit" ;; + "etc/pre-revprop-change" ) CONFIG_FILES="$CONFIG_FILES etc/pre-revprop-change" ;; "DEBIAN/Makefile" ) CONFIG_FILES="$CONFIG_FILES DEBIAN/Makefile" ;; "DEBIAN/control" ) CONFIG_FILES="$CONFIG_FILES DEBIAN/control" ;; "DEBIAN/postinst" ) CONFIG_FILES="$CONFIG_FILES DEBIAN/postinst" ;; diff --git a/codepot/configure.ac b/codepot/configure.ac index ecaf3357..7dbf44ba 100644 --- a/codepot/configure.ac +++ b/codepot/configure.ac @@ -87,6 +87,7 @@ AC_CONFIG_FILES([ etc/codepot.ini etc/codepot.a2ldap etc/start-commit + etc/pre-revprop-change DEBIAN/Makefile DEBIAN/control DEBIAN/postinst diff --git a/codepot/etc/Makefile.am b/codepot/etc/Makefile.am index 8b8107fd..1c43fe99 100644 --- a/codepot/etc/Makefile.am +++ b/codepot/etc/Makefile.am @@ -1,7 +1,10 @@ cfgdir=$(CFGDIR) cfg_DATA = codepot.ini codepot.mysql codepot.a2ldap -cfg_SCRIPTS = start-commit pre-commit post-commit pre-revprop-change post-revprop-change +cfg_SCRIPTS = start-commit pre-commit post-commit pre-revprop-change post-revprop-change -EXTRA_DIST = $(cfg_DATA) $(cfg_SCRIPTS) +perldir=$(CFGDIR)/perl/Codepot +perl_SCRIPTS=perl/Codepot/AccessHandler.pm perl/Codepot/AuthenHandler.pm + +EXTRA_DIST = $(cfg_DATA) $(cfg_SCRIPTS) $(perl_SCRIPTS) diff --git a/codepot/etc/Makefile.in b/codepot/etc/Makefile.in index d48b70e2..c4aad7c8 100644 --- a/codepot/etc/Makefile.in +++ b/codepot/etc/Makefile.in @@ -38,7 +38,7 @@ POST_UNINSTALL = : subdir = etc DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ $(srcdir)/codepot.a2ldap.in $(srcdir)/codepot.ini.in \ - $(srcdir)/start-commit.in + $(srcdir)/pre-revprop-change.in $(srcdir)/start-commit.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/ac/m4/as-ac-expand.m4 \ $(top_srcdir)/configure.ac @@ -46,10 +46,13 @@ am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/./config.h -CONFIG_CLEAN_FILES = codepot.ini codepot.a2ldap start-commit -am__installdirs = "$(DESTDIR)$(cfgdir)" "$(DESTDIR)$(cfgdir)" +CONFIG_CLEAN_FILES = codepot.ini codepot.a2ldap start-commit \ + pre-revprop-change +am__installdirs = "$(DESTDIR)$(cfgdir)" "$(DESTDIR)$(perldir)" \ + "$(DESTDIR)$(cfgdir)" cfgSCRIPT_INSTALL = $(INSTALL_SCRIPT) -SCRIPTS = $(cfg_SCRIPTS) +perlSCRIPT_INSTALL = $(INSTALL_SCRIPT) +SCRIPTS = $(cfg_SCRIPTS) $(perl_SCRIPTS) SOURCES = DIST_SOURCES = am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; @@ -145,8 +148,10 @@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ wwwdir = @wwwdir@ cfg_DATA = codepot.ini codepot.mysql codepot.a2ldap -cfg_SCRIPTS = start-commit pre-commit post-commit pre-revprop-change post-revprop-change -EXTRA_DIST = $(cfg_DATA) $(cfg_SCRIPTS) +cfg_SCRIPTS = start-commit pre-commit post-commit pre-revprop-change post-revprop-change +perldir = $(CFGDIR)/perl/Codepot +perl_SCRIPTS = perl/Codepot/AccessHandler.pm perl/Codepot/AuthenHandler.pm +EXTRA_DIST = $(cfg_DATA) $(cfg_SCRIPTS) $(perl_SCRIPTS) all: all-am .SUFFIXES: @@ -185,6 +190,8 @@ codepot.a2ldap: $(top_builddir)/config.status $(srcdir)/codepot.a2ldap.in cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ start-commit: $(top_builddir)/config.status $(srcdir)/start-commit.in cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ +pre-revprop-change: $(top_builddir)/config.status $(srcdir)/pre-revprop-change.in + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ install-cfgSCRIPTS: $(cfg_SCRIPTS) @$(NORMAL_INSTALL) test -z "$(cfgdir)" || $(mkdir_p) "$(DESTDIR)$(cfgdir)" @@ -204,6 +211,25 @@ uninstall-cfgSCRIPTS: echo " rm -f '$(DESTDIR)$(cfgdir)/$$f'"; \ rm -f "$(DESTDIR)$(cfgdir)/$$f"; \ done +install-perlSCRIPTS: $(perl_SCRIPTS) + @$(NORMAL_INSTALL) + test -z "$(perldir)" || $(mkdir_p) "$(DESTDIR)$(perldir)" + @list='$(perl_SCRIPTS)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + if test -f $$d$$p; then \ + f=`echo "$$p" | sed 's|^.*/||;$(transform)'`; \ + echo " $(perlSCRIPT_INSTALL) '$$d$$p' '$(DESTDIR)$(perldir)/$$f'"; \ + $(perlSCRIPT_INSTALL) "$$d$$p" "$(DESTDIR)$(perldir)/$$f"; \ + else :; fi; \ + done + +uninstall-perlSCRIPTS: + @$(NORMAL_UNINSTALL) + @list='$(perl_SCRIPTS)'; for p in $$list; do \ + f=`echo "$$p" | sed 's|^.*/||;$(transform)'`; \ + echo " rm -f '$(DESTDIR)$(perldir)/$$f'"; \ + rm -f "$(DESTDIR)$(perldir)/$$f"; \ + done uninstall-info-am: install-cfgDATA: $(cfg_DATA) @$(NORMAL_INSTALL) @@ -230,6 +256,7 @@ CTAGS: distdir: $(DISTFILES) + $(mkdir_p) $(distdir)/perl/Codepot @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ list='$(DISTFILES)'; for file in $$list; do \ @@ -260,7 +287,7 @@ check-am: all-am check: check-am all-am: Makefile $(SCRIPTS) $(DATA) installdirs: - for dir in "$(DESTDIR)$(cfgdir)" "$(DESTDIR)$(cfgdir)"; do \ + for dir in "$(DESTDIR)$(cfgdir)" "$(DESTDIR)$(perldir)" "$(DESTDIR)$(cfgdir)"; do \ test -z "$$dir" || $(mkdir_p) "$$dir"; \ done install: install-am @@ -305,7 +332,8 @@ info: info-am info-am: -install-data-am: install-cfgDATA install-cfgSCRIPTS +install-data-am: install-cfgDATA install-cfgSCRIPTS \ + install-perlSCRIPTS install-exec-am: @@ -331,17 +359,19 @@ ps: ps-am ps-am: -uninstall-am: uninstall-cfgDATA uninstall-cfgSCRIPTS uninstall-info-am +uninstall-am: uninstall-cfgDATA uninstall-cfgSCRIPTS uninstall-info-am \ + uninstall-perlSCRIPTS .PHONY: all all-am check check-am clean clean-generic distclean \ distclean-generic distdir dvi dvi-am html html-am info info-am \ install install-am install-cfgDATA install-cfgSCRIPTS \ install-data install-data-am install-exec install-exec-am \ - install-info install-info-am install-man install-strip \ - installcheck installcheck-am installdirs maintainer-clean \ - maintainer-clean-generic mostlyclean mostlyclean-generic pdf \ - pdf-am ps ps-am uninstall uninstall-am uninstall-cfgDATA \ - uninstall-cfgSCRIPTS uninstall-info-am + install-info install-info-am install-man install-perlSCRIPTS \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-generic pdf pdf-am ps ps-am uninstall uninstall-am \ + uninstall-cfgDATA uninstall-cfgSCRIPTS uninstall-info-am \ + uninstall-perlSCRIPTS # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/codepot/etc/pre-revprop-change b/codepot/etc/pre-revprop-change deleted file mode 100755 index 263da313..00000000 --- a/codepot/etc/pre-revprop-change +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -REPOBASE="`basename "${1}"`" -REVISION="${2}" -USER="${3}" -PROPNAME="${4}" -ACTION="${5}" - -# [STDIN] PROPVAL ** the new property value is passed via STDIN. - -ans="`wget -q -O- "%API%/projectHasMember/${REPOBASE}/${USER}" 2>/dev/null`" -[ "${ans}" = "YES" ] && exit 0 - -[ "${ans}" = "NO" ] && { - echo "-------------------------------------------------------------" >&2 - echo " ${USER} is not a member of ${REPOBASE}" >&2 - echo "-------------------------------------------------------------" >&2 - exit 1 -} - -echo "---------------------------------------------------------------------" >&2 -echo " Failed to check membership of ${REPOBASE} for ${USER}" >&2 -echo "---------------------------------------------------------------------" >&2 -exit 1 diff --git a/codepot/etc/pre-revprop-change.in b/codepot/etc/pre-revprop-change.in new file mode 100644 index 00000000..f5a857c0 --- /dev/null +++ b/codepot/etc/pre-revprop-change.in @@ -0,0 +1,108 @@ +#!/usr/bin/perl + +use strict; + +use Config::Simple; +use DBI; +use File::Basename; + +my $CFG_FILE = '@CFGDIR@/codepot.ini'; +my $REPOBASE = basename($ARGV[0]); +my $REVISION= $ARGV[1]; +my $USER = $ARGV[2]; +my $PROPNAME = $ARGV[3]; +my $ACTION = $ARGV[4]; + +sub get_config +{ + my $cfg = new Config::Simple(); + + if (!$cfg->read ($CFG_FILE)) + { + return undef; + } + + my $config = { + database_hostname => $cfg->param ("database_hostname"), + database_username => $cfg->param ("database_username"), + database_password => $cfg->param ("database_password"), + database_name => $cfg->param ("database_name"), + database_driver => $cfg->param ("database_driver"), + database_prefix => $cfg->param ("database_prefix") + }; + + return $config; +} + +sub open_database +{ + my ($cfg) = @_; + + my $dbtype = $cfg->{database_driver}; + my $dbname = $cfg->{database_name}; + my $dbhost = $cfg->{database_hostname}; + + my $dbh = DBI->connect( + "DBI:$dbtype:$dbname:$dbhost", + $cfg->{database_username}, + $cfg->{database_password}, + { RaiseError => 0, PrintError => 0, AutoCommit => 0 } + ); + + return $dbh; +} + +sub close_database +{ + my ($dbh) = @_; + $dbh->disconnect (); +} + +sub is_project_member +{ + my ($dbh, $prefix, $projectid, $userid) = @_; + + my $query = $dbh->prepare ("SELECT projectid FROM ${prefix}project_membership WHERE userid=? AND projectid=?"); + if (!$query || !$query->execute ($userid, $projectid)) + { + return (-1, $dbh->errstr()); + } + + my @row = $query->fetchrow_array; + return (((scalar(@row) > 0)? 1: 0), undef); +} + +#------------------------------------------------------------ +# MAIN +#------------------------------------------------------------ + +my $cfg = get_config (); +if (!defined($cfg)) +{ + print (STDERR "Cannot load codepot configuration file\n"); + exit (1); +} + +my $dbh = open_database ($cfg); +if (!defined($dbh)) +{ + print (STDERR "Cannot open database\n"); + exit (1); +} + +my ($member, $errstr) = is_project_member ($dbh, $cfg->{database_prefix}, $REPOBASE, $USER); + +close_database ($dbh); + +if ($member <= -1) +{ + print (STDERR "Cannot check membership - $errstr\n"); + exit (1); +} +elsif ($member == 0) +{ + print (STDERR "$USER doesn't belong to the $REPOBASE project\n"); + exit (1); +} + +exit (0);