48 #include <rpcsvc/nis.h>
112 #define STR(x) vstring_str(x)
116 static const char *dict_nisplus_lookup(
DICT *dict,
const char *key)
118 const char *myname =
"dict_nisplus_lookup";
119 DICT_NISPLUS *dict_nisplus = (DICT_NISPLUS *) dict;
134 if (quoted_key == 0) {
159 for (cp = key; (ch = *(
unsigned const char *) cp) != 0; cp++) {
161 msg_warn(
"map %s:%s: lookup key with non-printing character 0x%x:"
162 " ignoring this request",
165 }
else if (ch ==
'"') {
183 reply = nis_list(
STR(query), FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL);
189 if (reply->status == NIS_SUCCESS) {
190 if ((count = NIS_RES_NUMOBJ(reply)) != 1) {
191 msg_warn(
"ambiguous match (%d results) for %s in NIS+ map %s:"
192 " ignoring this request",
193 count, key, dict_nisplus->dict.name);
194 nis_freeresult(reply);
197 last_col = NIS_RES_OBJECT(reply)->zo_data
198 .objdata_u.en_data.en_cols.en_cols_len - 1;
199 if (dict_nisplus->column > last_col)
200 msg_fatal(
"requested column %d > max column %d in table %s",
201 dict_nisplus->column, last_col,
202 dict_nisplus->dict.name);
204 NIS_RES_OBJECT(reply)->zo_data.objdata_u
205 .en_data.en_cols.en_cols_val[dict_nisplus->column]
206 .ec_value.ec_value_val);
208 msg_info(
"%s: %s, column %d -> %s", myname,
STR(query),
209 dict_nisplus->column,
STR(retval));
210 nis_freeresult(reply);
211 return (
STR(retval));
221 if (reply->status != NIS_NOTFOUND
222 && reply->status != NIS_PARTIAL) {
223 msg_warn(
"lookup %s, NIS+ map %s: %s",
224 key, dict_nisplus->dict.name,
225 nis_sperrno(reply->status));
229 msg_info(
"%s: not found: query %s", myname,
STR(query));
231 nis_freeresult(reply);
238 static void dict_nisplus_close(
DICT *dict)
240 DICT_NISPLUS *dict_nisplus = (DICT_NISPLUS *) dict;
242 myfree(dict_nisplus->template);
252 const char *myname =
"dict_nisplus_open";
253 DICT_NISPLUS *dict_nisplus;
259 if (open_flags != O_RDONLY)
261 "%s:%s map requires O_RDONLY access mode",
268 dict_nisplus = (DICT_NISPLUS *)
270 dict_nisplus->dict.
lookup = dict_nisplus_lookup;
271 dict_nisplus->dict.close = dict_nisplus_close;
288 dict_nisplus->template =
mystrdup(map);
289 translit(dict_nisplus->template,
";",
",");
290 if ((col_field = strstr(dict_nisplus->template,
".:")) != 0) {
293 if (!
alldig(col_field) || (dict_nisplus->column = atoi(col_field)) < 1)
294 msg_fatal(
"bad column field in NIS+ map name: %s", map);
296 dict_nisplus->column = 1;
299 msg_info(
"%s: opened NIS+ table %s for column %d",
300 myname, dict_nisplus->template, dict_nisplus->column);
char * mystrdup(const char *str)
DICT * dict_nisplus_open(const char *, int, int)
char * translit(char *, const char *, const char *)
int alldig(const char *string)
#define DICT_FLAG_FOLD_FIX
VSTRING * vstring_strcpy(VSTRING *vp, const char *src)
#define VSTRING_TERMINATE(vp)
#define VSTRING_ADDCH(vp, ch)
#define DICT_OWNER_TRUSTED
#define VSTRING_RESET(vp)
void msg_warn(const char *fmt,...)
VSTRING * vstring_alloc(ssize_t len)
#define DICT_TYPE_NISPLUS
VSTRING * vstring_sprintf(VSTRING *vp, const char *format,...)
char * lowercase(char *string)
const char *(* lookup)(struct DICT *, const char *)
NORETURN msg_fatal(const char *fmt,...)
VSTRING * vstring_free(VSTRING *vp)
DICT * dict_alloc(const char *, const char *, ssize_t)
DICT * dict_surrogate(const char *dict_type, const char *dict_name, int open_flags, int dict_flags, const char *fmt,...)
void msg_info(const char *fmt,...)