MCPcopy Create free account
hub / github.com/USBGuard/usbguard / ueventOpen

Method ueventOpen

src/Library/DeviceManagerBase.cpp:154–184  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

152 }
153
154 int DeviceManagerBase::ueventOpen()
155 {
156 int socket_fd = -1;
157 USBGUARD_SYSCALL_THROW("UEvent device manager",
158 (socket_fd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT)) < 0);
159
160 try {
161 const int optval = 1;
162 USBGUARD_SYSCALL_THROW("UEvent device manager",
163 setsockopt(socket_fd, SOL_SOCKET, SO_PASSCRED, &optval, sizeof optval) != 0);
164 /*
165 * Set a 1MiB receive buffer on the netlink socket to avoid ENOBUFS error
166 * in recvmsg.
167 */
168 const size_t rcvbuf_max = 1024 * 1024;
169 USBGUARD_SYSCALL_THROW("UEvent device manager",
170 setsockopt(socket_fd, SOL_SOCKET, SO_RCVBUF, &rcvbuf_max, sizeof rcvbuf_max) != 0);
171 struct sockaddr_nl sa = {};
172 sa.nl_family = AF_NETLINK;
173 sa.nl_pid = getpid();
174 sa.nl_groups = -1;
175 USBGUARD_SYSCALL_THROW("UEvent device manager",
176 bind(socket_fd, reinterpret_cast<const sockaddr*>(&sa), sizeof sa) != 0);
177 }
178 catch (...) {
179 (void)close(socket_fd);
180 throw;
181 }
182
183 return socket_fd;
184 }
185
186 void DeviceManagerBase::setDeviceAuthorizedDefault(SysFSDevice* device, DeviceManager::AuthorizedDefaultType auth_default)
187 {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected