Skip to content

Commit

Permalink
[users] Ensure UMASK= gets a leading 0 if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
adriaandegroot committed Nov 10, 2024
1 parent a93dc77 commit 3614fd0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/modules/users/CreateUserJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ createUser( const QString& loginName, const QString& fullName, const QString& sh
useraddCommand << "-c" << fullName;
if ( umask >= 0 )
{
useraddCommand << "-K" << ( QStringLiteral( "UMASK=" ) + QString::number( umask, 8 ) );
// The QChar() is needed to disambiguate from the overload that takes a double
useraddCommand << "-K" << ( QStringLiteral( "UMASK=%1" ).arg( umask, 3, 8, QChar( '0' ) ) );
}
useraddCommand << loginName;
#endif
Expand Down
23 changes: 14 additions & 9 deletions src/modules/users/Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,15 +519,17 @@ UserTests::testUserUmask_data()
QTest::addColumn< QString >( "filename" );
QTest::addColumn< int >( "permission" );
QTest::addColumn< int >( "umask" );

QTest::newRow( "good " ) << "tests/8a-issue-2362.conf" << 0700 << 0077;
QTest::newRow( "open " ) << "tests/8b-issue-2362.conf" << 0755 << 0022;
QTest::newRow( "weird" ) << "tests/8c-issue-2362.conf" << 0126 << 0651;
QTest::newRow( "rwxx " ) << "tests/8d-issue-2362.conf" << 0710 << 0067;
QTest::newRow( "-wrd " ) << "tests/8e-issue-2362.conf" << 0214 << 0563;
QTest::newRow( "bogus" ) << "tests/8f-issue-2362.conf" << -1 << -1;
QTest::newRow( "good2" ) << "tests/8g-issue-2362.conf" << 0750 << 0027;
QTest::newRow( "numrc" ) << "tests/8h-issue-2362.conf" << 0751 << 0026;
QTest::addColumn< QString >( "umask_string" );

QTest::newRow( "good " ) << "tests/8a-issue-2362.conf" << 0700 << 0077 << QStringLiteral( "077" );
QTest::newRow( "open " ) << "tests/8b-issue-2362.conf" << 0755 << 0022 << QStringLiteral( "022" );
QTest::newRow( "weird" ) << "tests/8c-issue-2362.conf" << 0126 << 0651 << QStringLiteral( "651" );
QTest::newRow( "rwxx " ) << "tests/8d-issue-2362.conf" << 0710 << 0067 << QStringLiteral( "067" );
QTest::newRow( "-wrd " ) << "tests/8e-issue-2362.conf" << 0214 << 0563 << QStringLiteral( "563" );
QTest::newRow( "bogus" ) << "tests/8f-issue-2362.conf" << -1 << -1
<< QStringLiteral( "-01" ); // Bogus 3-character representation
QTest::newRow( "good2" ) << "tests/8g-issue-2362.conf" << 0750 << 0027 << QStringLiteral( "027" );
QTest::newRow( "numrc" ) << "tests/8h-issue-2362.conf" << 0751 << 0026 << QStringLiteral( "026" );
}

void
Expand All @@ -550,6 +552,7 @@ UserTests::testUserUmask()
QFETCH( QString, filename );
QFETCH( int, permission );
QFETCH( int, umask );
QFETCH( QString, umask_string );

// Checks that the test-data is valid
if ( permission != -1 )
Expand All @@ -572,6 +575,8 @@ UserTests::testUserUmask()

QCOMPARE( c.homePermissions(), permission );
QCOMPARE( c.homeUMask(), umask );
// The QChar() is needed to disambiguate from the overload that takes a double
QCOMPARE( QStringLiteral( "%1" ).arg( umask, 3, 8, QChar( '0' ) ), umask_string );

QCOMPARE( c.forbiddenLoginNames(), forbidden );
}
Expand Down

0 comments on commit 3614fd0

Please sign in to comment.