summaryrefslogtreecommitdiffstats
path: root/cmdline/main.cpp
blob: 466af4df8d4a2fe5eaac1d260795b00583934751 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/***************************************************************************
 *   Copyright (C) 2013 by Timothy Pearson                                 *
 *   kb9vqf@pearsoncomputing.net                                           *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include <cstdlib>

#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <pwd.h>

#include <tdeapplication.h>
#include <tdestartupinfo.h>
#include <tdecmdlineargs.h>
#include <kuniqueapplication.h>
#include <tdeaboutdata.h>
#include <tdefileitem.h>

#include <ksimpleconfig.h>

#include <tqdatetime.h>
#include <tqfile.h>

#include <libtdeldap.h>

// FIXME
// Connect this to CMake/Automake
#define KDE_CONFDIR "/etc/trinity"

static const char description[] =
	I18N_NOOP("TDE utility for managing workstations in a Kerberos realm");

static const char version[] = "v0.0.1";

static const TDECmdLineOptions options[] =
{
	{ "adminusername <username>", I18N_NOOP("Specifies the username of the administrative user with permissions to perform the requested task"), 0 },
	{ "adminpasswordfile <password file>", I18N_NOOP("Specifies the location of a file which contains the password of the administrative user"), 0 },
	{ "!+command", I18N_NOOP("The command to execute on the Kerberos realm.  Valid commands are: bond unbond disable"), 0 },
	{ "!+realm", I18N_NOOP("The Kerberos realm on which to execute the specified command.  Example: MY.REALM"), 0 },
	{ "", I18N_NOOP("This utility requires an administrative user and password to be specified on the command line to function!"), 0 },
	TDECmdLineLastOption // End of options.
};

int main(int argc, char *argv[])
{
	TDEAboutData aboutData( "tdeldapbonding", I18N_NOOP("Kerberos Realm Bonding Manager"),
		version, description, TDEAboutData::License_GPL,
		"(c) 2013, Timothy Pearson");
		aboutData.addAuthor("Timothy Pearson",0, "kb9vqf@pearsoncomputing.net");
	TDECmdLineArgs::init(argc, argv, &aboutData);
 	TDECmdLineArgs::addCmdLineOptions(options);
	KUniqueApplication::addCmdLineOptions();
	TDEApplication::disableAutoDcopRegistration();

	TDEApplication app(false, false);

	TDEStartupInfo::appStarted();

	KSimpleConfig systemconfig( TQString::fromLatin1( KDE_CONFDIR "/ldap/ldapconfigrc" ));
	systemconfig.setFileWriteMode(S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);

	//======================================================================================================================================================
	//
	// Manager code follows
	//
	//======================================================================================================================================================

	TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
	if (args->count() > 1) {
		int retcode;

		TQString command = TQString(args->arg(0));
		TQString realm = TQString(args->arg(1));

		systemconfig.setGroup("LDAPRealm-" + realm);
		TQString host = systemconfig.readEntry("admin_server");
		LDAPCredentials credentials;
		if (args->isSet("adminusername") && args->isSet("adminpasswordfile")) {
			TQString passFileName = args->getOption("adminpasswordfile");
			TQFile passFile(passFileName);
			if (!passFile.open(IO_ReadOnly)) {
				printf("[ERROR] Unable to open specified password file '%s'\n", passFileName.ascii()); fflush(stdout);
				return -1;
			}
			TQTextStream stream(&passFile);
			credentials.username = args->getOption("adminusername");
			credentials.password = stream.readLine();
			passFile.close();
		}
		else {
			credentials.use_gssapi = true;
		}
		credentials.realm = realm;
		LDAPManager ldapmanager(realm, host, &credentials);

// FIXME
// Move core bonding functionality from ldapbonding.cpp into libtdeldap, then ***properly*** activate this code!
// 		if (command == "bond") {
// 			// FIXME
// 			LDAPRealmConfig realmConfig;
// 			TQString errorString;
// 
// 			realmConfig.name = realm;
// 			realmConfig.bonded = ;
// 			realmConfig.uid_offset;
// 			realmConfig.gid_offset;
// 			realmConfig.domain_mappings;
// 			realmConfig.kdc;
// 			realmConfig.kdc_port;
// 			realmConfig.admin_server;
// 			realmConfig.admin_server_port;
// 			realmConfig.pkinit_require_eku;
// 			realmConfig.pkinit_require_krbtgt_otherName;
// 			realmConfig.win2k_pkinit;
// 			realmConfig.win2k_pkinit_require_binding;
// 
// 			if (LDAPManager::bondRealm(realmConfig, credentials.username, credentials.password, credentials.realm, &errorString) == 0) {
// 				// Success!
// 			}
// 			else {
// 				// Failure
// 				return -1;
// 			}
// 		}
// 		else if (command == "unbond") {
// 			// FIXME
// 			TQString errorString;
// 
// 			if (LDAPManager::unbondRealm(realm, credentials.username, credentials.password, credentials.realm, &errorString) == 0) {
// 				// Success!
// 			}
// 			else {
// 				// Failure
// 				return -1;
// 			}
// 		}
// 		else if (command == "disable") {
// 			// FIXME
// 		}
// 		else {
			TDECmdLineArgs::usage(i18n("An invalid command was specified"));
			return -1;
// 		}
	}
	else {
		if (args->count() > 0) {
			TDECmdLineArgs::usage(i18n("No Kerberos realm was specified"));
			return -1;
		}
		else {
			TDECmdLineArgs::usage(i18n("No command was specified"));
			return -1;
		}
	}

	//======================================================================================================================================================

	return 0;
}