Commit 714d0548 authored by mr-ti's avatar mr-ti

No commit message

No commit message
parent dabbdd3a
......@@ -12,6 +12,7 @@
#include "auth.h"
#include <unicomctrl/exception.h>
#include <unicomctrl/dbexception.h>
Auth *Auth::auth=NULL;
......@@ -55,10 +56,12 @@ void Auth::mkListUser(String2DList& listUser){
db->execAndOpen();
db->extractAll(listUser);
db->close();
}catch(TemporarilyUnavailableException e){
throw;
}catch(Exception e){
onFatalError();
oute << e.getMsg() << endlIO;
throw Exception(10309,"Internal server error");
throw Exception("Internal server error");
}
}
......@@ -71,10 +74,12 @@ void Auth::mkListUser(StringList& listUser, const string &role) {
db->execAndOpen();
db->extractCol(listUser);
db->close();
}catch(TemporarilyUnavailableException e){
throw;
} catch (Exception e) {
onFatalError();
oute << e.getMsg() << endlIO;
throw Exception(10309,"Internal server error");
throw Exception("Internal server error");
}
}
......@@ -87,10 +92,12 @@ void Auth::mkListRole(String2DList& listRole, const string &user, bool cumul){
db->execAndOpen();
db->extractAll(listRole);
db->close();
}catch(TemporarilyUnavailableException e){
throw;
}catch(Exception e){
onFatalError();
oute << e.getMsg() << endlIO;
throw Exception(10309,"Internal server error");
throw Exception("Internal server error");
}
}
......@@ -103,10 +110,12 @@ void Auth::mkListRole(StringList& listRole, const string &user, bool cumul){
db->execAndOpen();
db->extractCol(listRole);
db->close();
}catch(TemporarilyUnavailableException e){
throw;
}catch(Exception e){
onFatalError();
oute << e.getMsg() << endlIO;
throw Exception(10309,"Internal server error");
throw Exception("Internal server error");
}
}
......@@ -117,10 +126,12 @@ void Auth::createUser(const string& user, const string& passwd, bool admin) {
try{
db->setSQL("INSERT INTO users (login,passwd,is_admin,is_role) VALUES('"+user+"',ENCRYPT('"+passwd+"'),"+admiStr+",'0');");
db->exec();
}catch(TemporarilyUnavailableException e){
throw;
}catch(Exception e){
onFatalError();
oute << e.getMsg() << endlIO;
throw Exception(10309,"Internal server error");
throw Exception("Internal server error");
}
}
......@@ -131,10 +142,12 @@ void Auth::alterUser(const string& user, const string& passwd, bool admin) {
try{
db->setSQL("UPDATE users SET passwd=ENCRYPT('"+passwd+"'),is_admin='"+admiStr+"' WHERE id_user='"+iduser+"';");
db->exec();
}catch(TemporarilyUnavailableException e){
throw;
}catch(Exception e){
onFatalError();
oute << e.getMsg() << endlIO;
throw Exception(10309,"Internal server error");
throw Exception("Internal server error");
}
}
......@@ -145,10 +158,12 @@ void Auth::alterUser(const string& user, bool admin) {
try{
db->setSQL("UPDATE users SET is_admin='"+admiStr+"' WHERE id_user='"+iduser+"';");
db->exec();
}catch(TemporarilyUnavailableException e){
throw;
}catch(Exception e){
onFatalError();
oute << e.getMsg() << endlIO;
throw Exception(10309,"Internal server error");
throw Exception("Internal server error");
}
}
......@@ -158,10 +173,12 @@ void Auth::alterUser(const string& user, const string& passwd) {
try{
db->setSQL("UPDATE users SET passwd=ENCRYPT('"+passwd+"') WHERE id_user='"+iduser+"';");
db->exec();
}catch(TemporarilyUnavailableException e){
throw;
}catch(Exception e){
onFatalError();
oute << e.getMsg() << endlIO;
throw Exception(10309,"Internal server error");
throw Exception("Internal server error");
}
}
......@@ -171,10 +188,12 @@ void Auth::dropUser(const string& user) {
try{
db->setSQL("DELETE FROM users WHERE id_user='"+iduser+"';");
db->exec();
}catch(TemporarilyUnavailableException e){
throw;
}catch(Exception e){
onFatalError();
oute << e.getMsg() << endlIO;
throw Exception(10309,"Internal server error");
throw Exception("Internal server error");
}
}
......@@ -188,17 +207,17 @@ void Auth::updUser(const string& user, const string& oldPasswd, const string& ne
db->next();
}catch(Exception e){
db->close();
throw Exception(10310,"Login failed");
throw Exception("Login failed");
}
db->close();
db->setSQL("UPDATE users SET passwd=ENCRYPT('"+newPasswd+"') WHERE id_user='"+iduser+"';");
db->exec();
}catch(TemporarilyUnavailableException e){
throw;
}catch(Exception e){
if(e.getNo()==10310)
throw e;
onFatalError();
oute << e.getMsg() << endlIO;
throw Exception(10309,"Internal server error");
throw Exception("Internal server error");
}
}
......@@ -209,10 +228,12 @@ void Auth::createRole(const string& role, bool admin){
try{
db->setSQL("INSERT INTO users (login,is_admin,is_role) VALUES('"+role+"',"+admiStr+",'1');");
db->exec();
}catch(TemporarilyUnavailableException e){
throw;
}catch(Exception e){
onFatalError();
oute << e.getMsg() << endlIO;
throw Exception(10309,"Internal server error");
throw Exception("Internal server error");
}
}
......@@ -223,10 +244,12 @@ void Auth::alterRole(const string& role, bool admin){
try{
db->setSQL("UPDATE users SET is_admin='"+admiStr+"' WHERE id_user='"+iduser+"';");
db->exec();
}catch(TemporarilyUnavailableException e){
throw;
}catch(Exception e){
onFatalError();
oute << e.getMsg() << endlIO;
throw Exception(10309,"Internal server error");
throw Exception("Internal server error");
}
}
......@@ -236,10 +259,12 @@ void Auth::dropRole(const string& role){
try{
db->setSQL("DELETE FROM users WHERE id_user='"+iduser+"';");
db->exec();
}catch(TemporarilyUnavailableException e){
throw;
}catch(Exception e){
onFatalError();
oute << e.getMsg() << endlIO;
throw Exception(10309,"Internal server error");
throw Exception("Internal server error");
}
}
......@@ -252,10 +277,12 @@ void Auth::grant(const string& role, const string& user) {
db->exec();
db->setSQL("INSERT INTO user_role (id_user,id_role) VALUES("+iduser+","+idrole+")");
db->exec();
}catch(TemporarilyUnavailableException e){
throw;
}catch(Exception e){
onFatalError();
oute << e.getMsg() << endlIO;
throw Exception(10309,"Internal server error");
throw Exception("Internal server error");
}
}
......@@ -266,10 +293,12 @@ void Auth::revoke(const string& role, const string& user){
try{
db->setSQL("DELETE FROM user_role WHERE id_user="+iduser+" AND id_role="+idrole);
db->exec();
}catch(TemporarilyUnavailableException e){
throw;
}catch(Exception e){
onFatalError();
oute << e.getMsg() << endlIO;
throw Exception(10309,"Internal server error");
throw Exception("Internal server error");
}
}
......@@ -279,43 +308,45 @@ DB *Auth::getDB(){
void Auth::getIduser(const string& user, string &iduser, bool isRequered, bool isRole, bool isUserRole){
if (user.empty()){
throw Exception(10120,"Empty name");
throw Exception("Empty name");
}
bool role=false;
try{
try {
db->setSQL("SELECT id_user,is_role FROM users WHERE login='"+user+"';");
db->execAndOpen();
db->next();
role=db->extractRowToBool(1);
iduser=db->extractRow();
db->close();
}catch(Exception e){
if(e.getNo()!=1004){
onFatalError();
oute << e.getMsg() << endlIO;
throw Exception(10309,"Internal server error");
}
} catch (ResultEndDBException e) {
db->close();
if(isRequered){
if(isRole)
throw Exception(10301,"The role don't exist");
if (isRequered) {
if (isRole)
throw Exception("The role don't exist");
else
throw Exception(10302,"The user don't exist");
throw Exception("The user don't exist");
}
return;
}catch(TemporarilyUnavailableException e){
throw;
}catch(Exception e){
onFatalError();
oute << e.getMsg() << endlIO;
throw Exception("Internal server error");
}
if((isRole && role) || (!isRole && !role) || isUserRole){
if(!isRequered){
if(isRole)
throw Exception(10303,"The role already exist");
if ((isRole && role) || (!isRole && !role) || isUserRole) {
iduser=db->extractRow();
db->close();
if (!isRequered) {
if (isRole)
throw Exception("The role already exist");
else
throw Exception(10304,"The user already exist");
throw Exception("The user already exist");
}
}else{
if(isRole)
throw Exception(10305,"The role '"+user+"' is expected, but an user with the same name already exist.");
} else {
db->close();
if (isRole)
throw Exception("The role '"+user+"' is expected, but an user with the same name already exist.");
else
throw Exception(10306,"The user '"+user+"' is expected, but a role with the same name already exist.");
throw Exception("The user '"+user+"' is expected, but a role with the same name already exist.");
}
}
......
......@@ -56,7 +56,7 @@ void ReqAnalyzer::exec(const string& request) {
else
return2DList(list2D);
} catch (Exception e) {
throw Exception(0,db->className().substr(6)+" error : "+e.getMsg());
throw Exception(db->className().substr(6)+" error : "+e.getMsg());
}
} else {
db->setSQL(sql);
......@@ -64,14 +64,14 @@ void ReqAnalyzer::exec(const string& request) {
db->exec();
returnMessage("SQL OK.");
} catch (Exception e) {
throw Exception(0,db->className().substr(6)+" error : "+e.getMsg());
throw Exception(db->className().substr(6)+" error : "+e.getMsg());
}
}
} else {
throw Exception(0,"Empty SQL request.");
throw Exception("Empty SQL request.");
}
} else {
throw Exception(0,"SQL request not aviable.");
throw Exception("SQL request not aviable.");
}
} else {
cut(request);
......@@ -95,7 +95,7 @@ void ReqAnalyzer::exec(const string& request) {
" * BUILD; To get the build date.\n"
" NB:\n{choice|other choice} => choice or other choice.\n[Option] => this is an option.\n");
} else {
throw Exception(0,"HELP request error.");
throw Exception("HELP request error.");
}
} else if (equ(elts.at(0),"VERSION")) { // KW
checkNb("VERSION",1);
......@@ -111,7 +111,7 @@ void ReqAnalyzer::exec(const string& request) {
returnMessage("authmanager");
} else if (equ(elts.at(0),"LIST")) { // KW KW
if (elts.size()<2) {
throw Exception(0,"The command \"LIST\" require 1 arguments at least.");
throw Exception("The command \"LIST\" require 1 arguments at least.");
} else {
checkIsKeyword(1,true);
checkIsFlagAdmin();
......@@ -130,7 +130,7 @@ void ReqAnalyzer::exec(const string& request) {
Auth::auth->mkListUser(list2D);
return2DList(list2D);
} else {
throw Exception(0,"The command \"LIST USER\" require 0,1 or 2 arguments.");
throw Exception("The command \"LIST USER\" require 0,1 or 2 arguments.");
}
} else if ((equ(elts.at(1),"ROLE"))) {
if (elts.size()==2) {
......@@ -150,10 +150,10 @@ void ReqAnalyzer::exec(const string& request) {
Auth::auth->mkListRole(list2D,elts.at(2));
return2DList(list2D);
} else {
throw Exception(0,"The command \"LIST ROLE\" require 0,1,2 or 3 arguments.");
throw Exception("The command \"LIST ROLE\" require 0,1,2 or 3 arguments.");
}
} else {
throw Exception(0,"Syntax error at character "+charno.at(1)+" : unreconized arguments \""+elts.at(1)+"\".");
throw Exception("Syntax error at character "+charno.at(1)+" : unreconized arguments \""+elts.at(1)+"\".");
}
}
} else if (equ(elts.at(0),"CREATE")) { // KW KW ...
......@@ -172,7 +172,7 @@ void ReqAnalyzer::exec(const string& request) {
returnMessage("1 user created.");
}
} else {
throw Exception(0,"The command \"CREATE USER\" require 2 or 4 arguments.");
throw Exception("The command \"CREATE USER\" require 2 or 4 arguments.");
}
} else if (equ(elts.at(1),"ROLE")) {
if (elts.size()==3 || elts.size()==5) {
......@@ -186,13 +186,13 @@ void ReqAnalyzer::exec(const string& request) {
returnMessage("1 role created.");
}
} else {
throw Exception(0,"The command \"CREATE ROLE\" require 2 or 4 arguments.");
throw Exception("The command \"CREATE ROLE\" require 2 or 4 arguments.");
}
} else {
unreconizedKeyWord(1);
}
} else {
throw Exception(0,"The command \"CREATE\" require an instruction complement.");
throw Exception("The command \"CREATE\" require an instruction complement.");
}
} else if (equ(elts.at(0),"ALTER")) { // KW KW ...
if (elts.size()>1) {
......@@ -229,7 +229,7 @@ void ReqAnalyzer::exec(const string& request) {
}
}
} else {
throw Exception(0,"The command \"ALTER USER\" require 2,3 or 4 arguments.");
throw Exception("The command \"ALTER USER\" require 2,3 or 4 arguments.");
}
} else if (equ(elts.at(1),"ROLE")) {
checkNb("ALTER ROLE",5,2);
......@@ -248,7 +248,7 @@ void ReqAnalyzer::exec(const string& request) {
unreconizedKeyWord(1);
}
} else {
throw Exception(0,"The command \"ALTER\" require an instruction complement.");
throw Exception("The command \"ALTER\" require an instruction complement.");
}
} else if (equ(elts.at(0),"DROP")) {
if (elts.size()>1) {
......@@ -266,7 +266,7 @@ void ReqAnalyzer::exec(const string& request) {
unreconizedKeyWord(1);
}
} else {
throw Exception(0,"The command \"ALTER\" require an instruction complement.");
throw Exception("The command \"ALTER\" require an instruction complement.");
}
} else if (equ(elts.at(0),"GRANT")) { // KW KW KW KW|STR KW STR
checkNb("REVOKE",4);
......@@ -296,7 +296,7 @@ void ReqAnalyzer::exec(const string& request) {
unreconizedKeyWord(0);
}
} else if (elts.size()==0) {
throw Exception(0,"Empty request.");
throw Exception("Empty request.");
}
}
} catch (Exception e) {
......
......@@ -61,7 +61,7 @@ void ReqAnalyzer::exec(const string& request) {
else
return2DList(list2D);
} catch (Exception e) {
throw Exception(0,db->className().substr(6)+" error : "+e.getMsg());
throw Exception(db->className().substr(6)+" error : "+e.getMsg());
}
} else {
db->setSQL(sql);
......@@ -69,14 +69,14 @@ void ReqAnalyzer::exec(const string& request) {
db->exec();
returnMessage("SQL OK.");
} catch (Exception e) {
throw Exception(0,db->className().substr(6)+" error : "+e.getMsg());
throw Exception(db->className().substr(6)+" error : "+e.getMsg());
}
}
} else {
throw Exception(0,"Empty SQL request.");
throw Exception("Empty SQL request.");
}
} else {
throw Exception(0,"SQL request not aviable.");
throw Exception("SQL request not aviable.");
}
} else {
cut(request);
......@@ -97,7 +97,7 @@ void ReqAnalyzer::exec(const string& request) {
" * BUILD; Get the build date.\n"
" NB:\n{choice|other choice} => choice or other choice.\n[Option] => this is an option.\n");
} else {
throw Exception(0,"HELP request error.");
throw Exception("HELP request error.");
}
} else if (equ(elts.at(0),"VERSION")) { // KW
checkNb("VERSION",1);
......@@ -118,7 +118,7 @@ void ReqAnalyzer::exec(const string& request) {
returnMessage("commited.");
} else if (equ(elts.at(0),"LIST")) { // KW KW
if (elts.size()<2) {
throw Exception(0,"The command \"LIST\" require 2 arguments at least.");
throw Exception("The command \"LIST\" require 2 arguments at least.");
} else {
checkIsKeyword(1,true);
checkIsFlagAdmin();
......@@ -140,7 +140,7 @@ void ReqAnalyzer::exec(const string& request) {
return2DList(list2D);
}
} else {
throw Exception(0,"The command \"LIST PRIVILEGE\" (or \"LIST PRIV\") require 0,1 or 2 arguments.");
throw Exception("The command \"LIST PRIVILEGE\" (or \"LIST PRIV\") require 0,1 or 2 arguments.");
}
} else if (equ(elts.at(1),"REPOSITORY") || equ(elts.at(1),"REPO")) {
checkNb("LIST REPOSITORY",2,2);
......@@ -151,7 +151,7 @@ void ReqAnalyzer::exec(const string& request) {
SvnCtrl::svn->mkListRole(list);
returnList(list);
} else {
throw Exception(0,"Syntax error at character "+charno.at(1)+" : unreconized arguments \""+elts.at(1)+"\".");
throw Exception("Syntax error at character "+charno.at(1)+" : unreconized arguments \""+elts.at(1)+"\".");
}
}
} else if (equ(elts.at(0),"CREATE")) { // KW KW ...
......@@ -166,7 +166,7 @@ void ReqAnalyzer::exec(const string& request) {
unreconizedKeyWord(1);
}
} else {
throw Exception(0,"The command \"CREATE\" require an instruction complement.");
throw Exception("The command \"CREATE\" require an instruction complement.");
}
} else if (equ(elts.at(0),"DELETE")) { // KW KW ...
if (elts.size()>1) {
......@@ -180,7 +180,7 @@ void ReqAnalyzer::exec(const string& request) {
unreconizedKeyWord(1);
}
} else {
throw Exception(0,"The command \"DELETE\" require an instruction complement.");
throw Exception("The command \"DELETE\" require an instruction complement.");
}
} else if (equ(elts.at(0),"GRANT")) { // KW KW KW STR KW STR [STR]
if (elts.size()==6 || elts.size()==7) {
......@@ -203,7 +203,7 @@ void ReqAnalyzer::exec(const string& request) {
returnMessage("granted.");
}
} else {
throw Exception(0,"The command \"GRANT\" require 6 or 7 arguments.");
throw Exception("The command \"GRANT\" require 6 or 7 arguments.");
}
} else if (equ(elts.at(0),"REVOKE")) { // KW KW KW STR KW STR [STR]
if (elts.size()==6 || elts.size()==7) {
......@@ -225,13 +225,13 @@ void ReqAnalyzer::exec(const string& request) {
returnMessage("revoked.");
}
} else {
throw Exception(0,"The command \"REVOKE\" require 6 or 7 arguments.");
throw Exception("The command \"REVOKE\" require 6 or 7 arguments.");
}
} else {
unreconizedKeyWord(0);
}
} else if (elts.size()==0) {
throw Exception(0,"Empty request.");
throw Exception("Empty request.");
}
}
} catch (Exception e) {
......
......@@ -13,6 +13,7 @@
#include "svnctrl.h"
#include <fstream>
#include <unicomctrl/exception.h>
#include <unicomctrl/dbexception.h>
SvnCtrl *SvnCtrl::svn=NULL;
......@@ -64,7 +65,7 @@ void SvnCtrl::mkListRepo(StringList& listRepo) {
}catch(Exception e){
onFatalError();
oute << e.getMsg()+"\n" << endIO;
throw Exception(10309,"Internal server error");
throw Exception("Internal server error");
}
}
......@@ -84,7 +85,7 @@ void SvnCtrl::mkListPriv(const string& user, String2DList& listPriv, bool cumul)
}catch(Exception e){
onFatalError();
oute << e.getMsg()+"\n" << endIO;
throw Exception(10309,"Internal server error");
throw Exception("Internal server error");
}
}
......@@ -98,7 +99,7 @@ void SvnCtrl::mkListPriv(const string& user, const string& repo, String2DList& l
}catch(Exception e){
onFatalError();
oute << e.getMsg()+"\n" << endIO;
throw Exception(10309,"Internal server error");
throw Exception("Internal server error");
}
}
......@@ -111,7 +112,7 @@ void SvnCtrl::mkListRole(StringList& listRole){
}catch(Exception e){
onFatalError();
oute << e.getMsg()+"\n" << endIO;
throw Exception(10309,"Internal server error");
throw Exception("Internal server error");
}
}
......@@ -127,7 +128,7 @@ void SvnCtrl::grant(const string& user, const string& repo, const string& locati
}catch(Exception e){
onFatalError();
oute << e.getMsg()+"\n" << endIO;
throw Exception(10309,"Internal server error");
throw Exception("Internal server error");
}
}
......@@ -135,7 +136,7 @@ void SvnCtrl::revoke(const string& user, const string& repo, const string& locat
string iduser,idrepo;
getIduser(user,iduser,true,false,true);
if(repo.empty()){
throw Exception(10310,"Operation not supported.");
throw Exception("Operation not supported.");
}
getIdrepo(repo,idrepo,true);
try{
......@@ -145,7 +146,7 @@ void SvnCtrl::revoke(const string& user, const string& repo, const string& locat
}catch(Exception e){
onFatalError();
oute << e.getMsg()+"\n" << endIO;
throw Exception(10309,"Internal server error");
throw Exception("Internal server error");
}
}
......@@ -157,7 +158,7 @@ void SvnCtrl::createRepo(const string& repo) {
" VALUES ('"+repo+"', '', "+(*idParent)+", '0');");
db->exec();
}catch(...){
throw Exception(10309,"Internal server error");
throw Exception("Internal server error");
}
string path=(*pathParent)+"/"+repo;
......@@ -176,7 +177,7 @@ void SvnCtrl::createRepo(const string& repo) {
if(!svn_err_msg.empty()){
oute << "svn_repos_create() >> " << svn_err_msg << endIO;
throw Exception(10309,"Internal server error");
throw Exception("Internal server error");
}
}
......@@ -187,7 +188,7 @@ void SvnCtrl::deleteRepo(const string& repo) {
db->setSQL("DELETE FROM svn_repo WHERE id_svn_repo="+idrepo+";");
db->exec();
}catch(...){
throw Exception(10309,"Internal server error");
throw Exception("Internal server error");
}
string path=(*pathParent)+"/"+repo;
......@@ -205,7 +206,7 @@ void SvnCtrl::deleteRepo(const string& repo) {
if(!svn_err_msg.empty()){
oute << "svn_repos_delete() >> " << svn_err_msg << endIO;
throw Exception(10309,"Internal server error");
throw Exception("Internal server error");
}
}
......@@ -267,7 +268,7 @@ void SvnCtrl::commitAuthz(){
}catch(Exception e){
onFatalError();
oute << e.getMsg()+"\n" << endIO;
throw Exception(10309,"Internal server error");
throw Exception("Internal server error");
}
}
......@@ -276,41 +277,46 @@ DB *SvnCtrl::getDB(){
}
void SvnCtrl::getIduser(const string& user, string &iduser, bool isRequered, bool isRole, bool isUserRole){
if (user.empty()){
throw Exception("Empty name");
}
bool role=false;
try{
try {
db->setSQL("SELECT id_user,is_role FROM users WHERE login='"+user+"';");
db->execAndOpen();
db->next();
role=db->extractRowToBool(1);
iduser=db->extractRow();
} catch (ResultEndDBException e) {
db->close();
}catch(Exception e){
if(e.getNo()!=1004){
onFatalError();
oute << e.getMsg()+"\n" << endIO;
throw Exception(10309,"Internal server error");
}
db->close();
if(isRequered){
if(isRole)
throw Exception(10301,"The role don't exist");