示例#1
0
void test_MultipleEntryHandling() {
	char HOST1[] = "192.0.2.3";
	char REASON1[] = "DENY";

	char HOST2[] = "192.0.5.5";
	char REASON2[] = "RATE";

	char HOST3[] = "192.0.10.1";
	char REASON3[] = "DENY";

	add_entry(HOST1, REASON1);
	add_entry(HOST2, REASON2);
	add_entry(HOST3, REASON3);

	struct kod_entry* result;

	TEST_ASSERT_EQUAL(1, search_entry(HOST1, &result));
	TEST_ASSERT_EQUAL_STRING(HOST1, result->hostname);
	TEST_ASSERT_EQUAL_STRING(REASON1, result->type);

	TEST_ASSERT_EQUAL(1, search_entry(HOST2, &result));
	TEST_ASSERT_EQUAL_STRING(HOST2, result->hostname);
	TEST_ASSERT_EQUAL_STRING(REASON2, result->type);

	TEST_ASSERT_EQUAL(1, search_entry(HOST3, &result));
	TEST_ASSERT_EQUAL_STRING(HOST3, result->hostname);
	TEST_ASSERT_EQUAL_STRING(REASON3, result->type);

	free(result);
}
示例#2
0
void
test_AddDuplicate(void) {
	const char HOST[] = "192.0.2.3";
	const char REASON1[] = "RATE";
	const char REASON2[] = "DENY";

	add_entry(HOST, REASON1);
	struct kod_entry* result1;
	TEST_ASSERT_EQUAL(1, search_entry(HOST, &result1));

	/* 
	 * Sleeps for two seconds since we want to ensure that
	 * the timestamp is updated to a new value.
	 */
	sleep(2);

	add_entry(HOST, REASON2);
	struct kod_entry* result2;
	TEST_ASSERT_EQUAL(1, search_entry(HOST, &result2));

	TEST_ASSERT_FALSE(result1->timestamp == result2->timestamp);

	free(result1);
	free(result2);
}
示例#3
0
int
find_ino(const char *path)
		/* Returns inode number Or -1 on error */
{
	char 		m_path[strlen(path)+1];   /* mutable string for path2tokens() */
	int 		tokenc;
	char 	    **tokens;
	char		**tokenp;				  /* for travese tokens */
	char		*token;
	inode_t  	*inodep;
	dirent_t 	dir;
	entry_t  	ent;
	// indirect_t 	indirect;
	insert_t 	insert;

	strcpy(m_path, path);

	if ((strcmp(path, "/") == 0) ||
		(strcmp(path, "///") == 0))
		return 1;

	inodep = retrieve_root();
	tokenc = path2tokens(m_path, &tokens);
	if (tokenc < 0)
		return -1;
	tokenp = tokens;

	int i;
	int type = S_IFDIR; /* starts from root dir */
	for (i=0; 
		( i<(tokenc-1) && I_ISDIR(type) ); 
		i++, tokenp++)
	{
		token = *tokenp;
		if ( ( insert=search_entry(token, inodep, &dir, &ent) ) < 0 )
			return -1;
		if (!(inodep = retrieve_inode(ent.et_ino)))
			return -1;
		type = inodep->i_type;
		if (ent.et_ino != 1)
			free(inodep);
	}
	if (i != (tokenc-1))
		return -1;
	token = *tokenp;
	if ( (insert=search_entry(token, inodep, &dir, &ent)) < 0 )
		return -1;

	for (int i=0; i<tokenc; i++){		/* free tokens */
		free(*(tokens+i));
	}
	free(tokens);
	return ent.et_ino;
}
示例#4
0
/*
 * _config_get:
 * @cfg: Configuration file identifier.
 * @section: Section to gather the entry from.
 * @entry: Entry to gather the value from.
 * @line: Pointer to a line number we should start the search at.
 *
 * Gets value associated with @entry, in the optionaly specified
 * @section, in the configuration file represented by the @cfg
 * abstracted data type. If @entry is found, update @line to reflect
 * the line it was found at.
 *
 * If the value gathered starts with a '$', which means it is
 * a variable, the variable is automatically looked up.
 *
 * If both @entry and @section are NULL, config_get() will try to
 * look up another entry of the same name (and in the same section if
 * section was previously set) as the one previously searched.
 *
 * Returns: The entry value on success, an empty string if the entry
 * exists but has no value, NULL on error.
 */
char *_config_get(config_t *cfg, const char *section, const char *entry, unsigned int *line)
{
        int ret;
        const char *var;
        char *tmp, *value;
        unsigned int index;

        if ( ! cfg->content )
                return NULL;

        index = (*line) ? *line - 1 : 0;

        ret = search_entry(cfg, section, entry, &index, &tmp, &value);
        if ( ret < 0 )
                return NULL;

        *line = index + 1;
        free(tmp);

        /*
         * The requested value point to a variable.
         */
        if ( value[0] == '$' ) {
                var = get_variable_content(cfg, value + 1);
                if ( var ) {
                        free(value);
                        value = strdup(var);
                }
        }

        return value;
}
示例#5
0
int _config_del(config_t *cfg, const char *section, const char *entry)
{
        int start;
        char *tmp, *value;
        unsigned int line = 0, end;

        if ( ! entry ) {
                start = search_section(cfg, section, 0);
                if ( start < 0 )
                        return start;

                for ( end = (unsigned int) start + 1; end < cfg->elements && ! is_section(cfg->content[end]); end++ );

                while ( start >= 2 && ! *cfg->content[start - 1] && ! *cfg->content[start - 2] )
                        start--;

        } else {
                start = search_entry(cfg, section, entry, &line, &tmp, &value);
                if ( start < 0 )
                        return start;

                free_val(&tmp);
                free_val(&value);

                end = (unsigned int) start + 1;
        }

        cfg->need_sync = TRUE;
        return op_delete_line(cfg, start, end);
}
示例#6
0
int main() {
 if(count < 3)
  {
  count++; 
  add_entry("Ankit Request","Monday","Cache",true);
  }
 if(count < 3)
  {
   count++;
   add_entry("Gupta Request","Friday","Namaste.txt",true);
  }
    
 cacheEntry * tmp = search_entry("Ankit Request");
 printf("tmp file is %s\n",tmp->filename);
  if(count < 3)
  {
  printf("Added\n");
  count++;
  add_entry("Atish Request","12-12-12","atish.txt",false);
  }
  print_cacheEntry();
  if(count < 4)
  {
   count++;add_entry("amruth Request","11-11-11","atish.txt",false);
  }
  printf("***********NOW DELETE *********************");
  delete_entry();
 print_cacheEntry();  
 printf("****************NOW DELETE AND ADD************************"); 
 updateremoveaddtoHead("Gupta Request","TIME X",false); 
print_cacheEntry();
    return 0;

}
示例#7
0
/* SYNOPSYS :
 *    int syr1_fopen_read(char *name, SYR1_FILE *file) {
 * DESCRIPTION :
 *   Ce sous-programme gère l'ouverture d'un fichier logique en mode lecture.
 * PARAMETRES :
 *   name : chaîne de caratère contenant le nom externe du fichier à ouvrir
 *   file : pointeur sur un Bloc Control Fichier (File Control Bloc)
 * RESULTAT :
 *  0 : ouverture réussie
 *   -1 : autre erreur
 */
int syr1_fopen_read(char *name, SYR1_FILE* file) {
    //Get the copy of the file descriptor from the catalog
    int result_copy = search_entry(name, &(file->descriptor));

    //If it's ok
    if (result_copy == 0) {

        //Create the buffer (a bloc is 512 Bytes long)
        file->buffer = malloc(IO_BLOCK_SIZE);

        //If there was an error during the malloc
        if (file->buffer != NULL) {

            //Put the first bloc into the buffer
            int result_read_block = read_block(file->descriptor.alloc[0], file->buffer);

            //If ok
            if (result_read_block == 1) {
                //Put the read mode
                strcpy(file->mode, "r");

                //The other parameters are initialized to 0
                file->current_block = 0;
                file->file_offset = 0;
                file->block_offset = 0;

                //Everything's ok here
                return 0;
            }
        }
    }

    //If errors
    return -1;
}
示例#8
0
文件: file_read.c 项目: Tha1n/ESIR2
/* SYNOPSYS :
 * 	  int sys2_fopen_read(char *name, SYS2_FILE *file) {
 * DESCRIPTION :
 *   Ce sous-programme gère l'ouverture d'un fichier logique en mode lecture.
 * PARAMETRES :
 *   name : chaîne de caratère contenant le nom externe du fichier à ouvrir
 *   file : pointeur sur un Bloc Control Fichier (File Control Bloc)
 * RESULTAT :
 *    0 : ouverture réussie
 *   -1 : autre erreur
 */
int sys2_fopen_read(char *name, SYS2_FILE* file) {
  //Search the file
  int erreurSearch = search_entry(name, &file->descriptor);
  if(erreurSearch != 0)
  {
    printf("sys2_fopen_read ERROR: search_entry error");
    return -1;
  }
  file->mode[0] = 'r';
  //Initialize the BCF
  file->current_block = 0;
  file->file_offset = 0;
  file->block_offset = 0;
  //Initialize the buffer
  file->buffer = malloc(sizeof(char)*IO_BLOCK_SIZE);
  if(file->buffer == NULL)
  {
    printf("sys2_fopen_read ERROR: NULL buffer");
    return -1;
  }
  //Read one block
  int errorReadBlock = read_block(file->descriptor.alloc[0], file->buffer);
  if(errorReadBlock != 1)
  {
    printf("sys2_fopen_read ERROR: read_block error");
    return -1;
  }
  return 0;
}
示例#9
0
void
test_HandleKodDemobilize(void)
{
	static const char *	HOSTNAME = "192.0.2.1";
	static const char *	REASON = "DENY";
	struct pkt		rpkt;
	sockaddr_u		host;
	int			rpktl;
	struct kod_entry *	entry;

	rpktl = KOD_DEMOBILIZE;
	ZERO(rpkt);
	memcpy(&rpkt.refid, REASON, 4);
	ZERO(host);
	host.sa4.sin_family = AF_INET;
	host.sa4.sin_addr.s_addr = inet_addr(HOSTNAME);

	/* Test that the KOD-entry is added to the database. */
	kod_init_kod_db("/dev/null", TRUE);

	TEST_ASSERT_EQUAL(1, handle_pkt(rpktl, &rpkt, &host, HOSTNAME));

	TEST_ASSERT_EQUAL(1, search_entry(HOSTNAME, &entry));
	TEST_ASSERT_EQUAL_MEMORY(REASON, entry->type, 4);
}
示例#10
0
文件: kodFile.cpp 项目: benjit89/ntp
TEST_F(kodFileTest, ReadCorrectFile) {
	kod_init_kod_db(CreatePath("kod-test-correct", INPUT_DIR).c_str(), TRUE);
	
	EXPECT_EQ(2, kod_db_cnt);

	kod_entry* res;

	ASSERT_EQ(1, search_entry("192.0.2.5", &res));
	EXPECT_STREQ("DENY", res->type);
	EXPECT_STREQ("192.0.2.5", res->hostname);
	EXPECT_EQ(0x12345678, res->timestamp);

	ASSERT_EQ(1, search_entry("192.0.2.100", &res));
	EXPECT_STREQ("RSTR", res->type);
	EXPECT_STREQ("192.0.2.100", res->hostname);
	EXPECT_EQ(0xfff, res->timestamp);
}
示例#11
0
void
test_ReadCorrectFile(void) {
	kod_init_kod_db(CreatePath("kod-test-correct", INPUT_DIR), TRUE);
	
	TEST_ASSERT_EQUAL(2, kod_db_cnt);

	struct kod_entry* res;

	TEST_ASSERT_EQUAL(1, search_entry("192.0.2.5", &res));
	TEST_ASSERT_EQUAL_STRING("DENY", res->type);
	TEST_ASSERT_EQUAL_STRING("192.0.2.5", res->hostname);
	TEST_ASSERT_EQUAL(0x12345678, res->timestamp);

	TEST_ASSERT_EQUAL(1, search_entry("192.0.2.100", &res));
	TEST_ASSERT_EQUAL_STRING("RSTR", res->type);
	TEST_ASSERT_EQUAL_STRING("192.0.2.100", res->hostname);
	TEST_ASSERT_EQUAL(0xfff, res->timestamp);
}
示例#12
0
 void ARM_TLB::invalidate_single_entry(word_t virt_addr)
 {
   TLBEntry<word_t> **tlb_entry;
   tlb_entry = search_entry(virt_addr);
   if (tlb_entry!=NULL) {
     delete *tlb_entry;
     *tlb_entry = NULL;
   }
   if(next)
     next->invalidate_single_entry(virt_addr);
 }
示例#13
0
void test_SingleEntryHandling() {
	char HOST[] = "192.0.2.5";
	char REASON[] = "DENY";

	add_entry(HOST, REASON);

	struct kod_entry* result;

	TEST_ASSERT_EQUAL(1, search_entry(HOST, &result));
	TEST_ASSERT_EQUAL_STRING(HOST, result->hostname);
	TEST_ASSERT_EQUAL_STRING(REASON, result->type);
}
示例#14
0
void test_NoMatchInSearch() {
	char HOST_ADD[] = "192.0.2.6";
	char HOST_NOTADD[] = "192.0.6.1";
	char REASON[] = "DENY";

	add_entry(HOST_ADD, REASON);

	struct kod_entry* result;

	TEST_ASSERT_EQUAL(0, search_entry(HOST_NOTADD, &result));
	TEST_ASSERT_TRUE(result == NULL);
}
示例#15
0
文件: kodFile.cpp 项目: benjit89/ntp
TEST_F(kodFileTest, ReadFileWithBlankLines) {
	kod_init_kod_db(CreatePath("kod-test-blanks", INPUT_DIR).c_str(), TRUE);

	EXPECT_EQ(3, kod_db_cnt);

	kod_entry* res;

	ASSERT_EQ(1, search_entry("192.0.2.5", &res));
	EXPECT_STREQ("DENY", res->type);
	EXPECT_STREQ("192.0.2.5", res->hostname);
	EXPECT_EQ(0x12345678, res->timestamp);

	ASSERT_EQ(1, search_entry("192.0.2.100", &res));
	EXPECT_STREQ("RSTR", res->type);
	EXPECT_STREQ("192.0.2.100", res->hostname);
	EXPECT_EQ(0xfff, res->timestamp);

	ASSERT_EQ(1, search_entry("example.com", &res));
	EXPECT_STREQ("DENY", res->type);
	EXPECT_STREQ("example.com", res->hostname);
	EXPECT_EQ(0xabcd, res->timestamp);
}
示例#16
0
void test_DeleteEntry() {
	char HOST1[] = "192.0.2.1";
	char HOST2[] = "192.0.2.2";
	char HOST3[] = "192.0.2.3";
	char REASON[] = "DENY";

	add_entry(HOST1, REASON);
	add_entry(HOST2, REASON);
	add_entry(HOST3, REASON);

	struct kod_entry* result;
	
	TEST_ASSERT_EQUAL(1, search_entry(HOST2, &result));
	free(result);

	delete_entry(HOST2, REASON);

	TEST_ASSERT_EQUAL(0, search_entry(HOST2, &result));

	// Ensure that the other entry is still there.
	TEST_ASSERT_EQUAL(1, search_entry(HOST1, &result));
	free(result);
}
示例#17
0
void
test_ReadFileWithBlankLines(void) {
	kod_init_kod_db(CreatePath("kod-test-blanks", INPUT_DIR), TRUE);

	TEST_ASSERT_EQUAL(3, kod_db_cnt);

	struct kod_entry* res;

	TEST_ASSERT_EQUAL(1, search_entry("192.0.2.5", &res));
	TEST_ASSERT_EQUAL_STRING("DENY", res->type);
	TEST_ASSERT_EQUAL_STRING("192.0.2.5", res->hostname);
	TEST_ASSERT_EQUAL(0x12345678, res->timestamp);

	TEST_ASSERT_EQUAL(1, search_entry("192.0.2.100", &res));
	TEST_ASSERT_EQUAL_STRING("RSTR", res->type);
	TEST_ASSERT_EQUAL_STRING("192.0.2.100", res->hostname);
	TEST_ASSERT_EQUAL(0xfff, res->timestamp);

	TEST_ASSERT_EQUAL(1, search_entry("example.com", &res));
	TEST_ASSERT_EQUAL_STRING("DENY", res->type);
	TEST_ASSERT_EQUAL_STRING("example.com", res->hostname);
	TEST_ASSERT_EQUAL(0xabcd, res->timestamp);
}
示例#18
0
static int new_entry_line(config_t *cfg, const char *entry, const char *val, unsigned int *index)
{
        int ret;
        char *eout, *vout;

        ret = search_entry(cfg, NULL, entry, index, &eout, &vout);
        if ( ret < 0 )
                return op_insert_line(cfg, create_new_line(entry, val), *index);

        free_val(&eout);
        free_val(&vout);

        op_modify_line(&cfg->content[*index], create_new_line(entry, val));

        return 0;
}
示例#19
0
static int new_section_line(config_t *cfg, const char *section,
                            const char *entry, const char *val, unsigned int *index)
{
        int ret;
        char *eout, *vout;
        unsigned int eindex;

        ret = search_section(cfg, section, *index);
        if ( ret < 0 ) {
                char buf[1024];

                snprintf(buf, sizeof(buf), "[%s]", section);

                if ( *index )
                        *index = adjust_insertion_point(cfg, *index);
                else
                        *index = cfg->elements;

                ret = op_insert_line(cfg, strdup(buf), *index);
                if ( ret < 0 )
                        return ret;

                return (! entry) ? 0 : op_insert_line(cfg, create_new_line(entry, val), *index + 1);
        }

        *index = ret;
        if ( ! entry )
                return 0;

        eindex = *index + 1;

        ret = search_entry(cfg, section, entry, &eindex, &eout, &vout);
        if ( ret < 0 )
                return op_insert_line(cfg, create_new_line(entry, val), eindex);

        free_val(&eout);
        free_val(&vout);

        op_modify_line(&cfg->content[eindex], create_new_line(entry, val));

        return 0;
}
示例#20
0
/* SYNOPSYS :
 * 	  int syr1_fopen_write(char *name, SYR1_FILE *file) {
 * DESCRIPTION :
 *   Ce sous-programme gère l'ouverture d'un fichier logique en mode écriture.
 * PARAMETRES :
 *   name : chaîne de caratère contenant le nom externe du fichier à ouvrir
 *   file : pointeur sur un Bloc Control Fichier (File Control Bloc)
 * RESULTAT :
 *    0 : ouverture réussie
 *   -1 : autre erreur
 */
int syr1_fopen_write(char *name, SYR1_FILE *file) {
  int error = 0;
  //Si le fichier existe déjà, suppression
  if(search_entry(name, &(file->descriptor)) == 0)
	remove_entry(name);
  //initialisation du descripteur
  strcpy(file->descriptor.name, name);
  file->descriptor.size = 0;
  file->descriptor.alloc[0] = get_allocation_unit();
  //création du fichier sur disque
  create_entry(name, &(file->descriptor));
  //initialisation du BCF
  strcpy(file->mode, "w");
  file->current_block = 0;
  file->file_offset = 0;
  file->block_offset = 0;
  file->buffer = malloc(512*sizeof(unsigned char));

  return -1;
}
示例#21
0
TEST_F(mainTest, HandleKodDemobilize) {
	const char *	HOSTNAME = "192.0.2.1";
	const char *	REASON = "DENY";
	pkt		rpkt;
	sockaddr_u	host;
	int		rpktl;
	kod_entry *	entry;

	rpktl = KOD_DEMOBILIZE;
	ZERO(rpkt);
	memcpy(&rpkt.refid, REASON, 4);
	ZERO(host);
	host.sa4.sin_family = AF_INET;
	host.sa4.sin_addr.s_addr = inet_addr(HOSTNAME);

	// Test that the KOD-entry is added to the database.
	kod_init_kod_db("/dev/null", TRUE);

	EXPECT_EQ(1, handle_pkt(rpktl, &rpkt, &host, HOSTNAME));

	ASSERT_EQ(1, search_entry(HOSTNAME, &entry));
	EXPECT_TRUE(memcmp(REASON, entry->type, 4) == 0);
}
示例#22
0
/*
** check_kod
*/
int
check_kod(
	const struct addrinfo *	ai
	)
{
	char *hostname;
	struct kod_entry *reason;

	/* Is there a KoD on file for this address? */
	hostname = addrinfo_to_str(ai);
	TRACE(2, ("check_kod: checking <%s>\n", hostname));
	if (search_entry(hostname, &reason)) {
		printf("prior KoD for %s, skipping.\n",
			hostname);
		free(reason);
		free(hostname);

		return 1;
	}
	free(hostname);

	return 0;
}
示例#23
0
void load_conf(void)
{
   FILE *fc;
   char line[128];
   char *p, *q, **tmp;
   int lineno = 0;
   size_t tmplen;
   struct conf_entry *curr_section = NULL;
   void *value = NULL;

   /* initialize the structures */
   init_structures();
   
   DEBUG_MSG("load_conf");
  
   /* the user has specified an alternative config file */
   if (GBL_CONF->file) {
      DEBUG_MSG("load_conf: alternative config: %s", GBL_CONF->file);
      fc = fopen(GBL_CONF->file, FOPEN_READ_TEXT);
      ON_ERROR(fc, NULL, "Cannot open %s", GBL_CONF->file);
   } else {
      /* errors are handled by the function */
      fc = open_data("etc", ETTER_CONF, FOPEN_READ_TEXT);
      ON_ERROR(fc, NULL, "Cannot open %s", ETTER_CONF);
   }
  
   /* read the file */
   while (fgets(line, 128, fc) != 0) {
      
      /* update the line count */
      lineno++;
      
      /* trim out the comments */
      if ((p = strchr(line, '#')))
         *p = '\0';
      
      /* trim out the new line */
      if ((p = strchr(line, '\n')))
         *p = '\0';

      q = line;
      
      /* trim the initial spaces */
      while (q < line + sizeof(line) && *q == ' ')
         q++;
      
      /* skip empty lines */
      if (line[0] == '\0' || *q == '\0')
         continue;
      
      /* here starts a new section [...] */
      if (*q == '[') {
         
         /* remove the square brackets */
         if ((p = strchr(line, ']')))
            *p = '\0';
         else
            FATAL_ERROR("Missing ] in %s line %d", ETTER_CONF, lineno);
         
         p = q + 1;
         
         DEBUG_MSG("load_conf: SECTION: %s", p);

         /* get the pointer to the right structure */
         if ( (curr_section = search_section(p)) == NULL)
            FATAL_ERROR("Invalid section in %s line %d", ETTER_CONF, lineno);
         
         /* read the next line */
         continue;
      }
   
      /* variable outside a section */
      if (curr_section == NULL)
         FATAL_ERROR("Entry outside a section in %s line %d", ETTER_CONF, lineno);
      
      /* sanity check */
      if (!strchr(q, '='))
         FATAL_ERROR("Parse error %s line %d", ETTER_CONF, lineno);
      
      p = q;

      /* split the entry name from the value */
      do {
         if (*p == ' ' || *p == '='){
            *p = '\0';
            break;
         }
      } while (p++ < line + sizeof(line) );
      
      /* move p to the value */
      p++;
      do {
         if (*p != ' ' && *p != '=')
            break;
      } while (p++ < line + sizeof(line) );
      
      /* 
       * if it is the "dissector" section,
       * do it in a different way
       */
      if (curr_section == (struct conf_entry *)&dissectors) {
         set_dissector(q, p, lineno);
         continue;
      }
     
      /* search the entry name */
      if ( (value = search_entry(curr_section, q)) == NULL)
         FATAL_ERROR("Invalid entry in %s line %d", ETTER_CONF, lineno);
   
      /* strings must be handled in a different way */
      if (curr_section == (struct conf_entry *)&strings) {
         /* trim the quotes */
         if (*p == '"')
            p++;
         
         /* set the string value */ 
         tmp = (char **)value;
         *tmp = strdup(p);
         
         /* trim the ending quotes */
         p = *tmp;
         tmplen = strlen(*tmp);
         do {
            if (*p == '"') {
               *p = 0;
               break;
            }
         } while (p++ < *tmp + tmplen );
         
         DEBUG_MSG("load_conf: \tENTRY: %s  [%s]", q, *tmp);
      } else {
         /* set the integer value */ 
         *(int *)value = strtol(p, (char **)NULL, 10);
         DEBUG_MSG("load_conf: \tENTRY: %s  %d", q, *(int *)value);
      }
   }

   sanity_checks();
   fclose(fc);
}
示例#24
0
文件: checker.c 项目: jamjr/Helios-NG
/************************************************************************
 * BASIC TEST ROUTINES TO CHECK UNIQUE DATA STRUCTURES LIKE SUPERBLOCK AND
 * ROOT DIRECTORY AND GET MEMORY FOR THE CHECKER
 *
 * - Make sure, that the superblock and all copies are valid.
 *
 *   THIS TEST HAS BEEN REMOVED FROM THE BASIC VERSION, BECAUSE THE SUPERBLOCK
 *   DATA IS ACTUALLY NOT USED BY THE FILE-SERVER. ALL DATA, DESCRIBING A FILE
 *   SYSTEM IS DERIVED FROM 'devinfo'. ON THE OTHER SIDE, IT IS A NON-TRIVIAL
 *   TASK TO FIND OTHER, EVENTUALLY PARTLY DAMAGED SUPERBLOCKS ON THE MEDIA TO
 *   BE CHECKED. TO HAVE A BASIC IDEA, WHETHER THE RELEVANT DATA (number of
 *   cyl.groups, cyl.group size and cyl.group offset) KEPT IN THE 'devinfo'-
 *   FILE AND ON DISK DESCRIBE THE SAME PHYSICAL DISK, THEY ARE COMPARED FOR
 *   ALL CYLINDER-GROUPS.
 *  
 * - Compare the # number of free blocks in the bit-maps with the
 *   values, referenced in the cylinder group info structs.
 * - Allocate all needed memory for the checker.
 * - Check the root-directory inode and look for the /lost+found - directory
 *
 * Parameter  : - nothing -
 * Return     : TRUE  = no error at all
 *		FALSE = occurrence of a fatal error
 *
 *************************************************************************/
word
check_unique ( void )
{
 struct fs tmp;			/* For intermediate operation		*/
 struct buf *bp, *bp_2;
 word cgnr, i, j, c, free_cnt, ecnt, try, off;

 /*--------- Make a basic comparison of file-system parameters ---------*/

 IOdebug ("%s***    Step 1.1 : Plausibility test of file-system parameters", S_INFO);
 
					/* cgnr and ncg are the values	*/
					/* taken from devinfo. If no	*/
					/* valid superblock is found 	*/
					/* there or the disk parameters	*/
					/* are different, the checking	*/
					/* process is aborted.		*/
					
					/* Make incore copies of the 	*/
					/* superblock data into i_fs and*/
					/* incore_fs.			*/
 /*------------------ Tests on the super-block -------------------------*/

				/* We have to copy the first 		*/
				/* superblock from the cg 0 info-block. */
 bp = bread ( 0, 2, 1, SAVEA );

 memcpy ( &tmp, &bp->b_un.b_info->fs, sizeof (struct fs) );
 brelse ( bp->b_tbp, TAIL );

 				/* Run until we have a valid copy and	*/
 				/* scan the cylinder groups		*/
 for ( cgnr = 0 , try = -1 ;; cgnr++ ) 
 {	
	corrupt_cnt = 0;	/* At the beginning: no errors at all	*/
	try++;			/* Count the tries which are needed to	*/
				/* get a valid super-block.		*/
#if DEBUG
IOdebug ("	check_unique :	Try to validate a sample superblock.");
#endif
				/*------- I.Definitely errors ----------*/
				/* Block-no 1-3 are always the same !	*/
	if ( tmp.fs_sblknr != 1 || tmp.fs_iblknr != 2 || tmp.fs_rblknr != 3 )
		corrupt_cnt++;
				/* The magic number is fixed.		*/
	if ( tmp.fs_magic != MAGIC_NUMBER )
		corrupt_cnt++;

	if ( tmp.fs_szfs != sizeof (struct fs) )
		corrupt_cnt++;
			
	if ( tmp.fs_szcg != sizeof (struct cg) )
		corrupt_cnt++;
				/*------ II.Plausibility errors	--------*/
	if ( tmp.fs_size != tmp.fs_cgsize * tmp.fs_ncg )
		corrupt_cnt++;
	if ( tmp.fs_dsize != tmp.fs_size - tmp.fs_ncg - 3 )
		corrupt_cnt++;
	if ( tmp.fs_fsize != tmp.fs_bsize / tmp.fs_frag )
		corrupt_cnt++;
	if ( tmp.fs_maxdpb != tmp.fs_bsize / sizeof (struct dir_elem) )
		corrupt_cnt++;
	if ( tmp.fs_maxcontig != tmp.fs_bsize / sizeof (daddr_t) )
		corrupt_cnt++;
	if ( tmp.fs_ncgcgoff != tmp.fs_ncg * tmp.fs_cgoffset )
		corrupt_cnt++;
	if ( tmp.fs_minfree < 0 || tmp.fs_minfree > 99 )
		corrupt_cnt++;		
	if ( tmp.fs_psmal > tmp.fs_maxpsz || tmp.fs_pmedi > tmp.fs_maxpsz ||
	     tmp.fs_phuge > tmp.fs_maxpsz )
		corrupt_cnt++;

					/* Were there errors detected ?	 */
	if ( corrupt_cnt )
	{
		unique_err++;
		if ( cgnr == 0 )
			cgnr++;
			
		IOdebug ("The Superblock is damaged (%d errors counted) !",
			    corrupt_cnt);
					/* Is it possible to select 	 */
					/* automatically a new one ?	 */
		if ( tmp.fs_size     == tmp.fs_cgsize * tmp.fs_ncg &&
		     tmp.fs_ncgcgoff == tmp.fs_cgoffset * tmp.fs_ncg &&
		     tmp.fs_size     != 0 &&
		     tmp.fs_ncgcgoff != 0 )
		{
			IOdebug ("Try to interpret block no: %d as an info-block.",
	 			    map_cgtoib (cgnr,tmp.fs_cgoffset,tmp.fs_cgsize));
	 			    
					/* Read in info-blk from next cg */
			bp = bread ( 0, map_cgtoib (cgnr,tmp.fs_cgoffset,tmp.fs_cgsize),
				     1, SAVEA );
				     
			/* There are possibly two reasons why we cannot */
			/* read the block. If we have used a block-num  */
			/* which is invalid, we need help from the user */
			/* to find a correct number for an info-block	*/

				     	/* Copy in temporary struct	*/
			memcpy ( &tmp, &bp->b_un.b_info->fs,
				 sizeof (struct fs) );
				 	/* Release unused packet	*/
			brelse ( bp->b_tbp, TAIL );
					/* Try to validate the new copy	*/
					/* of the Superblock.		*/
			continue;
		}
		else			/* No automatically selection:	*/
					/* Give the user the choice to	*/
		{			/* select manually a new one	*/
			IOdebug ("Unable to select a new info block automatically!");
					/* Assisted search or manual	*/
					/* 'rebuild' of a superblock!	*/
				return FALSE;
		}
	}
	else				/* No errors were detected	*/
	{
		if ( try > 0 )
			IOdebug ("Valid superblock in use now !");
					/* Keep the valid data incore 	*/
					/* in a separated storage area.	*/
		memcpy ( &incore_fs, &tmp, sizeof (struct fs) );
 					/* Make a copy in i_fs, which is*/
					/* for exclusive checker's use	*/
		memcpy ( &i_fs, &tmp, sizeof (struct fs) );
		break;		 	/* We can finish the search for */
					/* a valid superblock !		*/
	} /* end of <if (corrupt_cnt)> */

 } /* end of <for(cgnr)> */

			/* At this point we are sure, that the incore-	*/
			/* copy of the super-block is valid. So we can	*/
			/* use it further on, if we need file system	*/
			/* parameters!					*/
		
 { 	
 					/* Update each cylinder-group	*/
					/* if necessary.		*/
	for ( cgnr = 0 ; cgnr < i_fs.fs_ncg ; cgnr++ )
 	{				/* Read appropriate info block	*/
		bp = bread ( 0, map_cgtoib (cgnr,i_fs.fs_cgoffset,i_fs.fs_cgsize),
			     1, SAVEA );
	
#if DEBUG
IOdebug ("	check_unique :	Compare it with the copy in cylinder-group %d.", cgnr);
#endif
					/* Updating is only recommended, */
					/* if changes were made.	 */
		if ( my_memcmp ( &i_fs, &bp->b_un.b_info->fs, tmp.fs_szfs ) )
		{
#if DEBUG
IOdebug ("	check_unique :	Copy superblock to cylinder-group %d.", cgnr);
#endif
			unique_err++;
					/* Update it's superblock copy	 */
			memcpy ( &bp->b_un.b_info->fs, &i_fs, sizeof (struct fs) );
					/* ... and write it back to disk */
			fst.corrected_sb++;
			test_bwrite ( bp );
		}				
		else			/* They are the same: don't copy */
			brelse ( bp->b_tbp, TAIL );
	} /* end <for (cgnr)> */
 }
				/* Report differences between data kept  */
				/* in the superblock and in the 'devinfo'*/
				/* structures 				 */
#if DEBUG
IOdebug ("	check_unique : Compare 'devinfo' data with the superblock");
#endif

 if ( i_fs.fs_ncg != vvi->CgCount )
 	IOdebug ("Number of cylinder groups               Sb : %4d / devinfo : %d", 
 	            i_fs.fs_ncg, vvi->CgCount);
 if ( i_fs.fs_cgsize != vvi->CgSize )
 	IOdebug ("Size of a cylinder group                Sb : %4d / devinfo : %d", 
 	            i_fs.fs_cgsize, vvi->CgSize);
 if ( i_fs.fs_cgoffset != vvi->CgOffset )
 	IOdebug ("Relative offset into a cylinder group   Sb : %4d / devinfo : %d", 
 		    i_fs.fs_cgoffset, vvi->CgOffset);
 if ( i_fs.fs_psmal != fsi->SmallPkt )
 	IOdebug ("Size of a of small packet               Sb : %d / devinfo : %d", 
 		    i_fs.fs_psmal, fsi->SmallPkt);
 if ( i_fs.fs_pmedi != fsi->MediumPkt )
 	IOdebug ("Size of a of medium packet              Sb : %d / devinfo : %d", 
 	  	    i_fs.fs_pmedi, fsi->MediumPkt);
 if ( i_fs.fs_phuge != fsi->HugePkt )
 	IOdebug ("Size of a huge packet                   Sb : %d / devinfo : %d", 
 		    i_fs.fs_phuge, fsi->HugePkt);
 if ( i_fs.fs_pscnt != fsi->SmallCount )
 	IOdebug ("Number of samll packets                 Sb : %d / devinfo : %d", 
 		    i_fs.fs_pscnt, fsi->SmallCount);
 if ( i_fs.fs_pmcnt != fsi->MediumCount )
 	IOdebug ("Number of medium packtes                Sb : %d / devinfo : %d", 
 	            i_fs.fs_pmcnt, fsi->MediumCount);
 if ( i_fs.fs_phcnt != fsi->HugeCount )
 	IOdebug ("Number of huge packets                  Sb : %d / devinfo : %d", 
 	            i_fs.fs_phcnt, fsi->HugeCount);
 if ( i_fs.fs_maxnii != fsi->MaxInodes )
 	IOdebug ("Maximal number of incore inodes         Sb : %d / devinfo : %d", 
 	            i_fs.fs_maxnii, fsi->MaxInodes);
 if ( i_fs.fs_minfree != vvi->MinFree )
 	IOdebug ("Percentage of space to be kept free     Sb : %d / devinfo : %d", 
 	            i_fs.fs_minfree, vvi->MinFree);

					
 /*---- To ease addressing of info-blocks: create an info-bnr table ----*/
 
#if DEBUG
IOdebug ("	check_unique :	Create an info-block number table.");
#endif
 					/* Calculate all block numbers	*/
 for ( cgnr = 0 ; cgnr < i_fs.fs_ncg ; cgnr++ )
 					/* ... and fill the table	*/
 	info_blocks[cgnr] = map_cgtoib (cgnr, i_fs.fs_cgoffset, i_fs.fs_cgsize);

 
 /*--------- Discrepancy between bit-maps and cg-info ?	----------------*/

			/* This part is only used to detect differences	*/
			/* in the bit-maps and summary-structures and   */
			/* to report them. No attempts to correct them	*/
			/* are made. This is done later by check_blocks.*/ 
			
 IOdebug ("%s***    Step 1.2 : First inspection of bitmap-data", S_INFO);

					/* Scan all cylinder groups	*/
 for ( corrupt_cnt = 0 , cgnr = 0 ; cgnr < i_fs.fs_ncg ; cgnr++ )
 {					/* Read the cg info-block	*/
	bp = bread ( 0, info_blocks[cgnr], 1, SAVEA );
					/* Read error			*/
	if ( bp == (struct buf *) NULL )
	{
		IOdebug ("%sUnexpected read error for block no: %d.",
			    S_SERIOUS, info_blocks[cgnr]);
		return FALSE;
	}
	
	if ( bp->b_un.b_info->cgx.cg_cgx != cgnr ) {
		IOdebug ("%sInvalid cgnr (%d) found in info block %d!", S_WARNING, bp->b_un.b_info->cgx.cg_cgx ,cgnr);	
	}
					/* Scan through the bit-map !	*/
	for ( i = 0 , free_cnt = 0 , ecnt = 0 ; i < i_fs.fs_cgsize ; i++ )
	{
		switch ( bp->b_un.b_info->cgx.cg_free[i] )
		{			/* Test for errors		*/
			case 0x00 : free_cnt++;  
 				    break;
			case 0xff : continue;
				    break;
			default   : ecnt++;
				    fst.bitmap_errors++;
				    corrupt_cnt++;
		}
	}
	
	if ( free_cnt != bp->b_un.b_info->cgx.cg_s.s_nbfree )
	{				/* By comparing with cg-sum	*/
		corrupt_cnt++;
		unique_err++;
		fst.summary_errors++;
	IOdebug ("%sDifferent number of free blocks found.", S_WARNING);
	IOdebug ("%s> Cyl. Group : %d   FREE  counted= %d   cg-summary= %u",
		            S_INFO, cgnr, free_cnt,
			    bp->b_un.b_info->cgx.cg_s.s_nbfree);
	}

					/* Definitely errors in maps ?	*/
	if ( ecnt )			/* ( != 0 && != 0xff )		*/
	{
		unique_err++;
		IOdebug ("%sCorrupted bits in bit-map found.", S_WARNING);
		IOdebug ("%s> Cyl. Group : %d   ERRORS       =%d  blocks",
			    S_INFO, cgnr, ecnt);
					/* We have reached the limit ?	*/
		if ( ecnt > i_fs.fs_cgsize * maxbmerr / 100 )
		{			/* Note cg-bitmap as unusable	*/
			cg_bitmap_usable[cgnr] = FALSE;
			IOdebug ("%sThe bit-map is not usable!", S_SERIOUS);
		}
		else
			cg_bitmap_usable[cgnr] = TRUE;
 			
	}				/* We have found a bitmap in an	*/
	else				/* usable state !		*/
		cg_bitmap_usable[cgnr] = TRUE;
		
					/* Release unused block		*/
	brelse ( bp->b_tbp, TAIL );
 } /* end < for (cgnr) > */
 
 /*--------- Allocate enough memory for a reference bit-map array ------*/

 IOdebug ("%s***    Step 1.3 : Allocate memory for reference bit-map array.", S_INFO);

 bit_maps_allocated = alloc_ref_maps ();			

 if ( ! bit_maps_allocated )	/* No success again, that's bad!  */
 {
	IOdebug ("%sUnable to allocate memory for reference bit-maps.", S_FATAL);
	return FALSE;
 }
 					/* Blocks 0-2 always allocated !  */
 bit_maps[0][0] = 1;			/* Boot-block			  */
 found_blocks++;
 bitmap_incr (1);			/* Summary block		  */
 found_blocks++;
					/* Mark all info-blocks as being  */
					/* allocated.			  */
 for ( cgnr = 0 ; cgnr < i_fs.fs_ncg ; cgnr++ )
 {
 	found_blocks++;
	bitmap_incr (info_blocks[cgnr]); 
 }

 /*-----------  Prepare the hash-table for directory entries  ------------*/

#if DEBUG
IOdebug ("	check_unique :	Prepare directory-entry hash table.");
#endif

					/* We have to initialize all	*/
 for ( i = 0 ; i < DEHASHSZ ; i++ )	/* hash-pointers !		*/
	de_hash_tab[i].denxt = (struct de_name *) NULL;
 
 /*------  Prepare the hash-table for duplicate block numbers  ---------*/

#if DEBUG
IOdebug ("	check_unique :	Prepare duplicate block-number hash table.");
#endif

					/* We have to initialize all	*/
 for ( i = 0 ; i < DUPHASHSZ ; i++ )	/* hash-pointers !		*/
	dup_hash_tab[i].dupnxt = (struct dup_bnr *) NULL;

 /*--------  Prepare the hash-table for symbolic link references  ------*/ 
 
#if DEBUG
IOdebug ("	check_unique :	Prepare symbolic-link hash-table.");
#endif
					/* We have to initialize all	*/
 for ( i = 0 ; i < LINKHASHSZ ; i++ )	/* hash-pointers		*/
 	link_hash_tab[i].lnnxt = (struct de_link *) NULL;
 
 /*--------------- Valid root directory data ? -------------------------*/

 IOdebug ("%s***    Step 1.4 : Check the root directory inode.", S_INFO);

					/* Read summary block with the	*/
 bp = bread ( 0, 1, 1, SAVEA );		/* root-dir inode in it.	*/
					/* if read fails, longjmp 	*/
					/* term_jmp			*/
 changes_de = 0;			/* Nothing done so far ...	*/
 					/* Check the root-dir entry 	*/
 if ( ! validate_entry ( &bp->b_un.b_sum->root_dir , "/", Type_Directory, TRUE ) )
 {					/* Is it totally damaged !	*/
 
 		/* It is a very dangerous situation, if we have no root-*/
 		/* directory available. The user can create an		*/
 		/* empty one and hope, that lost subdiretory-information*/
 		/* is picked up during the "lost+found" pass over the	*/
 		/* cylinder-group bit-maps.				*/

	unique_err++;
	IOdebug ("%sThe root-directory is not usable !", S_SERIOUS);
					/* Pioneer's work: we create a	*/
					/* new inode from scratch !	*/
	IOdebug ("%sA new root-directory is created from scratch.", S_INFO);
	
 					/* Pioneer's work: we create a	*/
 					/* new root-inode from scratch  */
 	create_new_root_dir ( &bp->b_un.b_sum->root_dir );
 					/* Write the root-inode back on */
 					/* disk.			*/
 	test_bwrite ( bp );
 }
 else					/* After finding a usable root- */
 {					/* directory entry ...		*/
	if (!bp->b_un.b_sum->sum_same)
		unique_err++;
 	if ( changes_de )		/* Any changes made ?		*/
 	{
#if DEBUG
IOdebug ("	check_unique :	Update root-directory inode on disk.");
#endif
		unique_err++;
					/* Write corrected summary-block */
 		test_bwrite ( bp );	/* directly to disk		 */
 	}
 	else
		brelse ( bp->b_tbp, TAIL );
 }

 /*----------------  Look for the "lost+found" directory  --------------*/


 IOdebug ("%s***    Step 1.5 : Look for the '/lost+found'- directory.", S_INFO);

 bp = bread ( 0, 1, 1, SAVEA );		/* Get root-directory		*/
					/* if read fails, longjmp 	*/
					/* term_jmp			*/
					
 					/* Look for the "lost+found"-dir */
 bp_2 = search_entry ( &bp->b_un.b_sum->root_dir.de_inode, "lost+found", &off );
					/* We have found it ?		*/
 if ( bp_2 != (struct buf *) NULL )
 {					/* We have found a usable 	*/
	lost_found = TRUE;		/* /lost+found - directory.	*/
	brelse ( bp_2->b_tbp, TAIL );
	brelse ( bp->b_tbp, TAIL );
 }
 					/* If we have not found the 	*/
 else					/* /lost+found-inode, we have to */
 {					/* create a new one.		*/
 	IOdebug ("%sUnable to find a '/lost+found' entry in the root-directory.", S_WARNING);
	IOdebug ("%sA new '/lost+found' entry is created.", S_INFO);
	unique_err++;
 	if ( create_lostfound_inode ( &bp->b_un.b_sum->root_dir.de_inode ) )
	{
		IOdebug ("%sHave created a new /lost+found directory!", S_INFO);
		lost_found = TRUE; 	
 		test_bwrite ( bp );	/* Write modified root back.	*/
 	}
 	else				/* We cannot create a /lost+found*/
 	{				/* inode, because we have no    */
 					/* slot available.		*/
		IOdebug ("%sCannot create a new '/lost+found' directory !", S_WARNING);
		lost_found = FALSE;
		brelse ( bp->b_tbp, TAIL );
	}
 }

 return TRUE;
}

/*--  Procedures dealing with the creation of a new basic structures ---*/

/************************************************************************
 * CREATE A TOTALLY EMPTY ROOT-DIRECTORY ENTRY FROM SCRATCH
 *
 * - This procedure is called, if the checker was not able to find a 
 *   valid root-directory.
 *
 * Parameter   : dp    = Pointer to the root directory-element
 * Return      : - nothing -
 *
 ***********************************************************************/
static void
create_new_root_dir ( struct dir_elem *dp )
{
 Date date;
 
#if DEBUG
IOdebug ("	create_new_root_dir :	Create the new entry");
#endif
					/* Clear the directory-entry	*/
 memset ( dp, 0, sizeof (struct dir_elem) );
 					/* .. and fill in with the data	*/
 					/* for the root-directory	*/
 strcpy ( dp->de_name, i_fs.fs_name );
 dp->de_inode.i_mode   = Type_Directory;
 dp->de_inode.i_matrix = DefDirMatrix;
 date = GetDate ();
 dp->de_inode.i_ctime  = date;
 dp->de_inode.i_mtime  = date;
 dp->de_inode.i_atime  = date;
}
示例#25
0
/*
 * The actual main function.
 */
int  
sntp_main (
	int argc, 
	char **argv
	) 
{
	register int c;
	struct kod_entry *reason = NULL;
	int optct;
	/* boolean, u_int quiets gcc4 signed overflow warning */
	u_int sync_data_suc;
	struct addrinfo **bcastaddr = NULL;
	struct addrinfo **resh = NULL;
	struct addrinfo *ai;
	int resc;
	int kodc;
	int ow_ret;
	int bcast = 0;
	char *hostname;

	optct = optionProcess(&sntpOptions, argc, argv);
	argc -= optct;
	argv += optct; 

	/* Initialize logging system */
	init_logging();
	if (HAVE_OPT(LOGFILE))
		open_logfile(OPT_ARG(LOGFILE));

	msyslog(LOG_NOTICE, "Started sntp");

	/* IPv6 available? */
	if (isc_net_probeipv6() != ISC_R_SUCCESS) {
		ai_fam_pref = AF_INET;
#ifdef DEBUG
		printf("No ipv6 support available, forcing ipv4\n");
#endif
	} else {
		/* Check for options -4 and -6 */
		if (HAVE_OPT(IPV4))
			ai_fam_pref = AF_INET;
		else if (HAVE_OPT(IPV6))
			ai_fam_pref = AF_INET6;
	}

	/* Parse config file if declared TODO */

	/* 
	 * If there's a specified KOD file init KOD system.  If not use
	 * default file.  For embedded systems with no writable
	 * filesystem, -K /dev/null can be used to disable KoD storage.
	 */
	if (HAVE_OPT(KOD))
		kod_init_kod_db(OPT_ARG(KOD));
	else
		kod_init_kod_db("/var/db/ntp-kod");

	if (HAVE_OPT(KEYFILE))
		auth_init(OPT_ARG(KEYFILE), &keys);

#ifdef EXERCISE_KOD_DB
	add_entry("192.168.169.170", "DENY");
	add_entry("192.168.169.171", "DENY");
	add_entry("192.168.169.172", "DENY");
	add_entry("192.168.169.173", "DENY");
	add_entry("192.168.169.174", "DENY");
	delete_entry("192.168.169.174", "DENY");
	delete_entry("192.168.169.172", "DENY");
	delete_entry("192.168.169.170", "DENY");
	if ((kodc = search_entry("192.168.169.173", &reason)) == 0)
		printf("entry for 192.168.169.173 not found but should have been!\n");
	else
		free(reason);
#endif

	/* Considering employing a variable that prevents functions of doing anything until 
	 * everything is initialized properly 
	 */
	resc = resolve_hosts((void *)argv, argc, &resh, ai_fam_pref);
	if (resc < 1) {
		printf("Unable to resolve hostname(s)\n");
		return -1;
	}
	bcast = ENABLED_OPT(BROADCAST);
	if (bcast) {
		const char * myargv[2];

		myargv[0] = OPT_ARG(BROADCAST);
		myargv[1] = NULL;
		bcast = resolve_hosts(myargv, 1, &bcastaddr, ai_fam_pref);
	}

	/* Select a certain ntp server according to simple criteria? For now
	 * let's just pay attention to previous KoDs.
	 */
	sync_data_suc = FALSE;
	for (c = 0; c < resc && !sync_data_suc; c++) {
		ai = resh[c];
		do {
			hostname = addrinfo_to_str(ai);
			if ((kodc = search_entry(hostname, &reason)) == 0) {
				if (is_reachable(ai)) {
					ow_ret = on_wire(ai, bcast ? bcastaddr[0] : NULL);
					if (0 == ow_ret)
						sync_data_suc = TRUE;
				}
			} else {
				printf("%d prior KoD%s for %s, skipping.\n", 
					kodc, (kodc > 1) ? "s" : "", hostname);
				free(reason);
			}
			free(hostname);
			ai = ai->ai_next;
		} while (NULL != ai);
		freeaddrinfo(resh[c]);
	}
	free(resh);

	if (!sync_data_suc)
		return 1;
	return 0;
}
示例#26
0
int main ( void )
{
  FILE *fcost,*fp_extra,*fp_entries;
  int ask,cost_exists;
  char i='0',ar_ext[8], ch='&',entries[13]="Entries.txt",cost[9]="Cost.txt",extra[10]="Extra.txt";
  
  
  fcost=fopen(cost,"r");
  if(fcost==NULL)
  {
   printf("Couldn't find %s\nThe file will now be created. Please insert the different cost values, before advancing to menu.\n",cost);
   edit_cost(cost,1);
  }
  else 
  {
   printf("Cost file detected. Advancing to menu.\n",cost);
   fclose(fcost);
  }
    
  
  
  
  
  while(ch!='8')
  {
  printf("\n1. New entry\n2. Calculate cost\n3. Print entry status\n4. Print non delivered entries\n5. Profits\n6. Services cost\n7. Update services cost\n8. Quit\n Your input:");
   ch=getchar();
   printf("\n**  Your input was: %c  ** \n",ch);

   switch (ch)
   {
    case '1': {
               ask=0;
               add_entry(entries,extra,cost,ask);
               
              }break;//don't ask.
              
    case '2': {
               ask=1;
               add_entry(entries,extra,cost,ask);
               //fflushnew(&ch);
              }break;//ask.
              
    case '3': 
               {fflushnew(&ch);search_entry(entries);
               }
               break;
              
    case '4':  {incomplete(entries);
    					 }
               break;
                  
    case '5':  {profits(entries);}
               break;
    
    case '6':  {edit_cost(cost,0);}
               break;//view cost file
    
    case '7':  {edit_cost(cost,1);fflushnew(&ch);}
               break;//edit cost file
    
    case '8':  break;//quit
    
    default: printf("Please enter correct input (1-8)");
   }
   
   if(ch!='8')fflushnew(&ch);
  }

  system ("pause");
  return 0;
}
示例#27
0
文件: ld_cmd.c 项目: 2pac/kamailio
int ld_cmd_next(db_res_t* res)
{
	return search_entry(res, 0);
}
示例#28
0
文件: ld_cmd.c 项目: 2pac/kamailio
int ld_cmd_first(db_res_t* res)
{
	return search_entry(res, 1);
}