#include <shadow.h>
#include <string.h>
#include "nis_common.h"
static int
nis_str2spent(instr, lenstr, ent, buffer, buflen)
const char *instr;
int lenstr;
void *ent;
char *buffer;
int buflen;
{
struct spwd *spwd = (struct spwd *)ent;
char *p, *q, *r;
if ((p = memchr(instr, ':', lenstr)) == 0) {
return (NSS_STR_PARSE_PARSE);
}
if ((q = memchr(p + 1, ':', lenstr - (p + 1 - instr))) == 0) {
return (NSS_STR_PARSE_PARSE);
}
if (q + 1 - instr > buflen) {
return (NSS_STR_PARSE_ERANGE);
}
(void) memcpy(buffer, instr, q - instr);
if (spwd) {
buffer[p - instr] = '\0';
buffer[q - instr] = '\0';
spwd->sp_namp = buffer;
spwd->sp_pwdp = buffer + (p + 1 - instr);
spwd->sp_lstchg = -1;
spwd->sp_min = -1;
spwd->sp_max = -1;
spwd->sp_warn = -1;
spwd->sp_inact = -1;
spwd->sp_expire = -1;
spwd->sp_flag = 0;
} else {
r = buffer + (q - instr);
*r = '\0';
if (strlcat(buffer, ":::::::", buflen) >= buflen)
return (NSS_STR_PARSE_ERANGE);
}
return (NSS_STR_PARSE_SUCCESS);
}
typedef int (*cstr2ent_t)(const char *, int, void *, char *, int);
static nss_status_t
getbyname(be, a)
nis_backend_ptr_t be;
void *a;
{
nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a;
cstr2ent_t save_c2e;
nss_status_t res;
struct spwd *spwd;
char *p;
save_c2e = argp->str2ent;
argp->str2ent = nis_str2spent;
res = _nss_nis_lookup(be, argp, 0, "passwd.byname", argp->key.name, 0);
spwd = (struct spwd *)argp->buf.result;
if (res == NSS_SUCCESS) {
if (spwd) {
if ((spwd->sp_pwdp) && (*(spwd->sp_pwdp) == '#') &&
(*(spwd->sp_pwdp + 1) == '#')) {
res = _nss_nis_lookup_rsvdport(be, argp, 0,
"passwd.adjunct.byname",
argp->key.name, 0);
}
} else {
if ((p = memchr(argp->buf.buffer, ':',
argp->buf.buflen)) == NULL)
return (NSS_STR_PARSE_PARSE);
if (strncmp(p + 1, "##", 2) == 0)
res = _nss_nis_lookup_rsvdport(be, argp, 0,
"passwd.adjunct.byname",
argp->key.name, 0);
if (res == NSS_SUCCESS) {
argp->returnval = argp->buf.buffer;
argp->returnlen = strlen(argp->buf.buffer);
}
}
}
argp->str2ent = save_c2e;
return (res);
}
#define NIS_SP_GETENT
#ifdef NIS_SP_GETENT
static nss_status_t
getent(be, a)
nis_backend_ptr_t be;
void *a;
{
nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a;
cstr2ent_t save_c2e;
nss_status_t res;
struct spwd *spwd;
char *p;
save_c2e = argp->str2ent;
argp->str2ent = nis_str2spent;
res = _nss_nis_getent_rigid(be, argp);
spwd = (struct spwd *)argp->buf.result;
if (res == NSS_SUCCESS) {
if (spwd) {
if ((spwd->sp_pwdp) && (*(spwd->sp_pwdp) == '#') &&
(*(spwd->sp_pwdp + 1) == '#')) {
res = _nss_nis_lookup_rsvdport(be, argp, 0,
"passwd.adjunct.byname",
spwd->sp_namp, 0);
}
} else {
if ((p = memchr(argp->buf.buffer, ':',
argp->buf.buflen)) == NULL)
return (NSS_STR_PARSE_PARSE);
if (strncmp(p + 1, "##", 2) == 0) {
*p = '\0';
res = _nss_nis_lookup_rsvdport(be, argp, 0,
"passwd.adjunct.byname", p, 0);
}
if (res == NSS_SUCCESS) {
argp->returnval = argp->buf.buffer;
argp->returnlen = strlen(argp->buf.buffer);
}
}
}
argp->str2ent = save_c2e;
return (res);
}
#endif
static nis_backend_op_t shadow_ops[] = {
_nss_nis_destr,
_nss_nis_endent,
_nss_nis_setent,
#ifdef NIS_SP_GETENT
getent,
#else
0,
#endif
getbyname
};
nss_backend_t *
_nss_nis_shadow_constr(dummy1, dummy2, dummy3)
const char *dummy1, *dummy2, *dummy3;
{
return (_nss_nis_constr(shadow_ops,
sizeof (shadow_ops) / sizeof (shadow_ops[0]),
"passwd.byname"));
}