示例#1
0
static int
group_test_correctness(struct group *grp, void *mdata)
{
	printf("testing correctness with the following data:\n");
	dump_group(grp);

	if (grp == NULL)
		goto errfin;

	if (grp->gr_name == NULL)
		goto errfin;

	if (grp->gr_passwd == NULL)
		goto errfin;

	if (grp->gr_mem == NULL)
		goto errfin;

	printf("correct\n");

	return (0);
errfin:
	printf("incorrect\n");

	return (-1);
}
示例#2
0
static int
group_test_getgrnam(struct group *grp_model, void *mdata)
{
	struct group *grp;
		
	if (debug) {
		printf("testing getgrnam() with the following data:\n");
		dump_group(grp_model);
	}

	grp = getgrnam(grp_model->gr_name);
	if (group_test_correctness(grp, NULL) != 0)
		goto errfin;
	
	if ((compare_group(grp, grp_model, NULL) != 0) &&
	    (group_check_ambiguity((struct group_test_data *)mdata, grp) 
	    !=0))
	    goto errfin;
		
	if (debug)
		printf("ok\n");
	return (0);
	
errfin:
	if (debug)
		printf("not ok\n");
	
	return (-1);
}
示例#3
0
int
main(int argc, char *argv[])
{
  if (uim_init() < 0) {
    fprintf(stderr, "uim_init() failed.\n");
    return -1;
  }

  if (uim_custom_enable()) {
    char **primary_groups, **grp;

    primary_groups = uim_custom_primary_groups();
    for (grp = primary_groups; *grp; grp++) {
      dump_group(*grp);
    }
    uim_custom_symbol_list_free(primary_groups);
  } else {
    fprintf(stderr, "uim_custom_enable() failed.\n");
    uim_quit();
    return -1;
  }

  uim_quit();

  return 0;
}
示例#4
0
文件: db.c 项目: Distrotech/mcelog
void dump_database(struct database *db, FILE *out)
{
	struct group *g; 	
	for (g = db->groups; g && !ferror(out); g = g->next) {
		if (g->comment) {
			fprintf(out, "#%s", g->comment);
			continue;
		}
		dump_group(g, out);
	}
}
示例#5
0
static  int
compare_group(struct group *grp1, struct group *grp2, void *mdata)
{
	char **c1, **c2;

	if (grp1 == grp2)
		return (0);

	if (grp1 == NULL || grp2 == NULL)
		goto errfin;

	if (strcmp(grp1->gr_name, grp2->gr_name) != 0 ||
	    strcmp(grp1->gr_passwd, grp2->gr_passwd) != 0 ||
	    grp1->gr_gid != grp2->gr_gid)
			goto errfin;

	c1 = grp1->gr_mem;
	c2 = grp2->gr_mem;

	if (grp1->gr_mem == NULL || grp2->gr_mem == NULL)
		goto errfin;

	for (; *c1 && *c2; ++c1, ++c2)
		if (strcmp(*c1, *c2) != 0)
			goto errfin;

	if (*c1 != '\0' || *c2 != '\0')
		goto errfin;

	return 0;

errfin:
	if (mdata == NULL) {
		printf("following structures are not equal:\n");
		dump_group(grp1);
		dump_group(grp2);
	}

	return (-1);
}
示例#6
0
static void
dump_list (void)
{
	GSList *groups, *p;

	groups = e_source_list_peek_groups (list);
	if (groups == NULL) {
		g_print ("(No items)\n");
		return;
	}

	for (p = groups; p != NULL; p = p->next)
		dump_group (E_SOURCE_GROUP (p->data));
}
示例#7
0
static int
group_test_getgrgid(struct group *grp_model, void *mdata)
{
	struct group *grp;

	printf("testing getgrgid() with the following data...\n");
	dump_group(grp_model);

	grp = getgrgid(grp_model->gr_gid);
	if (group_test_correctness(grp, NULL) != 0 ||
	    (compare_group(grp, grp_model, NULL) != 0 &&
	     group_check_ambiguity((struct group_test_data *)mdata, grp) != 0)) {
		return (-1);
	} else {
		return (0);
	}
}
示例#8
0
static int
group_test_getgrgid(struct group *grp_model, void *mdata)
{
	struct group *grp;
		
	if (debug) {
		printf("testing getgrgid() with the following data...\n");
		dump_group(grp_model);
	}	
	
	grp = getgrgid(grp_model->gr_gid);
	if ((group_test_correctness(grp, NULL) != 0) || 
	    ((compare_group(grp, grp_model, NULL) != 0) &&
	    (group_check_ambiguity((struct group_test_data *)mdata, grp)
	    != 0))) {
	    if (debug)
		printf("not ok\n");
	    return (-1);
	} else {
	    if (debug)
		printf("ok\n");
	    return (0);
	}
}
示例#9
0
文件: dbquery.c 项目: VertiPub/mcelog
int main(int ac, char **av)
{
	struct database *db;
	struct group *group = NULL;
	char *line = NULL;
	size_t linesz = 0;
	if (!av[1]) {
		printf("%s database\n", av[0]);
		exit(1);
	}
	printf("dbtest\n");
	db = open_db(av[1], 1);
	while (printf("> "),
		fflush(stdout),
		getline(&line, &linesz, stdin) > 0) {
		char *p = line + strlen(line) - 1;
		while (p >= line && isspace(*p))
			*p-- = 0;
		switch (line[0]) {
		case 's':
			C(sync_db(db));
			break;
		case 'q':
			C(close_db(db));
			exit(0);
		case 'g':
			group = find_group(db, line + 1);
			if (group)
				printf("found\n");
			break;
		case 'G':
			NEEDGROUP;
			C(delete_group(db, group));
			group = NULL;
			break;
		case 'a': {
			int existed = 0;
			group = add_group(db, line + 1, &existed);
			if (existed)
				printf("existed\n");
			break;
		}
		case 'v':
			NEEDGROUP;
			printf("%s\n", entry_val(group, line + 1));
			break;
		case 'c': {
			p = line + 1;
			char *entry = strsep(&p, ",");
			NEEDGROUP;
			change_entry(db, group, entry, strsep(&p, ""));
			break;
		}
		case 'L':
			NEEDGROUP;
			clone_group(db, group, line + 1);
			break;
		case 'f': {
			struct group *g;
			p = line + 1;
			char *entry = strsep(&p, ",");
			char *val = strsep(&p, "");
			g = NULL;
			int nr = 0;
			while ((g = find_entry(db, g, entry, val)) != NULL) {
				if (nr == 0)
					group = g;
				nr++;
				dump_group(group, stdout);
			}
			if (nr == 0)
				printf("not found\n");
			break;
		}
		case 'C':
			NEEDGROUP;
			add_comment(db, group, line + 1);
			break;
		case 'd':
			NEEDGROUP;
			dump_group(group, stdout);
			break;
		case 'D':
			dump_database(db, stdout);
			break;
		default:
			usage();
			break;
		}
	}
	return 0;
}