50
49
{ "p <priority>", I18N_NOOP("Process priority, between 0 and 100, 0 the lowest [50]"), 0},
51
50
{ "r", I18N_NOOP("Use realtime scheduling"), 0},
52
51
{ "f <file>", I18N_NOOP("Use target UID if <file> is not writeable"), 0},
53
{ "t", I18N_NOOP("Enable terminal output (no password keeping)"), 0 },
52
{ "t", I18N_NOOP("Fake option for KDE's KdeSu compatibility"), 0 },
54
53
{ "n", I18N_NOOP("Do not keep password"), 0},
55
54
{ "nonewdcop", I18N_NOOP("Use existing DCOP server"), 0},
56
55
{ "comment <dialog text>", I18N_NOOP("The comment that should be displayed in the dialog"), 0},
64
63
KAboutData aboutData("kdesudo", I18N_NOOP("KdeSudo"),
65
64
VERSION, description, KAboutData::License_GPL,
66
"(c) 2003, Robert Gruber", 0, 0, "rgruber@users.sourceforge.net");
65
"(c) 2007-2008, Anthony Mercatante", 0, 0, "tonio@ubuntu.com");
67
66
aboutData.addAuthor("Robert Gruber",0, "rgruber@users.sourceforge.net");
67
aboutData.addAuthor("Anthony Mercatante",0, "tonio@ubuntu.com");
68
68
KCmdLineArgs::init(argc, argv, &aboutData);
69
69
KCmdLineArgs::addCmdLineOptions(options); // Add our own options.
71
71
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
72
/* Get the comment out of cli args */
73
QByteArray commentBytes = args->getOption("comment");
74
QTextCodec* tCodecConv = QTextCodec::codecForLocale();
75
QString commentArg = tCodecConv->toUnicode(commentBytes, commentBytes.size());
79
QString strRunas = args->getOption("u");
82
76
QString executable;
85
79
QStringList commandlist;
87
bool showPriority = false;
88
bool cleanCachedPwd = false;
89
bool changeUID = true;
90
bool useTerminal = false;
93
82
bool withIgnoreButton = args->isSet("ignorebutton");
95
/* forget passwords */
97
cleanCachedPwd = true;
102
/* -i icon parameter */
104
if (args->isSet("i"))
105
icon = args->getOption("i");
107
/* command prompt handling */
108
bool showCommand = true;
109
if (args->isSet("d"))
112
if (args->isSet("r"))
114
strCmd = QString("nice -n 10");
117
priority = i18n("realtime:") + QChar(' ') + QString("50/100");
119
else if (args->isSet("p"))
121
QString n = args->getOption("n");
123
intn = (intn * 40 / 100) - (20 + 0.5);
126
strn.sprintf("%d",intn);
127
strCmd = KProcess::quote("nice") + QChar(' ') + KProcess::quote("-n") + QChar(' ') + KProcess::quote(strn);
130
priority = n + QString("/100");
133
if (args->isSet("c"))
135
command = args->getOption("c");
136
commandlist = QStringList::split(" ", command);
137
executable = commandlist[0];
141
if (args->count()==1)
143
86
if (executable.isEmpty())
146
89
commandlist = QStringList::split(QChar(' '), command);
147
90
executable = commandlist[0];
152
else if (args->count())
154
for (int i = 0; i < args->count(); i++)
156
command = args->arg(i);
157
if (executable.isEmpty())
159
commandlist = QStringList::split(" ", command);
160
executable = commandlist[0];
163
strCmd += QChar(' ') + KProcess::quote(command);
167
strCmd = strCmd.stripWhiteSpace();
169
if (args->isSet("f"))
171
// If file is writeable, do not change uid
172
QString filename = QFile::decodeName(args->getOption("f"));
173
QString file = filename;
176
if (file.at(0) != '/')
179
dirs.addKDEDefaults();
180
file = dirs.findResource("config", file);
183
kdError(1206) << "Config file not found: " << file << "\n";
190
kdError(1206) << "File does not exist: " << file << "\n";
200
if (args->isSet("t"))
203
if (strCmd.isEmpty() && cleanCachedPwd==false)
205
KMessageBox::information(NULL, i18n("No command arguments supplied!\nUsage: kdesudo [-u <runas>] <command>\nKdeSudo will now exit..."));
209
94
/* Kubuntu has a bug in it - this is a workaround for it */
210
95
KGlobal::dirs()->addResourceDir("apps","/usr/share/applications/kde");
211
96
KGlobal::dirs()->addResourceDir("apps","/usr/share/applications");
213
97
QString deskFilePath = KGlobal::dirs()->findResource("apps",executable + ".desktop");
214
98
KDesktopFile desktopFile(deskFilePath,true);
101
if (args->isSet("i"))
102
icon = args->getOption("i");
217
105
QString iconName = desktopFile.readIcon();
218
//qDebug(deskFilePath);
219
106
icon = KGlobal::iconLoader()->iconPath(iconName, -1* KIcon::StdSizes(KIcon::SizeHuge), true);
221
109
/* generic name parsing */
222
110
QString name = desktopFile.readName();
223
111
QString genericName = desktopFile.readGenericName();
230
118
else if (!genericName.isEmpty())
231
119
name = genericName;
233
bool newDcop = args->isSet("newdcop");
235
KdeSudo *kdesudo = new KdeSudo(0,0,strCmd,strRunas,commentArg,icon,name,withIgnoreButton,newDcop,cleanCachedPwd,changeUID,useTerminal,keepPwd);
237
if(showCommand==true)
238
(*kdesudo).addLine(i18n("Command:"), strCmd);
240
if((showPriority==true) && (priority!=QString()))
241
(*kdesudo).addLine(i18n("Priority:"), priority);
121
KdeSudo *kdesudo = new KdeSudo(0,0,icon,name,withIgnoreButton);
243
123
a.setMainWidget(kdesudo);