// File: /workspace/github_cpp_makefile_star2_O1/tylerkaraszewski[P]Argyle/main.cpp
// Function: setUser(char const*, Logger&)
bool setUser(const char* runAs, Logger& logger)
{
  bool retval = true;
  struct passwd pwd;
  struct passwd* pwdPtr = 0;

  size_t bufsize = 32;
  char* buffer = static_cast<char*>(malloc(bufsize));
  if (buffer == NULL)
  {
    logger.logError("Setuser malloc error: Out of Memory");
    return false;
  }
  int e;
  while ((e = getpwnam_r(runAs, &pwd, buffer, bufsize, &pwdPtr)) == ERANGE)
  {
    bufsize *= 2;
    // this needs to do a better job of freeing things if it fails.
    buffer = static_cast<char*>(realloc(static_cast<void*>(buffer), bufsize));
    if (buffer == NULL)
    {
      logger.logError("Setuser realloc error: Out of Memory");
      return false;
    }
  }
  if (e != 0)
  {
    logger.logError("Getpwdnam_r error(" + Utils::llToString(errno) + "): " + strerror(errno));
    retval = false;
  }
  else if (pwdPtr == 0)
  {
    logger.logError(string("Getpwdnam_r failed, couldn't find user ") + runAs);
    retval = false;
  }

  // Haven't failed yet.
  if (retval)
  {
    // Set group first or we lose the abilty to after we're not superuser.
    if (setegid(pwd.pw_gid) == -1)
    {
      logger.logError("Setegid error(" + Utils::llToString(errno) + "): " + strerror(errno));
      retval = false;
    }
    else if (seteuid(pwd.pw_uid) == -1)
    {
      logger.logError("Seteuid error(" + Utils::llToString(errno) + "): " + strerror(errno));
      retval = false;
    }
  }
  free(buffer);
  return retval;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, %r14
movq %rdi, %r15
movq $0x0, 0x80(%rsp)
movl $0x20, %r12d
movl $0x20, %edi
callq 0x3380
testq %rax, %rax
je 0x6304
movq %rax, %rbx
leaq 0x88(%rsp), %r13
leaq 0x80(%rsp), %rbp
movq %r15, %rdi
movq %r13, %rsi
movq %rbx, %rdx
movq %r12, %rcx
movq %rbp, %r8
callq 0x3510
cmpl $0x22, %eax
jne 0x628e
addq %r12, %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x34d0
movq %rax, %rbx
testq %rax, %rax
jne 0x6230
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x5f45(%rip), %rsi      # 0xc1b4
leaq 0x5f62(%rip), %rdx      # 0xc1d8
movq %rsp, %rdi
callq 0x513e
movq %rsp, %rsi
movq %r14, %rdi
callq 0xac26
jmp 0x632e
testl %eax, %eax
jne 0x634b
movb $0x1, %bpl
cmpq $0x0, 0x80(%rsp)
jne 0x6531
leaq 0x30(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x5f33(%rip), %rsi      # 0xc1ec
leaq 0x5f53(%rip), %rdx      # 0xc213
leaq 0x20(%rsp), %rdi
callq 0x513e
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
callq 0x3560
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x64d9
movq %rdx, (%rsp)
movq (%rcx), %rdx
movq %rdx, 0x10(%rsp)
jmp 0x64e0
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x5e7c(%rip), %rsi      # 0xc190
leaq 0x5e98(%rip), %rdx      # 0xc1b3
movq %rsp, %rdi
callq 0x513e
movq %rsp, %rsi
movq %r14, %rdi
callq 0xac26
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x6344
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3290
xorl %ebp, %ebp
jmp 0x683f
callq 0x3040
movq %rax, %r15
movslq (%rax), %rsi
leaq 0x60(%rsp), %r12
movq %r12, %rdi
callq 0xac34
leaq 0x5e6f(%rip), %rcx      # 0xc1d9
movl $0x12, %r8d
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x32e0
leaq 0x50(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x63a3
movq %rdx, 0x40(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x50(%rsp)
jmp 0x63ab
movups (%rcx), %xmm0
movups %xmm0, (%r13)
movq 0x8(%rax), %rdx
leaq 0x40(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x5c60(%rip), %rsi      # 0xc02e
callq 0x3560
leaq 0x30(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x63fa
movq %rdx, 0x20(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x30(%rsp)
jmp 0x6401
movups (%rcx), %xmm0
movups %xmm0, (%rbp)
movq 0x8(%rax), %rdx
leaq 0x20(%rsp), %r12
movq %rdx, 0x8(%r12)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl (%r15), %edi
callq 0x3120
movq %r12, %rdi
movq %rax, %rsi
callq 0x3560
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x6457
movq %rdx, (%rsp)
movq (%rcx), %rdx
movq %rdx, 0x10(%rsp)
jmp 0x645e
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
movq %rsp, %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %r14, %rdi
callq 0xac26
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x6496
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x20(%rsp), %rdi
cmpq %rbp, %rdi
je 0x64ad
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x40(%rsp), %rdi
cmpq %r13, %rdi
je 0x64c4
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x652f
movq 0x70(%rsp), %rsi
jmp 0x6527
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
movq %rsp, %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %r14, %rdi
callq 0xac26
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x6518
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x20(%rsp), %rdi
cmpq %r12, %rdi
je 0x652f
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3290
xorl %ebp, %ebp
testb %bpl, %bpl
je 0x6837
movl 0x9c(%rsp), %edi
callq 0x3370
cmpl $-0x1, %eax
je 0x65bf
movl 0x98(%rsp), %edi
callq 0x3150
cmpl $-0x1, %eax
jne 0x6837
callq 0x3040
movq %rax, %r15
movslq (%rax), %rsi
leaq 0x60(%rsp), %r12
movq %r12, %rdi
callq 0xac34
leaq 0x5ca4(%rip), %rcx      # 0xc223
movl $0xe, %r8d
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x32e0
leaq 0x50(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x66f9
movq %rdx, 0x40(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x50(%rsp)
jmp 0x6701
callq 0x3040
movq %rax, %r15
movslq (%rax), %rsi
leaq 0x60(%rsp), %r12
movq %r12, %rdi
callq 0xac34
leaq 0x5c36(%rip), %rcx      # 0xc214
movl $0xe, %r8d
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x32e0
leaq 0x50(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x6617
movq %rdx, 0x40(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x50(%rsp)
jmp 0x661f
movups (%rcx), %xmm0
movups %xmm0, (%r13)
movq 0x8(%rax), %rdx
leaq 0x40(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x59ec(%rip), %rsi      # 0xc02e
callq 0x3560
leaq 0x30(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x666e
movq %rdx, 0x20(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x30(%rsp)
jmp 0x6675
movups (%rcx), %xmm0
movups %xmm0, (%rbp)
movq 0x8(%rax), %rdx
leaq 0x20(%rsp), %r12
movq %rdx, 0x8(%r12)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl (%r15), %edi
callq 0x3120
movq %r12, %rdi
movq %rax, %rsi
callq 0x3560
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x66cb
movq %rdx, (%rsp)
movq (%rcx), %rdx
movq %rdx, 0x10(%rsp)
jmp 0x66d2
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
movq %rsp, %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %r14, %rdi
callq 0xac26
jmp 0x67d6
movups (%rcx), %xmm0
movups %xmm0, (%r13)
movq 0x8(%rax), %rdx
leaq 0x40(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x590a(%rip), %rsi      # 0xc02e
callq 0x3560
leaq 0x30(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x6750
movq %rdx, 0x20(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x30(%rsp)
jmp 0x6757
movups (%rcx), %xmm0
movups %xmm0, (%rbp)
movq 0x8(%rax), %rdx
leaq 0x20(%rsp), %r12
movq %rdx, 0x8(%r12)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl (%r15), %edi
callq 0x3120
movq %r12, %rdi
movq %rax, %rsi
callq 0x3560
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x67ad
movq %rdx, (%rsp)
movq (%rcx), %rdx
movq %rdx, 0x10(%rsp)
jmp 0x67b4
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
movq %rsp, %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %r14, %rdi
callq 0xac26
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x67ec
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x20(%rsp), %rdi
cmpq %rbp, %rdi
je 0x6803
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x40(%rsp), %rdi
cmpq %r13, %rdi
je 0x681a
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6835
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x3290
xorl %ebp, %ebp
movq %rbx, %rdi
callq 0x3330
movl %ebp, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x68ae
jmp 0x68c9
jmp 0x68e5
jmp 0x6901
jmp 0x68ae
jmp 0x68c9
jmp 0x68e5
jmp 0x6901
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x688a
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x688a
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r12, %rdi
je 0x6937
movq 0x30(%rsp), %rsi
jmp 0x692a
jmp 0x6934
jmp 0x6919
jmp 0x6934
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x68cc
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x68cc
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %rbp, %rdi
je 0x68e8
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x68e8
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r13, %rdi
je 0x6904
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x6904
movq %rax, %rbx
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6937
movq 0x70(%rsp), %rsi
jmp 0x692a
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x6937
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x6937
movq %rax, %rbx
movq %rbx, %rdi
callq 0x3520