예제 #1
0
파일: test.c 프로젝트: CSU-GH/okl4_3.0
void
test6A(void)
{
	char 	path[PATH_MAX + NAME_MAX];
	int 	ret_val;

	if(getcwd(path, sizeof(path)) == NULL) {
		perror("getcwd");
		cleanup_function();
		fail_exit();
	}
	(void)strcat(path, "/tmp/data/dirh");

#ifdef DEBUG
	fprintf(temp, "TEST: nftw with FTW_CHDIR changes to each dir before reporting files in it\n");
#endif

	ret_val = nftw(path, test_func5, MAX_FD, FTW_CHDIR);
	if (ret_val == -1) {
		perror("nftw");
		cleanup_function();
		fail_exit();
	}
	if ((ret_val == 998) || (ret_val == 999)) {
		cleanup_function();
		fail_exit();
	}
}
예제 #2
0
파일: test.c 프로젝트: CSU-GH/okl4_3.0
void
test5A(void)
{
	char 	path[] = "./tmp/data/d777";
	int	ret_val;

#ifdef DEBUG
	fprintf(temp, "TEST: Verify traversal without FTW_DEPTH set\n");
#endif

	visit = 0;
	if((ret_val = nftw(path, test_func4, MAX_FD, 0)) == -1) {
		perror("nftw");
		cleanup_function();
		fail_exit();
	}
	if(ret_val != 999) {
		fprintf(temp, "ERROR: %s never visited\n", path);
		cleanup_function();
		fail_exit();
	}

	if (visit != 1)
	{
		fprintf(temp, "ERROR: Visited contents before directory\n");
		cleanup_function();
		fail_exit();
	}
}
예제 #3
0
파일: test.c 프로젝트: CSU-GH/okl4_3.0
void
test3A(void)
{
	int         ret;

#ifdef DEBUG
	fprintf(temp, "TEST: nftw without FTW_PHYS follows symbolic links\n");
#endif

	visit = 0;

	if((ret = nftw("./tmp/data/dirl", test_func3, MAX_FD, 0)) == -1) {
		perror("nftw");
		cleanup_function();
		fail_exit();
	}
	if(ret == 999) {
		cleanup_function();
		fail_exit();
	}

	if (visit != LINK_CNT-1)
	{
		fprintf(temp, "ERROR: Expected %d files to be visited.  nftw() visited %d\n", LINK_CNT-1, visit);
		cleanup_function(); 
		fail_exit();
	}
}
예제 #4
0
파일: test.c 프로젝트: CSU-GH/okl4_3.0
void
test2A(void)
{
	int         i, ret;

	temp = stderr;
#ifdef DEBUG
	fprintf(temp, "TEST: nftw with FTW_PHYS does not follow symbolic links\n");
#endif

	visit = 0;
	if((ret = nftw("./tmp/data/dirl", test_func1, MAX_FD, FTW_PHYS)) 
			== -1) {
		perror("nftw");
		cleanup_function();
		fail_exit();
	}

	if(ret == 999) {
		cleanup_function();
		fail_exit();
	}

	if (visit != NO_LINK_CNT)
	{
		fprintf(temp, "ERROR: Expected %d files to be visited.  nftw() visited %d\n", NO_LINK_CNT, visit);
		cleanup_function();
		fail_exit();
	}

	for (i = 0; i < visit; i++) {
		if (dirlist[i] != (char *)NULL)
			free(dirlist[i]);
	}
}
예제 #5
0
파일: test.c 프로젝트: CSU-GH/okl4_3.0
void
test11A(void)
{
	int         i, ret;

	for (i = 0; i < nbads; i++)
		if (badlist[i].i == FTW_D)
			badlist[i].i = FTW_DP;

#ifdef DEBUG
	fprintf(temp, "TEST: nftw passes FTW_DP when file is directory and subdirs already visited\n");
#endif

	if((ret = nftw("./tmp/data/dirg", test_func11, MAX_FD, FTW_DEPTH |
			FTW_PHYS)) == -1) {
		perror("nftw");
		cleanup_function();
		fail_exit();
	}

	if (ret == 999) {
		cleanup_function();
		fail_exit();
	}
}
예제 #6
0
JNIEXPORT void JNICALL Java_com_fiftyply_mosaic_MainActivity_getKeymap(JNIEnv* env, jobject obj, jobject map) {
  const char* map_class_name = "java/util/Map";
  jclass mapClass = env->FindClass(map_class_name);
  if(mapClass == NULL) {
    fail_exit("couldn't find %s", map_class_name);
  }

  jmethodID putMethod = env->GetMethodID(mapClass, "put",
                                         "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
  if(putMethod == NULL) {
    fail_exit("couldn't find put method");
  }

  jclass intCls = env->FindClass("java/lang/Integer");
  jmethodID newInt = env->GetMethodID(intCls, "<init>", "(I)V");

  jstring keyNameString;
  jobject keyValue;

#define GEN_INPUT_TABLE(name, value)                                    \
  keyNameString = env->NewStringUTF(#name);                             \
  keyValue = env->NewObject(intCls, newInt, value);                     \
  env->CallObjectMethod(map, putMethod, keyNameString, keyValue);

  KEY_TABLE(GEN_INPUT_TABLE);
}
예제 #7
0
파일: lib64.c 프로젝트: 1587/ltp
static void
execute_function(char *name, int (*callback) (const char *), char *buffer,
		 int expected)
{
	int result;

	temp = stderr;
#ifdef DEBUG
	fprintf(temp, "TEST: %s fails with ENAMETOOLONG\n", name);
#endif

	errno = 0;
	result = (*callback) (buffer);

	/*callback found an error, fail */
	if (result == -752) {
		tst_resm(TFAIL, "%s callback did not work correctly", name);
		cleanup_function();
		fail_exit();
	}
	if (result != expected) {
		tst_resm(TFAIL,
			 "%s did not return value as expected; Expected=%d Received=%d",
			 name, expected, result);
		cleanup_function();
		fail_exit();
	}
	if (errno != ENAMETOOLONG) {
		tst_resm(TFAIL, "%s failed: errno should be %i but is %i", name,
			 ENAMETOOLONG, errno);
		cleanup_function();
		fail_exit();
	}
}
예제 #8
0
/*
 * close_files - close and unlock the password databases
 */
static void close_files (void)
{
	if (is_shadow_pwd) {
		if (spw_close () == 0) {
			fprintf (stderr,
			         _("%s: failure while writing changes to %s\n"),
			         Prog, spw_dbname ());
			SYSLOG ((LOG_ERR, "failure while writing changes to %s", spw_dbname ()));
			fail_exit (1);
		}
		if (spw_unlock () == 0) {
			fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ());
			SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ()));
			/* continue */
		}
		spw_locked = false;
	}

	if (pw_close () == 0) {
		fprintf (stderr,
		         _("%s: failure while writing changes to %s\n"),
		         Prog, pw_dbname ());
		SYSLOG ((LOG_ERR, "failure while writing changes to %s", pw_dbname ()));
		fail_exit (1);
	}
	if (pw_unlock () == 0) {
		fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ());
		SYSLOG ((LOG_ERR, "failed to unlock %s", pw_dbname ()));
		/* continue */
	}
	pw_locked = false;
}
예제 #9
0
/*
 * close_files - close and unlock the password/shadow databases
 */
static void close_files (void)
{
	/*
	 * Now close the shadow password file, which will cause all of the
	 * entries to be re-written.
	 */
	if (spw_close () == 0) {
		fprintf (stderr,
		         _("%s: failure while writing changes to %s\n"), Prog, spw_dbname ());
		SYSLOG ((LOG_ERR, "failure while writing changes to %s", spw_dbname ()));
		fail_exit (E_NOPERM);
	}

	/*
	 * Close the password file. If any entries were modified, the file
	 * will be re-written.
	 */
	if (pw_close () == 0) {
		fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname ());
		SYSLOG ((LOG_ERR, "failure while writing changes to %s", pw_dbname ()));
		fail_exit (E_NOPERM);
	}
	if (spw_unlock () == 0) {
		fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ());
		SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ()));
		/* continue */
	}
	spw_locked = false;
	if (pw_unlock () == 0) {
		fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ());
		SYSLOG ((LOG_ERR, "failed to unlock %s", pw_dbname ()));
		/* continue */
	}
	pw_locked = false;
}
예제 #10
0
파일: chgpasswd.c 프로젝트: bfeeny/shadow
/*
 * close_files - close and unlock the group databases
 */
static void close_files (void)
{
#ifdef SHADOWGRP
	if (is_shadow_grp) {
		if (sgr_close () == 0) {
			fprintf (stderr,
			         _("%s: failure while writing changes to %s\n"),
			         Prog, sgr_dbname ());
			SYSLOG ((LOG_ERR, "failure while writing changes to %s", sgr_dbname ()));
			fail_exit (1);
		}
		if (sgr_unlock () == 0) {
			fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ());
			SYSLOG ((LOG_ERR, "failed to unlock %s", sgr_dbname ()));
			/* continue */
		}
		sgr_locked = false;
	}
#endif

	if (gr_close () == 0) {
		fprintf (stderr,
		         _("%s: failure while writing changes to %s\n"),
		         Prog, gr_dbname ());
		SYSLOG ((LOG_ERR, "failure while writing changes to %s", gr_dbname ()));
		fail_exit (1);
	}
	if (gr_unlock () == 0) {
		fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ());
		SYSLOG ((LOG_ERR, "failed to unlock %s", gr_dbname ()));
		/* continue */
	}
	gr_locked = false;
}
예제 #11
0
파일: lib64.c 프로젝트: 1587/ltp
void test_ENOENT_empty(char *name, int (*callback) (const char *), int expected)
{
	char *empty_string;

	empty_string = "";

	errno = 0;

	temp = stderr;
#ifdef DEBUG
	fprintf(temp, "TEST: ENOENT when empty string is passed\n");
#endif

	if ((s2 = (*callback) (empty_string)) == expected) {
		if (errno != ENOENT) {
			tst_resm(TFAIL,
				 "%s failed: errno should be %i but is %i",
				 name, ENOENT, errno);
			cleanup_function();
			fail_exit();
		}
	} else {
		tst_resm(TFAIL,
			 "%s did not return correct value; Expected=%d Received=%d",
			 name, expected, s2);
		cleanup_function();
		fail_exit();
	}
}
예제 #12
0
static void open_files (void)
{
    if (!gr_lock ()) {
        fprintf (stderr, _("%s: unable to lock group file\n"),
                 Prog);
        exit (E_GRP_UPDATE);
    }
    if (!gr_open (O_RDWR)) {
        fprintf (stderr, _("%s: unable to open group file\n"),
                 Prog);
        fail_exit (E_GRP_UPDATE);
    }
#ifdef	SHADOWGRP
    if (is_shadow_grp && !sgr_lock ()) {
        fprintf (stderr,
                 _("%s: unable to lock shadow group file\n"),
                 Prog);
        fail_exit (E_GRP_UPDATE);
    }
    if (is_shadow_grp && !sgr_open (O_RDWR)) {
        fprintf (stderr,
                 _("%s: unable to open shadow group file\n"),
                 Prog);
        fail_exit (E_GRP_UPDATE);
    }
#endif				/* SHADOWGRP */
}
예제 #13
0
파일: test.c 프로젝트: CSU-GH/okl4_3.0
void
test23A(void)
{
	int 	ret;

	visit=0;

#ifdef DEBUG
	fprintf(temp, "TEST: The function nftw should return with value set by fn\n");
#endif

	if((ret=nftw("./tmp/data/dirh", test_func23, MAX_FD, FTW_PHYS)) == -1) {
		perror("nftw");
		cleanup_function();
		fail_exit();
	}

	if (ret != 999) {
		fprintf(temp, "ERROR: nftw did not return value returned by fn()\n");
		cleanup_function();
		fail_exit();
	}
	if(visit != 4){
		fprintf(temp, "ERROR: nftw() did not return immediately on non-zero fn() return\n");
		cleanup_function();
		fail_exit();
	}
}
예제 #14
0
파일: test.c 프로젝트: CSU-GH/okl4_3.0
void
test19A(void)
{
	int	ret_val;

#ifdef DEBUG
	fprintf(temp, "TEST: Can not traverse directory with no read permission\n");
#endif

	visit = 0;

	ret_val = nftw("./tmp/data/d333", test_func19, MAX_FD, 0);
	if (ret_val == -1) {
		perror("nftw");
		cleanup_function();
		fail_exit();
	}

	if (ret_val == 999) {
		cleanup_function();
		fail_exit();
	}

#ifdef DEBUG
	fprintf(temp, "TEST: fn only be called once\n");
#endif

	if (visit != 1)
	{
		fprintf(temp, "ERROR: %s","Directory without read permission allows traversing\n");
		fprintf(temp, "       Visited %d files\n", visit);
		cleanup_function();
		fail_exit();
	}
}
예제 #15
0
파일: lib64.c 프로젝트: 1587/ltp
void
test_ENOENT_nofile(char *name, int (*callback) (const char *), int expected)
{

	remove_test_ENOENT_files();

	temp = stderr;
#ifdef DEBUG
	fprintf(temp, "TEST: ENOENT when file does not exist\n");
#endif

	if ((s2 = (*callback) (no_file)) == expected) {
		if (errno != ENOENT) {
			tst_resm(TFAIL,
				 "%s failed: errno should be %i but is %i",
				 name, ENOENT, errno);
			cleanup_function();
			fail_exit();
		}
	} else {
		tst_resm(TFAIL,
			 "%s did not return correct value; Expected=%d Received=%d",
			 name, expected, s2);
		cleanup_function();
		fail_exit();
	}
}
예제 #16
0
파일: test.c 프로젝트: CSU-GH/okl4_3.0
void
test13A(void)
{
	int         i, ret;

	if(unlink("./tmp/byebye") == -1){
		perror("unlink");
		cleanup_function();
		fail_exit();	
	}

	for (i = 0; i < nbads; i++)
		if (badlist[i].i == FTW_SL)
			badlist[i].i = FTW_SLN;

#ifdef DEBUG
	fprintf(temp, "TEST: nftw with FTW_PHYS passes FTW_SLN when file");
	fprintf(temp, " is symlink pointing \n to non-existent file\n");
#endif

	if((ret = nftw("./tmp/data/dirg", test_func13, MAX_FD,
			FTW_PHYS)) == -1) {
		perror("nftw");
		cleanup_function();
		fail_exit();
	}

	if (ret == 999) {
		cleanup_function();
		fail_exit();
	}
}
예제 #17
0
파일: pwck.c 프로젝트: Romutk/SPIVT1
/*
 * open_files - open the shadow database
 *
 *	In read-only mode, the databases are not locked and are opened
 *	only for reading.
 */
static void open_files (void)
{
	bool use_tcb = false;
#ifdef WITH_TCB
	use_tcb = getdef_bool ("USE_TCB");
#endif				/* WITH_TCB */

	/*
	 * Lock the files if we aren't in "read-only" mode
	 */
	if (!read_only) {
		if (pw_lock () == 0) {
			fprintf (stderr,
			         _("%s: cannot lock %s; try again later.\n"),
			         Prog, pw_dbname ());
			fail_exit (E_CANTLOCK);
		}
		pw_locked = true;
		if (is_shadow && !use_tcb) {
			if (spw_lock () == 0) {
				fprintf (stderr,
				         _("%s: cannot lock %s; try again later.\n"),
				         Prog, spw_dbname ());
				fail_exit (E_CANTLOCK);
			}
			spw_locked = true;
		}
	}

	/*
	 * Open the files. Use O_RDONLY if we are in read_only mode, O_RDWR
	 * otherwise.
	 */
	if (pw_open (read_only ? O_RDONLY : O_RDWR) == 0) {
		fprintf (stderr, _("%s: cannot open %s\n"),
		         Prog, pw_dbname ());
		if (use_system_pw_file) {
			SYSLOG ((LOG_WARN, "cannot open %s", pw_dbname ()));
		}
		fail_exit (E_CANTOPEN);
	}
	pw_opened = true;
	if (is_shadow && !use_tcb) {
		if (spw_open (read_only ? O_RDONLY : O_RDWR) == 0) {
			fprintf (stderr, _("%s: cannot open %s\n"),
			         Prog, spw_dbname ());
			if (use_system_spw_file) {
				SYSLOG ((LOG_WARN, "cannot open %s",
				         spw_dbname ()));
			}
			fail_exit (E_CANTOPEN);
		}
		spw_opened = true;
	}
}
예제 #18
0
/*
 * check_perms - check if the caller is allowed to add a group
 *
 *	Non-root users are only allowed to display their aging information.
 *	(we will later make sure that the user is only listing her aging
 *	information)
 *
 *	With PAM support, the setuid bit can be set on chage to allow
 *	non-root users to groups.
 *	Without PAM support, only users who can write in the group databases
 *	can add groups.
 *
 *	It will not return if the user is not allowed.
 */
static void check_perms (void)
{
#ifdef ACCT_TOOLS_SETUID
#ifdef USE_PAM
	pam_handle_t *pamh = NULL;
	struct passwd *pampw;
	int retval;
#endif				/* USE_PAM */
#endif				/* ACCT_TOOLS_SETUID */

	/*
	 * An unprivileged user can ask for their own aging information, but
	 * only root can change it, or list another user's aging
	 * information.
	 */

	if (!amroot && !lflg) {
		fprintf (stderr, _("%s: Permission denied.\n"), Prog);
		fail_exit (E_NOPERM);
	}

#ifdef ACCT_TOOLS_SETUID
#ifdef USE_PAM
	pampw = getpwuid (getuid ()); /* local, no need for xgetpwuid */
	if (NULL == pampw) {
		fprintf (stderr,
		         _("%s: Cannot determine your user name.\n"),
		         Prog);
		exit (E_NOPERM);
	}

	retval = pam_start ("chage", pampw->pw_name, &conv, &pamh);

	if (PAM_SUCCESS == retval) {
		retval = pam_authenticate (pamh, 0);
	}

	if (PAM_SUCCESS == retval) {
		retval = pam_acct_mgmt (pamh, 0);
	}

	if (PAM_SUCCESS != retval) {
		fprintf (stderr, _("%s: PAM: %s\n"),
		         Prog, pam_strerror (pamh, retval));
		SYSLOG((LOG_ERR, "%s", pam_strerror (pamh, retval)));
		if (NULL != pamh) {
			(void) pam_end (pamh, retval);
		}
		fail_exit (E_NOPERM);
	}
	(void) pam_end (pamh, retval);
#endif				/* USE_PAM */
#endif				/* ACCT_TOOLS_SETUID */
}
예제 #19
0
파일: test64.c 프로젝트: CSU-GH/okl4_3.0
void
test18A(void)
{
	int         ret;

	unlink("./tmp/byebye");

	visit=0;

	temp=stderr;
#ifdef DEBUG
	fprintf(temp, "TEST: nftw64 with FTW_PHYS does not pass FTW_SLN\n");
#endif

	if((ret = nftw64("./tmp/data/dirg", test_func18, MAX_FD, FTW_PHYS)) 
			== -1) {
		perror("nftw64");
		cleanup_function();
		fail_exit();
	}
	if (ret == 999) {
		fprintf(temp, "ERROR: nftw64() passed FTW_SLN\n");
		cleanup_function();
		fail_exit();
	}

	visit=0;

#ifdef DEBUG
	fprintf(temp, "TEST: nftw64 without FTW_PHYS passes FTW_SLN\n");
#endif

	if((ret=nftw64("./tmp/data/dirg", test_func18, MAX_FD, 0)) == -1) {
		perror("nftw64");
		cleanup_function();
		fail_exit();
	}
	
	if (visit == 1) {
		if (ret == 999) {
			/* Test is passed */
			return;
		} else { 
			fprintf(temp, "ERROR: nftw64 passed FTW_SLN but did"); 
			fprintf(temp, "not return value returned by fn()\n");
			cleanup_function();
			fail_exit();
		}
	} else {
		fprintf(temp, "ERROR: nftw64() did not pass FTW_SLN\n");
		cleanup_function();
		fail_exit();
	}
}
예제 #20
0
파일: test.c 프로젝트: CSU-GH/okl4_3.0
void
test1A(void)
{
	int         i, j, ret;

        temp = stderr;
#ifdef DEBUG
	fprintf(temp, "TEST: nftw() succeeds\n");
#endif

	visit = 0;
	if((ret = nftw("./tmp/data/dirh", test_func1, MAX_FD,0 )) == -1) {
		perror("ERROR: nftw failed");
		cleanup_function();
		fail_exit();
	}

	if(ret == 999) {
		cleanup_function();
		fail_exit();
	}

#ifdef DEBUG
	fprintf(temp, "TEST: Whole tree traversed\n");
#endif

	if (visit != ngoods) {
		fprintf(temp, "ERROR: Count of objects visited incorrect\n");
		fprintf(temp, "       Expected %d, Received %d\n", ngoods, visit);
		cleanup_function();
		fail_exit();
	}

	for (i = 0; i < visit; i++) {
		for (j = 0; j < ngoods; j++) {
			if (strcmp(dirlist[i], goodlist[j]) == 0) {
				free(dirlist[i]);
				dirlist[i] = (char *)NULL;
				break;
			}
		}
	}

	for (i = 0; i < visit; i++) {
		if (dirlist[i] != (char *)NULL) {
			free(dirlist[i]);
			fprintf(temp, "ERROR: Unexpected visit to %s\n", dirlist[i]);
			cleanup_function();
			fail_exit();
		}
	}
}
예제 #21
0
파일: passwd.c 프로젝트: Gioragg1/Test
static void update_noshadow (void)
{
	const struct passwd *pw;
	struct passwd *npw;

	if (pw_lock () == 0) {
		fprintf (stderr,
		         _("%s: cannot lock %s; try again later.\n"),
		         Prog, pw_dbname ());
		exit (E_PWDBUSY);
	}
	pw_locked = true;
	if (pw_open (O_RDWR) == 0) {
		fprintf (stderr,
		         _("%s: cannot open %s\n"),
		         Prog, pw_dbname ());
		SYSLOG ((LOG_WARN, "cannot open %s", pw_dbname ()));
		fail_exit (E_MISSING);
	}
	pw = pw_locate (name);
	if (NULL == pw) {
		fprintf (stderr,
		         _("%s: user '%s' does not exist in %s\n"),
		         Prog, name, pw_dbname ());
		fail_exit (E_NOPERM);
	}
	npw = __pw_dup (pw);
	if (NULL == npw) {
		oom ();
	}
	npw->pw_passwd = update_crypt_pw (npw->pw_passwd);
	if (pw_update (npw) == 0) {
		fprintf (stderr,
		         _("%s: failed to prepare the new %s entry '%s'\n"),
		         Prog, pw_dbname (), npw->pw_name);
		fail_exit (E_FAILURE);
	}
	if (pw_close () == 0) {
		fprintf (stderr,
		         _("%s: failure while writing changes to %s\n"),
		         Prog, pw_dbname ());
		SYSLOG ((LOG_ERR, "failure while writing changes to %s", pw_dbname ()));
		fail_exit (E_FAILURE);
	}
	if (pw_unlock () == 0) {
		fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ());
		SYSLOG ((LOG_ERR, "failed to unlock %s", pw_dbname ()));
		/* continue */
	}
	pw_locked = false;
}
예제 #22
0
파일: lib64.c 프로젝트: 1587/ltp
void test_ENOTDIR(char *name, int (*callback) (const char *), int expected)
{
	int fd;

	if ((fd = creat(is_a_file, (mode_t) (S_IRWXU | S_IRWXG | S_IRWXO)))
	    == -1) {
		tst_resm(TFAIL, "creat(%s) failed: %s", is_a_file,
			 strerror(errno));
		cleanup_function();
		fail_exit();
	}

	if (close(fd) == -1) {
		tst_resm(TFAIL, "close(%i) failed: %s", fd, strerror(errno));
		remove_test_ENOTDIR_files();
		cleanup_function();
		fail_exit();
	}

	errno = 0;

	temp = stderr;
#ifdef DEBUG
	fprintf(temp, "TEST: ENOTDIR when a component is not a directory\n");
#endif

	s2 = (*callback) ("./tmp/is_a_file/no_file");
	/*callback found an error, bail */
	if (s2 == -752) {
		remove_test_ENOTDIR_files();
		cleanup_function();
		fail_exit();
	}
	if (s2 == expected) {
		if (errno != ENOTDIR) {
			tst_resm(TFAIL,
				 "%s failed: errno should be %i but is %i",
				 name, ENOTDIR, errno);
			cleanup_function();
			fail_exit();
		}
	} else {
		tst_resm(TFAIL,
			 "%s did not return correct value; Expected=%d Received=%d",
			 name, expected, s2);
		cleanup_function();
		fail_exit();
	}
	remove_test_ENOTDIR_files();
}
예제 #23
0
static void
open_files(void)
{
	if (!pw_lock()) {
		fprintf(stderr, _("%s: unable to lock password file\n"), Prog);
		exit(E_PW_UPDATE);
	}
	if (! pw_open (O_RDWR)) {
		fprintf(stderr, _("%s: unable to open password file\n"), Prog);
		fail_exit(E_PW_UPDATE);
	}
#ifdef	SHADOWPWD
	if (is_shadow_pwd && ! spw_lock ()) {
		fprintf(stderr, _("%s: cannot lock shadow password file\n"),
			Prog);
		fail_exit(E_PW_UPDATE);
	}
	if (is_shadow_pwd && ! spw_open (O_RDWR)) {
		fprintf(stderr, _("%s: cannot open shadow password file\n"),
			Prog);
		fail_exit(E_PW_UPDATE);
	}
#endif
#ifdef	HAVE_TCFS
	if (!tcfs_lock()) {
		fprintf(stderr, _("%s: cannot lock TCFS key file\n"), Prog);
		fail_exit(E_PW_UPDATE);
	}
	if (!tcfs_open(O_RDWR)) {
		fprintf(stderr, _("%s: cannot open TCFS key file\n"), Prog);
		fail_exit(E_PW_UPDATE);
	}
#endif
	if (! gr_lock ()) {
		fprintf(stderr, _("%s: unable to lock group file\n"), Prog);
		fail_exit(E_GRP_UPDATE);
	}
	if (! gr_open (O_RDWR)) {
		fprintf(stderr, _("%s: cannot open group file\n"), Prog);
		fail_exit(E_GRP_UPDATE);
	}
#ifdef	SHADOWGRP
	if (is_shadow_grp && ! sgr_lock ()) {
		fprintf(stderr, _("%s: unable to lock shadow group file\n"),
			Prog);
		fail_exit(E_GRP_UPDATE);
	}
	if (is_shadow_grp && ! sgr_open (O_RDWR)) {
		fprintf(stderr, _("%s: cannot open shadow group file\n"),
				Prog);
		fail_exit(E_GRP_UPDATE);
	}
#endif
}
예제 #24
0
/*
 * open_files - open the shadow database
 *
 *	In read-only mode, the databases are not locked and are opened
 *	only for reading.
 */
static void open_files (void)
{
	/*
	 * Lock the files if we aren't in "read-only" mode
	 */
	if (!read_only) {
		if (gr_lock () == 0) {
			fprintf (stderr,
			         _("%s: cannot lock %s; try again later.\n"),
			         Prog, grp_file);
			fail_exit (E_CANT_LOCK);
		}
		gr_locked = true;
#ifdef	SHADOWGRP
		if (is_shadow) {
			if (sgr_lock () == 0) {
				fprintf (stderr,
				         _("%s: cannot lock %s; try again later.\n"),
				         Prog, sgr_file);
				fail_exit (E_CANT_LOCK);
			}
			sgr_locked = true;
		}
#endif
	}

	/*
	 * Open the files. Use O_RDONLY if we are in read_only mode,
	 * O_RDWR otherwise.
	 */
	if (gr_open (read_only ? O_RDONLY : O_RDWR) == 0) {
		fprintf (stderr, _("%s: cannot open %s\n"), Prog,
		         grp_file);
		if (use_system_grp_file) {
			SYSLOG ((LOG_WARN, "cannot open %s", grp_file));
		}
		fail_exit (E_CANT_OPEN);
	}
#ifdef	SHADOWGRP
	if (is_shadow && (sgr_open (read_only ? O_RDONLY : O_RDWR) == 0)) {
		fprintf (stderr, _("%s: cannot open %s\n"), Prog,
		         sgr_file);
		if (use_system_sgr_file) {
			SYSLOG ((LOG_WARN, "cannot open %s", sgr_file));
		}
		fail_exit (E_CANT_OPEN);
	}
#endif
}
예제 #25
0
/*
 * update_age - update the aging information in the database
 *
 *	It will not return in case of error
 */
static void update_age (/*@null@*/const struct spwd *sp,
                        /*@notnull@*/const struct passwd *pw)
{
	struct spwd spwent;

	/*
	 * There was no shadow entry. The new entry will have the encrypted
	 * password transferred from the normal password file along with the
	 * aging information.
	 */
	if (NULL == sp) {
		struct passwd pwent = *pw;

		memzero (&spwent, sizeof spwent);
		spwent.sp_namp = xstrdup (pwent.pw_name);
		spwent.sp_pwdp = xstrdup (pwent.pw_passwd);
		spwent.sp_flag = SHADOW_SP_FLAG_UNSET;

		pwent.pw_passwd = SHADOW_PASSWD_STRING;	/* XXX warning: const */
		if (pw_update (&pwent) == 0) {
			fprintf (stderr,
			         _("%s: failed to prepare the new %s entry '%s'\n"), Prog, pw_dbname (), pwent.pw_name);
			fail_exit (E_NOPERM);
		}
	} else {
		spwent.sp_namp = xstrdup (sp->sp_namp);
		spwent.sp_pwdp = xstrdup (sp->sp_pwdp);
		spwent.sp_flag = sp->sp_flag;
	}

	/*
	 * Copy the fields back to the shadow file entry and write the
	 * modified entry back to the shadow file. Closing the shadow and
	 * password files will commit any changes that have been made.
	 */
	spwent.sp_max = maxdays;
	spwent.sp_min = mindays;
	spwent.sp_lstchg = lstchgdate;
	spwent.sp_warn = warndays;
	spwent.sp_inact = inactdays;
	spwent.sp_expire = expdate;

	if (spw_update (&spwent) == 0) {
		fprintf (stderr,
		         _("%s: failed to prepare the new %s entry '%s'\n"), Prog, spw_dbname (), spwent.sp_namp);
		fail_exit (E_NOPERM);
	}

}
예제 #26
0
파일: shaders.cpp 프로젝트: netguy204/earth
int renderer_load_shader(const char* src, GLenum kind) {
  int shader = glCreateShader(kind);
  gl_check_("glCreateShader");

  const int max_shader = 8 * 1024;
  if(!shader_buffer) {
    shader_buffer = (char*)malloc(max_shader);
  }

#ifndef ANDROID
  snprintf(shader_buffer, max_shader, "#version 120\n%s", src);
#else
  snprintf(shader_buffer, max_shader, "%s", src);
#endif

  glShaderSource(shader, 1, (const char**)&shader_buffer, NULL);
  gl_check_("glShaderSource");

  glCompileShader(shader);
  gl_check_("glCompileShader");

  int status;
  glGetShaderiv(shader, GL_COMPILE_STATUS, &status);

  if(status == GL_FALSE) {
    char buffer[1024];
    int length;
    glGetShaderInfoLog(shader, sizeof(buffer), &length, buffer);
    fail_exit("glCompileShader: %s, %s\n", buffer, src);
  }

  return shader;
}
예제 #27
0
파일: passwd.c 프로젝트: Gioragg1/Test
static char *update_crypt_pw (char *cp)
{
#ifndef USE_PAM
	if (do_update_pwd) {
		cp = insert_crypt_passwd (cp, crypt_passwd);
	}
#endif				/* !USE_PAM */

	if (dflg) {
		*cp = '\0';
	}

	if (uflg && *cp == '!') {
		if (cp[1] == '\0') {
			fprintf (stderr,
			         _("%s: unlocking the password would result in a passwordless account.\n"
			           "You should set a password with usermod -p to unlock the password of this account.\n"),
			         Prog);
			fail_exit (E_FAILURE);
		} else {
			cp++;
		}
	}

	if (lflg && *cp != '!') {
		char *newpw = xmalloc (strlen (cp) + 2);

		strcpy (newpw, "!");
		strcat (newpw, cp);
		cp = newpw;
	}
	return cp;
}
예제 #28
0
파일: test.c 프로젝트: CSU-GH/okl4_3.0
void
test16A(void)
{
	char        path[PATH_MAX + NAME_MAX];
	char        orig[PATH_MAX];

	if(getcwd(orig, sizeof(orig)) == NULL) {
		perror("getcwd on original wd");
		cleanup_function();
		fail_exit();
	}

	strcpy(path, orig);
	(void)strcat(path, "/tmp/data/dirg");

#ifdef DEBUG
	fprintf(temp, "TEST: nftw with absolute pathname %s\n", path);
#endif

	if((s2 = nftw(path, test_func16, MAX_FD, 0)) == -1) {
		perror("nftw");
		cleanup_function();
		fail_exit();
	}
	if (s2 == 999) {
		cleanup_function();
		fail_exit();
	}

	(void)strcpy(path, "./tmp/data/dirg");

#ifdef DEBUG
	fprintf(temp, "TEST: nftw with relative pathname %s\n", path);
#endif

	if((s2 = nftw(path, test_func16, MAX_FD, 0)) == -1) {
		perror("nftw");
		cleanup_function();
		fail_exit();
	}

	if (s2 == 999) {
		cleanup_function();
		fail_exit();
	}
}
예제 #29
0
Animation* spriter_find(Entity* entity, const char* name) {
  for(int ii = 0; ii < entity->nanimations; ++ii) {
    Animation* anim = &entity->animations[ii];
    if(strncmp(anim->name, name, MAX_ENTRY_NAME - 1) == 0) return anim;
  }
  fail_exit("couldn't find animation %s in Entity", name);
  return NULL;
}
예제 #30
0
/*
 * open_files - open the shadow database
 *
 *	In read-only mode, the databases are not locked and are opened
 *	only for reading.
 */
static void open_files (void)
{
	/*
	 * Lock the files if we aren't in "read-only" mode
	 */
	if (!read_only) {
		if (pw_lock () == 0) {
			fprintf (stderr,
			         _("%s: cannot lock %s; try again later.\n"),
			         Prog, pwd_file);
			fail_exit (E_CANTLOCK);
		}
		pw_locked = true;
		if (is_shadow) {
			if (spw_lock () == 0) {
				fprintf (stderr,
				         _("%s: cannot lock %s; try again later.\n"),
				         Prog, spw_file);
				fail_exit (E_CANTLOCK);
			}
			spw_locked = true;
		}
	}

	/*
	 * Open the files. Use O_RDONLY if we are in read_only mode, O_RDWR
	 * otherwise.
	 */
	if (pw_open (read_only ? O_RDONLY : O_RDWR) == 0) {
		fprintf (stderr, _("%s: cannot open %s\n"),
		         Prog, pwd_file);
		if (use_system_pw_file) {
			SYSLOG ((LOG_WARN, "cannot open %s", pwd_file));
		}
		fail_exit (E_CANTOPEN);
	}
	if (is_shadow && (spw_open (read_only ? O_RDONLY : O_RDWR) == 0)) {
		fprintf (stderr, _("%s: cannot open %s\n"),
		         Prog, spw_file);
		if (use_system_spw_file) {
			SYSLOG ((LOG_WARN, "cannot open %s", spw_file));
		}
		fail_exit (E_CANTOPEN);
	}
}