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"
44 //-----------------------------------------------------------------------------
45 //-----------------------------------------------------------------------------
46 //-----------------------------------------------------------------------------
49 std::cout << "Usage:\n\nsgauth <path_to_config>" << std::endl;
51 //-----------------------------------------------------------------------------
56 //-----------------------------------------------------------------------------
57 static void SetSignalHandlers()
59 struct sigaction newsa, oldsa;
62 sigemptyset(&sigmask);
63 sigaddset(&sigmask, SIGTERM);
64 newsa.sa_handler = CatchTERM;
65 newsa.sa_mask = sigmask;
67 sigaction(SIGTERM, &newsa, &oldsa);
69 sigemptyset(&sigmask);
70 sigaddset(&sigmask, SIGINT);
71 newsa.sa_handler = CatchTERM;
72 newsa.sa_mask = sigmask;
74 sigaction(SIGINT, &newsa, &oldsa);
78 //-----------------------------------------------------------------------------
79 int main(int argc, char *argv[])
85 settings.SetConfFile(argv[1]);
88 if (settings.ReadSettings())
90 std::cerr << "Failed to read settings: '"
91 << settings.GetStrError() << "'" << std::endl;
98 PROTO proto(settings.GetServerName(),
99 settings.GetServerPort(),
100 settings.GetLocalPort(),
103 STORE_LOADER storeLoader(settings.GetModulesPath(), settings.GetStoreModuleSettings());
104 if (storeLoader.Load())
106 std::cerr << "Failed to load storage plugin: '" << storeLoader.GetStrError() << "'" << std::endl;
110 STORE * dataStore = storeLoader.GetStore();
112 std::vector<std::string> userList;
113 if (dataStore->GetUsersList(&userList))
115 std::cerr << "Failed to get user list: '" << dataStore->GetStrError() << "'" << std::endl;
119 std::vector<std::string>::const_iterator it;
120 for (it = userList.begin(); it != userList.end(); ++it)
123 if (dataStore->RestoreUserConf(&userConf, *it))
125 std::cerr << "Failed to read user conf: '" << dataStore->GetStrError() << "'" << std::endl;
137 std::cout << "Successfully loaded " << proto.UserCount() << " users" << std::endl;
145 storeLoader.Unload();
149 //-----------------------------------------------------------------------------