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

Method ueventEnumerateFilterDevice

src/Library/DeviceManagerBase.cpp:107–401  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

105 }
106
107 std::string DeviceManagerBase::ueventEnumerateFilterDevice(const std::string& filepath, const struct dirent* direntry)
108 {
109#if defined(_DIRENT_HAVE_D_TYPE)
110
111 if (direntry->d_type != DT_UNKNOWN) {
112 switch (direntry->d_type) {
113 case DT_LNK:
114 return symlinkPath(filepath);
115
116 case DT_DIR:
117 return filepath;
118
119 default:
120 return std::string();
121 }
122 }
123 else {
124 /*
125 * Unknown type. We have to call lstat.
126 */
127#endif
128 struct stat st = {};
129
130 if (lstat(filepath.c_str(), &st) != 0) {
131 /*
132 * Cannot stat, skip this entry.
133 */
134 USBGUARD_LOG(Warning) << "lstat(" << filepath << "): errno=" << errno;
135 return std::string();
136 }
137
138 if (S_ISLNK(st.st_mode)) {
139 return symlinkPath(filepath, &st);
140 }
141 else if (S_ISDIR(st.st_mode)) {
142 return filepath;
143 }
144 else {
145 return std::string();
146 }
147
148#if defined(_DIRENT_HAVE_D_TYPE)
149 }
150
151#endif
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 /*

Callers

nothing calls this directly

Calls 1

symlinkPathFunction · 0.85

Tested by

no test coverage detected