Changeset View
Changeset View
Standalone View
Standalone View
src/ioslaves/file/file_unix.cpp
Show First 20 Lines • Show All 1279 Lines • ▼ Show 20 Line(s) | |||||
1280 | } | 1280 | } | ||
1281 | 1281 | | |||
1282 | PrivilegeOperationReturnValue FileProtocol::execWithElevatedPrivilege(ActionType action, const QVariantList &args, int errcode) | 1282 | PrivilegeOperationReturnValue FileProtocol::execWithElevatedPrivilege(ActionType action, const QVariantList &args, int errcode) | ||
1283 | { | 1283 | { | ||
1284 | if (privilegeOperationUnitTestMode()) { | 1284 | if (privilegeOperationUnitTestMode()) { | ||
1285 | return PrivilegeOperationReturnValue::success(); | 1285 | return PrivilegeOperationReturnValue::success(); | ||
1286 | } | 1286 | } | ||
1287 | 1287 | | |||
1288 | // temporarily disable privilege execution | | |||
1289 | if (true) { | | |||
1290 | return PrivilegeOperationReturnValue::failure(errcode); | | |||
1291 | } | | |||
1292 | | ||||
1293 | if (!(errcode == EACCES || errcode == EPERM)) { | 1288 | if (!(errcode == EACCES || errcode == EPERM)) { | ||
1294 | return PrivilegeOperationReturnValue::failure(errcode); | 1289 | return PrivilegeOperationReturnValue::failure(errcode); | ||
1295 | } | 1290 | } | ||
1296 | 1291 | | |||
1297 | const QString operationDetails = actionDetails(action, args); | 1292 | const QString operationDetails = actionDetails(action, args); | ||
1298 | KIO::PrivilegeOperationStatus opStatus = requestPrivilegeOperation(operationDetails); | 1293 | KIO::PrivilegeOperationStatus opStatus = requestPrivilegeOperation(operationDetails); | ||
1299 | if (opStatus != KIO::OperationAllowed) { | 1294 | if (opStatus != KIO::OperationAllowed) { | ||
1300 | if (opStatus == KIO::OperationCanceled) { | 1295 | if (opStatus == KIO::OperationCanceled) { | ||
Show All 26 Lines | |||||
1327 | const QString actionId = QStringLiteral("org.kde.kio.file.exec"); | 1322 | const QString actionId = QStringLiteral("org.kde.kio.file.exec"); | ||
1328 | KAuth::Action execAction(actionId); | 1323 | KAuth::Action execAction(actionId); | ||
1329 | execAction.setHelperId(QStringLiteral("org.kde.kio.file")); | 1324 | execAction.setHelperId(QStringLiteral("org.kde.kio.file")); | ||
1330 | 1325 | | |||
1331 | QVariantMap argv; | 1326 | QVariantMap argv; | ||
1332 | argv.insert(QStringLiteral("arguments"), helperArgs); | 1327 | argv.insert(QStringLiteral("arguments"), helperArgs); | ||
1333 | execAction.setArguments(argv); | 1328 | execAction.setArguments(argv); | ||
1334 | 1329 | | |||
1330 | KAuth::Action::DetailsMap details; | ||||
1331 | details.insert(KAuth::Action::AuthDetail::DetailMessage, QStringLiteral("Authentication is required to perform this action.")); | ||||
chinmoyr: We need to set a different message for each action. | |||||
1332 | execAction.setDetailsV2(details); | ||||
1333 | | ||||
1335 | auto reply = execAction.execute(); | 1334 | auto reply = execAction.execute(); | ||
1336 | if (reply->exec()) { | 1335 | if (reply->exec()) { | ||
1337 | addTemporaryAuthorization(actionId); | 1336 | addTemporaryAuthorization(actionId); | ||
1338 | return PrivilegeOperationReturnValue::success(); | 1337 | return PrivilegeOperationReturnValue::success(); | ||
1339 | } | 1338 | } | ||
1340 | 1339 | | |||
1341 | return PrivilegeOperationReturnValue::failure(KIO::ERR_ACCESS_DENIED); | 1340 | return PrivilegeOperationReturnValue::failure(KIO::ERR_ACCESS_DENIED); | ||
1342 | } | 1341 | } | ||
1343 | 1342 | | |||
ngraham: Shouldn't these be localized?
Also can you change "directory" to "folder"? | |||||
1344 | int FileProtocol::setACL(const char *path, mode_t perm, bool directoryDefault) | 1343 | int FileProtocol::setACL(const char *path, mode_t perm, bool directoryDefault) | ||
1345 | { | 1344 | { | ||
1346 | int ret = 0; | 1345 | int ret = 0; | ||
1347 | #if HAVE_POSIX_ACL | 1346 | #if HAVE_POSIX_ACL | ||
1348 | 1347 | | |||
1349 | const QString ACLString = metaData(QStringLiteral("ACL_STRING")); | 1348 | const QString ACLString = metaData(QStringLiteral("ACL_STRING")); | ||
1350 | const QString defaultACLString = metaData(QStringLiteral("DEFAULT_ACL_STRING")); | 1349 | const QString defaultACLString = metaData(QStringLiteral("DEFAULT_ACL_STRING")); | ||
1351 | // Empty strings mean leave as is | 1350 | // Empty strings mean leave as is | ||
1352 | if (!ACLString.isEmpty()) { | 1351 | if (!ACLString.isEmpty()) { | ||
1353 | acl_t acl = nullptr; | 1352 | acl_t acl = nullptr; | ||
1354 | if (ACLString == QLatin1String("ACL_DELETE")) { | 1353 | if (ACLString == QLatin1String("ACL_DELETE")) { | ||
1355 | // user told us to delete the extended ACL, so let's write only | 1354 | // user told us to delete the extended ACL, so let's write only | ||
1356 | // the minimal (UNIX permission bits) part | 1355 | // the minimal (UNIX permission bits) part | ||
1357 | acl = acl_from_mode(perm); | 1356 | acl = acl_from_mode(perm); | ||
1358 | } | 1357 | } | ||
1359 | acl = acl_from_text(ACLString.toLatin1().constData()); | 1358 | acl = acl_from_text(ACLString.toLatin1().constData()); | ||
1360 | if (acl_valid(acl) == 0) { // let's be safe | 1359 | if (acl_valid(acl) == 0) { // let's be safe | ||
1361 | ret = acl_set_file(path, ACL_TYPE_ACCESS, acl); | 1360 | ret = acl_set_file(path, ACL_TYPE_ACCESS, acl); | ||
1362 | // qDebug() << "Set ACL on:" << path << "to:" << aclToText(acl); | 1361 | // qDebug() << "Set ACL on:" << path << "to:" << aclToText(acl); | ||
1363 | } | 1362 | } | ||
1364 | acl_free(acl); | 1363 | acl_free(acl); | ||
1365 | if (ret != 0) { | 1364 | if (ret != 0) { | ||
1366 | return ret; // better stop trying right away | 1365 | return ret; // better stop trying right away | ||
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… | |||||
1367 | } | 1366 | } | ||
1368 | } | 1367 | } | ||
1369 | 1368 | | |||
1370 | if (directoryDefault && !defaultACLString.isEmpty()) { | 1369 | if (directoryDefault && !defaultACLString.isEmpty()) { | ||
1371 | if (defaultACLString == QLatin1String("ACL_DELETE")) { | 1370 | if (defaultACLString == QLatin1String("ACL_DELETE")) { | ||
1372 | // user told us to delete the default ACL, do so | 1371 | // user told us to delete the default ACL, do so | ||
1373 | ret += acl_delete_def_file(path); | 1372 | ret += acl_delete_def_file(path); | ||
1374 | } else { | 1373 | } else { | ||
Show All 15 Lines |
We need to set a different message for each action.