ypclnt
struct ypclnt *ypclnt;
ypclnt = ypclnt_new(yp_domain, "passwd.byname", yp_server);
if (ypclnt == NULL)
if (ypclnt_connect(ypclnt) == -1) {
ypclnt_free(ypclnt);
retval = ypclnt_havepasswdd(ypclnt);
ypclnt_free(ypclnt);
ypclnt = ypclnt_new(yp_domain,
if (ypclnt == NULL) {
} else if (ypclnt_connect(ypclnt) == -1 ||
ypclnt_passwd(ypclnt, pwd, old_pass) == -1) {
openpam_log(PAM_LOG_ERROR, "%s", ypclnt->error);
ypclnt_free(ypclnt);
typedef struct ypclnt ypclnt_t;
ypclnt_connect(ypclnt_t *ypclnt)
if (ypclnt->domain == NULL) {
if ((ypclnt->domain = malloc(MAXHOSTNAMELEN)) == NULL) {
ypclnt_error(ypclnt, __func__,
if (getdomainname(ypclnt->domain, MAXHOSTNAMELEN) != 0) {
ypclnt_error(ypclnt, __func__,
if (ypclnt->map == NULL) {
ypclnt_error(ypclnt, __func__,
if (ypclnt->server == NULL) {
r = yp_master(ypclnt->domain, ypclnt->map, &ypclnt->server);
ypclnt_error(ypclnt, __func__,
ypclnt_error(ypclnt, NULL, NULL);
ypclnt_error(ypclnt_t *ypclnt, const char *func, const char *fmt, ...)
free(ypclnt->error);
ypclnt->error = NULL;
asprintf(&ypclnt->error, "%s(): %s", func, errmsg);
ypclnt_free(ypclnt_t *ypclnt)
if (ypclnt != NULL) {
free(ypclnt->domain);
free(ypclnt->map);
free(ypclnt->server);
free(ypclnt->error);
free(ypclnt);
ypclnt_t *ypclnt;
if ((ypclnt = calloc(1, sizeof *ypclnt)) == NULL)
if (domain != NULL && (ypclnt->domain = strdup(domain)) == NULL)
if (map != NULL && (ypclnt->map = strdup(map)) == NULL)
if (server != NULL && (ypclnt->server = strdup(server)) == NULL)
return (ypclnt);
free(ypclnt->domain);
free(ypclnt->map);
free(ypclnt->server);
free(ypclnt);
clnt_spcreateerror(ypclnt->server));
ypclnt_passwd(ypclnt_t *ypclnt, const struct passwd *pwd, const char *passwd)
switch (ypclnt_havepasswdd(ypclnt)) {
return (yppasswd_remote(ypclnt, pwd, passwd));
return (yppasswd_local(ypclnt, pwd));
yppasswd_local(ypclnt_t *ypclnt, const struct passwd *pwd)
yppwd.domain = strdup(ypclnt->domain);
ypclnt_error(ypclnt, __func__, "%s", strerror(errno));
ypclnt_error(ypclnt, __func__,
ypclnt_error(ypclnt, __func__,
clnt_spcreateerror(ypclnt->server));
ypclnt_error(ypclnt, __func__,
clnt_sperror(clnt, ypclnt->server));
ypclnt_error(ypclnt, __func__,
ypclnt_error(ypclnt, NULL, NULL);
yppasswd_remote(ypclnt_t *ypclnt, const struct passwd *pwd, const char *passwd)
ypclnt_error(ypclnt, __func__, "%s", strerror(errno));
clnt = clnt_create(ypclnt->server, YPPASSWDPROG, YPPASSWDVERS, "udp");
ypclnt_error(ypclnt, __func__,
clnt_spcreateerror(ypclnt->server));
ypclnt_error(ypclnt, __func__,
clnt_sperror(clnt, ypclnt->server));
ypclnt_error(ypclnt, __func__,
ypclnt_error(ypclnt, NULL, NULL);
ypclnt_havepasswdd(ypclnt_t *ypclnt)
if (getrpcport(ypclnt->server, YPPASSWDPROG,
ypclnt_error(ypclnt, __func__, "no rpc.yppasswdd on server");
ypclnt_error(ypclnt, __func__,
ypclnt_error(ypclnt, __func__,
ypclnt = ypclnt_new(yp_domain, "passwd.byname", yp_host);
master_mode = (ypclnt != NULL &&
ypclnt_connect(ypclnt) != -1 &&
ypclnt_havepasswdd(ypclnt) == 1);
ypclnt_free(ypclnt);
ypclnt = ypclnt_new(yp_domain, "passwd.byname", yp_host);
if (ypclnt == NULL) {
if (ypclnt_connect(ypclnt) == -1 ||
ypclnt_passwd(ypclnt, pw, password) == -1) {
warnx("%s", ypclnt->error);
ypclnt_free(ypclnt);
ypclnt_free(ypclnt);
struct ypclnt *ypclnt;