/*
 * gcc -Wall -o debug1_lustre debug1_lustre.c && strace ./debug1_lustre
 */

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <grp.h>
#include <stdio.h>
#include <errno.h>
#include <assert.h>

int main(int argc, char **argv)
{
  int rc;
  char *filename;
  const int UNKNOWN_UID=111111;

  if (argc != 2)
    return 1;

  /* must be root */
  assert( 0 == getuid() );

  filename = argv[1];

  rc = seteuid(UNKNOWN_UID);
  if (rc != 0){
    perror("seteuid");
    return 2;
  }

  rc = open(filename, O_RDWR|O_CREAT, 0644);
  if (rc == -1){
    perror(filename);
    return 3;
  }

  return 0;
}

