#!/bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #!/bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
# xdr.c
# ypstuff.c
# This archive created: Thu Apr 27 22:18:34 1995
export PATH; PATH=/bin:$PATH
echo shar: extracting "'xdr.c'" '(1389 characters)'
if test -f 'xdr.c'
then
echo shar: over-writing existing file "'xdr.c'"
fi
sed 's/^X//' << \SHAR_EOF > 'xdr.c'
X
X/*
XFile: xdr.c
XChange History:
X94/7/19 AnnKian created for xdr_yppasswd and xdr_passwd since xdr_yppasswd
X is missing from /usr/lib/librpcsvc.a in Sol2.3.
X A pointer to the struct "passwd" must be passed to
X xdr_reference, so have to declare pw_ptr.
X pw_age and pw_comment are not used by NIS, so commented out.
X*/
X#ifdef sol2
X
X#include <rpc/rpc.h>
X#include <stdio.h>
X#include <rpcsvc/yppasswd.h>
X
Xbool_t
Xxdr_passwd(xdrs, objp)
X XDR *xdrs;
X struct passwd *objp;
X{
X if (!xdr_string(xdrs, &objp->pw_name, ~0)) { return (FALSE); }
X if (!xdr_string(xdrs, &objp->pw_passwd, ~0)) { return (FALSE); }
X if (!xdr_int(xdrs, &objp->pw_uid)) { return (FALSE); }
X if (!xdr_int(xdrs, &objp->pw_gid)) { return (FALSE); }
X/*
X if (!xdr_string(xdrs, &objp->pw_age, ~0)) { return (FALSE); }
X if (!xdr_string(xdrs, &objp->pw_comment, ~0)) { return (FALSE); }
X*/
X if (!xdr_string(xdrs, &objp->pw_gecos, ~0)) { return (FALSE); }
X if (!xdr_string(xdrs, &objp->pw_dir, ~0)) { return (FALSE); }
X if (!xdr_string(xdrs, &objp->pw_shell, ~0)) { return (FALSE); }
X return (TRUE);
X}
X
X
X
Xbool_t
Xxdr_yppasswd(xdrs, objp)
X XDR *xdrs;
X struct yppasswd *objp;
X{
X struct passwd *pw_ptr;
X pw_ptr=&objp->newpw;
X
X if (!xdr_string(xdrs, &objp->oldpass, ~0)) {
X return (FALSE);
X }
X if (!xdr_reference(xdrs, (char **)&pw_ptr, sizeof(struct passwd), xdr_passwd)) {
X return (FALSE);
X }
X
X return (TRUE);
X}
X
X#endif /* sol2 */
X
SHAR_EOF
if test 1389 -ne "`wc -c 'xdr.c'`"
then
echo shar: error transmitting "'xdr.c'" '(should have been 1389 characters)'
fi
echo shar: extracting "'ypstuff.c'" '(3743 characters)'
if test -f 'ypstuff.c'
then
echo shar: over-writing existing file "'ypstuff.c'"
fi
sed 's/^X//' << \SHAR_EOF > 'ypstuff.c'
X/* New for Sol2 */
X#include <stdio.h>
X#include <rpc/rpc.h>
X#include <rpcsvc/ypclnt.h>
X#include <pwd.h>
X#include <rpcsvc/yppasswd.h>
X#ifdef sol2
X#include <netdb.h>
X#include <netconfig.h>
X#include <sys/tiuser.h>
X#include <rpc/pmap_clnt.h>
X#define index (char *)strchr
X#endif
X/*
X * Invoke the rpc call to argv[1]. Stdin should be, on separate lines,
X * the cleartext passwd, followed by the elements of the new passwd
X * struct.
X */
X
X#define LINE_CLEAR 0
X#define LINE_NAME 1
X#define LINE_PASSWD 2
X#define LINE_UID 3
X#define LINE_GID 4
X#define LINE_AGE 5
X#define LINE_COMMENT 6
X#define LINE_GECOS 7
X#define LINE_DIR 8
X#define LINE_SHELL 9
X
Xtypedef char Line[100];
X
Xmain(argc, argv)
Xint argc;
Xchar **argv;
X{
X int rc, why;
X char *host, *s;
X Line lines[10];
X int i;
X int ypport;
X struct yppasswd ypp;
X#ifdef sol2
X struct hostent *hostentry;
X struct sockaddr_in hostaddr, *hostaddr_ptr;
X struct netconfig *udp_netconf;
X char *netid, portbuf[10];
X struct netbuf *svcport_ptr, svcport;
X
X svcport.buf=portbuf;
X svcport.maxlen=10;
X svcport_ptr=&svcport;
X#endif
X
X if (argc != 2)
X {
X printf("ERROR: args\n");
X exit(1);
X }
X
X host = argv[1];
X for (i = 0; i < 10; i++)
X {
X if (fgets(lines[i], sizeof(lines[i]), stdin) == NULL)
X {
X printf("ERROR: Short input\n");
X exit(1);
X }
X if ((s = index(lines[i], '\n')) != NULL)
X *s = 0;
X }
X
X ypp.oldpass = lines[LINE_CLEAR];
X
X ypp.newpw.pw_name = lines[LINE_NAME];
X ypp.newpw.pw_passwd = lines[LINE_PASSWD];
X ypp.newpw.pw_uid = atoi(lines[LINE_UID]);
X ypp.newpw.pw_gid = atoi(lines[LINE_GID]);
X#ifdef sun
X ypp.newpw.pw_age = lines[LINE_AGE];
X#else
X#ifndef AIX
X ypp.newpw.pw_quota = atoi(lines[LINE_AGE]);
X#endif
X#endif
X#ifndef AIX
X ypp.newpw.pw_comment = lines[LINE_COMMENT];
X#endif
X ypp.newpw.pw_gecos = lines[LINE_GECOS];
X ypp.newpw.pw_dir = lines[LINE_DIR];
X ypp.newpw.pw_shell = lines[LINE_SHELL];
X
X#ifndef sol2
X if ((ypport = getrpcport(host, YPPASSWDPROG,
X YPPASSWDPROC_UPDATE, IPPROTO_UDP)) == 0)
X {
X printf("ERROR: %s is not running ypassswdd.\n", host);
X exit(1);
X }
X#else
X/*
X **********************************************************************
X Note: rpcb_getaddr is to replace pmap_getport, but it does not
X seem to work. Still use pmap_getport. Worry about it when it
X is not supported by Solaris.
X ***********************************************************************
X */
X/*
X netid="udp";
X udp_netconf=getnetconfigent(netid);
X if (udp_netconf == NULL) printf("udp_netconfi is NULL\n");
X if (TRUE==rpcb_getaddr(YPPASSWDPROG, YPPASSWDPROC_UPDATE, udp_netconf,
X svcport_ptr, host)) printf("true\n");
X printf("svcprot_ptr=%s maxlen=%d len=%d\n",svcport_ptr->buf,svcport_ptr->maxlen,
X svcport_ptr->len);
X*/
X hostentry = gethostbyname(host);
X hostaddr.sin_family=AF_INET;
X hostaddr.sin_port=0;
X hostaddr.sin_addr.s_addr=inet_addr(inet_ntoa(hostentry->h_addr));
X hostaddr_ptr=&hostaddr;
X
X if ((ypport = pmap_getport(hostaddr_ptr, YPPASSWDPROG,
X YPPASSWDPROC_UPDATE, IPPROTO_UDP)) == 0)
X {
X printf("ERROR: %s is not running ypassswdd.\n", host);
X exit(1);
X }
X
X#endif
X
X if (ypport >= IPPORT_RESERVED)
X {
X printf("ERROR: yppasswdd on %s not privleged.\n", host);
X exit(1);
X }
X
X rc = callrpc(host, YPPASSWDPROG, YPPASSWDVERS,
X YPPASSWDPROC_UPDATE,
X xdr_yppasswd, &ypp, xdr_int, &why);
X
X if (rc > 0)
X {
X#ifdef dynix
X printf("ERROR: callrpc failed: rc=%d Dynix won't decode\n", rc);
X#else
X printf("ERROR: callrpc failed: rc=%d %s\n", rc,clnt_sperrno(rc));
X#endif
X exit(1);
X }
X
X if (why > 0)
X {
X printf("ERROR: callrpc failed: why=%d\n", why);
X exit(1);
X }
X
X printf("SUCCESS\n");
X
X exit(0);
X}
X
SHAR_EOF
if test 3743 -ne "`wc -c 'ypstuff.c'`"
then
echo shar: error transmitting "'ypstuff.c'" '(should have been 3743 characters)'
fi
# End of shell archive
exit 0