From 941a4951442a628a47dcefb4d0190699bacf71f7 Mon Sep 17 00:00:00 2001 From: Loic d'Anterroches Date: Mon, 19 Jan 2009 20:44:03 +0100 Subject: [PATCH] Added the bulk of the access control to the git repositories. --- scripts/gitcron.php | 41 ++++++++++++++++++++++++++++++++ scripts/gitserve.py | 34 ++++++++++++++++++++++++++ src/IDF/Plugin/SyncGit/Cron.php | 19 +++++++++++---- src/IDF/Plugin/SyncGit/Serve.php | 34 +++++++++++++++----------- 4 files changed, 110 insertions(+), 18 deletions(-) create mode 100644 scripts/gitcron.php create mode 100644 scripts/gitserve.py diff --git a/scripts/gitcron.php b/scripts/gitcron.php new file mode 100644 index 0000000..ee44091 --- /dev/null +++ b/scripts/gitcron.php @@ -0,0 +1,41 @@ +template; - $keys = Pluf::factory('IDF_Key')->getList(array('view'=>'join_user')); - $cmd = Pluf::f('idf_plugin_syncgit_path_gitserve', '/bin/false'); + $cmd = Pluf::f('idf_plugin_syncgit_path_gitserve', '/dev/null'); $authorized_keys = Pluf::f('idf_plugin_syncgit_path_authorized_keys', false); if (false == $authorized_keys) { throw new Pluf_Exception_SettingError('Setting git_path_authorized_keys not set.'); @@ -48,6 +46,7 @@ class IDF_Plugin_SyncGit_Cron throw new Exception('Cannot create file: '.$authorized_keys); } $out = ''; + $keys = Pluf::factory('IDF_Key')->getList(array('view'=>'join_user')); foreach ($keys as $key) { if (strlen($key->content) > 40 // minimal check and preg_match('/^[a-zA-Z][a-zA-Z0-9_.-]*(@[a-zA-Z][a-zA-Z0-9.-]*)?$/', $key->login)) { @@ -57,4 +56,16 @@ class IDF_Plugin_SyncGit_Cron } file_put_contents($authorized_keys, $out, LOCK_EX); } + + /** + * Check if a sync is needed. + * + */ + public static function main() + { + if (file_exists(Pluf::f('idf_plugin_syncgit_sync_file'))) { + @unlink(Pluf::f('idf_plugin_syncgit_sync_file')); + self::sync(); + } + } } diff --git a/src/IDF/Plugin/SyncGit/Serve.php b/src/IDF/Plugin/SyncGit/Serve.php index 5a25696..6ee1132 100644 --- a/src/IDF/Plugin/SyncGit/Serve.php +++ b/src/IDF/Plugin/SyncGit/Serve.php @@ -104,15 +104,13 @@ class IDF_Plugin_SyncGit_Serve */ public static function main($argv, $env) { - if (count($argv) != 1) { - print('Missing argument USER.'); - exit(1); + if (count($argv) != 2) { + self::fatalError('Missing argument USER.'); } - $username = $argv[0]; + $username = $argv[1]; umask(0022); if (!isset($env['SSH_ORIGINAL_COMMAND'])) { - print('Need SSH_ORIGINAL_COMMAND in environment.'); - exit(1); + self::fatalError('Need SSH_ORIGINAL_COMMAND in environment.'); } $cmd = $env['SSH_ORIGINAL_COMMAND']; chdir(Pluf::f('idf_plugin_syncgit_git_home_dir', '/home/git')); @@ -120,15 +118,10 @@ class IDF_Plugin_SyncGit_Serve try { $new_cmd = $serve->serve($username, $cmd); } catch (Exception $e) { - print($e->getMessage()); - exit(1); + self::fatalError($e->getMessage()); } - passthru(sprintf('git shell -c %s', $new_cmd), $res); - if ($res != 0) { - print('Cannot execute git-shell.'); - exit(1); - } - exit(); + print $new_cmd; + exit(0); } /** @@ -164,6 +157,8 @@ class IDF_Plugin_SyncGit_Serve $user = $users[0]; $request = new StdClass(); $request->user = $user; + $request->conf = $conf; + $request->project = $project; if (true === IDF_Precondition::accessTabGeneric($request, 'source_access_rights')) { if ($mode == 'readonly') { return array(Pluf::f('idf_plugin_syncgit_base_repositories', '/home/git/repositories'), @@ -177,6 +172,17 @@ class IDF_Plugin_SyncGit_Serve return false; } + /** + * Die on a message on stderr. + * + * @param string Message + */ + public static function fatalError($mess) + { + fwrite(STDERR, $mess."\n"); + exit(1); + } + /** * Init a new empty bare repository. *