Changeset View
Changeset View
Standalone View
Standalone View
src/ioslaves/file/file_unix.cpp
Show First 20 Lines • Show All 1286 Lines • ▼ Show 20 Line(s) | |||||
1287 | } | 1287 | } | ||
1288 | 1288 | | |||
1289 | PrivilegeOperationReturnValue FileProtocol::execWithElevatedPrivilege(ActionType action, const QVariantList &args, int errcode) | 1289 | PrivilegeOperationReturnValue FileProtocol::execWithElevatedPrivilege(ActionType action, const QVariantList &args, int errcode) | ||
1290 | { | 1290 | { | ||
1291 | if (privilegeOperationUnitTestMode()) { | 1291 | if (privilegeOperationUnitTestMode()) { | ||
1292 | return PrivilegeOperationReturnValue::success(); | 1292 | return PrivilegeOperationReturnValue::success(); | ||
1293 | } | 1293 | } | ||
1294 | 1294 | | |||
1295 | // temporarily disable privilege execution | | |||
1296 | if (true) { | | |||
1297 | return PrivilegeOperationReturnValue::failure(errcode); | | |||
1298 | } | | |||
1299 | | ||||
1300 | if (!(errcode == EACCES || errcode == EPERM)) { | 1295 | if (!(errcode == EACCES || errcode == EPERM)) { | ||
1301 | return PrivilegeOperationReturnValue::failure(errcode); | 1296 | return PrivilegeOperationReturnValue::failure(errcode); | ||
1302 | } | 1297 | } | ||
1303 | 1298 | | |||
1304 | const QString operationDetails = actionDetails(action, args); | 1299 | const QString operationDetails = actionDetails(action, args); | ||
1305 | KIO::PrivilegeOperationStatus opStatus = requestPrivilegeOperation(operationDetails); | 1300 | KIO::PrivilegeOperationStatus opStatus = requestPrivilegeOperation(operationDetails); | ||
1306 | if (opStatus != KIO::OperationAllowed) { | 1301 | if (opStatus != KIO::OperationAllowed) { | ||
1307 | if (opStatus == KIO::OperationCanceled) { | 1302 | if (opStatus == KIO::OperationCanceled) { | ||
Show All 26 Lines | |||||
1334 | const QString actionId = QStringLiteral("org.kde.kio.file.exec"); | 1329 | const QString actionId = QStringLiteral("org.kde.kio.file.exec"); | ||
1335 | KAuth::Action execAction(actionId); | 1330 | KAuth::Action execAction(actionId); | ||
1336 | execAction.setHelperId(QStringLiteral("org.kde.kio.file")); | 1331 | execAction.setHelperId(QStringLiteral("org.kde.kio.file")); | ||
1337 | 1332 | | |||
1338 | QVariantMap argv; | 1333 | QVariantMap argv; | ||
1339 | argv.insert(QStringLiteral("arguments"), helperArgs); | 1334 | argv.insert(QStringLiteral("arguments"), helperArgs); | ||
1340 | execAction.setArguments(argv); | 1335 | execAction.setArguments(argv); | ||
1341 | 1336 | | |||
1337 | const auto actionHelper = [](ActionType action) -> QString { | ||||
1338 | switch (action) { | ||||
chinmoyr: We need to set a different message for each action. | |||||
1339 | case ActionType::CHMOD: return QStringLiteral("Authentication is required to change this file's permissions."); | ||||
1340 | case ActionType::CHOWN: return QStringLiteral("Authentication is required to change who owns this file."); | ||||
1341 | case ActionType::DEL: return QStringLiteral("Authentication is required to delete this file."); | ||||
1342 | case ActionType::MKDIR: return QStringLiteral("Authentication is required to create a directory."); | ||||
1343 | case ActionType::OPEN: return QStringLiteral("Authentication is required to open this file."); | ||||
1344 | case ActionType::OPENDIR: return QStringLiteral("Authentication is required to open this directory."); | ||||
1345 | case ActionType::RENAME: return QStringLiteral("Authentication is required to rename this file."); | ||||
1346 | case ActionType::RMDIR: return QStringLiteral("Authentication is required to delete this directory."); | ||||
1347 | case ActionType::SYMLINK: return QStringLiteral("Authentication is required to create a symlink."); | ||||
1348 | case ActionType::UTIME: return QStringLiteral("Authentication is required to modify this file's last updated time."); | ||||
1349 | case ActionType::UNKNOWN: return QStringLiteral("Authentication is required to perform this action."); | ||||
ngraham: Shouldn't these be localized?
Also can you change "directory" to "folder"? | |||||
1350 | } | ||||
1351 | Q_UNREACHABLE(); | ||||
1352 | return QString(); | ||||
1353 | }; | ||||
1354 | | ||||
1355 | KAuth::Action::DetailsMap details; | ||||
1356 | details.insert(KAuth::Action::AuthDetail::DetailMessage, actionHelper(action)); | ||||
1357 | execAction.setDetailsV2(details); | ||||
1358 | | ||||
1342 | auto reply = execAction.execute(); | 1359 | auto reply = execAction.execute(); | ||
1343 | if (reply->exec()) { | 1360 | if (reply->exec()) { | ||
1344 | addTemporaryAuthorization(actionId); | 1361 | addTemporaryAuthorization(actionId); | ||
1345 | return PrivilegeOperationReturnValue::success(); | 1362 | return PrivilegeOperationReturnValue::success(); | ||
1346 | } | 1363 | } | ||
1347 | 1364 | | |||
1348 | return PrivilegeOperationReturnValue::failure(KIO::ERR_ACCESS_DENIED); | 1365 | return PrivilegeOperationReturnValue::failure(KIO::ERR_ACCESS_DENIED); | ||
1349 | } | 1366 | } | ||
1350 | 1367 | | |||
1351 | int FileProtocol::setACL(const char *path, mode_t perm, bool directoryDefault) | 1368 | int FileProtocol::setACL(const char *path, mode_t perm, bool directoryDefault) | ||
1352 | { | 1369 | { | ||
1353 | int ret = 0; | 1370 | int ret = 0; | ||
1354 | #if HAVE_POSIX_ACL | 1371 | #if HAVE_POSIX_ACL | ||
1355 | 1372 | | |||
I'd advise handling default cases. The compiler can no longer warn of unhandled enum values when default is used. Instead I'd convert the entire switch into a helper function static QString actionTypeToString(ActionType action) and in there switch like so: switch (action) { case ActionType::CHMOD: return QStringLiteral("Authentication is required to change this file's permissions."); case ActionType::CHOWN: ... } // any values not explicitly handled gets here making this the de-facto default handling Q_UNREACHABLE() return QString() } This then makes the code here less repetitive as the entire switch gets squashed down to details.insert(KAuth::Action::AuthDetail::DetailMessage, actionTypeToString(action)); sitter: I'd advise handling default cases. The compiler can no longer warn of unhandled enum values… | |||||
1356 | const QString ACLString = metaData(QStringLiteral("ACL_STRING")); | 1373 | const QString ACLString = metaData(QStringLiteral("ACL_STRING")); | ||
1357 | const QString defaultACLString = metaData(QStringLiteral("DEFAULT_ACL_STRING")); | 1374 | const QString defaultACLString = metaData(QStringLiteral("DEFAULT_ACL_STRING")); | ||
1358 | // Empty strings mean leave as is | 1375 | // Empty strings mean leave as is | ||
1359 | if (!ACLString.isEmpty()) { | 1376 | if (!ACLString.isEmpty()) { | ||
1360 | acl_t acl = nullptr; | 1377 | acl_t acl = nullptr; | ||
1361 | if (ACLString == QLatin1String("ACL_DELETE")) { | 1378 | if (ACLString == QLatin1String("ACL_DELETE")) { | ||
1362 | // user told us to delete the extended ACL, so let's write only | 1379 | // user told us to delete the extended ACL, so let's write only | ||
1363 | // the minimal (UNIX permission bits) part | 1380 | // the minimal (UNIX permission bits) part | ||
Show All 33 Lines |
We need to set a different message for each action.