2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
23 $Date: 2010/04/14 09:01:29 $
32 #include "stg/common.h"
33 #include "stg/store.h"
34 #include "stg/user_conf.h"
37 #include "store_loader.h"
43 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
45 //-----------------------------------------------------------------------------
48 std::cout << "Usage:\n\nsgauth <path_to_config>" << std::endl;
50 //-----------------------------------------------------------------------------
55 //-----------------------------------------------------------------------------
56 static void SetSignalHandlers()
58 struct sigaction newsa, oldsa;
61 sigemptyset(&sigmask);
62 sigaddset(&sigmask, SIGTERM);
63 newsa.sa_handler = CatchTERM;
64 newsa.sa_mask = sigmask;
66 sigaction(SIGTERM, &newsa, &oldsa);
68 sigemptyset(&sigmask);
69 sigaddset(&sigmask, SIGINT);
70 newsa.sa_handler = CatchTERM;
71 newsa.sa_mask = sigmask;
73 sigaction(SIGINT, &newsa, &oldsa);
77 //-----------------------------------------------------------------------------
78 int main(int argc, char *argv[])
84 settings.SetConfFile(argv[1]);
87 if (settings.ReadSettings())
89 std::cerr << "Failed to read settings: '"
90 << settings.GetStrError() << "'" << std::endl;
97 STORE_LOADER storeLoader(settings.GetModulesPath(), settings.GetStoreModuleSettings());
98 if (storeLoader.Load())
100 std::cerr << "Failed to load storage plugin: '" << storeLoader.GetStrError() << "'" << std::endl;
104 STORE * dataStore = storeLoader.GetStore();
106 std::vector<std::string> userList;
107 if (dataStore->GetUsersList(&userList))
109 std::cerr << "Failed to get user list: '" << dataStore->GetStrError() << "'" << std::endl;
113 std::vector<USER> users;
114 std::vector<std::string>::const_iterator it;
115 for (it = userList.begin(); it != userList.end(); ++it)
118 if (dataStore->RestoreUserConf(&userConf, *it))
120 std::cerr << "Failed to read user conf: '" << dataStore->GetStrError() << "'" << std::endl;
125 settings.GetServerName(),
126 settings.GetServerPort(),
127 settings.GetLocalPort(),
134 std::cout << "Successfully loaded " << users.size() << " users" << std::endl;
142 storeLoader.Unload();
146 //-----------------------------------------------------------------------------