* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with FusionForge; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
forge_define_config_item ('default_server', 'scmgit', forge_get_config ('web_host')) ;
$b .= '<p>';
$b .= _('Only project developers can access the GIT tree via this method. SSH must be installed on your client machine. Enter your site password when prompted.');
$b .= '</p>';
- $b .= '<p><tt>git clone git+ssh://'.$d.'@' . $project->getSCMBox() . '/'. forge_get_config('scm_root', 'scmgit') .'/'. $project->getUnixName() .'/'. $project->getUnixName() .'.git</tt></p>' ;
+ $b .= '<p><tt>git clone git+ssh://'.$d.'@' . $project->getSCMBox() . '/'. forge_get_config('repos_path', 'scmgit') .'/'. $project->getUnixName() .'/'. $project->getUnixName() .'.git</tt></p>' ;
} elseif (forge_get_config('use_dav', 'scmgit')) {
$protocol = forge_get_config('use_ssl', 'scmgit')? 'https' : 'http';
$b = '<h2>';
$b .= '<p>';
$b .= _('Only project developers can access the GIT tree via this method. Enter your site password when prompted.');
$b .= '</p>';
- $b .= '<p><tt>git clone '.$protocol.'://'.$d.'@' . $project->getSCMBox() . '/'. forge_get_config('scm_root', 'scmgit') .'/'. $project->getUnixName() .'/'. $project->getUnixName() .'.git</tt></p>' ;
+ $b .= '<p><tt>git clone '.$protocol.'://'.$d.'@' . $project->getSCMBox() . '/'. forge_get_config('repos_path', 'scmgit') .'/'. $project->getUnixName() .'/'. $project->getUnixName() .'.git</tt></p>' ;
}
} else {
- $b = '<h2>';
- $b .= _('Developer GIT Access via SSH');
- $b .= '</h2>';
- $b .= '<p>';
- $b .= _('Only project developers can access the GIT tree via this method. SSH must be installed on your client machine. Substitute <i>developername</i> with the proper value. Enter your site password when prompted.');
- $b .= '</p>';
- $b .= '<p><tt>git clone git+ssh://<i>'._('developername').'</i>@' . $project->getSCMBox() . '/'. forge_get_config('scm_root', 'scmgit') .'/'. $project->getUnixName() .'/'. $project->getUnixName() .'.git</tt></p>' ;
+ if (forge_get_config('use_ssh', 'scmgit')) {
+ $b = '<h2>';
+ $b .= _('Developer GIT Access via SSH');
+ $b .= '</h2>';
+ $b .= '<p>';
+ $b .= _('Only project developers can access the GIT tree via this method. SSH must be installed on your client machine. Substitute <i>developername</i> with the proper value. Enter your site password when prompted.');
+ $b .= '</p>';
+ $b .= '<p><tt>git clone git+ssh://<i>'._('developername').'</i>@' . $project->getSCMBox() . '/'. forge_get_config('repos_path', 'scmgit') .'/'. $project->getUnixName() .'/'. $project->getUnixName() .'.git</tt></p>' ;
+ } elseif (forge_get_config('use_dav', 'scmgit')) {
+ $protocol = forge_get_config('use_ssl', 'scmgit')? 'https' : 'http';
+ $b = '<h2>';
+ $b .= _('Developer GIT Access via HTTP');
+ $b .= '</h2>';
+ $b .= '<p>';
+ $b .= _('Only project developers can access the GIT tree via this method. Enter your site password when prompted.');
+ $b .= '</p>';
+ $b .= '<p><tt>git clone '.$protocol.'://<i>'._('developername').'</i>@' . $project->getSCMBox() . '/'. forge_get_config('repos_path', 'scmgit') .'/'. $project->getUnixName() .'/'. $project->getUnixName() .'.git</tt></p>' ;
+ }
}
if (session_loggedin()) {
$b .= '<p>';
$b .= _('You have a personal repository for this project, accessible through SSH with the following method. Enter your site password when prompted.');
$b .= '</p>';
- $b .= '<p><tt>git clone git+ssh://'.$u->getUnixName().'@' . $project->getSCMBox() . forge_get_config('scm_path', 'scmgit') .'/'. $project->getUnixName() .'/users/'. $u->getUnixName() .'.git</tt></p>' ;
+ $b .= '<p><tt>git clone git+ssh://'.$u->getUnixName().'@' . $project->getSCMBox() . forge_get_config('repos_path', 'scmgit') .'/'. $project->getUnixName() .'/users/'. $u->getUnixName() .'.git</tt></p>' ;
} else {
$glist = $u->getGroups();
foreach ($glist as $g) {
if ($project->usesPlugin ($this->name)) {
if ($this->browserDisplayable ($project)) {
- print '<iframe src="'.util_make_url ("/plugins/scmgit/cgi-bin/gitweb.cgi?p=".$project->getUnixName().'/'.$project->getUnixName().'.git').'" frameborder="no" width=100% height=700></iframe>' ;
+ print '<iframe src="'.util_make_url ("/plugins/scmgit/cgi-bin/gitweb.cgi?p=".$project->getUnixName().'/'.$project->getUnixName().'.git').'" frameborder="0" width=100% height=700></iframe>' ;
}
}
}
return ;
}
+ static function createUserRepo ($params) {
+ $project = $params['project'];
+ $project_name = $project->getUnixName();
+ $user_name = $params['user_name'];
+ $unix_group = $params['unix_group'];
+ $main_repo = $params['main_repo'];
+ $root = $params['root'];
+
+ $repodir = $root . '/users/' . $user_name . '.git' ;
+ system("su - $user_name -c 'chgrp $unix_group $repodir'");
+ if ($project->enableAnonSCM()) {
+ chmod ($repodir, 02755);
+ } else {
+ chmod ($repodir, 02750);
+ }
+ if (!is_file ("$repodir/HEAD") && !is_dir("$repodir/objects") && !is_dir("$repodir/refs")) {
+ system ("git clone --bare $main_repo $repodir") ;
+ system ("GIT_DIR=\"$repodir\" git update-server-info") ;
+ if (is_file ("$repodir/hooks/post-update.sample")) {
+ rename ("$repodir/hooks/post-update.sample",
+ "$repodir/hooks/post-update") ;
+ }
+ if (!is_file ("$repodir/hooks/post-update")) {
+ $f = fopen ("$repodir/hooks/post-update","x+") ;
+ fwrite ($f, "exec git-update-server-info\n") ;
+ fclose ($f) ;
+ }
+ if (is_file ("$repodir/hooks/post-update")) {
+ system ("chmod +x $repodir/hooks/post-update") ;
+ }
+ system("echo \"Git repository for user $user_name in project $project_name\" > $repodir/description");
+ }
+ }
+
function createOrUpdateRepo ($params) {
$project = $this->checkParams ($params) ;
if (!$project) {
system ("mkdir -p $root") ;
$main_repo = $root . '/' . $project_name . '.git' ;
- if (!is_file ("$main_repo/HEAD") && !is_dir("$main_repo/objects") && !is_dir("$main_repo/refs")) {
- system ("GIT_DIR=\"$main_repo\" git init --bare --shared=group") ;
- system ("GIT_DIR=\"$main_repo\" git update-server-info") ;
- if (is_file ("$main_repo/hooks/post-update.sample")) {
- rename ("$main_repo/hooks/post-update.sample",
- "$main_repo/hooks/post-update") ;
+ if (!is_dir($main_repo) || (!is_file("$main_repo/HEAD") &&
+ !is_dir("$main_repo/objects") && !is_dir("$main_repo/refs"))) {
+ $tmp_repo = util_mkdtemp('.git', $project_name);
+ if ($tmp_repo == false) {
+ return false;
}
- if (!is_file ("$main_repo/hooks/post-update")) {
- $f = fopen ("$main_repo/hooks/post-update") ;
+ system ("GIT_DIR=\"$tmp_repo\" git init --bare --shared=group") ;
+ system ("GIT_DIR=\"$tmp_repo\" git update-server-info") ;
+ if (is_file ("$tmp_repo/hooks/post-update.sample")) {
+ rename ("$tmp_repo/hooks/post-update.sample",
+ "$tmp_repo/hooks/post-update") ;
+ }
+ if (!is_file ("$tmp_repo/hooks/post-update")) {
+ $f = fopen ("$tmp_repo/hooks/post-update") ;
fwrite ($f, "exec git-update-server-info\n") ;
fclose ($f) ;
}
- if (is_file ("$main_repo/hooks/post-update")) {
- system ("chmod +x $main_repo/hooks/post-update") ;
+ if (is_file ("$tmp_repo/hooks/post-update")) {
+ system ("chmod +x $tmp_repo/hooks/post-update") ;
+ }
+ system ("echo \"Git repository for $project_name\" > $tmp_repo/description") ;
+ system ("find $tmp_repo -type d | xargs chmod g+s") ;
+ system ("chgrp -R $unix_group $tmp_repo") ;
+ if ($project->enableAnonSCM()) {
+ system ("chmod g+wX,o+rX-w $root") ;
+ system ("chmod -R g+wX,o+rX-w $tmp_repo") ;
+ } else {
+ system ("chmod g+wX,o-rwx $root") ;
+ system ("chmod -R g+wX,o-rwx $tmp_repo") ;
+ }
+ $ret = true;
+ /*
+ * $main_repo can already exist, for example if it’s
+ * not a directory or doesn’t contain a HEAD file or
+ * an objects or refs subdirectory… move it out of
+ * the way in these cases
+ */
+ system("if test -e $main_repo || test -h $main_repo; then d=\$(mktemp -d $main_repo.scmgit-moved.XXXXXXXXXX) && mv -f $main_repo \$d/; fi");
+ /* here’s still a TOCTOU but we check $ret below */
+ system("mv $tmp_repo $main_repo", $ret);
+ if (!$ret) {
+ return false;
}
- system ("echo \"Git repository for $project_name\" > $main_repo/description") ;
- system ("find $main_repo -type d | xargs chmod g+s") ;
}
- system ("chgrp -R $unix_group $root") ;
+ system ("chgrp $unix_group $root") ;
system ("chmod g+s $root") ;
if ($project->enableAnonSCM()) {
system ("chmod g+wX,o+rX-w $root") ;
- system ("chmod -R g+wX,o+rX-w $main_repo") ;
+ system ("chmod g+wX,o+rX-w $main_repo") ;
} else {
system ("chmod g+wX,o-rwx $root") ;
- system ("chmod -R g+wX,o-rwx $main_repo") ;
+ system ("chmod g+wX,o-rwx $main_repo") ;
}
$result = db_query_params ('SELECT u.user_name FROM plugin_scmgit_personal_repos p, users u WHERE p.group_id=$1 AND u.user_id=p.user_id AND u.unix_status=$2',
system ("mkdir -p $root/users") ;
$user_name = db_result($result,$i,'user_name');
$repodir = $root . '/users/' . $user_name . '.git' ;
-
- if (!is_file ("$repodir/HEAD") && !is_dir("$repodir/objects") && !is_dir("$repodir/refs")) {
- system ("git clone --bare $main_repo $repodir") ;
- system ("GIT_DIR=\"$repodir\" git update-server-info") ;
- if (is_file ("$repodir/hooks/post-update.sample")) {
- rename ("$repodir/hooks/post-update.sample",
- "$repodir/hooks/post-update") ;
- }
- if (!is_file ("$repodir/hooks/post-update")) {
- $f = fopen ("$repodir/hooks/post-update") ;
- fwrite ($f, "exec git-update-server-info\n") ;
- fclose ($f) ;
- }
- if (is_file ("$repodir/hooks/post-update")) {
- system ("chmod +x $repodir/hooks/post-update") ;
- }
- system ("echo \"Git repository for user $owner in project $project_name\" > $repodir/description") ;
- system ("chown -R $user_name:$unix_group $repodir") ;
+
+ if (!is_dir($repodir) && mkdir ($repodir, 0700)) {
+ chown ($repodir, $user_name) ;
+
+ $params = array();
+ $params['project'] = $project;
+ $params['user_name'] = $user_name;
+ $params['unix_group'] = $unix_group;
+ $params['root'] = $root;
+ $params['main_repo'] = $main_repo;
+
+ util_sudo_effective_user($user_name,
+ array("GitPlugin","createUserRepo"),
+ $params);
}
}
if (is_dir ("$root/users")) {
if ($project->enableAnonSCM()) {
- system ("chmod -R g+rX-w,o+rX-w $root/users") ;
+ system ("chmod g+rX-w,o+rX-w $root/users") ;
} else {
- system ("chmod -R g+rX-w,o-rwx $root/users") ;
+ system ("chmod g+rX-w,o-rwx $root/users") ;
}
}
}
function getRepositories($path) {
if (! is_dir($path))
- return;
+ return array();
$list = array();
$entries = scandir($path);
foreach ($entries as $entry) {