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 $
33 #include "stg/common.h"
34 #include "stg/store.h"
37 #include "store_loader.h"
42 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
47 std::cout << "Usage:\n\nsgauth <path_to_config>" << std::endl;
49 //-----------------------------------------------------------------------------
50 void StatUpdate(const LOADSTAT &, void *)
53 //-----------------------------------------------------------------------------
54 void StatusChanged(int, void *)
57 //-----------------------------------------------------------------------------
58 void ShowMessage(const string &, int, int, int, void *)
61 //-----------------------------------------------------------------------------
62 void ShowError(const string &, int, void *)
65 //-----------------------------------------------------------------------------
70 //-----------------------------------------------------------------------------
71 static void SetSignalHandlers()
73 struct sigaction newsa, oldsa;
76 sigemptyset(&sigmask);
77 sigaddset(&sigmask, SIGTERM);
78 newsa.sa_handler = CatchTERM;
79 newsa.sa_mask = sigmask;
81 sigaction(SIGTERM, &newsa, &oldsa);
83 sigemptyset(&sigmask);
84 sigaddset(&sigmask, SIGINT);
85 newsa.sa_handler = CatchTERM;
86 newsa.sa_mask = sigmask;
88 sigaction(SIGINT, &newsa, &oldsa);
92 //-----------------------------------------------------------------------------
93 int main(int argc, char *argv[])
99 settings.SetConfFile(argv[1]);
102 if (settings.ReadSettings())
104 std::cerr << "Failed to read settings: '"
105 << settings.GetStrError() << "'" << std::endl;
112 STORE_LOADER storeLoader(settings.GetModulesPath(), settings.GetStoreModuleSettings());
113 if (storeLoader.Load())
115 std::cerr << "Failed to load storage plugin: '" << storeLoader.GetStrError() << "'" << std::endl;
119 STORE * dataStore = storeLoader.GetStore();
121 std::vector<std::string> userList;
122 if (dataStore->GetUsersList(&userList))
124 std::cerr << "Failed to get user list: '" << dataStore->GetStrError() << "'" << std::endl;
128 std::cout << "Successfully loaded " << userList.size() << " users" << std::endl;
130 IA_CLIENT_PROT proto(settings.GetServerName(), settings.GetServerPort(), settings.GetLocalPort());
132 proto.SetLogin(settings.GetLogin());
133 proto.SetPassword(settings.GetPassword());
135 proto.SetStatusChangedCb(StatusChanged, NULL);
136 proto.SetInfoCb(ShowMessage, NULL);
137 proto.SetErrorCb(ShowError, NULL);
138 proto.SetStatChangedCb(StatUpdate, NULL);
154 storeLoader.Unload();
158 //-----------------------------------------------------------------------------