Esempio n. 1
0
File: user.c Progetto: blochl/diod
static char *
_get_usercache (char *name, void *a)
{
	Npsrv *srv = (Npsrv *)a;
	Npusercache *uc = srv->usercache;
	Npuser *u;
	time_t now = time (NULL);
	char *s = NULL;
	int len = 0;

	xpthread_mutex_lock (&uc->lock);
	_usercache_expire (srv);
	for (u = uc->users; u != NULL; u = u->next) {
		int ttl = uc->ttl - (now - u->t);

		if (aspf (&s, &len, "%s(%d,%d+%d) %d\n", u->uname,
			  u->uid, u->gid, u->nsg, u->uid ? ttl : 0) < 0) {
			np_uerror (ENOMEM);
			xpthread_mutex_unlock (&uc->lock);
			goto error;
		}
	}
	xpthread_mutex_unlock (&uc->lock);
	return s;
error:
	if (s)
		free (s);
	return NULL;
}
Esempio n. 2
0
static Npuser *
_usercache_lookup (Npsrv *srv, char *uname, uid_t uid)
{
    Npusercache *uc = srv->usercache;
    Npuser *u;

    _usercache_expire (srv);
    for (u = uc->users; u != NULL; u = u->next) {
        if (!uname && uid == u->uid)
            break;
        if (uname && !strcmp (uname, u->uname))
            break;
    }
    return u;
}