FreeBSD/usr.sbin/gssd/gssd.c
/*
 * Search a directory for the most likely candidate to be used as the
 * credential cache for a uid. If successful, return 1 and fill the
 * file's path id into "rpath". Otherwise, return 0.
 */
Search a directory for the most likely candidate to be used as the
credential cache for a uid. If successful, return 1 and fill the
file's path id into "rpath". Otherwise, return 0.
Search a directory for the most likely candidate to be used as the credential cache for a uid . If successful return 1 and fill the file ' s path id into " rpath " . Otherwise return 0 .
static int
find_ccache_file(const char *dirpath, uid_t uid, char *rpath)
{
	DIR *dirp;
	struct dirent *dp;
	struct stat sb;
	time_t exptime, oexptime;
	int gotone, len, rating, orating;
	char namepath[PATH_MAX + 5 + 1];
	char retpath[PATH_MAX + 5 + 1];
	dirp = opendir(dirpath);
	if (dirp == NULL)
		return (0);
	gotone = 0;
	orating = 0;
	oexptime = 0;
	while ((dp = readdir(dirp)) != NULL) {
		len = snprintf(namepath, sizeof(namepath), "%s/%s", dirpath,
		    dp->d_name);
		if (len < sizeof(namepath) &&
		    (hostbased_initiator_cred == 0 || strcmp(namepath,
		     GSSD_CREDENTIAL_CACHE_FILE) != 0) &&
		    strstr(dp->d_name, ccfile_substring) != NULL &&
		    lstat(namepath, &sb) >= 0 &&
		    sb.st_uid == uid &&
		    S_ISREG(sb.st_mode)) {
			len = snprintf(namepath, sizeof(namepath), "FILE:%s/%s",
			    dirpath, dp->d_name);
			if (len < sizeof(namepath) &&
			    is_a_valid_tgt_cache(namepath, uid, &rating,
			    &exptime) != 0) {
				if (gotone == 0 || rating > orating ||
				    (rating == orating && exptime > oexptime)) {
					orating = rating;
					oexptime = exptime;
					strcpy(retpath, namepath);
					gotone = 1;
				}
			}
		}
	}
	closedir(dirp);
	if (gotone != 0) {
		strcpy(rpath, retpath);
		return (1);
	}
	return (0);
}
static int find_ccache_file ( const char * dirpath , uid_t uid , char * rpath ) { DIR * dirp ; struct dirent * dp ; struct stat sb ; time_t exptime , oexptime ; int gotone , len , rating , orating ; char namepath [ PATH_MAX + 5 + 1 ] ; char retpath [ PATH_MAX + 5 + 1 ] ; dirp = opendir ( dirpath ) ; if ( dirp == NULL ) return ( 0 ) ; gotone = 0 ; orating = 0 ; oexptime = 0 ; while ( ( dp = readdir ( dirp ) ) != NULL ) { len = snprintf ( namepath , sizeof ( namepath ) , " " , dirpath , dp -> d_name ) ; if ( len < sizeof ( namepath ) && ( hostbased_initiator_cred == 0 || strcmp ( namepath , GSSD_CREDENTIAL_CACHE_FILE ) != 0 ) && strstr ( dp -> d_name , ccfile_substring ) != NULL && lstat ( namepath , & sb ) >= 0 && sb . st_uid == uid && S_ISREG ( sb . st_mode ) ) { len = snprintf ( namepath , sizeof ( namepath ) , " " , dirpath , dp -> d_name ) ; if ( len < sizeof ( namepath ) && is_a_valid_tgt_cache ( namepath , uid , & rating , & exptime ) != 0 ) { if ( gotone == 0 || rating > orating || ( rating == orating && exptime > oexptime ) ) { orating = rating ; oexptime = exptime ; strcpy ( retpath , namepath ) ; gotone = 1 ; } } } } closedir ( dirp ) ; if ( gotone != 0 ) { strcpy ( rpath , retpath ) ; return ( 1 ) ; } return ( 0 ) ; }
Search a directory for the most likely candidate to be used as the
 credential cache for a uid.
Search a directory for the most likely candidate to be used as the credential cache for a uid .