add rpm suid bits

This commit is contained in:
Jörg Prante 2023-10-23 19:58:38 +02:00
parent 001a4e3177
commit 553c397856
4 changed files with 46 additions and 13 deletions

View file

@ -127,6 +127,14 @@ class Rpm extends AbstractArchiveTask {
@Input @Input
Integer gid Integer gid
@Optional
@Input
Boolean setuid
@Optional
@Input
Boolean setgid
@Optional @Optional
@Input @Input
String maintainer String maintainer
@ -349,10 +357,15 @@ class Rpm extends AbstractArchiveTask {
sb.toString() sb.toString()
} }
Directory directory(String path) { Directory directory(String path) {
Directory directory = new Directory(path: path) Directory directory = new Directory(path: path)
directories << directory directories.add(directory)
directory
}
Directory directory(String path, String user, String group) {
Directory directory = new Directory(path: path, user: user, group: group)
directories.add(directory)
directory directory
} }

View file

@ -1,5 +1,6 @@
package org.xbib.gradle.plugin package org.xbib.gradle.plugin
import groovy.util.logging.Log
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.file.DuplicatesStrategy import org.gradle.api.file.DuplicatesStrategy
import org.gradle.api.file.FileCopyDetails import org.gradle.api.file.FileCopyDetails
@ -18,7 +19,10 @@ import org.xbib.rpm.payload.Directive
import java.nio.file.Files import java.nio.file.Files
import java.nio.file.Path import java.nio.file.Path
import java.nio.file.StandardOpenOption import java.nio.file.StandardOpenOption
import java.nio.file.attribute.PosixFileAttributeView
import java.nio.file.attribute.PosixFileAttributes
@Log
class RpmCopyAction implements CopyAction { class RpmCopyAction implements CopyAction {
Project project Project project
@ -105,8 +109,9 @@ class RpmCopyAction implements CopyAction {
builder.addProvides(provides.packageName, provides.flags, provides.version) builder.addProvides(provides.packageName, provides.flags, provides.version)
} }
for (Directory directory : task.directories) { for (Directory directory : task.directories) {
String user = directory.user ? directory.user : task.user String user = directory.user ?: task.user
String group = directory.group ? directory.group : task.group String group = directory.group ?: task.group
log.info("dir = " + directory.path)
builder.addDirectory(directory.path, directory.permissions, null, user, group, directory.addParents) builder.addDirectory(directory.path, directory.permissions, null, user, group, directory.addParents)
} }
} }
@ -123,20 +128,29 @@ class RpmCopyAction implements CopyAction {
private class StreamAction implements CopyActionProcessingStreamAction { private class StreamAction implements CopyActionProcessingStreamAction {
@Override @Override
void processFile(FileCopyDetailsInternal fileCopyDetailsInternal) { void processFile(FileCopyDetailsInternal details) {
boolean addParents = task.addParentDirs != null ? task.addParentDirs : task.addParentDirs boolean addParents = task.addParentDirs != null ? task.addParentDirs : false
Path path = extractPath(tempDir, fileCopyDetailsInternal) Path path = extractPath(tempDir, details)
String p = "/${fileCopyDetailsInternal.path}" PosixFileAttributeView view = Files.getFileAttributeView(path, PosixFileAttributeView)
PosixFileAttributes attributes = view.readAttributes()
String user = task.user ?: attributes.owner().name
String group = task.group ?: attributes.group().name
String p = "/${details.path}"
if (Files.isSymbolicLink(path)) { if (Files.isSymbolicLink(path)) {
builder.addLink(p, Files.readSymbolicLink(path).toFile().path, -1) builder.addLink(p, Files.readSymbolicLink(path).toFile().path, -1)
} else if (!fileCopyDetailsInternal.isDirectory()) { } else if (!details.isDirectory()) {
int mode = fileCopyDetailsInternal.mode int mode = details.mode
if (task.setuid) {
mode |= 01000
} task.group
int dirmode = -1 int dirmode = -1
if (task.setgid) {
dirmode |= 02000
}
EnumSet<Directive> directive = makeDirective(task.fileType) EnumSet<Directive> directive = makeDirective(task.fileType)
String user = task.user ?: task.user
String group = task.group ?: task.group
builder.addFile(p, path, mode, dirmode, directive, user, group, addParents) builder.addFile(p, path, mode, dirmode, directive, user, group, addParents)
} }
// we skip all directories
} }
} }

View file

@ -101,7 +101,7 @@ class RpmFullTest {
packageName = 'test' packageName = 'test'
packageVersion = '1.0.0' packageVersion = '1.0.0'
packageRelease = '1' packageRelease = '1'
directory '/lib' directory '/lib', 'root', 'root'
}) })
project.tasks.buildRpm.copy() project.tasks.buildRpm.copy()
RpmReader rpmReader = new RpmReader() RpmReader rpmReader = new RpmReader()

View file

@ -1,5 +1,6 @@
package org.xbib.gradle.plugin package org.xbib.gradle.plugin
import groovy.util.logging.Log
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder import org.gradle.testfixtures.ProjectBuilder
import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.BeforeEach
@ -7,7 +8,11 @@ import org.junit.jupiter.api.Test
import org.xbib.rpm.RpmReaderResult import org.xbib.rpm.RpmReaderResult
import org.xbib.rpm.RpmReader import org.xbib.rpm.RpmReader
import org.xbib.rpm.format.Format import org.xbib.rpm.format.Format
import java.nio.file.Paths import java.nio.file.Paths
import java.util.logging.Level
import java.util.logging.Logger
import static org.hamcrest.MatcherAssert.assertThat import static org.hamcrest.MatcherAssert.assertThat
import static org.hamcrest.CoreMatchers.* import static org.hamcrest.CoreMatchers.*
import static org.junit.jupiter.api.Assertions.assertTrue import static org.junit.jupiter.api.Assertions.assertTrue
@ -24,6 +29,7 @@ import static org.xbib.rpm.lead.Architecture.I386
import static org.xbib.rpm.lead.Os.LINUX import static org.xbib.rpm.lead.Os.LINUX
import static org.xbib.rpm.lead.PackageType.BINARY import static org.xbib.rpm.lead.PackageType.BINARY
@Log
class RpmSimpleTest { class RpmSimpleTest {
File projectDir File projectDir