src/server/security-server-cookie.c
/* Check stored default cookie, if it's not exist make a new one and store it */
Check stored default cookie, if it's not exist make a new one and store it
Check stored default cookie if it ' s not exist make a new one and store it
int check_stored_cookie(unsigned char *cookie, int size)
{
	int fd, ret;
	fd = open(SECURITY_SERVER_DEFAULT_COOKIE_PATH, O_RDONLY);
	if(fd < 0)
	{
		if(errno != ENOENT)
		{
			SEC_SVR_DBG("Cannot open default cookie. errno=%d", errno);
			ret = SECURITY_SERVER_ERROR_FILE_OPERATION;
			unlink(SECURITY_SERVER_DEFAULT_COOKIE_PATH);
		}
		ret = generate_random_cookie(cookie, size);
		fd = open(SECURITY_SERVER_DEFAULT_COOKIE_PATH, O_WRONLY | O_CREAT, 0600);
		if (fd < 0)
		{
			SEC_SVR_DBG("Cannot open default cookie errno=%d", errno);
			ret = SECURITY_SERVER_ERROR_FILE_OPERATION;
			goto error;
		}
		ret = write(fd, cookie, size);
		if(ret < size)
		{
			SEC_SVR_DBG("%s", "Cannot save default cookie");
			ret = SECURITY_SERVER_ERROR_FILE_OPERATION;
			goto error;
		}
		ret = fchmod(fd, 0600);
		if (ret < 0)
		{
			SEC_SVR_DBG("%s", "Cannot chmod default cookie");
			ret = SECURITY_SERVER_ERROR_FILE_OPERATION;
			goto error;
		}
		close(fd);
		return SECURITY_SERVER_SUCCESS;
	}
	ret = read (fd, cookie, size);
	if(ret < size)
	{
		SEC_SVR_DBG("Cannot read default cookie errno=%d", errno);
		ret = SECURITY_SERVER_ERROR_FILE_OPERATION;
		goto error;
	}
	ret = SECURITY_SERVER_SUCCESS;
error:
	if(fd > 0)
		close(fd);
	return ret;
}
int check_stored_cookie ( unsigned char * cookie , int size ) { int fd , ret ; fd = open ( SECURITY_SERVER_DEFAULT_COOKIE_PATH , O_RDONLY ) ; if ( fd < 0 ) { if ( errno != ENOENT ) { SEC_SVR_DBG ( " " , errno ) ; ret = SECURITY_SERVER_ERROR_FILE_OPERATION ; unlink ( SECURITY_SERVER_DEFAULT_COOKIE_PATH ) ; } ret = generate_random_cookie ( cookie , size ) ; fd = open ( SECURITY_SERVER_DEFAULT_COOKIE_PATH , O_WRONLY | O_CREAT , 0600 ) ; if ( fd < 0 ) { SEC_SVR_DBG ( " " , errno ) ; ret = SECURITY_SERVER_ERROR_FILE_OPERATION ; goto error ; } ret = write ( fd , cookie , size ) ; if ( ret < size ) { SEC_SVR_DBG ( " " , " " ) ; ret = SECURITY_SERVER_ERROR_FILE_OPERATION ; goto error ; } ret = fchmod ( fd , 0600 ) ; if ( ret < 0 ) { SEC_SVR_DBG ( " " , " " ) ; ret = SECURITY_SERVER_ERROR_FILE_OPERATION ; goto error ; } close ( fd ) ; return SECURITY_SERVER_SUCCESS ; } ret = read ( fd , cookie , size ) ; if ( ret < size ) { SEC_SVR_DBG ( " " , errno ) ; ret = SECURITY_SERVER_ERROR_FILE_OPERATION ; goto error ; } ret = SECURITY_SERVER_SUCCESS ; error : if ( fd > 0 ) close ( fd ) ; return ret ; }
Check stored default cookie, if it's not exist make a new one and store it
Check stored default cookie if it ' s not exist make a new one and store it
/* First, check the default cookie is stored */ /* Save cookie to disk */ /* Change mod only allow root process to read */