コード例 #1
0
ファイル: cmd3.c プロジェクト: Gwenio/DragonFlyBSD
/*
 * Put add users to a group.
 */
int
group(char **argv)
{
    struct grouphead *gh;
    struct group *gp;
    char **ap, *gname, **p;
    int h, s;

    if (*argv == NULL) {
        for (h = 0, s = 1; h < HSHSIZE; h++)
            for (gh = groups[h]; gh != NULL; gh = gh->g_link)
                s++;
        ap = (char **)salloc(s * sizeof(*ap));
        for (h = 0, p = ap; h < HSHSIZE; h++)
            for (gh = groups[h]; gh != NULL; gh = gh->g_link)
                *p++ = gh->g_name;
        *p = NULL;
        sort(ap);
        for (p = ap; *p != NULL; p++)
            printgroup(*p);
        return (0);
    }
    if (argv[1] == NULL) {
        printgroup(*argv);
        return (0);
    }
    gname = *argv;
    h = hash(gname);
    if ((gh = findgroup(gname)) == NULL) {
        gh = calloc(sizeof(*gh), 1);
        gh->g_name = vcopy(gname);
        gh->g_list = NULL;
        gh->g_link = groups[h];
        groups[h] = gh;
    }

    /*
     * Insert names from the command list into the group.
     * Who cares if there are duplicates?  They get tossed
     * later anyway.
     */

    for (ap = argv+1; *ap != NULL; ap++) {
        gp = calloc(sizeof(*gp), 1);
        gp->ge_name = vcopy(*ap);
        gp->ge_link = gh->g_list;
        gh->g_list = gp;
    }
    return (0);
}
コード例 #2
0
static int test_function(int function, const char *param) {
	int ret = 0;
	int errnop;
	char buffer[1024];
	struct passwd *resultp = NULL;
	struct group *resultg = NULL;
	enum nss_status code = NSS_STATUS_UNAVAIL;

	switch(function) {
	case GETPWNAM:
		resultp = (struct passwd *) malloc(sizeof(struct passwd));
		code = _nss_shib_getpwnam_r(param, resultp, buffer, 1024, &errnop);
		break;
	case GETPWUID:
		resultp = (struct passwd *) malloc(sizeof(struct passwd));
		code = _nss_shib_getpwuid_r(atoi(param), resultp, buffer, 1024, &errnop);
		break;
	case SETPWENT:
		//code = _nss_shib_setpwent();
		break;
	case GETPWENT:
		resultp = (struct passwd *) malloc(sizeof(struct passwd));
		code = _nss_shib_getpwent_r(resultp, buffer, 1024, &errnop);
		break;
	case SETGRENT:
		//code = _nss_shib_setgrent_r(resultg, (void *)param);
		break;
	case ENDGRENT:
		//code = _nss_shib_endgrent_r(NULL, (void *)param);
		break;
	case GETGRENT:
		resultg = (struct group *) malloc(sizeof(struct group));
		code = _nss_shib_getgrent_r(resultg, buffer, 1024, &errnop);
		break;
	case GETGRNAM:
		resultg = (struct group *) malloc(sizeof(struct group));
		code = _nss_shib_getgrnam_r(param, resultg, buffer, 1024, &errnop);
		break;
	case GETGRGID:
		resultg = (struct group *) malloc(sizeof(struct group));
		code = _nss_shib_getgrgid_r(atoi(param), resultg, buffer, 1024, &errnop);
		break;
	}

	if (code != NSS_STATUS_SUCCESS && code != NSS_STATUS_TRYAGAIN) {
		printf("Error while calling function (result code = %d).\n", code);
		ret = 0;
	}
	else {
		if (resultp) printpasswd(resultp);
		if (resultg) printgroup(resultg);
		ret = 1;
	}

	buffer[0] = '\0';
	if (resultp) free(resultp);
	if (resultg) free(resultg);

	return ret;
}
コード例 #3
0
ファイル: nntpfs.c プロジェクト: dancrossnyc/harvey
static int
printgroup(char *s, Group *g)
{
	if(g->parent == g)
		return 0;

	if(printgroup(s, g->parent))
		strcat(s, ".");
	strcat(s, g->name);
	return 1;
}
コード例 #4
0
ファイル: nntpfs.c プロジェクト: dancrossnyc/harvey
int
nntpcurrentgroup(Netbuf *n, Group *g)
{
	char cmd[1024];

	if(n->currentgroup != g){
		strcpy(cmd, "GROUP ");
		printgroup(cmd, g);
		if(nntpcmd(n, cmd, 21) < 0)
			return -1;
		n->currentgroup = g;
	}
	return 0;
}
コード例 #5
0
ファイル: res.c プロジェクト: alhazred/onarm
/*
 * this function prints the list of resource groups and their members
 */
void
printgroups(int type)
{
	int header = 0;

	if ((type & AC_PROC) && (type & AC_TASK) && (type & AC_FLOW))
		header = 1;

	if (type & AC_PROC) {
		if (header == 1)
			(void) printf("process:\n");
		printgroup(AC_PROC);
	}
	if (type & AC_TASK) {
		if (header == 1)
			(void) printf("task:\n");
		printgroup(AC_TASK);
	}
	if (type & AC_FLOW) {
		if (header == 1)
			(void) printf("flow:\n");
		printgroup(AC_FLOW);
	}
}
コード例 #6
0
ファイル: nntpfs.c プロジェクト: dancrossnyc/harvey
void
nntprefresh(Netbuf *n, Group *g)
{
	char cmd[1024];
	char *f[5];
	int lo, hi;

	if(g->isgroup==0)
		return;

	if(time(0) - g->atime < 30)
		return;

	strcpy(cmd, "GROUP ");
	printgroup(cmd, g);
	if(nntpcmd(n, cmd, 21) < 0){
		n->currentgroup = nil;
		return;
	}
	n->currentgroup = g;

	if(tokenize(n->response, f, nelem(f)) < 4){
		fprint(2, "error reading GROUP response");
		return;
	}

	/* backwards from LIST! */
	hi = strtol(f[3], 0, 10)+1;
	lo = strtol(f[2], 0, 10);
	if(g->hi != hi){
		g->mtime = time(0);
		if(g->lo==0)
			g->lo = lo;
		g->hi = hi;
	}
	g->atime = time(0);
}