getexecattr.c revision bf1f3d9222ae6fcadd490d70a03838f7a2d30bb0
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdlib.h>
#include <string.h>
#include <exec_attr.h>
#include "nis_common.h"
/* extern from nis_common.c */
extern void massage_netdb(const char **, int *);
/* externs from libnsl */
extern int _doexeclist(nss_XbyY_args_t *);
extern char *_exec_wild_id(char *, const char *);
extern char *_strtok_escape(char *, char *, char **);
typedef struct __exec_nis_args {
int *yp_status;
/*
* check_match: returns 1 if - matching entry found and no more entries needed,
* or, entry cannot be found because of error;
* returns 0 if - no matching entry found, or,
* matching entry found and next match needed.
*/
static int
{
/*
* NSS_DBOP_EXECATTR_BYNAMEID searched for name and id in
* _exec_nis_lookup already.
* If we're talking to pre-Solaris9 nis servers, check policy,
* as policy was not a searchable column then.
*/
if ((check_policy && policy &&
return (0);
}
return (0);
}
return (1);
}
/*
* check_match_strbuf: set up the data needed by check_match()
* and call it to match exec_attr data in strbuf and argp->key.attrp
*/
static int
{
char *sep = KV_TOKEN_DELIMIT;
void *sp;
int rc;
/*
* Remove newline that yp_match puts at the
* end of the entry it retrieves from the map.
*/
}
return (rc);
}
static nss_status_t
_exec_nis_parse(const char *instr,
int instr_len,
int check_policy)
{
int parse_stat;
char *strbuf;
int check_matched;
switch (parse_stat) {
case NSS_STR_PARSE_SUCCESS:
/* if exec_attr file format requested */
res = NSS_UNAVAIL;
} else {
}
if (check_matched) {
res = NSS_SUCCESS;
if (_doexeclist(argp) == 0) {
res = NSS_UNAVAIL;
}
}
} else {
res = NSS_NOTFOUND;
}
break;
case NSS_STR_PARSE_ERANGE:
res = NSS_NOTFOUND;
break;
default:
res = NSS_UNAVAIL;
break;
}
return (res);
}
/*
* This is the callback for yp_all. It returns 0 to indicate that it wants to
* be called again for further key-value pairs, or returns non-zero to stop the
* flow of key-value pairs. If it returns a non-zero value, it is not called
* again. The functional value of yp_all is then 0.
*/
/*ARGSUSED*/
static int
_exec_nis_cb(int instatus,
char *inkey,
int inkeylen,
char *inval,
int invallen,
void *indata)
{
int stop_cb;
const char *filter;
/*
* If we have no more data to look at, we want to
* that we processed.
* If this is the 1st time we enter this callback,
* yp_status is already set to YPERR_YPERR
* (see _exec_nis_lookup() for when this callback
* and arguments are set initially).
*/
}
return (0); /* yp_all may decide otherwise... */
}
/*
* yp_all does not null terminate the entry it retrieves from the
* map, unlike yp_match. so we do it explicitly here.
*/
/*
* Optimization: if the entry doesn't contain the filter string then
* it can't be the entry we want, so don't bother looking more closely
* at it.
*/
if ((_priv_exec->policy &&
return (0);
}
switch (res) {
case NSS_SUCCESS:
break;
case NSS_UNAVAIL:
stop_cb = 1;
break;
default:
stop_cb = 0;
break;
}
return (stop_cb);
}
static nss_status_t
{
int ypstatus;
if (getby_flag == NSS_DBOP_EXECATTR_BYNAMEID) {
int check_policy = 0;
int vallen;
char *val;
/*
* Try using policy as part of search key. If that fails,
* (it will, in case of pre-Solaris9 nis server where policy
* was not searchable), try again without using policy.
*/
return (NSS_NOTFOUND);
do {
_priv_exec->id);
check_policy = 1;
continue;
} else if (ypres != NSS_SUCCESS) {
break;
} else {
break;
}
} while (res == NSS_SUCCESS);
} else {
int ypstat = YPERR_YPERR;
struct ypall_callback cback;
/*
* Instead of calling yp_all() doing hard lookup, we use
* the alternative function, __yp_all_cflookup(), to
* perform soft lookup when binding to nis servers with
* time-out control. Other than that, these two functions
* do exactly the same thing.
*/
/*
* For GET_ALL, check if we found anything at all.
*/
return (NSS_SUCCESS);
switch (ypstat) {
case 0:
res = NSS_SUCCESS;
break;
case YPERR_BUSY:
res = NSS_TRYAGAIN;
break;
case YPERR_KEY:
/*
* If no such key, return NSS_NOTFOUND
* as this looks more relevant; it will
* also help libnsl to try with another
* policy (see _getexecprof()).
*/
res = NSS_NOTFOUND;
break;
default:
res = NSS_UNAVAIL;
break;
}
}
return (res);
}
/*
* If search for exact match for id failed, get_wild checks if we have
* a wild-card entry for that id.
*/
static nss_status_t
{
const char *orig_id;
if (res == NSS_SUCCESS)
break;
}
if (old_id)
return (res);
}
static nss_status_t
{
return (res);
}
static nss_status_t
{
/*LINTED*/
if (res != NSS_SUCCESS)
return (res);
}
static nss_status_t
{
/*LINTED*/
if (res != NSS_SUCCESS)
return (res);
}
static nis_backend_op_t execattr_ops[] = {
};
/*ARGSUSED*/
_nss_nis_exec_attr_constr(const char *dummy1,
const char *dummy2,
const char *dummy3,
const char *dummy4,
const char *dummy5,
const char *dummy6,
const char *dummy7)
{
return (_nss_nis_constr(execattr_ops,
sizeof (execattr_ops)/sizeof (execattr_ops[0]),
}