src/communication/security-server-comm.c
/* Authenticate the application is middleware daemon
 * The middleware must run as root and the cmd line must be pre listed */
Authenticate the application is middleware daemon
The middleware must run as root and the cmd line must be pre listed
Authenticate the application is middleware daemon The middleware must run as root and the cmd line must be pre listed
int authenticate_client_middleware(int sockfd, int *pid)
{
	int retval = SECURITY_SERVER_ERROR_AUTHENTICATION_FAILED;
	struct ucred cr;
	unsigned int cl = sizeof(cr);
	char *cmdline = NULL;
	*pid = 0;
	if(getsockopt(sockfd, SOL_SOCKET, SO_PEERCRED, &cr, &cl) != 0)
	{
		retval = SECURITY_SERVER_ERROR_SOCKET;
		SEC_SVR_DBG("%s", "Error on getsockopt");
		goto error;
	}
	if(cr.uid != 0)
	{
		retval = SECURITY_SERVER_ERROR_AUTHENTICATION_FAILED;
		SEC_SVR_DBG("Non root process has called API: %d", cr.uid);
		goto error;
	}
	cmdline = read_cmdline_from_proc(cr.pid);
	if(cmdline  == NULL)
	{
		retval = SECURITY_SERVER_ERROR_FILE_OPERATION;
		SEC_SVR_DBG("Error on opening /proc/%d/cmdline", cr.pid);
		goto error;
	}
	retval = search_middleware_cmdline(cmdline);
	*pid = cr.pid;
error:
	if(cmdline != NULL)
		free(cmdline);
	return retval;
}
int authenticate_client_middleware ( int sockfd , int * pid ) { int retval = SECURITY_SERVER_ERROR_AUTHENTICATION_FAILED ; struct ucred cr ; unsigned int cl = sizeof ( cr ) ; char * cmdline = NULL ; * pid = 0 ; if ( getsockopt ( sockfd , SOL_SOCKET , SO_PEERCRED , & cr , & cl ) != 0 ) { retval = SECURITY_SERVER_ERROR_SOCKET ; SEC_SVR_DBG ( " " , " " ) ; goto error ; } if ( cr . uid != 0 ) { retval = SECURITY_SERVER_ERROR_AUTHENTICATION_FAILED ; SEC_SVR_DBG ( " " , cr . uid ) ; goto error ; } cmdline = read_cmdline_from_proc ( cr . pid ) ; if ( cmdline == NULL ) { retval = SECURITY_SERVER_ERROR_FILE_OPERATION ; SEC_SVR_DBG ( " " , cr . pid ) ; goto error ; } retval = search_middleware_cmdline ( cmdline ) ; * pid = cr . pid ; error : if ( cmdline != NULL ) free ( cmdline ) ; return retval ; }
Authenticate the application is middleware daemon
 The middleware must run as root and the cmd line must be pre listed
Authenticate the application is middleware daemon The middleware must run as root and the cmd line must be pre listed
/* get PID of socket peer */ /* All middlewares will run as root */ /* Read command line of the PID from proc fs */ /* It's weired. no file in proc file system, */ /* Search cmdline of the peer that is really middleware executable */