getpwnam method
Search the user database for a name. Note: This is a structural mock mapped to current process environment.
Implementation
passwd? getpwnam(String name) {
try {
final user = stdlibGetenv('USER') ?? stdlibGetenv('USERNAME') ?? 'user';
if (name != user && name != 'root') return null;
final pw = passwd();
pw.pw_name = name;
pw.pw_uid = name == 'root' ? 0 : 1000;
pw.pw_gid = name == 'root' ? 0 : 1000;
pw.pw_dir = name == 'root' ? '/root' : (stdlibGetenv('HOME') ?? stdlibGetenv('USERPROFILE') ?? '/home/$name');
pw.pw_shell = stdlibGetenv('SHELL') ?? '/bin/sh';
return pw;
} catch (_) {
return null;
}
}