netgroup.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <netconfig.h>
#include <netdir.h>
#include <sys/resource.h>
#include <sys/pathconf.h>
#include <sys/systeminfo.h>
#include <signal.h>
#include <locale.h>
#include <unistd.h>
#include <thread.h>
#include "../lib/sharetab.h"
#include "mountd.h"
struct cache_entry {
char *cache_host;
int cache_belong;
char **cache_grl;
int cache_grc;
struct cache_entry *cache_next;
};
static struct cache_entry *cache_head;
void
{
}
/*
* Check whether any of the hostnames in clnames are
* members (or non-members) of the netgroups in glist.
* Since the innetgr lookup is rather expensive, the
* result is cached. The cached entry is valid only
* for VALID_TIME seconds. This works well because
* typically these lookups occur in clusters when
* a client is mounting.
*
* Note that this routine establishes a host membership
* in a list of netgroups - we've no idea just which
* netgroup in the list it is a member of.
*
* glist is a character array containing grc strings
* representing netgroup names (optionally prefixed
* with '-'). Each string is ended with '\0' and
* followed immediately by the next string.
*/
int
{
char **grl;
char *gr;
int i, j, n;
int response;
int belong = 0;
static char *domain;
int ssize;
}
/* Check for error in syscall or NULL domain name */
if (ssize <= 1) {
return (0);
}
}
return (0);
/*
* If the netgroup name has a '-' prepended
* then a match of this name implies a failure
* instead of success.
*/
/*
* Subsequent names with or without a '-' (but no mix)
* can be grouped together for a single check.
*/
break;
}
/*
* If not in cache check the netgroup for each
* of the hosts names (usually just one).
* Enter the result into the cache.
*/
if (__multi_innetgr(n, grl,
1, &host,
0, NULL,
1, &domain))
belong = 1;
}
}
}
}
/*
* Free a cache entry and all entries
* further down the chain since they
* will also be expired.
*/
static void
{
int i;
if (ce->cache_host)
}
}
/*
* Search the entries in the cache chain looking
* for an entry with a matching hostname and group
* list. If a match is found then return the "belong"
* value which may be 1 or 0 depending on whether the
* client is a member of the list or not. This is
* both a positive and negative cache.
*
* Cache entries have a validity of VALID_TIME seconds.
* If we find an expired entry then blow away the entry
* and the rest of the chain since entries further down
* the chain will be expired too because we always add
* new entries to the head of the chain.
*/
static int
{
int i;
(void) rw_rdlock(&cache_lock);
/*
* If we find a stale entry, there can't
* be any valid entries from here on.
* Acquire a write lock, search the chain again
* and delete the stale entry and all following
* entries.
*/
(void) rw_unlock(&cache_lock);
(void) rw_wrlock(&cache_lock);
break;
if (prev)
else
cache_head = NULL;
cache_free(ce);
}
(void) rw_unlock(&cache_lock);
return (0);
}
continue; /* no match */
continue; /* no match */
for (i = 0; i < grc; i++)
break; /* no match */
if (i < grc)
continue;
(void) rw_unlock(&cache_lock);
return (1);
}
(void) rw_unlock(&cache_lock);
return (0);
}
/*
* Put a new entry in the cache chain by
* prepending it to the front.
* If there isn't enough memory then just give up.
*/
static void
{
struct cache_entry *entry;
int i;
return;
return;
}
return;
}
for (i = 0; i < grc; i++) {
return;
}
}
(void) rw_wrlock(&cache_lock);
cache_head = entry;
(void) rw_unlock(&cache_lock);
}
/*
* Full cache flush
*/
void
netgrp_cache_flush(void)
{
(void) rw_wrlock(&cache_lock);
cache_head = NULL;
(void) rw_unlock(&cache_lock);
}