src/server/security-server-cookie.c
/* Search existing cookie from the cookie list for the client process *
 * At the same time, it collects garbage cookie which PID is no longer exist and delete them */
Search existing cookie from the cookie list for the client process
At the same time, it collects garbage cookie which PID is no longer exist and delete them
Search existing cookie from the cookie list for the client process At the same time it collects garbage cookie which PID is no longer exist and delete them
cookie_list *search_existing_cookie(int pid, const cookie_list *c_list)
{
	cookie_list *current =(cookie_list *)c_list, *cookie = NULL;
	char *cmdline = NULL, *debug_cmdline = NULL;
	while(current != NULL)
	{
		current = garbage_collection(current);
		if(current == NULL)
			break;
		if(current->pid == pid)
		{
			cmdline = (char*)read_cmdline_from_proc(pid);
			if(cmdline == NULL)
			{
				SEC_SVR_DBG("%s", "cannot read cmdline");
				return NULL;
			}
			if(strncmp(cmdline, current->path, current->path_len) != 0 || strlen(cmdline) != current->path_len)
			{
				SEC_SVR_DBG("pid [%d] has been reused by %s. deleting the old cookie.", pid, cmdline);
				debug_cmdline = malloc(current->path_len + 1);
				if(debug_cmdline == NULL)
				{
					SEC_SVR_DBG("%s", "out of memory error");
					return NULL;
				}
				strncpy(debug_cmdline, current->path, current->path_len);
				debug_cmdline[current->path_len] = 0;
				SEC_SVR_DBG("[%s] --> [%s]", cmdline, debug_cmdline);
				if(debug_cmdline != NULL)
				{
					free(debug_cmdline);
					debug_cmdline = NULL;
				}
				current = delete_cookie_item(current);
				if(cmdline != NULL)
				{
					free(cmdline);
					cmdline = NULL;
				}
				continue;
			}
			else
			{
				SEC_SVR_DBG("%s", "cookie found");
				cookie = current;
			}
			if(cmdline != NULL)
			{
				free(cmdline);
				cmdline = NULL;
			}
		}
		current = current->next;
	}
	return cookie;
}
cookie_list * search_existing_cookie ( int pid , const cookie_list * c_list ) { cookie_list * current = ( cookie_list * ) c_list , * cookie = NULL ; char * cmdline = NULL , * debug_cmdline = NULL ; while ( current != NULL ) { current = garbage_collection ( current ) ; if ( current == NULL ) break ; if ( current -> pid == pid ) { cmdline = ( char * ) read_cmdline_from_proc ( pid ) ; if ( cmdline == NULL ) { SEC_SVR_DBG ( " " , " " ) ; return NULL ; } if ( strncmp ( cmdline , current -> path , current -> path_len ) != 0 || strlen ( cmdline ) != current -> path_len ) { SEC_SVR_DBG ( " " , pid , cmdline ) ; debug_cmdline = malloc ( current -> path_len + 1 ) ; if ( debug_cmdline == NULL ) { SEC_SVR_DBG ( " " , " " ) ; return NULL ; } strncpy ( debug_cmdline , current -> path , current -> path_len ) ; debug_cmdline [ current -> path_len ] = 0 ; SEC_SVR_DBG ( " " , cmdline , debug_cmdline ) ; if ( debug_cmdline != NULL ) { free ( debug_cmdline ) ; debug_cmdline = NULL ; } current = delete_cookie_item ( current ) ; if ( cmdline != NULL ) { free ( cmdline ) ; cmdline = NULL ; } continue ; } else { SEC_SVR_DBG ( " " , " " ) ; cookie = current ; } if ( cmdline != NULL ) { free ( cmdline ) ; cmdline = NULL ; } } current = current -> next ; } return cookie ; }
Search existing cookie from the cookie list for the client process
 At the same time, it collects garbage cookie which PID is no longer exist and delete them
Search existing cookie from the cookie list for the client process At the same time it collects garbage cookie which PID is no longer exist and delete them
/* Search from the list */ /* print_cookie(current);*/ /* PID must be same */ /* Found cookie for the pid. Check the cookie is reused by dirrent executable */ /* Check the path of the process */ /* Check the path is different */ /* Okay. delete current cookie */