
com.aoindustries.aoserv.master.CvsHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aoserv-master Show documentation
Show all versions of aoserv-master Show documentation
Master server for the AOServ Platform.
/*
* aoserv-master - Master server for the AOServ Platform.
* Copyright (C) 2002-2013, 2015, 2017, 2018, 2019, 2020 AO Industries, Inc.
* [email protected]
* 7262 Bull Pen Cir
* Mobile, AL 36695
*
* This file is part of aoserv-master.
*
* aoserv-master is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* aoserv-master is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with aoserv-master. If not, see .
*/
package com.aoindustries.aoserv.master;
import com.aoindustries.aoserv.client.distribution.OperatingSystemVersion;
import com.aoindustries.aoserv.client.linux.PosixPath;
import com.aoindustries.aoserv.client.linux.UserType;
import com.aoindustries.aoserv.client.schema.Table;
import com.aoindustries.aoserv.client.scm.CvsRepository;
import com.aoindustries.collections.IntList;
import com.aoindustries.dbc.DatabaseConnection;
import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
/**
* The CvsHandler
handles all the accesses to the scm.CvsRepository
table.
*
* @author AO Industries, Inc.
*/
final public class CvsHandler {
private final static Map disabledCvsRepositories = new HashMap<>();
public static int addCvsRepository(
DatabaseConnection conn,
RequestSource source,
InvalidateList invalidateList,
int linuxServer, // TODO: Redundant with linuxUserServer and linuxGroupServer
PosixPath path,
int linuxUserServer,
int linuxGroupServer,
long mode
) throws IOException, SQLException {
synchronized(CvsHandler.class) {
// Security checks
NetHostHandler.checkAccessHost(conn, source, "addCvsRepository", linuxServer);
LinuxAccountHandler.checkAccessUserServer(conn, source, "addCvsRepository", linuxUserServer);
LinuxAccountHandler.checkAccessGroupServer(conn, source, "addCvsRepository", linuxGroupServer);
if(LinuxAccountHandler.isUserServerDisabled(conn, linuxUserServer)) throw new SQLException("Unable to add CvsRepository, UserServer disabled: "+linuxUserServer);
// OperatingSystem settings
int osv = NetHostHandler.getOperatingSystemVersionForHost(conn, linuxServer);
PosixPath httpdSharedTomcatsDir = OperatingSystemVersion.getHttpdSharedTomcatsDirectory(osv);
String httpdSharedTomcatsDirStr = httpdSharedTomcatsDir.toString();
PosixPath httpdSitesDir = OperatingSystemVersion.getHttpdSitesDirectory(osv);
String httpdSitesDirStr = httpdSitesDir.toString();
// Integrity checks
if(!CvsRepository.isValidPath(path)) throw new SQLException("Invalid path: "+path);
String pathStr = path.toString();
if(pathStr.startsWith("/home/")) {
// Must be able to access one of the linux.UserServer with that home directory
//
// This means there must be an accessible account that has a home directory that is a prefix of this docbase.
// Such as /home/e/example/ being a prefix of /home/e/example/my-webapp
IntList lsas = conn.executeIntListQuery(
"select\n"
+ " id\n"
+ "from\n"
+ " linux.\"UserServer\"\n"
+ "where\n"
+ " ao_server=?\n"
+ " and (home || '/')=substring(? from 1 for (length(home) + 1))",
linuxServer,
pathStr
);
boolean found=false;
for(int c=0;c
© 2015 - 2025 Weber Informatics LLC | Privacy Policy