/**************************************************************************************************
 * @fn      HalGpioResetInit
 *
 *
 * @brief   Initialise RESET GPIO.
 *
 * @param   gpioCfg - Reset pin configuration parameters
 *
 * @return  STATUS
 **************************************************************************************************/
int HalGpioResetInit(halGpioCfg_t *gpioCfg)
{
	memcpy(resetGpioCfg.gpio.value,
			gpioCfg->gpio.value,
			strlen(gpioCfg->gpio.value));
	if (__BIG_DEBUG_ACTIVE == TRUE)
	{
		time_printf("[%s] resetGpioCfg.gpio.value = '%s'\n", __FUNCTION__, resetGpioCfg.gpio.value);
	}
	memcpy(resetGpioCfg.gpio.direction,
			gpioCfg->gpio.direction,
			strlen(gpioCfg->gpio.direction));
	if (__BIG_DEBUG_ACTIVE == TRUE)
	{
		time_printf("[%s] resetGpioCfg.gpio.direction = '%s'\n", __FUNCTION__, resetGpioCfg.gpio.direction);
	}
	resetGpioCfg.gpio.active_high_low = gpioCfg->gpio.active_high_low;

	if ( ( gpioCfg->levelshifter.value) &&
			( gpioCfg->levelshifter.active_high_low) &&
			( gpioCfg->levelshifter.direction))
	{
		memcpy(resetGpioCfg.levelshifter.value,
				gpioCfg->levelshifter.value,
				strlen(gpioCfg->levelshifter.value));
		if (__BIG_DEBUG_ACTIVE == TRUE)
		{
			time_printf("[%s] resetGpioCfg.levelshifter.value = '%s'\n", __FUNCTION__, resetGpioCfg.levelshifter.value);
		}
		memcpy(resetGpioCfg.levelshifter.direction,
				gpioCfg->levelshifter.direction,
				strlen(gpioCfg->levelshifter.direction));
		resetGpioCfg.levelshifter.active_high_low = gpioCfg->levelshifter.active_high_low;
		if (__BIG_DEBUG_ACTIVE == TRUE)
		{
			time_printf("[%s] resetGpioCfg.levelshifter.direction = '%s'\n", __FUNCTION__, resetGpioCfg.levelshifter.direction);
		}

		//open the GPIO DIR file for the level shifter direction signal
		gpioResetFd = open(resetGpioCfg.levelshifter.direction, O_RDWR);
		if(gpioResetFd == 0)
		{
			perror(resetGpioCfg.levelshifter.direction);
			if (__BIG_DEBUG_ACTIVE == TRUE)
			{
				time_printf("[%s] %s open failed\n", __FUNCTION__, resetGpioCfg.levelshifter.direction);
			}
			npi_ipc_errno = NPI_LNX_ERROR_HAL_GPIO_RESET_LVLSHFT_DIR_OPEN;
			return NPI_LNX_FAILURE;
		}

		//Set the direction of the GPIO to output
		if (ERROR == write(gpioResetFd, "out", 3))
		{
			perror(resetGpioCfg.levelshifter.direction);
			if (__BIG_DEBUG_ACTIVE == TRUE)
			{
				time_printf("[%s] can't write in %s \n", __FUNCTION__, resetGpioCfg.levelshifter.direction);
			}
			npi_ipc_errno = NPI_LNX_ERROR_HAL_GPIO_RESET_LVLSHFT_DIR_WRITE;
			return NPI_LNX_FAILURE;
		}
		//close the DIR file
		close(gpioResetFd);

		//open the GPIO VALUE file for the level shifter direction signal
		gpioResetFd = open(resetGpioCfg.levelshifter.value, O_RDWR);
		if(gpioResetFd == 0)
		{
			perror(resetGpioCfg.levelshifter.value);
			if (__BIG_DEBUG_ACTIVE == TRUE)
			{
				time_printf("[%s] %s open failed\n", __FUNCTION__, resetGpioCfg.levelshifter.value);
			}
			npi_ipc_errno = NPI_LNX_ERROR_HAL_GPIO_RESET_LVLSHFT_VAL_OPEN;
			return NPI_LNX_FAILURE;
		}

		//Set the value of the GPIO to 0 (level shifter direction from Host to CC2531)
		if(ERROR == write(gpioResetFd, "1", 1))
		{
			perror(resetGpioCfg.levelshifter.value);
			if (__BIG_DEBUG_ACTIVE == TRUE)
			{
				time_printf("[%s] can't write in %s\n", __FUNCTION__, resetGpioCfg.levelshifter.value);
			}
			npi_ipc_errno = NPI_LNX_ERROR_HAL_GPIO_RESET_LVLSHFT_VAL_WRITE;
			return NPI_LNX_FAILURE;
		}
		//close the DIR file
		close(gpioResetFd);
	}
	else
	{
		if (__BIG_DEBUG_ACTIVE == TRUE)
		{
			LOG_ALWAYS("[%s] Wrong Configuration File, one of the  following Key value are missing for MRDY.Level Shifter definition: '\n", __FUNCTION__);
			LOG_ALWAYS("value: \t\t%s\n", resetGpioCfg.gpio.value);
			LOG_ALWAYS("direction: \t%s\n", resetGpioCfg.gpio.direction);
			LOG_ALWAYS("active_high_low: %d\n", resetGpioCfg.gpio.active_high_low);
			LOG_ALWAYS("Level Shifter is optional, please check if you need it or not before continuing...\n");
		}
	}

	//open the RESET GPIO DIR file
	gpioResetFd = open(resetGpioCfg.gpio.direction, O_RDWR);
	if(gpioResetFd == 0)
	{
		perror(resetGpioCfg.gpio.direction);
		if (__BIG_DEBUG_ACTIVE == TRUE)
		{
			time_printf("[%s] %s open failed\n", __FUNCTION__, resetGpioCfg.gpio.direction);
		}
		npi_ipc_errno = NPI_LNX_ERROR_HAL_GPIO_RESET_GPIO_DIR_OPEN;
		return NPI_LNX_FAILURE;
	}

	//Set RESET GPIO as output
	if(ERROR == write(gpioResetFd, "out", 3))
	{
		perror(resetGpioCfg.gpio.direction);
		if (__BIG_DEBUG_ACTIVE == TRUE)
		{
			time_printf("[%s] can't write in %s\n", __FUNCTION__, resetGpioCfg.gpio.direction);
		}
		npi_ipc_errno = NPI_LNX_ERROR_HAL_GPIO_RESET_GPIO_DIR_WRITE;
		return NPI_LNX_FAILURE;
	}
	//close RESET DIR file
	close(gpioResetFd);

	//open the RESET GPIO VALUE file so it can be written to using the file handle later
	gpioResetFd = open(resetGpioCfg.gpio.value, O_RDWR);
	if(gpioResetFd == 0)
	{
		perror(resetGpioCfg.gpio.value);
		if (__BIG_DEBUG_ACTIVE == TRUE)
		{
			time_printf("[%s] %s open failed\n", __FUNCTION__, resetGpioCfg.gpio.value);
		}
		npi_ipc_errno = NPI_LNX_ERROR_HAL_GPIO_RESET_GPIO_VAL_OPEN;
		return NPI_LNX_FAILURE;
	}

	//Set RESET GPIO to 1 as default
	if(ERROR == write(gpioResetFd, "1", 3))
	{
		perror(resetGpioCfg.gpio.value);
		if (__BIG_DEBUG_ACTIVE == TRUE)
		{
			time_printf("[%s] can't write in %s\n", __FUNCTION__, resetGpioCfg.gpio.value);
		}
		npi_ipc_errno = NPI_LNX_ERROR_HAL_GPIO_RESET_GPIO_VAL_WRITE;
		return NPI_LNX_FAILURE;
	}

	return NPI_LNX_SUCCESS;
}
Beispiel #2
0
static int cli_main( int argc, char * argv[] )
{

    static const char * ini_defaults[] = {
        "report_zend_debug",    "0",
        "display_errors",       "1",
        "register_argc_argv",   "1",
        "html_errors",          "0",
        "implicit_flush",       "1",
        "output_buffering",     "0",
        "max_execution_time",   "0",
        "max_input_time",       "-1",
        NULL
    };

    const char ** ini;
    char ** p = &argv[1];
    char ** argend= &argv[argc];
    int ret = -1;
    int c;
#if PHP_MAJOR_VERSION >= 7
	zend_string * psKey;
#endif
    lsapi_mode = 0;        /* enter CLI mode */

#ifdef PHP_WIN32
    _fmode = _O_BINARY;            /*sets default for file streams to binary */
    setmode(_fileno(stdin), O_BINARY);    /* make the stdio mode be binary */
    setmode(_fileno(stdout), O_BINARY);   /* make the stdio mode be binary */
    setmode(_fileno(stderr), O_BINARY);   /* make the stdio mode be binary */
#endif

    zend_first_try     {
        SG(server_context) = (void *) 1;

        zend_uv.html_errors = 0; /* tell the engine we're in non-html mode */
        CG(in_compilation) = 0; /* not initialized but needed for several options */
        SG(options) |= SAPI_OPTION_NO_CHDIR;
        
#if PHP_MAJOR_VERSION < 7
        EG(uninitialized_zval_ptr) = NULL;
#endif
        for( ini = ini_defaults; *ini; ini+=2 ) {
#if PHP_MAJOR_VERSION >= 7
			psKey = zend_string_init(*ini, strlen( *ini ), 1);
            zend_alter_ini_entry_chars(psKey,
                                (char *)*(ini+1), strlen( *(ini+1) ),
                                PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
			zend_string_release(psKey);
#else
            zend_alter_ini_entry( (char *)*ini, strlen( *ini )+1,
                                (char *)*(ini+1), strlen( *(ini+1) ),
                                PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
#endif
        }

        while (( p < argend )&&(**p == '-' )) {
            c = *((*p)+1);
            ++p;
            switch( c ) {
            case 'q':
                break;
            case 'i':
                if (php_request_startup() != FAILURE) {
                    php_print_info(0xFFFFFFFF);
#ifdef PHP_OUTPUT_NEWAPI
                    php_output_end_all();
#else
                    php_end_ob_buffers(1);
#endif
                    php_request_shutdown( NULL );
                    ret = 0;
                }
                break;
            case 'v':
                if (php_request_startup() != FAILURE) {
#if ZEND_DEBUG
                    php_printf("PHP %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) 1997-2017 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
#else
                    php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) 1997-2017 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
#endif
#ifdef PHP_OUTPUT_NEWAPI
                    php_output_end_all();
#else
                    php_end_ob_buffers(1);
#endif
                    php_request_shutdown( NULL );
                    ret = 0;
                }
                break;
            case 'c':
                ++p;
            /* fall through */
            case 's':
                break;
            case 'l':
                source_highlight = 2;
                break;
            case 'h':
            case '?':
            default:
                cli_usage();
                ret = 0;
                break;

            }
        }
        if ( ret == -1 ) {
            if ( *p ) {
                zend_file_handle file_handle;
                memset(&file_handle, 0, sizeof(file_handle));
                file_handle.type = ZEND_HANDLE_FP;
                file_handle.handle.fp = VCWD_FOPEN(*p, "rb");

                if ( file_handle.handle.fp ) {
                    script_filename = *p;
                    php_self = *p;

                    SG(request_info).path_translated = estrdup(*p);
                    SG(request_info).argc = argc - (p - argv);
                    SG(request_info).argv = p;

                    if (php_request_startup() == FAILURE ) {
                        fclose( file_handle.handle.fp );
                        ret = 2;
                    } else {
                        if (source_highlight == 1) {
                            zend_syntax_highlighter_ini syntax_highlighter_ini;

                            php_get_highlight_struct(&syntax_highlighter_ini);
                            highlight_file(SG(request_info).path_translated, &syntax_highlighter_ini);
                        } else if (source_highlight == 2) {
                            file_handle.filename = *p;
                            file_handle.free_filename = 0;
                            file_handle.opened_path = NULL;
                            ret = php_lint_script(&file_handle);
                            if (ret==SUCCESS) {
                                zend_printf("No syntax errors detected in %s\n", file_handle.filename);
                            } else {
                                zend_printf("Errors parsing %s\n", file_handle.filename);
                            }

                        } else {
                            file_handle.filename = *p;
                            file_handle.free_filename = 0;
                            file_handle.opened_path = NULL;

                            php_execute_script(&file_handle);
                            ret = EG(exit_status);
                       }

                        php_request_shutdown( NULL );
                    }
                } else {
                    php_printf("Could not open input file: %s.\n", *p);
                }
            } else {
                cli_usage();
            }
        }

    }zend_end_try();

    php_module_shutdown();

#ifdef ZTS
    tsrm_shutdown();
#endif
    return ret;
}
Beispiel #3
0
/* ----------------------------- MNI Header -----------------------------------
@NAME       : ecat_open
@INPUT      : filename - name of file to open
@OUTPUT     : (none)
@RETURNS    : Pointer to ECAT file descriptor or NULL if an error occurs.
@DESCRIPTION: Routine to open an ECAT file (for reading only), given 
              its pathname.
@METHOD     : 
@GLOBALS    : 
@CALLS      : 
@CREATED    : January 4, 1996 (Peter Neelin)
@MODIFIED   : 
---------------------------------------------------------------------------- */
 Ecat_file *ecat_open(char *filename)
{
   Ecat_file *file;

   /* Allocate space for an ecat file structure */
   file = (void *) MALLOC(sizeof(*file));


   file->main_header = (void *) MALLOC(MAIN_HEADER_SIZE);
   file->subheader = (void *) MALLOC(SUBHEADER_SIZE);
   file->cur_subhdr_offset = -1;
   file->subhdr_offsets = NULL;

   /* Open the file */
   if ((file->file_pointer=fopen(filename, "rb")) == NULL) {
      ecat_close(file);
      return NULL;
   }

   /* Read in the main header */
   if (fread(file->main_header, sizeof(char), (size_t) MAIN_HEADER_SIZE, 
             file->file_pointer) != MAIN_HEADER_SIZE) {
      ecat_close(file);
      return NULL;
   }

   /* Figure out which type of file we are using */
   if (strncmp((char *)file->main_header, MAGIC_STRING, 
               strlen(MAGIC_STRING)) == 0) {
      file->header_description = ECAT_VER_7;
      file->vax_byte_order = FALSE;
   }
   else {
      file->header_description = ECAT_VER_PRE7;
      file->vax_byte_order = TRUE;
   }

   /* Get the number of frames, slices, bed positions and gates */
   if (ecat_get_main_value(file, ECAT_Num_Planes, 0, 
                           &file->num_planes, NULL, NULL) ||
       ecat_get_main_value(file, ECAT_Num_Frames, 0, 
                           &file->num_frames, NULL, NULL) ||
       ecat_get_main_value(file, ECAT_Num_Bed_Pos, 0, 
                           &file->num_bed_positions, NULL, NULL) ||
       ecat_get_main_value(file, ECAT_Num_Gates, 0, 
                           &file->num_gates, NULL, NULL)) {
      ecat_close(file);
      return NULL;
   }
   file->num_volumes = file->num_frames;
   if (file->num_volumes < file->num_bed_positions)
      file->num_volumes = file->num_bed_positions;
   if (file->num_volumes < file->num_gates)
      file->num_volumes = file->num_gates;


   /* Read the directory structure */
   if (ecat_read_directory(file)) {
      ecat_close(file);
      return NULL;
   }
   /* Return the file pointer */

   return file;
}
Beispiel #4
0
long long evaluate(TERM* term, EVALUATION_CONTEXT* context)
{
	size_t offs, hi_bound, lo_bound;
    long long op1;
    long long op2;
    long long index;
	unsigned int i;
	unsigned int needed;
	unsigned int satisfied;
	int ovector[3];
	int rc;
	
    STRING* string;
    STRING* saved_anonymous_string;
	
	TERM_CONST* term_const = ((TERM_CONST*) term);
	TERM_UNARY_OPERATION* term_unary = ((TERM_UNARY_OPERATION*) term);
	TERM_BINARY_OPERATION* term_binary = ((TERM_BINARY_OPERATION*) term);
	TERM_TERNARY_OPERATION* term_ternary = ((TERM_TERNARY_OPERATION*) term);
	TERM_STRING* term_string = ((TERM_STRING*) term);
	TERM_VARIABLE* term_variable = ((TERM_VARIABLE*) term);
	TERM_STRING_OPERATION* term_string_operation = ((TERM_STRING_OPERATION*) term);
	
    TERM_INTEGER_FOR* term_integer_for;
	
	MATCH* match;
    TERM* item;
    TERM_RANGE* range;
    TERM_ITERABLE* items;
	TERM_STRING* t;
	
	switch(term->type)
	{
	case TERM_TYPE_CONST:
		return term_const->value;
		
	case TERM_TYPE_FILESIZE:
		return context->file_size;
		
	case TERM_TYPE_ENTRYPOINT:
		return context->entry_point;
		
	case TERM_TYPE_RULE:
		return evaluate(term_binary->op1, context);
		
	case TERM_TYPE_STRING:
	
	    if (term_string->string == NULL) /* it's an anonymous string */
	    {
            string = context->current_string;
	    }
	    else
	    {
            string = term_string->string;
	    }
	    	
		return string->flags & STRING_FLAGS_FOUND;
		
	case TERM_TYPE_STRING_AT:
	
    	if (term_string->string == NULL) /* it's an anonymous string */
        {
            string = context->current_string;
        }
        else
        {
            string = term_string->string;
        }
	
		if (string->flags & STRING_FLAGS_FOUND)
		{	
			offs = evaluate(term_string->offset, context);
								
			match = string->matches_head;
			
			while (match != NULL)
			{
				if (match->offset == offs)
					return 1;
					
				match = match->next;
			}
			
			return 0;				
		}
		else return 0;
		
	case TERM_TYPE_STRING_IN_RANGE:
	
        if (term_string->string == NULL) /* it's an anonymous string */
        {
            string = context->current_string;
        }
        else
        {
            string = term_string->string;
        }
	
		if (string->flags & STRING_FLAGS_FOUND)
		{	
            range = (TERM_RANGE*) term_string->range;
		    
			lo_bound = evaluate(range->min, context);
			hi_bound = evaluate(range->max, context);
				
			match = string->matches_head;

			while (match != NULL)
			{
				if (match->offset >= lo_bound && match->offset <= hi_bound)
					return 1;

				match = match->next;
			}

			return 0;				
		}
		else return 0;
		
	case TERM_TYPE_STRING_IN_SECTION_BY_NAME:
		return 0; /*TODO: Implementar section by name*/
		
	case TERM_TYPE_STRING_COUNT:
	
		i = 0;
		
		if (term_string->string == NULL) /* it's an anonymous string */
        {
            string = context->current_string;
        }
        else
        {
            string = term_string->string;
        }
        
		match = string->matches_head;
		
		while (match != NULL)
		{
			i++;
			match = match->next;
		}
		
		return i;
		
	case TERM_TYPE_STRING_OFFSET:
	
        i = 1;
	    index = evaluate(term_string->index, context);
	
    	if (term_string->string == NULL) /* it's an anonymous string */
        {
            string = context->current_string;
        }
        else
        {
            string = term_string->string;
        }
	
        match = string->matches_head;
        
		while (match != NULL && i < index)
		{
			match = match->next;
            i++;
		}
		
		if (match != NULL && i == index)
		{
		    return match->offset; 
		}   

        return UNDEFINED;


	case TERM_TYPE_AND:
        
	    if (evaluate(term_binary->op1, context))
		    return evaluate(term_binary->op2, context);
	    else
		    return 0;
			
	case TERM_TYPE_OR:
	
		if (evaluate(term_binary->op1, context))
			return 1;
		else
			return evaluate(term_binary->op2, context);
			
	case TERM_TYPE_NOT:
		return !evaluate(term_unary->op, context);
		
	case TERM_TYPE_ADD:
	    ARITHMETIC_OPERATOR(+, term_binary, context);
		                      
	case TERM_TYPE_SUB:            
		ARITHMETIC_OPERATOR(-, term_binary, context);
		                      
	case TERM_TYPE_MUL:            
		ARITHMETIC_OPERATOR(*, term_binary, context);
		                      
	case TERM_TYPE_DIV:            
		ARITHMETIC_OPERATOR(/, term_binary, context);
		
	case TERM_TYPE_BITWISE_AND:
	    ARITHMETIC_OPERATOR(&, term_binary, context);
	    
	case TERM_TYPE_BITWISE_OR:
    	ARITHMETIC_OPERATOR(|, term_binary, context);
    	
	case TERM_TYPE_SHIFT_LEFT:
    	ARITHMETIC_OPERATOR(<<, term_binary, context);    	
	
	case TERM_TYPE_SHIFT_RIGHT:
    	ARITHMETIC_OPERATOR(>>, term_binary, context);
    
    case TERM_TYPE_BITWISE_NOT:
    
        op1 = evaluate(term_unary->op, context);
        if (IS_UNDEFINED(op1))
            return UNDEFINED;
        else
            return ~op1;
               
	case TERM_TYPE_GT:
        COMPARISON_OPERATOR(>, term_binary, context);
		                      
	case TERM_TYPE_LT:
	    COMPARISON_OPERATOR(<, term_binary, context);
		                      
	case TERM_TYPE_GE:             
		COMPARISON_OPERATOR(>=, term_binary, context);
		                      
	case TERM_TYPE_LE:             
		COMPARISON_OPERATOR(<=, term_binary, context);	
		                      
	case TERM_TYPE_EQ:    
		COMPARISON_OPERATOR(==, term_binary, context);
	
	case TERM_TYPE_NOT_EQ:             
		COMPARISON_OPERATOR(!=, term_binary, context);
		
	case TERM_TYPE_OF:
			
		t = (TERM_STRING*) term_binary->op2;
		needed = evaluate(term_binary->op1, context);
        satisfied = 0;
        i = 0;	
						
		while (t != NULL)
		{
			if (evaluate((TERM*) t, context)) 
			{
				satisfied++;
			}	
						
			t = t->next;
            i++;
		} 
		
		if (needed == 0)  /* needed == 0 means ALL*/
            needed = i;
        
        return (satisfied >= needed);
		
	case TERM_TYPE_STRING_FOR:

        t = (TERM_STRING*) term_ternary->op2;
		
		needed = evaluate(term_ternary->op1, context);		
        satisfied = 0;
        i = 0;

		while (t != NULL)
		{
            saved_anonymous_string = context->current_string;
            context->current_string = t->string;
            	    
			if (evaluate(term_ternary->op3, context)) 
			{
				satisfied++;
			}	
			
            context->current_string = saved_anonymous_string;
						
			t = t->next;	
            i++;
		} 
		
		if (needed == 0)  /* needed == 0 means ALL*/
            needed = i;
        
        return (satisfied >= needed);
	
	case TERM_TYPE_INTEGER_FOR:
		
        term_integer_for = (TERM_INTEGER_FOR*) term;
        items = term_integer_for->items;
        
        needed = evaluate(term_integer_for->count, context);
        satisfied = 0;
        i = 0;    
        
        item = items->first(items, evaluate, context);
        
        while (item != NULL)
        {                
            term_integer_for->variable->integer = evaluate(item, context);
                                           
            if (evaluate(term_integer_for->expression, context)) 
			{
				satisfied++;
			}
						
            item = items->next(items, evaluate, context);
            i++;	
        }
        
        if (needed == 0)  /* needed == 0 means ALL*/
            needed = i;
        
        return (satisfied >= needed);
    
    case TERM_TYPE_UINT8_AT_OFFSET:

        return read_uint8(context->mem_block, evaluate(term_unary->op, context));

    case TERM_TYPE_UINT16_AT_OFFSET:
        
        return read_uint16(context->mem_block, evaluate(term_unary->op, context));
        
    case TERM_TYPE_UINT32_AT_OFFSET:

        return read_uint32(context->mem_block, evaluate(term_unary->op, context));
        
    case TERM_TYPE_INT8_AT_OFFSET:

        return read_int8(context->mem_block, evaluate(term_unary->op, context));

    case TERM_TYPE_INT16_AT_OFFSET:

        return read_int16(context->mem_block, evaluate(term_unary->op, context));

    case TERM_TYPE_INT32_AT_OFFSET:

        return read_int32(context->mem_block, evaluate(term_unary->op, context));  
        
    case TERM_TYPE_VARIABLE:
    
        if (term_variable->variable->type == VARIABLE_TYPE_STRING)
        {
            return ( term_variable->variable->string != NULL && *term_variable->variable->string != '\0');
        }
        else
        {
            return term_variable->variable->integer;
        }
        
    case TERM_TYPE_STRING_MATCH:
        rc = regex_exec(&(term_string_operation->re),
                        FALSE,
                        term_string_operation->variable->string,
                        strlen(term_string_operation->variable->string));
        return (rc >= 0);

	case TERM_TYPE_STRING_CONTAINS:
		
		return (strstr(term_string_operation->variable->string, term_string_operation->string) != NULL);
     	
	default:
		return 0;
	}
}
Beispiel #5
0
/**
 * qla2x00_fdmi_rpa() -
 * @ha: HA context
 *
 * Returns 0 on success.
 */
static int
qla2x00_fdmi_rpa(scsi_qla_host_t *ha)
{
	int rval, alen;
	uint32_t size, max_frame_size;

	ms_iocb_entry_t *ms_pkt;
	struct ct_sns_req *ct_req;
	struct ct_sns_rsp *ct_rsp;
	uint8_t *entries;
	struct ct_fdmi_port_attr *eiter;
	struct init_cb_24xx *icb24 = (struct init_cb_24xx *)ha->init_cb;

	/* Issue RPA */
	/* Prepare common MS IOCB */
	/*   Request size adjusted after CT preparation */
	ms_pkt = ha->isp_ops.prep_ms_fdmi_iocb(ha, 0, RPA_RSP_SIZE);

	/* Prepare CT request */
	ct_req = qla2x00_prep_ct_fdmi_req(&ha->ct_sns->p.req, RPA_CMD,
	    RPA_RSP_SIZE);
	ct_rsp = &ha->ct_sns->p.rsp;

	/* Prepare FDMI command arguments -- attribute block, attributes. */
	memcpy(ct_req->req.rpa.port_name, ha->port_name, WWN_SIZE);
	size = WWN_SIZE + 4;

	/* Attributes */
	ct_req->req.rpa.attrs.count =
	    __constant_cpu_to_be32(FDMI_PORT_ATTR_COUNT);
	entries = ct_req->req.rpa.port_name;

	/* FC4 types. */
	eiter = (struct ct_fdmi_port_attr *) (entries + size);
	eiter->type = __constant_cpu_to_be16(FDMI_PORT_FC4_TYPES);
	eiter->len = __constant_cpu_to_be16(4 + 32);
	eiter->a.fc4_types[2] = 0x01;
	size += 4 + 32;

	DEBUG13(printk("%s(%ld): FC4_TYPES=%02x %02x.\n", __func__, ha->host_no,
	    eiter->a.fc4_types[2], eiter->a.fc4_types[1]));

	/* Supported speed. */
	eiter = (struct ct_fdmi_port_attr *) (entries + size);
	eiter->type = __constant_cpu_to_be16(FDMI_PORT_SUPPORT_SPEED);
	eiter->len = __constant_cpu_to_be16(4 + 4);
	if (IS_QLA25XX(ha))
		eiter->a.sup_speed = __constant_cpu_to_be32(8);
	else if (IS_QLA24XX(ha))
		eiter->a.sup_speed = __constant_cpu_to_be32(4);
	else if (IS_QLA23XX(ha))
		eiter->a.sup_speed = __constant_cpu_to_be32(2);
	else
		eiter->a.sup_speed = __constant_cpu_to_be32(1);
	size += 4 + 4;

	DEBUG13(printk("%s(%ld): SUPPORTED_SPEED=%x.\n", __func__, ha->host_no,
	    eiter->a.sup_speed));

	/* Current speed. */
	eiter = (struct ct_fdmi_port_attr *) (entries + size);
	eiter->type = __constant_cpu_to_be16(FDMI_PORT_CURRENT_SPEED);
	eiter->len = __constant_cpu_to_be16(4 + 4);
	switch (ha->link_data_rate) {
	case 0:
		eiter->a.cur_speed = __constant_cpu_to_be32(1);
		break;
	case 1:
		eiter->a.cur_speed = __constant_cpu_to_be32(2);
		break;
	case 3:
		eiter->a.cur_speed = __constant_cpu_to_be32(4);
		break;
	}
	size += 4 + 4;

	DEBUG13(printk("%s(%ld): CURRENT_SPEED=%x.\n", __func__, ha->host_no,
	    eiter->a.cur_speed));

	/* Max frame size. */
	eiter = (struct ct_fdmi_port_attr *) (entries + size);
	eiter->type = __constant_cpu_to_be16(FDMI_PORT_MAX_FRAME_SIZE);
	eiter->len = __constant_cpu_to_be16(4 + 4);
	max_frame_size = IS_QLA24XX(ha) || IS_QLA25XX(ha) ?
		(uint32_t) icb24->frame_payload_size:
		(uint32_t) ha->init_cb->frame_payload_size;
	eiter->a.max_frame_size = cpu_to_be32(max_frame_size);
	size += 4 + 4;

	DEBUG13(printk("%s(%ld): MAX_FRAME_SIZE=%x.\n", __func__, ha->host_no,
	    eiter->a.max_frame_size));

	/* OS device name. */
	eiter = (struct ct_fdmi_port_attr *) (entries + size);
	eiter->type = __constant_cpu_to_be16(FDMI_PORT_OS_DEVICE_NAME);
	sprintf(eiter->a.os_dev_name, "/proc/scsi/qla2xxx/%ld", ha->host_no);
	alen = strlen(eiter->a.os_dev_name);
	alen += (alen & 3) ? (4 - (alen & 3)) : 4;
	eiter->len = cpu_to_be16(4 + alen);
	size += 4 + alen;

	DEBUG13(printk("%s(%ld): OS_DEVICE_NAME=%s.\n", __func__, ha->host_no,
	    eiter->a.os_dev_name));

	/* Update MS request size. */
	qla2x00_update_ms_fdmi_iocb(ha, size + 16);

	DEBUG13(printk("%s(%ld): RPA portname="
	    "%02x%02x%02x%02x%02x%02x%02x%02x size=%d.\n", __func__,
	    ha->host_no, ct_req->req.rpa.port_name[0],
	    ct_req->req.rpa.port_name[1], ct_req->req.rpa.port_name[2],
	    ct_req->req.rpa.port_name[3], ct_req->req.rpa.port_name[4],
	    ct_req->req.rpa.port_name[5], ct_req->req.rpa.port_name[6],
	    ct_req->req.rpa.port_name[7], size));
	DEBUG13(qla2x00_dump_buffer(entries, size));

	/* Execute MS IOCB */
	rval = qla2x00_issue_iocb(ha, ha->ms_iocb, ha->ms_iocb_dma,
	    sizeof(ms_iocb_entry_t));
	if (rval != QLA_SUCCESS) {
		/*EMPTY*/
		DEBUG2_3(printk("scsi(%ld): RPA issue IOCB failed (%d).\n",
		    ha->host_no, rval));
	} else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp, "RPA") !=
	    QLA_SUCCESS) {
		rval = QLA_FUNCTION_FAILED;
	} else {
		DEBUG2(printk("scsi(%ld): RPA exiting normally.\n",
		    ha->host_no));
	}

	return rval;
}
Beispiel #6
0
int get_port(char const **s, unsigned int *err_out) {

    *err_out = UPARSE_ERROR;

    if (NULL == *s) {
        fprintf(stderr,"input s is null\n");
        return ERROR_PORT;
    }

    // If the string is empty, that means there was nothing after
    // the host (no port, no path), so we return 0.
    if (strlen(*s) == 0) {
        *err_out = NO_UPARSE_ERROR;
        return NO_PORT;
    }

    // Local copy we can advance.
    char const *c = *s;

    // If the first char is not ':', then there is no port designation.
    if (HOST_PORT_DELIM != c[0]) {
        *err_out = NO_UPARSE_ERROR;
        *s = c;
        return NO_PORT;
    }

    // Advance past the ':'
    c++;

    // Choose a sensible limit for a port string.
    size_t const max_port_chars_len = 6;
    char port_chars[max_port_chars_len+1];
    memset(&port_chars[0], 0, sizeof(port_chars));

    size_t j = 0;

    while (*c) {
        if ((PATH_DELIM     == c[0]) ||
            (QUERY_DELIM    == c[0]) ||
            (FRAGMENT_DELIM == c[0])) {
            break;
        } else if (!isdigit(c[0])) {
            fprintf(stderr,"port char '%c' is not a digit\n",c[0]);
            return ERROR_PORT;
        } else if (max_port_chars_len == j) {
            fprintf(stderr,"port str exceeds max port str len %lu\n",max_port_chars_len);
            return ERROR_PORT;
        } else {
            port_chars[j] = c[0];
        }
        c++;
        j++;
    }

    // We didn't set port chars. This is not an error: a port is not required.
    if (0 == j) {
        return NO_PORT;
    }

    // Convert the port chars to a long
    long port_long = (long) strtol(port_chars,NULL,10);
    if (0 >= port_long) {
        fprintf(stderr,"zero port or cannot convert port_chars %s to long\n",port_chars);
        return ERROR_PORT;
    }

    if (65535 <= port_long) {
        fprintf(stderr,"%lu exceeds the maximum port value\n",port_long);
        return ERROR_PORT;
    }

    // Advance pointer past the port.
    *s = c;

    *err_out = NO_UPARSE_ERROR;
    return (int) port_long;
}
Beispiel #7
0
static void ficlIncludeFile(FICL_VM *pVM) /* ( i*x fileid -- j*x ) */
{
    ficlFILE *ff = (ficlFILE *)stackPopPtr(pVM->pStack);
    CELL id = pVM->sourceID;
    int     result = VM_OUTOFTEXT;
    long currentPosition, totalSize;
    long size;
    pVM->sourceID.p = (void *)ff;

    currentPosition = ftell(ff->f);
    totalSize = fileSize(ff->f);
    size = totalSize - currentPosition;

    if ((totalSize != -1) && (currentPosition != -1) && (size > 0))
        {
        char *buffer = (char *)malloc(size);
        long got = fread(buffer, 1, size, ff->f);
        if (got == size)
            result = ficlExecC(pVM, buffer, size);
        }

#if 0
    ficlFILE *ff = (ficlFILE *)stackPopPtr(pVM->pStack);
    CELL id = pVM->sourceID;
    char    cp[nLINEBUF];
    int     nLine = 0;
    int     keepGoing;
    int     result;
    pVM->sourceID.p = (void *)ff;

    /* feed each line to ficlExec */
    keepGoing = TRUE;
    while (keepGoing && fgets(cp, nLINEBUF, ff->f))
    {
        int len = strlen(cp) - 1;

        nLine++;
        if (len <= 0)
            continue;

        if (cp[len] == '\n')
            cp[len] = '\0';

        result = ficlExec(pVM, cp);

        switch (result)
        {
            case VM_OUTOFTEXT:
            case VM_USEREXIT:
                break;

            default:
                pVM->sourceID = id;
                keepGoing = FALSE;
                break; 
        }
    }
#endif /* 0 */
    /*
    ** Pass an empty line with SOURCE-ID == -1 to flush
    ** any pending REFILLs (as required by FILE wordset)
    */
    pVM->sourceID.i = -1;
    ficlExec(pVM, "");

    pVM->sourceID = id;
    closeFiclFILE(ff);
}
void	TBL_VALUE_ADDED_EVENT_CLASS::Set_SWITCH_ID(char	* sParam)
{
		if ( strlen(sParam)>10 ) 
			 throw TException( " Set_SWITCH_ID  string over 10!");
		strcpy(item.SWITCH_ID,sParam);
}
void	TBL_VALUE_ADDED_EVENT_CLASS::Set_STATE_DATE(char	* sParam)
{
		if ( strlen(sParam)>14 ) 
			 throw TException( " Set_STATE_DATE  string over 14!");
		strcpy(item.STATE_DATE,sParam);
}
void DialogChangePassword::accept() {
  // Check the length of the old password
  if (minimumPasswordLength > strlen(ui->lineEdit_OldPW->text().toLatin1())) {
    clearFields();
    QString OutputText;

    OutputText = tr("The minimum length of the old password is ") +
                 QString("%1").arg(minimumPasswordLength) + tr(" chars");

    csApplet->warningBox(OutputText);
    return;
  }

  // Check for correct new password entrys
  if (0 !=
      strcmp(ui->lineEdit_NewPW_1->text().toLatin1(), ui->lineEdit_NewPW_2->text().toLatin1())) {
    clearFields();
    csApplet->warningBox(tr("The new password entrys are not the same"));
    return;
  }

  // Check the new length of password - max
  // obsolete since input field max length is set, but should be checked
  // nevertheless in case STICK20_PASSOWRD_LEN would be changed to lower value
  if (STICK20_PASSOWRD_LEN < strlen(ui->lineEdit_NewPW_1->text().toLatin1())) {
    clearFields();
    QString OutputText;

    OutputText = tr("The maximum length of a password is ") +
                 QString("%1").arg(STICK20_PASSOWRD_LEN) + tr(" chars");

    csApplet->warningBox(OutputText);
    return;
  }

  // Check the new length of password - min
  if (minimumPasswordLength > strlen(ui->lineEdit_NewPW_1->text().toLatin1())) {
    clearFields();
    QString OutputText;

    OutputText = tr("The minimum length of a password is ") +
                 QString("%1").arg(minimumPasswordLength) + tr(" chars");

    csApplet->warningBox(OutputText);
    return;
  }

  bool success = false;
  // Send password to Stick 2.0
  switch (PasswordKind) {
  case STICK20_PASSWORD_KIND_USER:
  case STICK20_PASSWORD_KIND_ADMIN:
    success = SendNewPassword();
    break;
  case STICK10_PASSWORD_KIND_USER:
  case STICK10_PASSWORD_KIND_ADMIN:
    success = Stick10ChangePassword();
    break;
  case STICK20_PASSWORD_KIND_RESET_USER:
    success = ResetUserPassword();
    break;
  case STICK10_PASSWORD_KIND_RESET_USER:
    success = ResetUserPasswordStick10();
    break;
  case STICK20_PASSWORD_KIND_UPDATE:
    success = Stick20ChangeUpdatePassword();
    break;
  default:
    break;
  }

  cryptostick->getStatus();

  if (success) {
    done(true);
    return;
  }
  this->UpdatePasswordRetry();
  this->clearFields();
}
Beispiel #11
0
static size_t system_mbstowcs(char *wcs, const char *mbs, size_t len)
{
    strncpy(wcs, mbs, len);
    return strlen(wcs);
}
Beispiel #12
0
/* _find_executable_file:
 *  Helper function: searches path and current directory for executable.
 *  Returns 1 on succes, 0 on failure.
 */
static int _find_executable_file(const char *filename, char *output, int size)
{
	char *path;

	/* If filename has an explicit path, search current directory */
	if (strchr (filename, '/')) {
		if (filename[0] == '/') {
			/* Full path; done */
			strncpy(output, filename, size);
			output[size - 1] = 0;
			return 1;
		}
		else {
			struct stat finfo;
			int len;

			/* Prepend current directory */
			const char* result = getcwd(output, size);
			if (!result) output[0] = 0;

			len = strlen(output);
			output[len] = '/';
			strncpy(output+len+1, filename, size-len-1);
			output[size - 1] = 0;

			if ((stat(output, &finfo)==0) && (!S_ISDIR (finfo.st_mode)))
				return 1;
		}
	}
	/* If filename has no explicit path, but we do have $PATH, search there */
	else if ((path = getenv("PATH"))) {
		char *start = path, *end = path, *buffer = NULL, *temp;
		struct stat finfo;

		while (*end) {
			end = strchr (start, ':');
			if (!end) end = strchr (start, '\0');

			/* Resize `buffer' for path component, slash, filename and a '\0' */
			temp = realloc (buffer, end - start + 1 + strlen (filename) + 1);
			if (temp) {
				buffer = temp;

				strcpy (buffer, start);
				*(buffer + (end - start)) = '/';
				strcpy (buffer + (end - start) + 1, filename);

				if ((stat(buffer, &finfo)==0) && (!S_ISDIR (finfo.st_mode))) {
					strncpy(output, buffer, size);
					output[size - 1] = 0;
					free (buffer);
					return 1;
				}
			} /* else... ignore the failure; `buffer' is still valid anyway. */

			start = end + 1;
		}
		/* Path search failed */
		free (buffer);
	}

	return 0;
}
Beispiel #13
0
/* _unix_get_executable_name:
 *  Return full path to the current executable, use proc fs if available.
 */
void get_executable_name(char *output, int size)
{
#ifdef ALLEGRO_HAVE_SV_PROCFS
	struct prpsinfo psinfo;
	int fd;
#endif
#if defined ALLEGRO_HAVE_SV_PROCFS || defined ALLEGRO_SYS_GETEXECNAME
	char *s;
#endif
	char linkname[1024];
	char filename[1024];
	struct stat finfo;
	FILE *pipe;
	pid_t pid;
	int len;

#ifdef ALLEGRO_HAVE_GETEXECNAME
	s = getexecname();
	if (s) {
		if (s[0] == '/') {   /* Absolute path */
			strncpy(output, s, size);
			output[size - 1] = 0;
			return;
		}
		else {               /* Not an absolute path */
			if (_find_executable_file(s, output, size))
				return;
		}
	}
	s = NULL;
#endif

	/* We need the PID in order to query procfs */
	pid = getpid();

	/* Try a Linux-like procfs */
	/* get symolic link to executable from proc fs */
	sprintf (linkname, "/proc/%d/exe", pid);
	if (stat (linkname, &finfo) == 0) {
		len = readlink (linkname, filename, sizeof(filename)-1);
		if (len>-1) {
			filename[len] = '\0';

			strncpy(output, filename, size);
			output[size - 1] = 0;
			return;
		}
   }

   /* Use System V procfs calls if available */
#ifdef ALLEGRO_HAVE_SV_PROCFS
	sprintf (linkname, "/proc/%d/exe", pid);
	fd = open(linkname, O_RDONLY);
	if (fd >= 0) {
		ioctl(fd, PIOCPSINFO, &psinfo);
		close(fd);

		/* Use argv[0] directly if we can */
#ifdef ALLEGRO_HAVE_PROCFS_ARGCV
	if (psinfo.pr_argv && psinfo.pr_argc) {
		if (_find_executable_file(psinfo.pr_argv[0], output, size))
			return;
	}
	else
#endif
	{
		/* Emulate it */
		/* We use the pr_psargs field to find argv[0]
		 * This is better than using the pr_fname field because we need
		 * the additional path information that may be present in argv[0]
		*/

		/* Skip other args */
		s = strchr(psinfo.pr_psargs, ' ');
		if (s) s[0] = '\0';
		if (_find_executable_file(psinfo.pr_psargs, output, size))
			 return;
	}

	/* Try the pr_fname just for completeness' sake if argv[0] fails */
	if (_find_executable_file(psinfo.pr_fname, output, size))
		return;
	}
#endif

	/* Last resort: try using the output of the ps command to at least find */
	/* the name of the file if not the full path */
	sprintf (filename, "ps -p %d", pid);
	pipe = popen(filename, "r");
	if (pipe) {
		/* The first line of output is a header */
		const char* result = fgets(linkname, sizeof(linkname), pipe);
		if (!result) linkname[0] = 0;

		/* The information we want is in the last column; find it */
		len = strlen(linkname);
		while (linkname[len] != ' ' && linkname[len] != '\t')
			len--;

		/* The second line contains the info we want */
		result = fgets(linkname, sizeof(linkname), pipe);
		if (!result) { linkname[0] = 0; len = 0; }
		pclose(pipe);

		/* Treat special cases: filename between [] and - for login shell */
		if (linkname[len] == '-')
			len++;

		/* Now, the filename should be in the last column */
		strcpy(filename, linkname+len+1);

		if (_find_executable_file(filename, output, size))
			return;

		/* Just return the output from ps... */
		strncpy(output, filename, size);
		output[size - 1] = 0;
		return;
	}

#ifdef ALLEGRO_WITH_MAGIC_MAIN
	/* Try the captured argv[0] */
	if (_find_executable_file(__crt0_argv[0], output, size))
		return;
#endif

	/* Give up; return empty string */
	if (size > 0)
		*output = '\0';
}
Beispiel #14
0
static int parse_afs_partitions(struct mtd_info *mtd, 
                         struct mtd_partition **pparts,
                         unsigned long origin)
{
	struct mtd_partition *parts;
	u_int mask, off, idx, sz;
	int ret = 0;
	char *str;

	/*
	 * This is the address mask; we use this to mask off out of
	 * range address bits.
	 */
	mask = mtd->size - 1;

	/*
	 * First, calculate the size of the array we need for the
	 * partition information.  We include in this the size of
	 * the strings.
	 */
	for (idx = off = sz = 0; off < mtd->size; off += mtd->erasesize) {
		struct image_info_struct iis;
		u_int iis_ptr, img_ptr;

		ret = afs_read_footer(mtd, &img_ptr, &iis_ptr, off, mask);
		if (ret < 0)
			break;
		if (ret == 0)
			continue;

		ret = afs_read_iis(mtd, &iis, iis_ptr);
		if (ret < 0)
			break;
		if (ret == 0)
			continue;

		sz += sizeof(struct mtd_partition);
		sz += strlen(iis.name) + 1;
		idx += 1;
	}

	if (!sz)
		return ret;

	parts = kmalloc(sz, GFP_KERNEL);
	if (!parts)
		return -ENOMEM;

	memset(parts, 0, sz);
	str = (char *)(parts + idx);

	/*
	 * Identify the partitions
	 */
	for (idx = off = 0; off < mtd->size; off += mtd->erasesize) {
		struct image_info_struct iis;
		u_int iis_ptr, img_ptr, size;

		/* Read the footer. */
		ret = afs_read_footer(mtd, &img_ptr, &iis_ptr, off, mask);
		if (ret < 0)
			break;
		if (ret == 0)
			continue;

		/* Read the image info block */
		ret = afs_read_iis(mtd, &iis, iis_ptr);
		if (ret < 0)
			break;
		if (ret == 0)
			continue;

		strcpy(str, iis.name);
		size = mtd->erasesize + off - img_ptr;

		/*
		 * In order to support JFFS2 partitions on this layout,
		 * we must lie to MTD about the real size of JFFS2
		 * partitions; this ensures that the AFS flash footer
		 * won't be erased by JFFS2.  Please ensure that your
		 * JFFS2 partitions are given image numbers between
		 * 1000 and 2000 inclusive.
		 */
		if (iis.imageNumber >= 1000 && iis.imageNumber < 2000)
			size -= mtd->erasesize;

		parts[idx].name		= str;
		parts[idx].size		= size;
		parts[idx].offset	= img_ptr;
		parts[idx].mask_flags	= 0;

		printk("  mtd%d: at 0x%08x, %5dKB, %8u, %s\n",
			idx, img_ptr, parts[idx].size / 1024,
			iis.imageNumber, str);

		idx += 1;
		str = str + strlen(iis.name) + 1;
	}

	if (!idx) {
		kfree(parts);
		parts = NULL;
	}

	*pparts = parts;
	return idx ? idx : ret;
}
Beispiel #15
0
void data_read(int dev_fd, FILE *file_fd)
{
	int cnt = 0;
	int tmp;
	int offs = 0;
	int drop = 10;

	/* Write TS info the file header.		*/
	/* pktsize mode aggr_pkts_num tmstmp_offset	*/
	sprintf(data_buff,"%d %d %d %d %d %d",
		TSU_TOOL_STAMP,g_buff_info.pkt_size,g_buff_info.aggr_mode,
		g_buff_info.aggr_num_packets,
		g_buff_info.aggr_mode2_tmstmp_off, g_frequency);
	tmp = strlen(data_buff);
	while(tmp < FILE_HDR_SIZE)
		data_buff[tmp++] = ' ';
	data_buff[tmp] = '\0';

	if(!g_raw_mode)
		cnt = fwrite(data_buff,1,strlen(data_buff),file_fd);
	else
		cnt = fwrite(data_buff,1,strlen(data_buff),g_stat_fd);

	if(cnt != strlen(data_buff)) {
		fprintf(stderr,"Error wrting file header.\n");
		return;
        }

	/* Calculate the values of g_ts_data_size & g_tms_data_size.	*/
	if(g_raw_mode) {
		if(g_buff_info.aggr_mode == aggrMode1) {
			g_ts_data_size =
				(g_buff_info.pkt_size *
				 g_buff_info.aggr_num_packets);
			g_tms_data_size = (TIMESTAMP_SIZE *
					   g_buff_info.aggr_num_packets);
		}
		else if(g_buff_info.aggr_mode == aggrMode2) {
			g_ts_data_size = g_buff_info.pkt_size;
			g_tms_data_size = g_buff_info.aggr_mode2_tmstmp_off;
		}
		else { /* Aggregation disabled.	*/
			g_ts_data_size = g_buff_info.pkt_size;
			g_tms_data_size = TIMESTAMP_SIZE;
		}
	} else {
		g_ts_data_size = g_data_blk_sz;
		g_tms_data_size = 0;
	}

	/* Setup frequency.		*/
        if(ioctl(dev_fd,MVTSU_IOCFREQSET,&g_frequency) < 0) {
		fprintf(stderr,"Error configuring port frequency.\n");
		goto done;
	}

//	fprintf(stderr,"g_raw_mode = %d, g_ts_data_size = %d, g_tms_data_size = %d.\n",
//	       g_raw_mode, g_ts_data_size,g_tms_data_size);
	cnt = 0;
	while(1) {

		if(offs != 0)
			fprintf(stderr,"offs = %d.\n");
		tmp = single_read_write(READ,dev_fd,data_buff + offs,
					g_data_blk_sz - offs);
		if(tmp < 0) {
			fprintf(stderr,"Error reading from source device / file.\n");
			break;
		}
		if(drop) {
			drop--;
			continue;
		}

		cnt += tmp;
		if(cnt == 0)
			break;
		while(cnt >= (g_ts_data_size + g_tms_data_size)) {
 //                       fprintf(stderr,"cnt - %d, ",cnt);
			tmp = 0;
			if(g_tms_data_size > 0) {
				if(g_buff_info.aggr_mode == aggrMode2) {
//					fprintf(stderr,"TMSW = %d, ",offs);
					/* write only the timestamp part.	*/
					tmp = single_fread_fwrite(WRITE,g_stat_fd,
								  data_buff + offs,
						    TIMESTAMP_SIZE);
					if(tmp < TIMESTAMP_SIZE) {
						fprintf(stderr,"Error writing to timestamps file.\n");
						goto done;
					}
				} else {
					tmp = single_fread_fwrite(WRITE,g_stat_fd,
								data_buff + offs,
								g_tms_data_size);
					if(tmp < g_tms_data_size) {
						fprintf(stderr,"Error writing to timestamps file.\n");
						goto done;
					}
				}

				offs += tmp;
			}
//			fprintf(stderr,"TSDW = %d.\n",offs);
			tmp = single_fread_fwrite(WRITE,file_fd,data_buff + offs,
						g_ts_data_size);
			if(tmp < g_ts_data_size) {
				fprintf(stderr,"Error writing to data file.\n");
				goto done;
			}
			offs += g_ts_data_size;
			cnt -= (g_ts_data_size + g_tms_data_size);
		}

		if(cnt > 0) {
			memmove(data_buff,data_buff + offs, cnt);
			offs = cnt;
		}
		else {
			offs = 0;
		}
	}
done:
	return;
}
void	TBL_VALUE_ADDED_EVENT_CLASS::Set_CARD_NO(char	* sParam)
{
		if ( strlen(sParam)>32 ) 
			 throw TException( " Set_CARD_NO  string over 32!");
		strcpy(item.CARD_NO,sParam);
}
Beispiel #17
0
int main(int argc, char *argv[])
{
	char *dev_name;
	char *file_name;
	int dev_fd = 0;
	FILE *file_fd = NULL;
	int cnt = 0;
	struct tsu_stat tsu_stat;

	/* Eecutable name.		*/
	util_name = argv[cnt++];

	if(argc < 4) {
		if(argc > 1)
			fprintf(stderr,"Missing parameters.\n");
		usage();
	}

	/* Device name			*/
	dev_name = argv[cnt++];

	/* Read / Write operation.	*/
	if(!strcmp(argv[cnt],"r")) {
		g_is_read = 1;
	} else if(!strcmp(argv[cnt],"w")) {
		g_is_read = 0;
	} else {
		fprintf(stderr,"Bad read / write option.\n");
		usage();
	}
	cnt++;

	/* Open the device.		*/
	if(g_is_read)
		dev_fd = open(dev_name, O_RDONLY);
	else
		dev_fd = open(dev_name, O_WRONLY);

	if(dev_fd <= 0) {
		fprintf(stderr,"%s - Cannot open device %s.\n",util_name,dev_name);
		exit(2);
	}

	/* Input / Output file name.	*/
	file_name = argv[cnt++];
	if(g_is_read) {
		if(!strncmp(file_name,"stdout",strlen("stdout")))
			file_fd = stdout;
	else
			file_fd = fopen(file_name, "w+");
	}else{
		file_fd = fopen(file_name, "r");
	}
	if(file_fd == NULL) {
		fprintf(stderr,"%s - Cannot open file %s.\n",util_name,file_name);
		goto error;
	}

	if(get_buff_info(dev_fd) < 0){
		fprintf(stderr,"%s - Failed to retrieve device buffer configuration.\n");
		goto error;
	}

	/* Allocate buffer.		*/
	data_buff = malloc(g_buf_size);
	if(data_buff == NULL) {
		fprintf(stderr,"%s - Failed to allocate memory (%d Bytes).\n",util_name,
		       BUFSIZE);
		goto error;
	}

	if(process_options(argc,argv,cnt,dev_fd) < 0) {
		fprintf(stderr,"Bad options.\n");
		goto error;
	}

	/* Clear statistics.			*/
	if(ioctl(dev_fd,MVTSU_IOCCLEARSTAT,0) < 0) {
		fprintf(stderr,"Error Clearing statistics.\n");
		goto error;
	}

	if(g_is_read)
		data_read(dev_fd,file_fd);
	else
		data_write(dev_fd,file_fd);

	/* Print statistics.			*/
	if(ioctl(dev_fd,MVTSU_IOCGETSTAT,&tsu_stat) < 0) {
		fprintf(stderr,"Error Printing statistics.\n");
		goto error;
	}
	tsu_print_stat(&tsu_stat);

error:
	if(dev_fd != 0)
		close(dev_fd);
	if(file_fd != NULL)
		fclose(file_fd);
	if(data_buff != NULL)
		free(data_buff);
	if(g_stat_fd != NULL)
		fclose(g_stat_fd);
	return 0;
}
void	TBL_VALUE_ADDED_EVENT_CLASS::Set_BILLING_AREA_CODE(char	* sParam)
{
		if ( strlen(sParam)>10 ) 
			 throw TException( " Set_BILLING_AREA_CODE  string over 10!");
		strcpy(item.BILLING_AREA_CODE,sParam);
}
Beispiel #19
0
fsal_status_t GPFSFSAL_readdir(fsal_dir_t * dir_desc,       /* IN */
                           fsal_cookie_t startposition,        /* IN */
                           fsal_attrib_mask_t get_attr_mask,    /* IN */
                           fsal_mdsize_t buffersize,    /* IN */
                           fsal_dirent_t * p_pdirent,   /* OUT */
                           fsal_cookie_t * end_position,      /* OUT */
                           fsal_count_t * p_nb_entries, /* OUT */
                           fsal_boolean_t * p_end_of_dir        /* OUT */
    )
{
  fsal_status_t st;
  fsal_count_t max_dir_entries;
  fsal_name_t entry_name;
  char buff[BUF_SIZE];
  struct linux_dirent *dp = NULL;
  int bpos = 0;
  int tmpfd = 0;
  gpfsfsal_dir_t *p_dir_descriptor = (gpfsfsal_dir_t *)dir_desc;
  gpfsfsal_cookie_t start_position;
  gpfsfsal_cookie_t *p_end_position = (gpfsfsal_cookie_t *)end_position;

  char d_type;
  struct stat buffstat;

  int rc = 0;

  memset(buff, 0, BUF_SIZE);
  memset(&entry_name, 0, sizeof(fsal_name_t));

  /*****************/
  /* sanity checks */
  /*****************/

  if(!p_dir_descriptor || !p_pdirent || !p_end_position || !p_nb_entries || !p_end_of_dir)
    Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_readdir);

  max_dir_entries = (buffersize / sizeof(fsal_dirent_t));

  /***************************/
  /* seek into the directory */
  /***************************/
  start_position.data.cookie = (off_t)startposition.data;
  errno = 0;
  if(start_position.data.cookie == 0)
    {
      //rewinddir(p_dir_descriptor->p_dir);
      rc = errno;
    }
  else
    {
      //seekdir(p_dir_descriptor->p_dir, start_position.cookie);
      rc = errno;
    }

  if(rc)
    Return(posix2fsal_error(rc), rc, INDEX_FSAL_readdir);

  /************************/
  /* browse the directory */
  /************************/

  *p_nb_entries = 0;
  while(*p_nb_entries < max_dir_entries)
    {
    /***********************/
      /* read the next entry */
    /***********************/
      TakeTokenFSCall();
      rc = syscall(SYS_getdents, p_dir_descriptor->fd, buff, BUF_SIZE);
      ReleaseTokenFSCall();
      if(rc < 0)
        {
          rc = errno;
          Return(posix2fsal_error(rc), rc, INDEX_FSAL_readdir);
        }
      /* End of directory */
      if(rc == 0)
        {
          *p_end_of_dir = 1;
          break;
        }

    /***********************************/
      /* Get information about the entry */
    /***********************************/

      for(bpos = 0; bpos < rc;)
        {
          dp = (struct linux_dirent *)(buff + bpos);
          d_type = *(buff + bpos + dp->d_reclen - 1);
                                                    /** @todo not used for the moment. Waiting for information on symlink management */
          bpos += dp->d_reclen;

          /* LogFullDebug(COMPONENT_FSAL,
                          "\tino=%8ld|%8lx off=%d|%x reclen=%d|%x name=%s|%d",
                          dp->d_ino, dp->d_ino, (int)dp->d_off, (int)dp->d_off,
                          dp->d_reclen, dp->d_reclen, dp->d_name, (int)dp->d_name[0]  ) ; */

          if(!(*p_nb_entries < max_dir_entries))
            break;

          /* skip . and .. */
          if(!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
            continue;

          /* build the full path of the file into "fsalpath */
          if(FSAL_IS_ERROR
             (st =
              FSAL_str2name(dp->d_name, FSAL_MAX_NAME_LEN,
                            &(p_pdirent[*p_nb_entries].name))))
            ReturnStatus(st, INDEX_FSAL_readdir);

          d_type = DT_UNKNOWN;

          // TODO: there is a race here, because between handle fetch
          // and open at things might change.  we need to figure out if there
          // is another way to open without the pcontext

          strncpy(entry_name.name, dp->d_name, sizeof(entry_name.name));
          entry_name.len = strlen(entry_name.name);

          if(FSAL_IS_ERROR
             (st =
              fsal_internal_get_handle_at(p_dir_descriptor->fd, &entry_name,
                                          &(p_pdirent[*p_nb_entries].handle))))
            ReturnStatus(st, INDEX_FSAL_readdir);

          if(FSAL_IS_ERROR
             (st =
              fsal_internal_handle2fd_at(p_dir_descriptor->fd,
                                         &(p_pdirent[*p_nb_entries].handle), &tmpfd,
                                         O_RDONLY | O_NOFOLLOW)))
            {
              if(errno != ELOOP)        /* ( p_dir_descriptor->fd, dp->d_name) is not a symlink */
                ReturnStatus(st, INDEX_FSAL_readdir);
              else
                d_type = DT_LNK;
            }

          /* get object handle */
          TakeTokenFSCall();
          if(d_type != DT_LNK)
            {
              close(tmpfd);
            }
          else
            {
              if(fstatat(p_dir_descriptor->fd, dp->d_name, &buffstat, AT_SYMLINK_NOFOLLOW)
                 < 0)
                {
                  ReleaseTokenFSCall();
                  Return(posix2fsal_error(errno), errno, INDEX_FSAL_readdir);
                }

              p_pdirent[*p_nb_entries].attributes.asked_attributes = get_attr_mask;

              st = posix2fsal_attributes(&buffstat, &p_pdirent[*p_nb_entries].attributes);
              if(FSAL_IS_ERROR(st))
                {
                  ReleaseTokenFSCall();
                  FSAL_CLEAR_MASK(p_pdirent[*p_nb_entries].attributes.asked_attributes);
                  FSAL_SET_MASK(p_pdirent[*p_nb_entries].attributes.asked_attributes,
                                FSAL_ATTR_RDATTR_ERR);
                  ReturnStatus(st, INDEX_FSAL_getattrs);
                }

            }
          ReleaseTokenFSCall();

          if(FSAL_IS_ERROR(st))
            ReturnStatus(st, INDEX_FSAL_readdir);

    /************************
     * Fills the attributes *
     ************************/
          if(d_type != DT_LNK)
            {
              p_pdirent[*p_nb_entries].attributes.asked_attributes = get_attr_mask;

              st = GPFSFSAL_getattrs(&(p_pdirent[*p_nb_entries].handle),
				     (fsal_op_context_t *)&p_dir_descriptor->context,
                                 &p_pdirent[*p_nb_entries].attributes);
              if(FSAL_IS_ERROR(st))
                {
                  FSAL_CLEAR_MASK(p_pdirent[*p_nb_entries].attributes.asked_attributes);
                  FSAL_SET_MASK(p_pdirent[*p_nb_entries].attributes.asked_attributes,
                                FSAL_ATTR_RDATTR_ERR);
                }
            }
          ((gpfsfsal_cookie_t *)(&p_pdirent[*p_nb_entries].cookie))->data.cookie = dp->d_off;
          p_pdirent[*p_nb_entries].nextentry = NULL;
          if(*p_nb_entries)
            p_pdirent[*p_nb_entries - 1].nextentry = &(p_pdirent[*p_nb_entries]);

	  memcpy((char *)p_end_position, (char *)&p_pdirent[*p_nb_entries].cookie,
                 sizeof(gpfsfsal_cookie_t));
          (*p_nb_entries)++;

        }                       /* for */
    }                           /* While */

  Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_readdir);

}
void	TBL_VALUE_ADDED_EVENT_CLASS::Set_BILLING_NBR(char	* sParam)
{
		if ( strlen(sParam)>32 ) 
			 throw TException( " Set_BILLING_NBR  string over 32!");
		strcpy(item.BILLING_NBR,sParam);
}
Beispiel #21
0
static int privacy_exec (struct cw_channel *chan, int argc, char **argv)
{
	char phone[30];
	struct localuser *u;
	struct cw_config *cfg;
	char *s;
	int res=0;
	int retries;
	int maxretries = 3;
	int minlength = 10;
	int x;

	LOCAL_USER_ADD (u);

	if (!cw_strlen_zero(chan->cid.cid_num)) {
		if (option_verbose > 2)
			cw_verbose (VERBOSE_PREFIX_3 "CallerID Present: Skipping\n");
		pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "SUCCESS");
	} else {
		/*Answer the channel if it is not already*/
		if (chan->_state != CW_STATE_UP) {
			res = cw_answer(chan);
			if (res) {
				pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "FAIL");
				LOCAL_USER_REMOVE(u);
				return 0;
			}
		}
		/*Read in the config file*/
		cfg = cw_config_load(PRIV_CONFIG);
		
		
		/*Play unidentified call*/
		res = cw_safe_sleep(chan, 1000);
		if (!res)
			res = cw_streamfile(chan, "privacy-unident", chan->language);
		if (!res)
			res = cw_waitstream(chan, "");

        if (cfg && (s = cw_variable_retrieve(cfg, "general", "maxretries"))) {
                if (sscanf(s, "%d", &x) == 1) {
                        maxretries = x;
                } else {
                        cw_log(LOG_WARNING, "Invalid max retries argument\n");
                }
        }
        if (cfg && (s = cw_variable_retrieve(cfg, "general", "minlength"))) {
                if (sscanf(s, "%d", &x) == 1) {
                        minlength = x;
                } else {
                        cw_log(LOG_WARNING, "Invalid min length argument\n");
                }
        }
			
		/*Ask for 10 digit number, give 3 attempts*/
		for (retries = 0; retries < maxretries; retries++) {
			if (!res ) 
				res = cw_app_getdata(chan, "privacy-prompt", phone, sizeof(phone), 0);

			if (res < 0)
				break;

			/*Make sure we get at least our minimum of digits*/
			if (strlen(phone) >= minlength ) 
				break;
			else {
				res = cw_streamfile(chan, "privacy-incorrect", chan->language);
				if (!res)
					res = cw_waitstream(chan, "");
			}
		}
		
		/*Got a number, play sounds and send them on their way*/
		if ((retries < maxretries) && res == 1 ) {
			res = cw_streamfile(chan, "privacy-thankyou", chan->language);
			if (!res)
				res = cw_waitstream(chan, "");
			cw_set_callerid (chan, phone, "Privacy Manager", NULL);
			if (option_verbose > 2)
				cw_verbose (VERBOSE_PREFIX_3 "Changed Caller*ID to %s\n",phone);
			pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "SUCCESS");
		} else {
			/* Flag Failure  */
			pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "FAIL");
		}
		if (cfg) 
			cw_config_destroy(cfg);
	}

  LOCAL_USER_REMOVE (u);
  return 0;
}
Beispiel #22
0
//*********************************************************
int server(void)
{
	struct sockaddr_in monadr, sonadr;
	int fd, opt=1, taille;
	int serv_sock, client_sock;
   int nb_lu;	
	int nfds;
	fd_set rfds, afds;
	int error;
	
	char message[20]="";
	char response[20]="";
	
	MyLog("Create server ...\n");
	serv_sock = socket(PF_INET, SOCK_STREAM, 0);
	setsockopt(serv_sock, SOL_SOCKET, SO_REUSEADDR,(char *) &opt, sizeof(opt));
	
	/* init socket serveur */
	bzero( (char *)&monadr, sizeof monadr);
	monadr.sin_family = AF_INET;
	monadr.sin_port = htons(PORT);
	monadr.sin_addr.s_addr = INADDR_ANY;

	if( bind(serv_sock, (struct sockaddr *)&monadr, sizeof(monadr)) == -1 ) {
		return(1);
	}

	if( listen(serv_sock, MAXCONN) == -1 ) {
		return(1);
	}
	
	/* init sockets list*/
	nfds = getdtablesize();
	FD_ZERO(&afds);
	FD_SET(serv_sock, &afds);

	/* gestion des clients */
	while(!Terminated) 
	{
		memcpy(&rfds, &afds, sizeof(rfds));
		if( select(nfds, &rfds, 0, 0, 0) == -1 ) 
			{/* signaux non bloquants */
				if( errno == EINTR ) continue;
				return(1);
			}
		if( FD_ISSET(serv_sock, &rfds) ) /* New connection ?*/
			{
				taille = sizeof sonadr;
				if( (client_sock = accept(serv_sock, (struct sockaddr *)&sonadr,(socklen_t *)&taille)) == -1 ) 
					{
						return(1);
					}
				//syslog(LOG_NOTICE,"client connection from %s \n", inet_ntoa(sonadr.sin_addr));
				fflush(stdout);
				FD_SET(client_sock, &afds);
				fcntl(client_sock, F_SETFL, O_NONBLOCK | fcntl(client_sock, F_GETFL, 0));
			}
		/* Tester si les sockets clientes ont boug�s */
		for( fd=0; fd<nfds; fd++ ) {
			if( fd != serv_sock && FD_ISSET(fd, &rfds) ) {
				/* traiter le client */
				strcpy(message,"");
				strcpy(response,"");
				nb_lu = read(fd, message, BUFSIZE);
				//MyLog("nb_lu : %d/%d/%d\n",nb_lu,strlen(message),fd);
				if( nb_lu > 0 ) {
					message[nb_lu]='\0';
					if ((error=read_socket(message,response))!=SUCCES) {
						sprintf(response,"error :%d\n",error);
					}
					strcat(response,"\n");
					write(fd, response, strlen(response));
				} else {
					close(fd);
					FD_CLR(fd, &afds);
				}
			}
		}
	}
	return(0);
}
Beispiel #23
0
/**
 * qla2x00_fdmi_rhba() -
 * @ha: HA context
 *
 * Returns 0 on success.
 */
static int
qla2x00_fdmi_rhba(scsi_qla_host_t *ha)
{
	int rval, alen;
	uint32_t size, sn;

	ms_iocb_entry_t *ms_pkt;
	struct ct_sns_req *ct_req;
	struct ct_sns_rsp *ct_rsp;
	uint8_t *entries;
	struct ct_fdmi_hba_attr *eiter;

	/* Issue RHBA */
	/* Prepare common MS IOCB */
	/*   Request size adjusted after CT preparation */
	ms_pkt = ha->isp_ops.prep_ms_fdmi_iocb(ha, 0, RHBA_RSP_SIZE);

	/* Prepare CT request */
	ct_req = qla2x00_prep_ct_fdmi_req(&ha->ct_sns->p.req, RHBA_CMD,
	    RHBA_RSP_SIZE);
	ct_rsp = &ha->ct_sns->p.rsp;

	/* Prepare FDMI command arguments -- attribute block, attributes. */
	memcpy(ct_req->req.rhba.hba_identifier, ha->port_name, WWN_SIZE);
	ct_req->req.rhba.entry_count = __constant_cpu_to_be32(1);
	memcpy(ct_req->req.rhba.port_name, ha->port_name, WWN_SIZE);
	size = 2 * WWN_SIZE + 4 + 4;

	/* Attributes */
	ct_req->req.rhba.attrs.count =
	    __constant_cpu_to_be32(FDMI_HBA_ATTR_COUNT);
	entries = ct_req->req.rhba.hba_identifier;

	/* Nodename. */
	eiter = (struct ct_fdmi_hba_attr *) (entries + size);
	eiter->type = __constant_cpu_to_be16(FDMI_HBA_NODE_NAME);
	eiter->len = __constant_cpu_to_be16(4 + WWN_SIZE);
	memcpy(eiter->a.node_name, ha->node_name, WWN_SIZE);
	size += 4 + WWN_SIZE;

	DEBUG13(printk("%s(%ld): NODENAME=%02x%02x%02x%02x%02x%02x%02x%02x.\n",
	    __func__, ha->host_no,
	    eiter->a.node_name[0], eiter->a.node_name[1], eiter->a.node_name[2],
	    eiter->a.node_name[3], eiter->a.node_name[4], eiter->a.node_name[5],
	    eiter->a.node_name[6], eiter->a.node_name[7]));

	/* Manufacturer. */
	eiter = (struct ct_fdmi_hba_attr *) (entries + size);
	eiter->type = __constant_cpu_to_be16(FDMI_HBA_MANUFACTURER);
	strcpy(eiter->a.manufacturer, "QLogic Corporation");
	alen = strlen(eiter->a.manufacturer);
	alen += (alen & 3) ? (4 - (alen & 3)) : 4;
	eiter->len = cpu_to_be16(4 + alen);
	size += 4 + alen;

	DEBUG13(printk("%s(%ld): MANUFACTURER=%s.\n", __func__, ha->host_no,
	    eiter->a.manufacturer));

	/* Serial number. */
	eiter = (struct ct_fdmi_hba_attr *) (entries + size);
	eiter->type = __constant_cpu_to_be16(FDMI_HBA_SERIAL_NUMBER);
	sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
	sprintf(eiter->a.serial_num, "%c%05d", 'A' + sn / 100000, sn % 100000);
	alen = strlen(eiter->a.serial_num);
	alen += (alen & 3) ? (4 - (alen & 3)) : 4;
	eiter->len = cpu_to_be16(4 + alen);
	size += 4 + alen;

	DEBUG13(printk("%s(%ld): SERIALNO=%s.\n", __func__, ha->host_no,
	    eiter->a.serial_num));

	/* Model name. */
	eiter = (struct ct_fdmi_hba_attr *) (entries + size);
	eiter->type = __constant_cpu_to_be16(FDMI_HBA_MODEL);
	strcpy(eiter->a.model, ha->model_number);
	alen = strlen(eiter->a.model);
	alen += (alen & 3) ? (4 - (alen & 3)) : 4;
	eiter->len = cpu_to_be16(4 + alen);
	size += 4 + alen;

	DEBUG13(printk("%s(%ld): MODEL_NAME=%s.\n", __func__, ha->host_no,
	    eiter->a.model));

	/* Model description. */
	eiter = (struct ct_fdmi_hba_attr *) (entries + size);
	eiter->type = __constant_cpu_to_be16(FDMI_HBA_MODEL_DESCRIPTION);
	if (ha->model_desc)
		strncpy(eiter->a.model_desc, ha->model_desc, 80);
	alen = strlen(eiter->a.model_desc);
	alen += (alen & 3) ? (4 - (alen & 3)) : 4;
	eiter->len = cpu_to_be16(4 + alen);
	size += 4 + alen;

	DEBUG13(printk("%s(%ld): MODEL_DESC=%s.\n", __func__, ha->host_no,
	    eiter->a.model_desc));

	/* Hardware version. */
	eiter = (struct ct_fdmi_hba_attr *) (entries + size);
	eiter->type = __constant_cpu_to_be16(FDMI_HBA_HARDWARE_VERSION);
	strcpy(eiter->a.hw_version, ha->adapter_id);
	alen = strlen(eiter->a.hw_version);
	alen += (alen & 3) ? (4 - (alen & 3)) : 4;
	eiter->len = cpu_to_be16(4 + alen);
	size += 4 + alen;

	DEBUG13(printk("%s(%ld): HARDWAREVER=%s.\n", __func__, ha->host_no,
	    eiter->a.hw_version));

	/* Driver version. */
	eiter = (struct ct_fdmi_hba_attr *) (entries + size);
	eiter->type = __constant_cpu_to_be16(FDMI_HBA_DRIVER_VERSION);
	strcpy(eiter->a.driver_version, qla2x00_version_str);
	alen = strlen(eiter->a.driver_version);
	alen += (alen & 3) ? (4 - (alen & 3)) : 4;
	eiter->len = cpu_to_be16(4 + alen);
	size += 4 + alen;

	DEBUG13(printk("%s(%ld): DRIVERVER=%s.\n", __func__, ha->host_no,
	    eiter->a.driver_version));

	/* Option ROM version. */
	eiter = (struct ct_fdmi_hba_attr *) (entries + size);
	eiter->type = __constant_cpu_to_be16(FDMI_HBA_OPTION_ROM_VERSION);
	strcpy(eiter->a.orom_version, "0.00");
	alen = strlen(eiter->a.orom_version);
	alen += (alen & 3) ? (4 - (alen & 3)) : 4;
	eiter->len = cpu_to_be16(4 + alen);
	size += 4 + alen;

	DEBUG13(printk("%s(%ld): OPTROMVER=%s.\n", __func__, ha->host_no,
	    eiter->a.orom_version));

	/* Firmware version */
	eiter = (struct ct_fdmi_hba_attr *) (entries + size);
	eiter->type = __constant_cpu_to_be16(FDMI_HBA_FIRMWARE_VERSION);
	ha->isp_ops.fw_version_str(ha, eiter->a.fw_version);
	alen = strlen(eiter->a.fw_version);
	alen += (alen & 3) ? (4 - (alen & 3)) : 4;
	eiter->len = cpu_to_be16(4 + alen);
	size += 4 + alen;

	DEBUG13(printk("%s(%ld): FIRMWAREVER=%s.\n", __func__, ha->host_no,
	    eiter->a.fw_version));

	/* Update MS request size. */
	qla2x00_update_ms_fdmi_iocb(ha, size + 16);

	DEBUG13(printk("%s(%ld): RHBA identifier="
	    "%02x%02x%02x%02x%02x%02x%02x%02x size=%d.\n", __func__,
	    ha->host_no, ct_req->req.rhba.hba_identifier[0],
	    ct_req->req.rhba.hba_identifier[1],
	    ct_req->req.rhba.hba_identifier[2],
	    ct_req->req.rhba.hba_identifier[3],
	    ct_req->req.rhba.hba_identifier[4],
	    ct_req->req.rhba.hba_identifier[5],
	    ct_req->req.rhba.hba_identifier[6],
	    ct_req->req.rhba.hba_identifier[7], size));
	DEBUG13(qla2x00_dump_buffer(entries, size));

	/* Execute MS IOCB */
	rval = qla2x00_issue_iocb(ha, ha->ms_iocb, ha->ms_iocb_dma,
	    sizeof(ms_iocb_entry_t));
	if (rval != QLA_SUCCESS) {
		/*EMPTY*/
		DEBUG2_3(printk("scsi(%ld): RHBA issue IOCB failed (%d).\n",
		    ha->host_no, rval));
	} else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp, "RHBA") !=
	    QLA_SUCCESS) {
		rval = QLA_FUNCTION_FAILED;
		if (ct_rsp->header.reason_code == CT_REASON_CANNOT_PERFORM &&
		    ct_rsp->header.explanation_code ==
		    CT_EXPL_ALREADY_REGISTERED) {
			DEBUG2_13(printk("%s(%ld): HBA already registered.\n",
			    __func__, ha->host_no));
			rval = QLA_ALREADY_REGISTERED;
		}
	} else {
		DEBUG2(printk("scsi(%ld): RHBA exiting normally.\n",
		    ha->host_no));
	}

	return rval;
}
int main(int argc, char *argv[])
{
    SSL_CTX *ctx;
    SSL *con;
    BIO *rbio;
    BIO *wbio;
    BIO *err;
    long len;
    unsigned char *data;
    unsigned char *dataend;
    char *dummytick = "Hello World!";
    unsigned int tmplen;
    unsigned int type;
    unsigned int size;
    int testresult = 0;
    int currtest = 0;

    SSL_library_init();
    SSL_load_error_strings();

    err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);

    CRYPTO_malloc_debug_init();
    CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
    CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);

    /*
     * For each test set up an SSL_CTX and SSL and see what ClientHello gets
     * produced when we try to connect
     */
    for (; currtest < TOTAL_NUM_TESTS; currtest++) {
        testresult = 0;
        if (currtest == TEST_SET_SESSION_TICK_DATA_TLS_1_2) {
            ctx = SSL_CTX_new(TLSv1_2_method());
        } else {
            ctx = SSL_CTX_new(SSLv23_method());
        }
        con = SSL_new(ctx);

        rbio = BIO_new(BIO_s_mem());
        wbio = BIO_new(BIO_s_mem());
        SSL_set_bio(con, rbio, wbio);
        SSL_set_connect_state(con);

        if (currtest == TEST_SET_SESSION_TICK_DATA_TLS_1_2
                || currtest == TEST_SET_SESSION_TICK_DATA_VER_NEG) {
            if (!SSL_set_session_ticket_ext(con, dummytick, strlen(dummytick)))
                goto end;
        }

        if (SSL_connect(con) > 0) {
            /* This shouldn't succeed because we don't have a server! */
            goto end;
        }

        len = BIO_get_mem_data(wbio, (char **)&data);
        dataend = data + len;

        /* Skip the record header */
        data += SSL3_RT_HEADER_LENGTH;
        /* Skip the handshake message header */
        data += SSL3_HM_HEADER_LENGTH;
        /* Skip client version and random */
        data += CLIENT_VERSION_LEN + SSL3_RANDOM_SIZE;
        if (data + SESSION_ID_LEN_LEN > dataend)
            goto end;
        /* Skip session id */
        tmplen = *data;
        data += SESSION_ID_LEN_LEN + tmplen;
        if (data + CIPHERS_LEN_LEN > dataend)
            goto end;
        /* Skip ciphers */
        tmplen = ((*data) << 8) | *(data + 1);
        data += CIPHERS_LEN_LEN + tmplen;
        if (data + COMPRESSION_LEN_LEN > dataend)
            goto end;
        /* Skip compression */
        tmplen = *data;
        data += COMPRESSION_LEN_LEN + tmplen;
        if (data + EXTENSIONS_LEN_LEN > dataend)
            goto end;
        /* Extensions len */
        tmplen = ((*data) << 8) | *(data + 1);
        data += EXTENSIONS_LEN_LEN;
        if (data + tmplen > dataend)
            goto end;

        /* Loop through all extensions */
        while (tmplen > EXTENSION_TYPE_LEN + EXTENSION_SIZE_LEN) {
            type = ((*data) << 8) | *(data + 1);
            data += EXTENSION_TYPE_LEN;
            size = ((*data) << 8) | *(data + 1);
            data += EXTENSION_SIZE_LEN;
            if (data + size > dataend)
                goto end;

            if (type == TLSEXT_TYPE_session_ticket) {
                if (currtest == TEST_SET_SESSION_TICK_DATA_TLS_1_2
                        || currtest == TEST_SET_SESSION_TICK_DATA_VER_NEG) {
                    if (size == strlen(dummytick)
                            && memcmp(data, dummytick, size) == 0) {
                        /* Ticket data is as we expected */
                        testresult = 1;
                    } else {
                        printf("Received session ticket is not as expected\n");
                    }
                    break;
                }
            }

            tmplen -= EXTENSION_TYPE_LEN + EXTENSION_SIZE_LEN + size;
            data += size;
        }

 end:
        SSL_free(con);
        SSL_CTX_free(ctx);
        if (!testresult) {
            printf("ClientHello test: FAILED (Test %d)\n", currtest);
            break;
        }
    }

    ERR_free_strings();
    ERR_remove_thread_state(NULL);
    EVP_cleanup();
    CRYPTO_cleanup_all_ex_data();
    CRYPTO_mem_leaks(err);

    return testresult?0:1;
}
Beispiel #25
0
/**
 * qla2x00_rsnn_nn() - SNS Register Symbolic Node Name (RSNN_NN) of the HBA.
 * @ha: HA context
 *
 * Returns 0 on success.
 */
int
qla2x00_rsnn_nn(scsi_qla_host_t *ha)
{
	int		rval;
	uint8_t		*snn;
	uint8_t		version[20];

	ms_iocb_entry_t	*ms_pkt;
	struct ct_sns_req	*ct_req;
	struct ct_sns_rsp	*ct_rsp;

	if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
		DEBUG2(printk("scsi(%ld): RSNN_ID call unsupported on "
		    "ISP2100/ISP2200.\n", ha->host_no));
		return (QLA_SUCCESS);
	}

	/* Issue RSNN_NN */
	/* Prepare common MS IOCB */
	/*   Request size adjusted after CT preparation */
	ms_pkt = ha->isp_ops.prep_ms_iocb(ha, 0, RSNN_NN_RSP_SIZE);

	/* Prepare CT request */
	ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, RSNN_NN_CMD,
	    RSNN_NN_RSP_SIZE);
	ct_rsp = &ha->ct_sns->p.rsp;

	/* Prepare CT arguments -- node_name, symbolic node_name, size */
	memcpy(ct_req->req.rsnn_nn.node_name, ha->node_name, WWN_SIZE);

	/* Prepare the Symbolic Node Name */
	/* Board type */
	snn = ct_req->req.rsnn_nn.sym_node_name;
	strcpy(snn, ha->model_number);
	/* Firmware version */
	strcat(snn, " FW:v");
	sprintf(version, "%d.%02d.%02d", ha->fw_major_version,
	    ha->fw_minor_version, ha->fw_subminor_version);
	strcat(snn, version);
	/* Driver version */
	strcat(snn, " DVR:v");
	strcat(snn, qla2x00_version_str);

	/* Calculate SNN length */
	ct_req->req.rsnn_nn.name_len = (uint8_t)strlen(snn);

	/* Update MS IOCB request */
	ms_pkt->req_bytecount =
	    cpu_to_le32(24 + 1 + ct_req->req.rsnn_nn.name_len);
	ms_pkt->dseg_req_length = ms_pkt->req_bytecount;

	/* Execute MS IOCB */
	rval = qla2x00_issue_iocb(ha, ha->ms_iocb, ha->ms_iocb_dma,
	    sizeof(ms_iocb_entry_t));
	if (rval != QLA_SUCCESS) {
		/*EMPTY*/
		DEBUG2_3(printk("scsi(%ld): RSNN_NN issue IOCB failed (%d).\n",
		    ha->host_no, rval));
	} else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp, "RSNN_NN") !=
	    QLA_SUCCESS) {
		rval = QLA_FUNCTION_FAILED;
	} else {
		DEBUG2(printk("scsi(%ld): RSNN_NN exiting normally.\n",
		    ha->host_no));
	}

	return (rval);
}
Beispiel #26
0
static void
parse_input(int argc, char *argv[])
{
	int ch, foundeof;
	char **avj;

	foundeof = 0;

	switch (ch = getchar()) {
	case EOF:
		/* No arguments since last exec. */
		if (p == bbp) {
			waitchildren(*av, 1);
			exit(rval);
		}
		goto arg1;
	case ' ':
	case '\t':
		/* Quotes escape tabs and spaces. */
		if (insingle || indouble || zflag)
			goto addch;
		goto arg2;
	case '\0':
		if (zflag) {
			/*
			 * Increment 'count', so that nulls will be treated
			 * as end-of-line, as well as end-of-argument.  This
			 * is needed so -0 works properly with -I and -L.
			 */
			count++;
			goto arg2;
		}
		goto addch;
	case '\n':
		if (zflag)
			goto addch;
		count++;	    /* Indicate end-of-line (used by -L) */

		/* Quotes do not escape newlines. */
arg1:		if (insingle || indouble)
			errx(1, "unterminated quote");
arg2:
		foundeof = *eofstr != '\0' &&
		    strncmp(argp, eofstr, p - argp) == 0;

		/* Do not make empty args unless they are quoted */
		if ((argp != p || wasquoted) && !foundeof) {
			*p++ = '\0';
			*xp++ = argp;
			if (Iflag) {
				size_t curlen;

				if (inpline == NULL)
					curlen = 0;
				else {
					/*
					 * If this string is not zero
					 * length, append a space for
					 * separation before the next
					 * argument.
					 */
					if ((curlen = strlen(inpline)))
						strcat(inpline, " ");
				}
				curlen++;
				/*
				 * Allocate enough to hold what we will
				 * be holding in a second, and to append
				 * a space next time through, if we have
				 * to.
				 */
				inpline = realloc(inpline, curlen + 2 +
				    strlen(argp));
				if (inpline == NULL)
					errx(1, "realloc failed");
				if (curlen == 1)
					strcpy(inpline, argp);
				else
					strcat(inpline, argp);
			}
		}

		/*
		 * If max'd out on args or buffer, or reached EOF,
		 * run the command.  If xflag and max'd out on buffer
		 * but not on args, object.  Having reached the limit
		 * of input lines, as specified by -L is the same as
		 * maxing out on arguments.
		 */
		if (xp == endxp || p > ebp || ch == EOF ||
		    (Lflag <= count && xflag) || foundeof) {
			if (xflag && xp != endxp && p > ebp)
				errx(1, "insufficient space for arguments");
			if (jfound) {
				for (avj = argv; *avj; avj++)
					*xp++ = *avj;
			}
			prerun(argc, av);
			if (ch == EOF || foundeof) {
				waitchildren(*av, 1);
				exit(rval);
			}
			p = bbp;
			xp = bxp;
			count = 0;
		}
		argp = p;
		wasquoted = 0;
		break;
	case '\'':
		if (indouble || zflag)
			goto addch;
		insingle = !insingle;
		wasquoted = 1;
		break;
	case '"':
		if (insingle || zflag)
			goto addch;
		indouble = !indouble;
		wasquoted = 1;
		break;
	case '\\':
		if (zflag)
			goto addch;
		/* Backslash escapes anything, is escaped by quotes. */
		if (!insingle && !indouble && (ch = getchar()) == EOF)
			errx(1, "backslash at EOF");
		/* FALLTHROUGH */
	default:
addch:		if (p < ebp) {
			*p++ = ch;
			break;
		}

		/* If only one argument, not enough buffer space. */
		if (bxp == xp)
			errx(1, "insufficient space for argument");
		/* Didn't hit argument limit, so if xflag object. */
		if (xflag)
			errx(1, "insufficient space for arguments");

		if (jfound) {
			for (avj = argv; *avj; avj++)
				*xp++ = *avj;
		}
		prerun(argc, av);
		xp = bxp;
		cnt = ebp - argp;
		memcpy(bbp, argp, (size_t)cnt);
		p = (argp = bbp) + cnt;
		*p++ = ch;
		break;
	}
}
Beispiel #27
0
//*************************************************************************
int main()
{
  SQLHENV env;
  SQLHDBC dbc;
  SQLHSTMT stmt;
  SQLRETURN ret;
  SQLCHAR outstr[1024];
  SQLSMALLINT outstrlen;
  
  // Aloocate an environment handle
  ret=SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&env);
  checkrc(ret,__LINE__);
  
   //we need odbc3 support
   SQLSetEnvAttr(env,SQL_ATTR_ODBC_VERSION,(void*)SQL_OV_ODBC3,0);
   
  //ALLOCATE A Connection handle
  ret = SQLAllocHandle(SQL_HANDLE_DBC,env,&dbc);
  checkrc(ret,__LINE__);
    
  // connect to the Data source
   ret = SQLConnect (dbc,
                   (SQLCHAR *) "DSN=mycsql;MODE=GATEWAY;SERVER=127.0.0.1;PORT=5678;", (SQLSMALLINT) strlen ("DSN=mycsql;MODE=GATEWAY;SERVER=127.0.0.1;PORT=5678;"),
                   (SQLCHAR *) "root",
                   (SQLSMALLINT) strlen ("root"),
                   (SQLCHAR *) "manager",
                   (SQLSMALLINT) strlen (""));


  if(SQL_SUCCEEDED(ret))
  {
     printf("\nConnected to the Data Source..\n");
     
  }  
     
  
   else
   {
        printf("error in connection\n");
        ret = SQLFreeHandle(SQL_HANDLE_DBC,dbc);
        checkrc(ret,__LINE__);

        ret = SQLFreeHandle(SQL_HANDLE_DBC,env);
        checkrc(ret,__LINE__);
        return 1;
   }
   //*********************************************************************
   //again call to driver connect
    
   ret = SQLConnect (dbc,
                   (SQLCHAR *) "DSN=mycsql;MODE=GATEWAY;SERVER=127.0.0.1;PORT=5678;", (SQLSMALLINT) strlen ("DSN=mycsql;MODE=GATEWAY;SERVER=127.0.0.1;PORT=5678;"),
                   (SQLCHAR *) "root",
                   (SQLSMALLINT) strlen ("root"),
                   (SQLCHAR *) "manager",
                   (SQLSMALLINT) strlen (""));

   int rettype = ret; 

  if(SQL_SUCCEEDED(ret))
  {
     printf("\nConnected to the Data Source..\n");
     
             
   }

  
   else
   {
        printf("Connection name  in use\n");
    }

   //**********************************************************************
   ret = SQLDisconnect(dbc);
   checkrc(ret,__LINE__);
   
   ret = SQLFreeHandle(SQL_HANDLE_DBC,dbc);
   checkrc(ret,__LINE__);
   
   ret = SQLFreeHandle(SQL_HANDLE_ENV,env);
   checkrc(ret,__LINE__);
   if(rettype ==0)return 1;
   return 0;
}         
Beispiel #28
0
int
main(int argc, char *argv[])
{
	long arg_max;
	int ch, Jflag, nargs, nflag, nline;
	size_t linelen;
	char *endptr;

	inpline = replstr = NULL;
	ep = environ;
	eofstr = "";
	Jflag = nflag = 0;

	(void)setlocale(LC_ALL, "");

	/*
	 * POSIX.2 limits the exec line length to ARG_MAX - 2K.  Running that
	 * caused some E2BIG errors, so it was changed to ARG_MAX - 4K.  Given
	 * that the smallest argument is 2 bytes in length, this means that
	 * the number of arguments is limited to:
	 *
	 *	 (ARG_MAX - 4K - LENGTH(utility + arguments)) / 2.
	 *
	 * We arbitrarily limit the number of arguments to 5000.  This is
	 * allowed by POSIX.2 as long as the resulting minimum exec line is
	 * at least LINE_MAX.  Realloc'ing as necessary is possible, but
	 * probably not worthwhile.
	 */
	nargs = 5000;
	if ((arg_max = sysconf(_SC_ARG_MAX)) == -1)
		errx(1, "sysconf(_SC_ARG_MAX) failed");
	nline = arg_max - 4 * 1024;
	while (*ep != NULL) {
		/* 1 byte for each '\0' */
		nline -= strlen(*ep++) + 1 + sizeof(*ep);
	}
	maxprocs = 1;
	while ((ch = getopt(argc, argv, "0E:I:J:L:n:oP:pR:S:s:rtx")) != -1)
		switch (ch) {
		case 'E':
			eofstr = optarg;
			break;
		case 'I':
			Jflag = 0;
			Iflag = 1;
			Lflag = 1;
			replstr = optarg;
			break;
		case 'J':
			Iflag = 0;
			Jflag = 1;
			replstr = optarg;
			break;
		case 'L':
			Lflag = atoi(optarg);
			break;
		case 'n':
			nflag = 1;
			if ((nargs = atoi(optarg)) <= 0)
				errx(1, "illegal argument count");
			break;
		case 'o':
			oflag = 1;
			break;
		case 'P':
			if ((maxprocs = atoi(optarg)) <= 0)
				errx(1, "max. processes must be >0");
			break;
		case 'p':
			pflag = 1;
			break;
		case 'R':
			Rflag = strtol(optarg, &endptr, 10);
			if (*endptr != '\0')
				errx(1, "replacements must be a number");
			break;
		case 'r':
			/* GNU compatibility */
			break;
		case 'S':
			Sflag = strtoul(optarg, &endptr, 10);
			if (*endptr != '\0')
				errx(1, "replsize must be a number");
			break;
		case 's':
			nline = atoi(optarg);
			break;
		case 't':
			tflag = 1;
			break;
		case 'x':
			xflag = 1;
			break;
		case '0':
			zflag = 1;
			break;
		case '?':
		default:
			usage();
	}
	argc -= optind;
	argv += optind;

	if (!Iflag && Rflag)
		usage();
	if (!Iflag && Sflag)
		usage();
	if (Iflag && !Rflag)
		Rflag = 5;
	if (Iflag && !Sflag)
		Sflag = 255;
	if (xflag && !nflag)
		usage();
	if (Iflag || Lflag)
		xflag = 1;
	if (replstr != NULL && *replstr == '\0')
		errx(1, "replstr may not be empty");

	pids_init();

	/*
	 * Allocate pointers for the utility name, the utility arguments,
	 * the maximum arguments to be read from stdin and the trailing
	 * NULL.
	 */
	linelen = 1 + argc + nargs + 1;
	if ((av = bxp = malloc(linelen * sizeof(char **))) == NULL)
		errx(1, "malloc failed");

	/*
	 * Use the user's name for the utility as argv[0], just like the
	 * shell.  Echo is the default.  Set up pointers for the user's
	 * arguments.
	 */
	if (*argv == NULL)
		cnt = strlen(*bxp++ = echo);
	else {
		do {
			if (Jflag && strcmp(*argv, replstr) == 0) {
				char **avj;
				jfound = 1;
				argv++;
				for (avj = argv; *avj; avj++)
					cnt += strlen(*avj) + 1;
				break;
			}
			cnt += strlen(*bxp++ = *argv) + 1;
		} while (*++argv != NULL);
	}

	/*
	 * Set up begin/end/traversing pointers into the array.  The -n
	 * count doesn't include the trailing NULL pointer, so the malloc
	 * added in an extra slot.
	 */
	endxp = (xp = bxp) + nargs;

	/*
	 * Allocate buffer space for the arguments read from stdin and the
	 * trailing NULL.  Buffer space is defined as the default or specified
	 * space, minus the length of the utility name and arguments.  Set up
	 * begin/end/traversing pointers into the array.  The -s count does
	 * include the trailing NULL, so the malloc didn't add in an extra
	 * slot.
	 */
	nline -= cnt;
	if (nline <= 0)
		errx(1, "insufficient space for command");

	if ((bbp = malloc((size_t)(nline + 1))) == NULL)
		errx(1, "malloc failed");
	ebp = (argp = p = bbp) + nline - 1;
	for (;;)
		parse_input(argc, argv);
}
int
main( int argc, char *argv[] )
{
	int		rc;
	LDAP		*ld = NULL;
	char		*matcheddn = NULL, *text = NULL, **refs = NULL;
	char		*retoid = NULL;
	struct berval	*retdata = NULL;
	int		id, code = 0;
	LDAPMessage	*res;
	LDAPControl	**ctrls = NULL;

	tool_init( TOOL_WHOAMI );
	prog = lutil_progname( "ldapwhoami", argc, argv );

	/* LDAPv3 only */
	protocol = LDAP_VERSION3;

	tool_args( argc, argv );

	if( argc - optind > 0 ) {
		usage();
	}

	if ( pw_file || want_bindpw ) {
		if ( pw_file ) {
			rc = lutil_get_filed_password( pw_file, &passwd );
			if( rc ) return EXIT_FAILURE;
		} else {
			passwd.bv_val = getpassphrase( _("Enter LDAP Password: "******"ldap_whoami", rc, NULL, NULL, NULL, NULL );
		rc = EXIT_FAILURE;
		goto skip;
	}

	for ( ; ; ) {
		struct timeval	tv;

		if ( tool_check_abandon( ld, id ) ) {
			return LDAP_CANCELLED;
		}

		tv.tv_sec = 0;
		tv.tv_usec = 100000;

		rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, &tv, &res );
		if ( rc < 0 ) {
			tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL );
			return rc;
		}

		if ( rc != 0 ) {
			break;
		}
	}

	rc = ldap_parse_result( ld, res,
		&code, &matcheddn, &text, &refs, &ctrls, 0 );

	if ( rc == LDAP_SUCCESS ) {
		rc = code;
	}

	if ( rc != LDAP_SUCCESS ) {
		tool_perror( "ldap_parse_result", rc, NULL, matcheddn, text, refs );
		rc = EXIT_FAILURE;
		goto skip;
	}

	rc = ldap_parse_extended_result( ld, res, &retoid, &retdata, 1 );

	if( rc != LDAP_SUCCESS ) {
		tool_perror( "ldap_parse_extended_result", rc, NULL, NULL, NULL, NULL );
		rc = EXIT_FAILURE;
		goto skip;
	}

	if( retdata != NULL ) {
		if( retdata->bv_len == 0 ) {
			printf(_("anonymous\n") );
		} else {
			printf("%s\n", retdata->bv_val );
		}
	}

skip:
	if ( verbose || ( code != LDAP_SUCCESS ) ||
		matcheddn || text || refs || ctrls )
	{
		printf( _("Result: %s (%d)\n"), ldap_err2string( code ), code );

		if( text && *text ) {
			printf( _("Additional info: %s\n"), text );
		}

		if( matcheddn && *matcheddn ) {
			printf( _("Matched DN: %s\n"), matcheddn );
		}

		if( refs ) {
			int i;
			for( i=0; refs[i]; i++ ) {
				printf(_("Referral: %s\n"), refs[i] );
			}
		}

		if (ctrls) {
			tool_print_ctrls( ld, ctrls );
			ldap_controls_free( ctrls );
		}
	}

	ber_memfree( text );
	ber_memfree( matcheddn );
	ber_memvfree( (void **) refs );
	ber_memfree( retoid );
	ber_bvfree( retdata );

	/* disconnect from server */
	tool_unbind( ld );
	tool_destroy();

	return code == LDAP_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE;
}
/**************************************************************************************************
 * @fn      HalGpioSrdyInit
 *
 *
 * @brief   Initialise SRDY GPIO.
 *
 * @param   gpioCfg - SRDY pin configuration parameters
 *
 * @return  STATUS
 **************************************************************************************************/
int HalGpioSrdyInit(halGpioCfg_t *gpioCfg)
{
	memcpy(srdyGpioCfg.gpio.value,
			gpioCfg->gpio.value,
			strlen(gpioCfg->gpio.value));
	if (__BIG_DEBUG_ACTIVE == TRUE)
	{
		time_printf("[%s] srdyGpioCfg.gpio.value = '%s'\n", __FUNCTION__, srdyGpioCfg.gpio.value);
	}
	memcpy(srdyGpioCfg.gpio.direction,
			gpioCfg->gpio.direction,
			strlen(gpioCfg->gpio.direction));
	if (__BIG_DEBUG_ACTIVE == TRUE)
	{
		time_printf("[%s] srdyGpioCfg.gpio.direction = '%s'\n", __FUNCTION__, srdyGpioCfg.gpio.direction);
	}

	srdyGpioCfg.gpio.active_high_low = gpioCfg->gpio.active_high_low;

	memcpy(srdyGpioCfg.gpio.edge,
			gpioCfg->gpio.edge,
			strlen(gpioCfg->gpio.edge));
	if (__BIG_DEBUG_ACTIVE == TRUE)
	{
		time_printf("[%s] srdyGpioCfg.gpio.edge = '%s'\n", __FUNCTION__, srdyGpioCfg.gpio.edge);
	}

	if ( ( gpioCfg->levelshifter.value) &&
			( gpioCfg->levelshifter.active_high_low) &&
			( gpioCfg->levelshifter.direction))
	{
		memcpy(srdyGpioCfg.levelshifter.value,
				gpioCfg->levelshifter.value,
				strlen(gpioCfg->levelshifter.value));
		if (__BIG_DEBUG_ACTIVE == TRUE)
		{
			time_printf("[%s] srdyGpioCfg.levelshifter.value = '%s'\n", __FUNCTION__, srdyGpioCfg.levelshifter.value);
		}
		memcpy(srdyGpioCfg.levelshifter.direction,
				gpioCfg->levelshifter.direction,
				strlen(gpioCfg->levelshifter.direction));
		srdyGpioCfg.levelshifter.active_high_low = gpioCfg->levelshifter.active_high_low;
		if (__BIG_DEBUG_ACTIVE == TRUE)
		{
			time_printf("[%s] srdyGpioCfg.levelshifter.direction = '%s'\n", __FUNCTION__, srdyGpioCfg.levelshifter.direction);
		}

		//open the GPIO DIR file for the level shifter direction signal
		gpioSrdyFd = open(srdyGpioCfg.levelshifter.direction, O_RDWR);
		if(gpioSrdyFd == 0)
		{
			perror(srdyGpioCfg.levelshifter.direction);
			if (__BIG_DEBUG_ACTIVE == TRUE)
			{
				time_printf("[%s] %s open failed\n", __FUNCTION__, srdyGpioCfg.levelshifter.direction);
			}
			npi_ipc_errno = NPI_LNX_ERROR_HAL_GPIO_SRDY_LVLSHFT_DIR_OPEN;
			return NPI_LNX_FAILURE;
		}

		//Set the direction of the GPIO to output
		if (ERROR == write(gpioSrdyFd, "out", 3))
		{
			perror(srdyGpioCfg.levelshifter.direction);
			if (__BIG_DEBUG_ACTIVE == TRUE)
			{
				time_printf("[%s] can't write in %s \n", __FUNCTION__, srdyGpioCfg.levelshifter.direction);
			}
			npi_ipc_errno = NPI_LNX_ERROR_HAL_GPIO_SRDY_LVLSHFT_DIR_WRITE;
			return NPI_LNX_FAILURE;
		}
		//close the DIR file
		close(gpioSrdyFd);

		//open the GPIO VALUE file for the level shifter direction signal
		gpioSrdyFd = open(srdyGpioCfg.levelshifter.value, O_RDWR);
		if(gpioSrdyFd == 0)
		{
			perror(srdyGpioCfg.levelshifter.value);
			if (__BIG_DEBUG_ACTIVE == TRUE)
			{
				time_printf("[%s] %s open failed\n", __FUNCTION__, srdyGpioCfg.levelshifter.value);
			}
			npi_ipc_errno = NPI_LNX_ERROR_HAL_GPIO_SRDY_LVLSHFT_VAL_OPEN;
			return NPI_LNX_FAILURE;
		}

		//Set the value of the GPIO to 0 (level shifter direction from CC2531 to Host)

		if (ERROR == write(gpioSrdyFd, "0", 1))
		{
			perror(srdyGpioCfg.levelshifter.value);
			if (__BIG_DEBUG_ACTIVE == TRUE)
			{
				time_printf("[%s] can't write in %s\n", __FUNCTION__, srdyGpioCfg.levelshifter.value);
			}
			npi_ipc_errno = NPI_LNX_ERROR_HAL_GPIO_SRDY_LVLSHFT_VAL_WRITE;
			return NPI_LNX_FAILURE;
		}
		//close the DIR file
		close(gpioSrdyFd);
	}
	else
	{
		if (__BIG_DEBUG_ACTIVE == TRUE)
		{
			LOG_ALWAYS("[%s] Wrong Configuration File, one of the  following Key value are missing for SRDY.Level Shifter definition: '\n", __FUNCTION__);
			LOG_ALWAYS("value: \t\t%s\n", srdyGpioCfg.gpio.value);
			LOG_ALWAYS("direction: \t%s\n", srdyGpioCfg.gpio.direction);
			LOG_ALWAYS("active_high_low: %d\n", srdyGpioCfg.gpio.active_high_low);
			LOG_ALWAYS("Level Shifter is optional, please check if you need it or not before continuing...\n");
		}
	}
	//TODO: Lock the shift register GPIO.

	//open the SRDY GPIO DIR file
	gpioSrdyFd = open(srdyGpioCfg.gpio.direction, O_RDWR);
	if(gpioSrdyFd == 0)
	{
		perror(srdyGpioCfg.gpio.direction);
		if (__BIG_DEBUG_ACTIVE == TRUE)
		{
			time_printf("[%s] %s open failed\n", __FUNCTION__, srdyGpioCfg.gpio.direction);
		}
		npi_ipc_errno = NPI_LNX_ERROR_HAL_GPIO_SRDY_GPIO_DIR_OPEN;
		return NPI_LNX_FAILURE;
	}

	//Set SRDY GPIO as input
	if(ERROR == write(gpioSrdyFd, "in", 2))
	{
		perror(srdyGpioCfg.levelshifter.direction);
		if (__BIG_DEBUG_ACTIVE == TRUE)
		{
			time_printf("[%s] can't write in %s\n", __FUNCTION__, srdyGpioCfg.gpio.direction);
		}
		npi_ipc_errno = NPI_LNX_ERROR_HAL_GPIO_SRDY_GPIO_DIR_WRITE;
		return NPI_LNX_FAILURE;
	}
	//close SRDY DIR file
	close(gpioSrdyFd);

	//open the SRDY GPIO Edge file
	gpioSrdyFd = open(srdyGpioCfg.gpio.edge, O_RDWR);
	if(gpioSrdyFd == 0)
	{
		perror(srdyGpioCfg.gpio.edge);
		if (__BIG_DEBUG_ACTIVE == TRUE)
		{
			time_printf("[%s] %s open failed\n", __FUNCTION__, srdyGpioCfg.gpio.edge);
		}
		npi_ipc_errno = NPI_LNX_ERROR_HAL_GPIO_SRDY_GPIO_EDGE_OPEN;
		return NPI_LNX_FAILURE;
	}

	//Set SRDY GPIO edge detection for both rising and falling
	if(ERROR == write(gpioSrdyFd, "both", 4))
	{
		perror(srdyGpioCfg.levelshifter.edge);
		if (__BIG_DEBUG_ACTIVE == TRUE)
		{
			time_printf("[%s] can't write in %s\n", __FUNCTION__, srdyGpioCfg.gpio.edge);
		}
		npi_ipc_errno = NPI_LNX_ERROR_HAL_GPIO_SRDY_GPIO_EDGE_WRITE;
		return NPI_LNX_FAILURE;
	}
	//close SRDY edge file
	close(gpioSrdyFd);

	//open the SRDY GPIO VALUE file so it can be written to using the file handle later
	gpioSrdyFd = open(srdyGpioCfg.gpio.value, O_RDWR| O_NONBLOCK);
	if(gpioSrdyFd == 0)
	{
		perror(srdyGpioCfg.gpio.value);
		if (__BIG_DEBUG_ACTIVE == TRUE)
		{
			time_printf("[%s] %s open failed\n", __FUNCTION__, srdyGpioCfg.gpio.value);
		}
		npi_ipc_errno = NPI_LNX_ERROR_HAL_GPIO_SRDY_GPIO_VAL_OPEN;
		return NPI_LNX_FAILURE;
	}

	return(gpioSrdyFd);
}