Fix crash if key bindings specified in profile cannot be found. Improve
[personal-kdebase.git] / apps / kdepasswd / kdepasswd.cpp
blob866f454ed123aaa4f92901cbed8a1474c87e4cc7
1 /* vi: ts=8 sts=4 sw=4
3 * This file is part of the KDE project, module kdesu.
4 * Copyright (C) 2000 Geert Jansen <jansen@kde.org>
6 Permission to use, copy, modify, and distribute this software
7 and its documentation for any purpose and without fee is hereby
8 granted, provided that the above copyright notice appear in all
9 copies and that both that the copyright notice and this
10 permission notice and warranty disclaimer appear in supporting
11 documentation, and that the name of the author not be used in
12 advertising or publicity pertaining to distribution of the
13 software without specific, written prior permission.
15 The author disclaim all warranties with regard to this
16 software, including all implied warranties of merchantability
17 and fitness. In no event shall the author be liable for any
18 special, indirect or consequential damages or any damages
19 whatsoever resulting from loss of use, data or profits, whether
20 in an action of contract, negligence or other tortious action,
21 arising out of or in connection with the use or performance of
22 this software.
26 #include <kdeversion.h>
27 #include <kuniqueapplication.h>
28 #include <klocale.h>
29 #include <kaboutdata.h>
30 #include <kcmdlineargs.h>
31 #include <kmessagebox.h>
32 #include <kuser.h>
33 #include <kdebug.h>
35 #include "passwd.h"
36 #include "passwddlg.h"
39 int main(int argc, char **argv)
41 KAboutData aboutData("kdepasswd", 0, ki18n("KDE passwd"),
42 KDE_VERSION_STRING, ki18n("Changes a UNIX password."),
43 KAboutData::License_Artistic, ki18n("Copyright (c) 2000 Geert Jansen"));
44 aboutData.addAuthor(ki18n("Geert Jansen"), ki18n("Maintainer"),
45 "jansen@kde.org");
46 aboutData.setProgramIconName( "preferences-desktop-user-password" );
48 KCmdLineArgs::init(argc, argv, &aboutData);
50 KCmdLineOptions options;
51 options.add("+[user]", ki18n("Change password of this user"));
52 KCmdLineArgs::addCmdLineOptions(options);
53 KUniqueApplication::addCmdLineOptions();
56 if (!KUniqueApplication::start()) {
57 kDebug() << "kdepasswd is already running";
58 return 2;
61 KUniqueApplication app;
63 KUser ku;
64 QString user;
65 bool bRoot = ku.isSuperUser();
66 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
68 if (args->count())
69 user = args->arg(0);
71 /* You must be able to run "kdepasswd loginName" */
72 if ( !user.isEmpty() && user!=KUser().loginName() && !bRoot)
74 KMessageBox::sorry(0, i18n("You need to be root to change the password of other users."));
75 return 1;
78 QByteArray oldpass;
79 if (!bRoot)
81 int result = KDEpasswd1Dialog::getPassword(oldpass);
82 if (result != KDEpasswd1Dialog::Accepted)
83 return 1;
86 KDEpasswd2Dialog *dlg = new KDEpasswd2Dialog(oldpass, user.toLocal8Bit());
89 dlg->exec();
90 if (dlg->result() == KDEpasswd2Dialog::Rejected)
91 return 1;
93 return 0;