* Center for Telecommunications Research
* Columbia University, New York City
*
- * $Id: pw_yp.c,v 1.9 1996/02/23 04:20:19 wpaul Exp $
+ * $Id: pw_yp.c,v 1.11 1997/07/29 15:45:36 wpaul Exp $
*/
#ifdef YP
#include <pw_util.h>
#include "pw_yp.h"
#include "ypxfr_extern.h"
-#include "yppasswd_comm.h"
#include "yppasswd_private.h"
#define PERM_SECURE (S_IRUSR|S_IWUSR)
int force_old = 0;
int _use_yp = 0;
int suser_override = 0;
+int yp_in_pw_file = 0;
char *yp_domain = NULL;
char *yp_server = NULL;
bzero((char *)buf, sizeof(buf));
if ((clnt = clnt_create(server, YPPROG,YPVERS,"udp")) == NULL) {
- warnx("%s", clnt_spcreateerror("failed to create handle"));
+ warnx("failed to create UDP handle: %s",
+ clnt_spcreateerror(server));
pw_error(tempname, 0, 1);
}
bf[0] = _PW_KEYYPENABLED;
key.data = (u_char *)bf;
key.size = 1;
- if (!(dbp->get)(dbp,&key,&data,0) || (yp_domain && yp_server)) {
+ yp_in_pw_file = !(dbp->get)(dbp,&key,&data,0);
+ if (_yp_check(NULL) || (yp_domain && yp_server)) {
server = get_yp_master(0);
/* Is the user in the NIS passwd map */
return(USER_LOCAL_ONLY);
else if (!user_exists)
return(USER_UNKNOWN);
+
return(-1);
}
char *mastername;
int rval, localport;
struct stat st;
+ char *sockname = YP_SOCKNAME;
+
+ /*
+ * Sometimes we are called just to probe for rpc.yppasswdd and
+ * set the suser_override flag. Just return NULL and leave
+ * suser_override at 0 if _use_yp doesn't indicate that NIS is
+ * in use and we weren't called from use_yp() itself.
+ * Without this check, we might try probing and fail with an NIS
+ * error in non-NIS environments.
+ */
+ if ((_use_yp == USER_UNKNOWN || _use_yp == USER_LOCAL_ONLY) &&
+ getserver)
+ return(NULL);
/* Get default NIS domain. */
char *master, *password;
int *status = NULL;
struct rpc_err err;
+ char *sockname = YP_SOCKNAME;
_use_yp = 1;
master_yppasswd.newpw.pw_gecos = strdup(pw->pw_gecos);
master_yppasswd.newpw.pw_dir = strdup(pw->pw_dir);
master_yppasswd.newpw.pw_shell = strdup(pw->pw_shell);
- master_yppasswd.newpw.pw_class = strdup(pw->pw_class);
+ master_yppasswd.newpw.pw_class = pw->pw_class != NULL ?
+ strdup(pw->pw_class) : "";
master_yppasswd.oldpass = ""; /* not really needed */
master_yppasswd.domain = yp_domain;
} else {
if (suser_override) {
/* Talk to server via AF_UNIX socket. */
- if (senddat(&master_yppasswd)) {
- warnx("failed to contact local rpc.yppasswdd");
+ clnt = clnt_create(sockname, MASTER_YPPASSWDPROG,
+ MASTER_YPPASSWDVERS, "unix");
+ if (clnt == NULL) {
+ warnx("failed to contact rpc.yppasswdd: %s",
+ clnt_spcreateerror(master));
pw_error(tempname, 0, 1);
}
- /* Get return code. */
- status = getresp();
} else {
/* Create a handle to yppasswdd. */
if ((clnt = clnt_create(master, YPPASSWDPROG,
YPPASSWDVERS, "udp")) == NULL) {
- warnx("failed to contact rpc.yppasswdd on %s: %s",
- master, clnt_spcreateerror(""));
+ warnx("failed to contact rpc.yppasswdd: %s",
+ clnt_spcreateerror(master));
pw_error(tempname, 0, 1);
}
+ }
- clnt->cl_auth = authunix_create_default();
+ clnt->cl_auth = authunix_create_default();
+ if (suser_override)
+ status = yppasswdproc_update_master_1(&master_yppasswd, clnt);
+ else
status = yppasswdproc_update_1(&yppasswd, clnt);
- clnt_geterr(clnt, &err);
+ clnt_geterr(clnt, &err);
- auth_destroy(clnt->cl_auth);
- clnt_destroy(clnt);
- }
+ auth_destroy(clnt->cl_auth);
+ clnt_destroy(clnt);
/* Call failed: signal the error. */
- if ((!suser_override && err.re_status) != RPC_SUCCESS || status == NULL || *status) {
- warnx("NIS update failed: %s", (err.re_status != RPC_SUCCESS &&
- !suser_override) ? clnt_sperrno(err.re_status) :
- "rpc.yppasswdd returned error status");
+ if (err.re_status != RPC_SUCCESS || status == NULL || *status) {
+ warnx("NIS update failed: %s", clnt_sperrno(err.re_status));
pw_error(NULL, 0, 1);
}