2025-11-22 02:29:49 +09:00
|
|
|
#include <MDE/Core/Users.h>
|
|
|
|
|
#include <MDE/Core/String.h>
|
2025-11-16 12:57:05 +09:00
|
|
|
|
|
|
|
|
#include <pwd.h>
|
|
|
|
|
|
2025-11-17 18:20:56 +09:00
|
|
|
void MDEUsersList(void (*call)(const char* name, void* user), void* user) {
|
2025-11-16 12:57:05 +09:00
|
|
|
struct passwd* pwd;
|
|
|
|
|
|
|
|
|
|
setpwent();
|
2025-11-17 18:20:56 +09:00
|
|
|
while((pwd = getpwent()) != NULL) {
|
2025-11-16 12:57:05 +09:00
|
|
|
char* dir;
|
2025-11-16 13:08:34 +09:00
|
|
|
char* shell;
|
2025-11-16 12:57:05 +09:00
|
|
|
|
|
|
|
|
/* this is BAD check. and i cannot do anything about it
|
|
|
|
|
*
|
|
|
|
|
* i appreciate the insanity
|
|
|
|
|
*/
|
|
|
|
|
|
2025-11-16 13:08:34 +09:00
|
|
|
if(pwd->pw_dir == NULL || pwd->pw_shell == NULL) continue;
|
2025-11-16 12:57:05 +09:00
|
|
|
if(pwd->pw_name[0] == '_') continue;
|
2025-11-16 13:08:34 +09:00
|
|
|
|
2025-11-16 13:12:23 +09:00
|
|
|
if(pwd->pw_uid != 0 && strstr(pwd->pw_dir, "/home/") == NULL) continue;
|
2025-11-16 13:10:34 +09:00
|
|
|
|
2025-11-16 13:08:34 +09:00
|
|
|
shell = strrchr(pwd->pw_shell, '/');
|
|
|
|
|
if(shell == NULL) break;
|
|
|
|
|
shell++;
|
|
|
|
|
|
|
|
|
|
if(strcmp(shell, "nologin") == 0) continue;
|
2025-11-17 18:20:56 +09:00
|
|
|
|
2025-11-16 12:57:05 +09:00
|
|
|
dir = strrchr(pwd->pw_dir, '/');
|
|
|
|
|
if(dir == NULL) break;
|
|
|
|
|
dir++;
|
|
|
|
|
|
2025-11-16 13:10:34 +09:00
|
|
|
if(strcmp(dir, pwd->pw_name) != 0) continue;
|
|
|
|
|
|
|
|
|
|
call(pwd->pw_name, user);
|
2025-11-16 12:57:05 +09:00
|
|
|
}
|
|
|
|
|
endpwent();
|
|
|
|
|
}
|