예제 #1
0
int main(int argc, char **argv)
{

	struct user_details *info = NULL;
	char *cmd = NULL;

	info = (struct user_details*)malloc(sizeof(struct user_details));

	get_user_details(info);

	while(TRUE)
	{
		getTimes = FALSE;
		sentToBackground = FALSE;
		fprintf(stdout,"%s@csd_sh%s/# ",info->user_name,info->working_dir);
		cmd = strdup(get_command());
		execute_command(cmd);
		free(cmd);
	}


	exit(EXIT_SUCCESS);
}
예제 #2
0
//change the user to passed user for executing/killing tasks
int change_user(const char * user) {
  if (get_user_details(user) < 0) {
    return -1;
  }
#ifdef DEBUG
  fprintf(LOGFILE,"change_user : setting user as %s ", user_detail->pw_name);
#endif
  errno = 0;
  setgid(user_detail->pw_gid);
  if (errno != 0) {
    fprintf(LOGFILE, "unable to setgid : %s\n", strerror(errno));
    cleanup();
    return SETUID_OPER_FAILED;
  }

  setegid(user_detail->pw_gid);
  if (errno != 0) {
    fprintf(LOGFILE, "unable to setegid : %s\n", strerror(errno));
    cleanup();
    return SETUID_OPER_FAILED;
  }

  setuid(user_detail->pw_uid);
  if (errno != 0) {
    fprintf(LOGFILE, "unable to setuid : %s\n", strerror(errno));
    cleanup();
    return SETUID_OPER_FAILED;
  }

  seteuid(user_detail->pw_uid);
  if (errno != 0) {
    fprintf(LOGFILE, "unable to seteuid : %s\n", strerror(errno));
    cleanup();
    return SETUID_OPER_FAILED;
  }
  return 0;
}