~ubuntu-branches/ubuntu/lucid/kdebase/lucid

1.1.13 by Jonathan Riddell
Import upstream version 4.0.80
1
/* vi: ts=8 sts=4 sw=4
2
 *
3
 * This file is part of the KDE project, module kdesu.
4
 * Copyright (C) 2000 Geert Jansen <jansen@kde.org>
5
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.
14
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.
23
24
 */
25
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>
34
35
#include "passwd.h"
36
#include "passwddlg.h"
37
38
39
int main(int argc, char **argv)
40
{
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" );
47
48
    KCmdLineArgs::init(argc, argv, &aboutData);
49
50
    KCmdLineOptions options;
51
    options.add("+[user]", ki18n("Change password of this user"));
52
    KCmdLineArgs::addCmdLineOptions(options);
53
    KUniqueApplication::addCmdLineOptions();
54
55
56
    if (!KUniqueApplication::start()) {
57
        kDebug() << "kdepasswd is already running";
1.1.22 by Steve Stalcup
Import upstream version 4.1.96
58
        return 2;
1.1.13 by Jonathan Riddell
Import upstream version 4.0.80
59
    }
60
61
    KUniqueApplication app;
62
63
    KUser ku;
64
    QString user;
65
    bool bRoot = ku.isSuperUser();
66
    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
67
68
    if (args->count())
69
        user = args->arg(0);
70
71
    /* You must be able to run "kdepasswd loginName" */
72
    if ( !user.isEmpty() && user!=KUser().loginName() && !bRoot)
73
    {
74
        KMessageBox::sorry(0, i18n("You need to be root to change the password of other users."));
1.1.22 by Steve Stalcup
Import upstream version 4.1.96
75
        return 1;
1.1.13 by Jonathan Riddell
Import upstream version 4.0.80
76
    }
77
78
    QByteArray oldpass;
79
    if (!bRoot)
80
    {
81
        int result = KDEpasswd1Dialog::getPassword(oldpass);
82
        if (result != KDEpasswd1Dialog::Accepted)
1.1.22 by Steve Stalcup
Import upstream version 4.1.96
83
            return 1;
1.1.13 by Jonathan Riddell
Import upstream version 4.0.80
84
    }
85
86
    KDEpasswd2Dialog *dlg = new KDEpasswd2Dialog(oldpass, user.toLocal8Bit());
87
88
89
    dlg->exec();
1.1.22 by Steve Stalcup
Import upstream version 4.1.96
90
    if (dlg->result() == KDEpasswd2Dialog::Rejected)
91
        return 1;
1.1.13 by Jonathan Riddell
Import upstream version 4.0.80
92
93
    return 0;
94
}
95