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 $
34 #include "stg/common.h"
35 #include "stg/store.h"
36 #include "stg/user_conf.h"
39 #include "store_loader.h"
46 //-----------------------------------------------------------------------------
47 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
51 std::cout << "Usage:\n\nsgauth <path_to_config>" << std::endl;
53 //-----------------------------------------------------------------------------
58 //-----------------------------------------------------------------------------
59 static void SetSignalHandlers()
61 struct sigaction newsa, oldsa;
64 sigemptyset(&sigmask);
65 sigaddset(&sigmask, SIGTERM);
66 newsa.sa_handler = CatchTERM;
67 newsa.sa_mask = sigmask;
69 sigaction(SIGTERM, &newsa, &oldsa);
71 sigemptyset(&sigmask);
72 sigaddset(&sigmask, SIGINT);
73 newsa.sa_handler = CatchTERM;
74 newsa.sa_mask = sigmask;
76 sigaction(SIGINT, &newsa, &oldsa);
80 //-----------------------------------------------------------------------------
81 int main(int argc, char *argv[])
87 settings.SetConfFile(argv[1]);
90 if (settings.ReadSettings())
92 std::cerr << "Failed to read settings: '"
93 << settings.GetStrError() << "'" << std::endl;
100 PROTO proto(settings.GetServerName(),
101 settings.GetServerPort(),
102 settings.GetLocalPort(),
105 STORE_LOADER storeLoader(settings.GetModulesPath(), settings.GetStoreModuleSettings());
106 if (storeLoader.Load())
108 std::cerr << "Failed to load storage plugin: '" << storeLoader.GetStrError() << "'" << std::endl;
112 STORE * dataStore = storeLoader.GetStore();
114 std::vector<std::string> userList;
115 if (dataStore->GetUsersList(&userList))
117 std::cerr << "Failed to get user list: '" << dataStore->GetStrError() << "'" << std::endl;
121 std::list<uint32_t> ips;
123 std::vector<std::string>::const_iterator it;
124 for (it = userList.begin(); it != userList.end(); ++it)
127 if (dataStore->RestoreUserConf(&userConf, *it))
129 std::cerr << "Failed to read user conf: '" << dataStore->GetStrError() << "'" << std::endl;
139 ips.push_back(userConf.ips[0].ip);
145 std::cerr << "Failed to start listening thread: '" << proto.GetStrError() << "'" << std::endl;
149 std::list<uint32_t>::const_iterator it;
150 for (it = ips.begin(); it != ips.end(); ++it)
155 std::cout << "Successfully loaded " << proto.UserCount() << " users" << std::endl;
160 struct timespec ts = {0, 200000000};
161 nanosleep(&ts, NULL);
166 storeLoader.Unload();
170 //-----------------------------------------------------------------------------