|
|
@ -19,12 +19,13 @@ const c = @cImport({
|
|
|
|
@cInclude("unistd.h");
|
|
|
|
@cInclude("unistd.h");
|
|
|
|
@cInclude("grp.h");
|
|
|
|
@cInclude("grp.h");
|
|
|
|
@cInclude("crypt.h");
|
|
|
|
@cInclude("crypt.h");
|
|
|
|
|
|
|
|
@cInclude("string.h");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
fn getGroups(alloc: mem.Allocator, passwd: c.passwd) ![]c.gid_t {
|
|
|
|
fn getGroups(alloc: mem.Allocator, passwd: c.passwd) ![]c.gid_t {
|
|
|
|
var ngr: c_int = 0;
|
|
|
|
var ngr: c_int = 0;
|
|
|
|
_ = c.getgrouplist(passwd.pw_name, passwd.pw_gid, null, &ngr);
|
|
|
|
_ = c.getgrouplist(passwd.pw_name, passwd.pw_gid, null, &ngr);
|
|
|
|
const groups = try alloc.alloc(c.gid_t, @intCast(usize, ngr));
|
|
|
|
const groups = try alloc.alloc(c.gid_t, @intCast(ngr));
|
|
|
|
_ = c.getgrouplist(passwd.pw_name, passwd.pw_gid, groups.ptr, &ngr);
|
|
|
|
_ = c.getgrouplist(passwd.pw_name, passwd.pw_gid, groups.ptr, &ngr);
|
|
|
|
return groups;
|
|
|
|
return groups;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -55,10 +56,12 @@ pub fn main() !u8 {
|
|
|
|
const gr = c.getgrgid(gr_id).*;
|
|
|
|
const gr = c.getgrgid(gr_id).*;
|
|
|
|
if (gr.gr_gid == wheel.gr_gid) {
|
|
|
|
if (gr.gr_gid == wheel.gr_gid) {
|
|
|
|
const pass = mem.span(c.getpass("#: "));
|
|
|
|
const pass = mem.span(c.getpass("#: "));
|
|
|
|
if (cstr.cmp(shadow.sp_pwdp, c.crypt(pass, shadow.sp_pwdp)) == 0) {
|
|
|
|
if (c.strcmp(shadow.sp_pwdp, c.crypt(pass, shadow.sp_pwdp)) == 0) {
|
|
|
|
crypto.utils.secureZero(u8, pass);
|
|
|
|
crypto.utils.secureZero(u8, pass);
|
|
|
|
_ = c.setuid(0);
|
|
|
|
_ = c.setuid(0);
|
|
|
|
_ = c.setgid(0);
|
|
|
|
_ = c.setgid(0);
|
|
|
|
|
|
|
|
const rootGroups = try getGroups(gpa, c.getpwuid(0).*);
|
|
|
|
|
|
|
|
_ = c.setgroups(rootGroups.len, rootGroups.ptr);
|
|
|
|
var argl = ArrayList([]const u8).init(gpa);
|
|
|
|
var argl = ArrayList([]const u8).init(gpa);
|
|
|
|
for (os.argv[1..]) |arg| {
|
|
|
|
for (os.argv[1..]) |arg| {
|
|
|
|
try argl.append(mem.span(arg));
|
|
|
|
try argl.append(mem.span(arg));
|
|
|
|