예제 #1
0
파일: 12-1.c 프로젝트: Mellanox/arc_ltp
int main() {
        int result;
        void *ptr;

        /* This test should be run under standard user permissions */
        if (getuid() == 0) {
                if (set_nonroot() != 0) {
			printf("Cannot run this test as non-root user\n");
			return PTS_UNTESTED;
		}
        }

	ptr = malloc(BUFSIZE);
	if (ptr == NULL) {
                printf("Can not allocate memory.\n");
                return PTS_UNRESOLVED;
        }

	result = mlock(ptr, BUFSIZE);

	if (result == -1 && errno == EPERM) {
		printf("Test PASSED\n");
		return PTS_PASS;
	} else if (result == 0) {
		printf("You have the right to call mlock\n");
		return PTS_FAIL;
	} else {
		perror("Unexpected error");
		return PTS_UNRESOLVED;
	}

}
예제 #2
0
파일: 7-1.c 프로젝트: Nan619/ltp
int main(void)
{

    int result = -1;

    /* We assume process Number 1 is created by root */
    /* and can only be accessed by root */
    /* This test should be run under standard user permissions */
    if (getuid() == 0) {
        if (set_nonroot() != 0) {
            printf("Cannot run this test as non-root user\n");
            return PTS_UNTESTED;
        }
    }

    result = sched_getscheduler(1);

    if (result == -1 && errno == EPERM) {
        printf("Test PASSED\n");
        return PTS_PASS;
    }
    if (result == 0) {
        printf("The function sched_getscheduler has successed.\n");
        return PTS_UNTESTED;
    }
    if (errno != EPERM) {
        perror("errno is not EPERM");
        return PTS_FAIL;
    } else {
        perror("Unresolved test error");
        return PTS_UNRESOLVED;
    }
}
예제 #3
0
파일: 20-1.c 프로젝트: Mellanox/arc_ltp
int main() {
	int result;
        struct sched_param param;

        /* We assume process Number 1 is created by root */
        /* and can only be accessed by root */
        /* This test should be run under standard user permissions */
        if (getuid() == 0) {
                if (set_nonroot() != 0) {
			printf("Cannot run this test as non-root user\n");
			return PTS_UNTESTED;
		}
        }

	param.sched_priority = sched_get_priority_max(SCHED_FIFO);

	result = sched_setscheduler(1, SCHED_FIFO, &param);

	if (result == -1 && errno == EPERM) {
		printf("Test PASSED\n");
		return PTS_PASS;
	} else if (errno != EPERM) {
	        perror("errno is not EPERM");
		return PTS_FAIL;
	} else {
		printf("The returned code is not -1.\n");
		return PTS_FAIL;
	}
}
예제 #4
0
파일: 32-1.c 프로젝트: Mellanox/arc_ltp
int main() {
	int fd;

        /* This test should be run under standard user permissions */
        if (getuid() == 0) {
                if (set_nonroot() != 0) {
			printf("Cannot run this test as non-root user\n");
			return PTS_UNTESTED;
		}
        }

	fd = shm_open(SHM_NAME, O_RDWR|O_CREAT, 0);
	if (fd == -1) {
		perror("An error occurs when calling shm_open()");
		return PTS_UNRESOLVED;
	}

	fd = shm_open(SHM_NAME, O_RDWR, 0);

	if (fd == -1 && errno == EACCES) {
		printf("Test PASSED\n");
		shm_unlink(SHM_NAME);
		return PTS_PASS;
	} else if (fd != -1) {
		printf("shm_open success.\n");
		shm_unlink(SHM_NAME);
		return PTS_FAIL;
	}

	perror("shm_open");
	return PTS_FAIL;
}
예제 #5
0
파일: 26-1.c 프로젝트: ystk/debian-ltp
int main(){
	int result;
        struct sched_param param;

        /* We assume process Number 1 is created by root */
        /* and can only be accessed by root */ 
        /* This test should be run under standard user permissions */
        if (getuid() == 0) {
	  	if (set_nonroot() != 0) {
			  printf("Cannot run this test as non-root user\n");	
                return PTS_UNTESTED;
        }
        }

	if(sched_getparam(0, &param) == -1) {
		perror("An error occurs when calling sched_getparam()");
		return PTS_UNRESOLVED;
	}

	result = sched_setparam(1, &param);

	if(result == -1 && errno == EPERM) {
		printf("Test PASSED\n");
		return PTS_PASS;
	} else if(errno != EPERM) {
	        perror("errno is not EPERM");
		return PTS_FAIL;
	} else {
		printf("The returned code is not -1.\n");
		return PTS_FAIL;
	}
}
예제 #6
0
파일: 3-1.c 프로젝트: shubmit/shub-ltp
int main()
{
	sem_t   *mysemp;
	char semname[50];

	if (getuid() == 0) {
                if (set_nonroot() != 0) {
			printf("Cannot run this test as non-root user\n");
			return PTS_UNTESTED;
		}
	}

	sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid());

	/*Trying to open the first Sem with read mode */
	mysemp = sem_open(semname, O_CREAT, 0444, 1);

	/* Opening the same existance SEM with write mode */
	mysemp = sem_open(semname, O_CREAT, 0222 , 1);

	if (mysemp  != SEM_FAILED)
	{
  		perror(ERROR_PREFIX "sem_open");
		return PTS_UNRESOLVED;
	}

	if (errno == EACCES)  {
		puts("TEST PASSED");
		sem_unlink(semname);
		return PTS_PASS;
	} else {
		puts("TEST FAILED");
		return PTS_FAIL;
	}
}
예제 #7
0
int main(void)
{

	union sigval value;
	value.sival_int = 0;	/* 0 is just an arbitrary value */

	/* We assume process Number 1 is created by root */
	/* and can only be accessed by root */
	/* This test should be run under standard user permissions */
	if (getuid() == 0) {
		if (set_nonroot() != 0) {
			printf("Cannot run this test as non-root user\n");
			return PTS_UNTESTED;
		}
	}

	if (sigqueue(1, 0, value) != -1) {
		printf
		    ("Test FAILED: sigqueue() succeeded even though this program's user id did not match the recieving process's user id\n");
		return PTS_FAIL;
	}

	if (EPERM != errno) {
		printf("Test FAILED: EPERM error not received\n");
		return PTS_FAIL;
	}

	return PTS_PASS;
}
예제 #8
0
파일: 6-1.c 프로젝트: barajas/Intel-GLTP
int main(int argc, char **argv)
{

	struct sched_param param;
	int result = -1;

	/* We assume process Number 1 is created by root */
	/* and can only be accessed by root */
	/* This test should be run under standard user permissions */
	if (geteuid() == 0) {
                if (set_nonroot() != 0) {
			printf("Cannot run this test as non-root user\n");
			return PTS_UNTESTED;
		}
	}

	result = sched_getparam(1, &param);

	if (result == -1 && errno == EPERM) {
		printf("Test PASSED\n");
		return PTS_PASS;
	}
	if (result == 0) {
		printf("The function sched_getparam has successed.\n");
		return PTS_FAIL;
	}
	if (errno != EPERM) {
		perror("errno is not EPERM: The system allows a non-root"
			"user to use sched_getparam()");
		return PTS_UNRESOLVED;
	} else {
		perror("Unresolved test error");
		return PTS_UNRESOLVED;
	}
}
예제 #9
0
파일: 15-1.c 프로젝트: Nan619/ltp-ddt
int main()
{
	int result;

	/* This test should be run under standard user permissions */
	if (getuid() == 0) {
		if (set_nonroot() != 0) {
			printf("Cannot run this test as non-root user\n");
			return PTS_UNTESTED;
		}
	}

	result = mlockall(MCL_CURRENT);

	if (result == -1 && errno == EPERM) {
		printf("Test PASSED\n");
		return PTS_PASS;
	} else if (result == 0) {
		printf("You have the right to call mlockall\n");
		return PTS_UNRESOLVED;
	} else {
		perror("Unexpected error");
		return PTS_UNRESOLVED;
	}
}
예제 #10
0
파일: 23-6.c 프로젝트: kraj/ltp
int main(void)
{
	int old_priority;
	struct sched_param param;
	int rc;

	/* We assume process Number 1 is created by root */
	/* and can only be accessed by root */
	/* This test should be run under standard user permissions */

	param.sched_priority = sched_get_priority_min(SCHED_FIFO);
	/* Cannot test SCHED_OTHER, on 0 valid as its priority */
	sched_setscheduler(0, SCHED_FIFO, &param);
	if (getuid() == 0) {
		if (set_nonroot() != 0) {
			printf("Cannot run this test as non-root user\n");
			return PTS_UNTESTED;
		}
	}

	if (sched_getparam(0, &param) == -1) {
		perror("An error occurs when calling sched_getparam()");
		return PTS_UNRESOLVED;
	}
	old_priority = param.sched_priority;

	param.sched_priority++;
	rc = sched_setparam(0, &param);
	if (rc != -1 || (rc == -1 && errno != EPERM)) {
		perror("sched_setparam() does not return EPERM\n");
		return PTS_UNRESOLVED;
	}

	if (sched_getparam(0, &param) != 0) {
		perror("An error occurs when calling sched_getparam()");
		return PTS_UNRESOLVED;
	}

	if (param.sched_priority == old_priority) {
		printf("Test PASSED\n");
		return PTS_PASS;
	} else {
		printf("The priority have changed.\n");
		return PTS_FAIL;
	}
}
예제 #11
0
파일: 17-6.c 프로젝트: shubmit/shub-ltp
int main() {
	int max_priority, old_priority, old_policy, new_policy, policy;
        struct sched_param param;

        /* We assume process Number 1 is created by root */
        /* and can only be accessed by root */
        /* This test should be run under standard user permissions */
        if (getuid() == 0) {
	  	if (set_nonroot() != 0) {
			printf("Cannot run this test as non-root user\n");
                return PTS_UNTESTED;
        }
        }

	if (sched_getparam(getpid(), &param) == -1) {
		perror("An error occurs when calling sched_getparam()");
		return PTS_UNRESOLVED;
	}
	old_priority = param.sched_priority;

	old_policy = sched_getscheduler(getpid());
	if (old_policy == -1) {
		perror("An error occurs when calling sched_getscheduler()");
		return PTS_UNRESOLVED;
	}

	/* Make sure that policy != old_policy */
	policy = old_policy == SCHED_FIFO ? SCHED_RR : SCHED_FIFO;

	/* Make sure that param.sched_priority != old_priority */
	max_priority = sched_get_priority_max(policy);
	param.sched_priority = (old_priority == max_priority) ?
		sched_get_priority_min(policy) :
		max_priority;

	sched_setscheduler(1, policy, &param);

	if (sched_getparam(getpid(), &param) != 0) {
		perror("An error occurs when calling sched_getparam()");
		return PTS_UNRESOLVED;
	}

	new_policy = sched_getscheduler(getpid());
	if (new_policy == -1) {
		perror("An error occurs when calling sched_getscheduler()");
		return PTS_UNRESOLVED;
	}

	if (old_policy == new_policy &&
	   old_priority == param.sched_priority) {
		printf("Test PASSED\n");
		return PTS_PASS;
	}

	if (param.sched_priority != old_priority) {
		printf("The param has changed\n");
	}
	if (new_policy != old_policy) {
		printf("The policy has changed\n");
	}
	return PTS_FAIL;
}
예제 #12
0
파일: 3-1.c 프로젝트: shubmit/shub-ltp
/* The main test function. */
int main(int argc, char * argv[])
{
	int ret, status;
	pid_t ch, ctl;
	sem_t * sem;

	/* Initialize output */
	output_init();

	/* Create the semaphore */
	sem = sem_open(SEM_NAME, O_CREAT | O_EXCL, 0744, 1);

	if ((sem == SEM_FAILED) && (errno == EEXIST))
	{
		sem_unlink(SEM_NAME);
		sem = sem_open(SEM_NAME, O_CREAT | O_EXCL, 0744, 1);
	}

	if (sem == SEM_FAILED)
	{
		UNRESOLVED(errno, "Failed to create the semaphore");
	}

	/* fork */
	ch = fork();

	if (ch == -1)
	{
		UNRESOLVED(errno, "Failed to fork");
	}

	if (ch == 0)         /* child */
	{
		/* connect to the semaphore */
		sem = sem_open(SEM_NAME, 0);

		if (sem == SEM_FAILED)
		{
			output("Failed to connect to the semaphore, error %d: %s\n", errno, strerror(errno));
			exit(1);
		}

		/* change euid */
		ret = set_nonroot();

		if (ret)
		{
			output("Changing euid failed\n");
			exit (1);
		}

		/* try and unlink, it should fail */
		ret = sem_unlink(SEM_NAME);

		if (ret == 0)
		{
			output("sem_unlink did not fail in child");
			exit(2);
		}

		if (errno != EACCES)
		{
			output("sem_unlink failed with unexpected error %d: %s\n", errno, strerror(errno));
			exit(2);
		}

		/* Ok, child is done. */
		exit(0);
	}

	/* Parent waits for the child to finish */
	ctl = waitpid(ch, &status, 0);

	if (ctl != ch)
	{
		UNRESOLVED(errno, "Waitpid returned the wrong PID");
	}

	if (!WIFEXITED(status))
	{
		FAILED("Child exited abnormally");
	}

	if (WEXITSTATUS(status) == 1)
	{
		UNRESOLVED(0, "An error occured in child");
	}

	if (WEXITSTATUS(status) == 2)
	{
		FAILED("Test failed in child");
	}

	if (WEXITSTATUS(status) != 0)
	{
		UNRESOLVED(0, "Unexpected return value from child");
	}

	/* Unlink */
	ret = sem_unlink(SEM_NAME);

	if (ret != 0)
	{
		UNRESOLVED(errno, "Failed to unlink the semaphore");
	}

	/* Test passed */
#if VERBOSE > 0
	output("Test passed\n");

#endif
	PASSED;
}