static int child( euca_opts *args, java_home_t *data, uid_t uid, gid_t gid ) {
	int ret = 0;
    jboolean r=0;
	__write_pid( GETARG(args,pidfile) );
	setpgrp( );
	__die(java_init( args, data ) != 1, "Failed to initialize Eucalyptus.");
    __die((r=(*env)->CallBooleanMethod(env,bootstrap.instance,bootstrap.init))==0,"Failed to init Eucalyptus.");
	__abort(4, set_keys_ownership( GETARG( args, home ), uid, gid ) != 0,"Setting ownership of keyfile failed." );
	__abort(4, linuxset_user_group( GETARG( args, user ), uid, gid ) != 0,"Setting the user failed." );
	__abort(4, (set_caps(0)!=0), "set_caps (0) failed");
    __die((r=(*env)->CallBooleanMethod(env,bootstrap.instance,bootstrap.load))==0,"Failed to load Eucalyptus.");
    __die((r=(*env)->CallBooleanMethod(env,bootstrap.instance,bootstrap.start))==0,"Failed to start Eucalyptus.");
	handle._hup = signal_set( SIGHUP, handler );
	handle._term = signal_set( SIGTERM, handler );
	handle._int = signal_set( SIGINT, handler );
	child_pid = getpid( );
	__debug( "Waiting for a signal to be delivered" );
	while( !stopping ) sleep( 60 );
	__debug( "Shutdown or reload requested: exiting" );
    __die((r=(*env)->CallBooleanMethod(env,bootstrap.instance,bootstrap.stop))==0,"Failed to stop Eucalyptus.");
	if( doreload == 1 ) ret = EUCA_RET_RELOAD;
	else ret = 0;
    __die((r=(*env)->CallBooleanMethod(env,bootstrap.instance,bootstrap.destroy))==0,"Failed to destroy Eucalyptus.");
	__die((JVM_destroy( ret ) != 1), "Failed trying to destroy JVM... bailing out seems like the right thing to do" );
	return ret;
}
static java_home_t *get_java_home( char *path ) {
	java_home_t *data = NULL;
	char buf[ 1024 ];
	int x = -1, k = 0, i = 0;

	if( path == NULL ) return NULL;
	__debug( "Looking for libjvm in %s", path );
	__abort(NULL, (CHECK_ISDIR( path ) == 0 ),"Path %s is not a directory", path );
	data = (java_home_t *) malloc( sizeof(java_home_t) );
	data->path = strdup( path );
	data->jvms = NULL;
	data->jnum = 0;
	while( libjvm_paths[ ++x ] != NULL ) {
		__abort(NULL, ((k = snprintf( buf, 1024, libjvm_paths[ x ], path ) ) <= 0 ),"Error mangling jvm path" );
		__debug( "Attempting to locate VM library %s", buf );
		if( CHECK_ISREG( buf ) == 1 ) {
			data->jvms = (jvm_info_t **) malloc( 2 * sizeof(jvm_info_t *) );
			data->jvms[ i ] = (jvm_info_t *) malloc( sizeof(jvm_info_t) );
			data->jvms[ i ]->libjvm_path = strdup( buf );
			char *dir, *base;
			dir = dirname(buf);
			base = basename(dir);
			data->jvms[ i ]->name = base;
			data->jvms[ ++i ] = NULL;
			data->jnum = i;
			return data;
		}
	}
	return data;
}
static int linuxset_user_group(char *user, int uid, int gid){
	if (set_caps(CAPS)!=0) __abort(-1,getuid()!= uid,"set_caps(CAPS) failed");
	__abort(-1,(prctl(PR_SET_KEEPCAPS,1,0,0,0) < 0),"prctl failed in linuxset_user_group");
	__abort(-1,(set_user_group(user,uid,gid)!=0),"set_user_group failed in linuxset_user_group");
	if (set_caps(CAPSMIN)!=0) __abort(-1,(getuid()!= uid),"set_caps(CAPSMIN) failed");
	return 0;
}
static int __write_pid( char *pidpath ) {
	FILE *pidfile;
	__abort(0,__get_pid(pidpath)>0,"");
	__abort(-1,(pidfile = fopen( pidpath, "w"))==NULL,"");
	fprintf( pidfile, "%d\n", (int) getpid( ) ),fflush(pidfile),fclose(pidfile);
	return 0;
}
Exemplo n.º 5
0
void
f90_bessel_yn(float *rslts, int *n1, int *n2, float *x)
{
  int i;
  float *rslt_p;

  if (*n1 < 0)
    __abort(0,"BESSEL_YN: order n1 must be >= 0");
  if (*n2 < 0)
    __abort(0,"BESSEL_YN: order n2 must be >= 0");
  if (*n1 > *n2)
    __abort(0,"BESSEL_YN: order n1 <= n2");

  for (i = *n1, rslt_p = rslts; i <= *n2; i++, rslt_p++) {
    switch (i) {
    case 0:
      *rslt_p = BESSEL_Y0F(*x);
      break;
    case 1:
      *rslt_p = BESSEL_Y1F(*x);
      break;
    default:
      *rslt_p = BESSEL_YNF(i, *x);
      break;
    }
  }
}
static int set_user_group( char *user, int uid, int gid ) {
	__abort(0,user==NULL,"No user to setuid to.");
	__abort(-1, setgid( gid ) != 0,"Cannot set group id for user '%s'", user );
	if( initgroups( user, gid ) != 0 ) __abort(-1, getuid( ) != uid, "Cannot set supplement group list for user '%s'", user );
	__abort(-1, setuid( uid ) != 0, "Cannot set user id for user '%s'", user );
	return 0;
}
static int __get_pid( char *pidpath ) {
	FILE* pidfile; int pid;
	__abort(-1,(pidfile = fopen( pidpath, "r"))==NULL,"");
	__abort(-1,(fscanf(pidfile,"%d",&pid)<0),"Failed to read pid file.");
	fclose( pidfile );
	__abort(pid,(kill( pid, 0 )==0),"");
	return -1;
}
Exemplo n.º 8
0
static int __update_limit(int resource,long long value) {
	struct rlimit r;
	__abort(1,getrlimit(resource, &r) == -1,"Failed to get rlimit for resource=%d",resource);
	printf("ulimit: resource=%d soft=%lld hard=%lld\n",resource,(long long) r.rlim_cur, (long long) r.rlim_max);
	if(r.rlim_cur==RLIM_INFINITY||r.rlim_cur<value) {
		r.rlim_cur = value;
		r.rlim_max = value;
		__abort(1,setrlimit(resource, &r) == -1,"Failed to set rlimit for resource=%d",resource);
		__abort(1,getrlimit(resource, &r) == -1,"Failed to set rlimit for resource=%d",resource);
		printf("ulimit: resource=%d soft=%lld hard=%lld\n",resource,(long long) r.rlim_cur, (long long) r.rlim_max);
	}
	return 0;
}
Exemplo n.º 9
0
static FILE *loc_freopen(char *outfile, char *mode, FILE *stream) {
	FILE *ftest;
	__abort(stream, (ftest = fopen(outfile, mode)) == NULL,
			"Unable to redirect to %s\n", outfile);
	fclose(ftest);
	return freopen(outfile, mode, stream);
}
Exemplo n.º 10
0
void _start(void)
{
    int i;
    unsigned int *src, *dst;

    // Copy .data from flash to RAM
    for (
            i = 0, dst = __load_info.data.base, src = __load_info.data_reloc;
            i < __load_info.data.len;
            i += sizeof(unsigned long)
        ) *dst++ = *src++;

    // Zero BSS
    for (
            i = 0, dst = __load_info.bss.base;
            i < __load_info.bss.len;
            i += sizeof(unsigned long)
        ) *dst++ = 0;

    SysCtlClockSet(
            SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL |
            SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN
            );

    stdio_init();

    main();
    __abort();
}
static int __update_limit(int resource, long long value)
{
    struct rlimit r;
    __abort(1, getrlimit(resource, &r) == -1, "Failed to get rlimit for resource=%d", resource);
    get_timestamp(ts_buff,sizeof(ts_buff));
    printf("%s INFO ulimit: resource=%d soft=%lld hard=%lld\n",ts_buff,resource, (long long)r.rlim_cur, (long long)r.rlim_max);
    fflush(stdout);
    if (r.rlim_cur == RLIM_INFINITY || r.rlim_cur < value) {
        r.rlim_cur = value;
        r.rlim_max = value;
        __abort(1, setrlimit(resource, &r) == -1, "Failed to set rlimit for resource=%d", resource);
        __abort(1, getrlimit(resource, &r) == -1, "Failed to set rlimit for resource=%d", resource);
        printf("%s INFO ulimit: resource=%d soft=%lld hard=%lld\n",ts_buff, resource, (long long)r.rlim_cur, (long long)r.rlim_max);
        fflush(stdout);
    }
    return 0;
}
Exemplo n.º 12
0
__chk_fail (void)
{
  const char message[] = "[%d] detected buffer overflow";

  syslog(LOG_CRIT, message, getpid());

  __abort();
}
static int checkuser( char *user, uid_t *uid, gid_t *gid ) {
	struct passwd *pwds = NULL;
	int status = 0;
	pid_t pid = 0;
	__abort(1, user == NULL,"" );
	pwds = getpwnam( user );
	__abort(0, (pwds == NULL ),"Invalid user name '%s' specified", user );
	*uid = pwds->pw_uid;
	*gid = pwds->pw_gid;
	pid = fork( );
	__abort(0,( pid == -1 ), "Cannot validate user name" );
	if( pid == 0 ) {
		__die( set_user_group( user, *uid, *gid ) != 0,"set_user_group failed." );
		exit( 0 );
	}
	while( waitpid( pid, &status, 0 ) != pid );
	if( WIFEXITED( status ) ) {
		status = WEXITSTATUS( status );
		__abort(0, (status != 0),"User '%s' validated", user );
	}
	return 1;
}