#include <libgen.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/xattr.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <tzplatform_config.h>
return std::min(std::max(timeout, SOCKET_TIMEOUT_MIN), SOCKET_TIMEOUT_MAX);
}
+int SetSocketLabel(int fd) {
+ if (fsetxattr(fd, "security.SMACK64IPOUT", "@", 1, 0) < 0) {
+ if (errno != EOPNOTSUPP && errno != EPERM) {
+ _E("Failed to set smack label(IPOUT). fd=%d, errno=%d", fd, errno);
+ return -1;
+ }
+ }
+
+ if (fsetxattr(fd, "security.SMACK64IPIN", "*", 1, 0) < 0) {
+ if (errno != EOPNOTSUPP && errno != EPERM) {
+ _E("Failed to set smack label(IPIN). fd=%d, errno=%d", fd, errno);
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
SocketTimeout socket_timeout;
SocketLink socket_link;
return -1;
ServerSocket socket;
+ if (getuid() == 0) {
+ if (SetSocketLabel(socket.GetFd()) != 0) {
+ _E("Failed to set socket label");
+ return -1;
+ }
+ }
+
socket.Bind(path);
aul_sock_set_sock_option(socket.GetFd(), 0);
socket.Listen(128);