Subject: Re: poppassd
To: None <netbsd-help@netbsd.org>
From: Noud de Brouwer <noud@axxes.be>
List: netbsd-help
Date: 07/13/1999 15:03:13
i've got poppassd working
given the following pwserve-5-osf1.install.sh
and poppassd.c.diff
(findpty is based on the one i found in /usr/pkgsrc/samba2)
comments welcome..,
~n
pwserve-5-osf1.install.sh:
#!/bin/csh
# extra logging
echo "local2.err /var/adm/poppassd-log" >> /etc/syslog.conf
# create log dir/file
mkdir /var/adm
touch /var/adm/poppassd-log
# create /bin/passwd
cp /usr/bin/passwd /bin/passwd
chown :bin /bin/passwd
chmod u+s /bin/passwd
# add to inetd.conf & services
echo "poppassd stream tcp nowait root /usr/local/bin/poppassd poppassd" >> /etc/inetd.conf
echo "poppassd 106/tcp" >> /etc/services
poppassd.c.diff:
*** poppassd.c.orig Mon Jul 12 15:45:41 1999
--- poppassd.c Tue Jul 13 14:29:25 1999
***************
*** 154,159 ****
--- 154,160 ----
"Changing password for *\n*'s Old password:",
"Changing password for *\nOld password: ", /* for Ultrix */
"Changing password for *.\n\nOld password:", /* for OSF/1 */
+ "Changing local password for *.\nOld password:", /* for NetBSD */
""};
static char *P2[] =
***************
*** 171,181 ****
--- 172,184 ----
"\nVerify: ", /* for Ultrix */
"\nWarning, only the first 8 characters of the password are significant.\nVerify: ", /* for Ultrix */
"\nRetype new password:", /* for OSF1 */
+ "\nPlease enter a longer password.\nNew password:", /* for NetBSD */
""};
static char *P4[] =
{"\n",
"NIS entry changed on *\n",
+ "\nRetype new password:", /* for NetBSD */
""};
***************
*** 199,205 ****
#ifdef ULTRIX
if (openlog ("poppassd", LOG_PID) < 0)
#else
! if (openlog ("poppassd", LOG_PID, LOG_LOCAL2) < 0)
#endif
{
WriteToClient ("500 Can't open syslog.");
--- 202,209 ----
#ifdef ULTRIX
if (openlog ("poppassd", LOG_PID) < 0)
#else
! openlog ("poppassd", LOG_PID, LOG_LOCAL2);
! if (0)
#endif
{
WriteToClient ("500 Can't open syslog.");
***************
*** 418,423 ****
--- 422,457 ----
return(0);
}
}
+ /*******************************************************************
+ safe string copy into a known length string. maxlength does not
+ include the terminating zero.
+ ********************************************************************/
+ char *safe_strcpy(char *dest, char *src, int maxlength)
+ {
+ int len;
+
+ if (!dest) {
+ /* DEBUG(0,("ERROR: NULL dest in safe_strcpy\n")); */
+ return NULL;
+ }
+
+ if (!src) {
+ *dest = 0;
+ return dest;
+ }
+
+ len = strlen(src);
+
+ if (len > maxlength) {
+ /* DEBUG(0,("ERROR: string overflow by %d in safe_strcpy [%.50s]\n",
+ len-maxlength, src)); */
+ len = maxlength;
+ }
+
+ memcpy(dest, src, len);
+ dest[len] = 0;
+ return dest;
+ }
/*
***************
*** 433,462 ****
* Modified by Norstad to remove assumptions about number of pty's allocated
* on this UNIX box.
*/
! findpty (slave)
! char **slave;
! {
! int master;
! static char *line = "/dev/ptyXX";
! DIR *dirp;
struct dirent *dp;
! dirp = opendir("/dev");
! while ((dp = readdir(dirp)) != NULL) {
! if (strncmp(dp->d_name, "pty", 3) == 0 && strlen(dp->d_name) == 5) {
! line[8] = dp->d_name[3];
! line[9] = dp->d_name[4];
! if ((master = open(line, O_RDWR)) >= 0) {
! line[5] = 't';
! *slave = line;
! closedir(dirp);
! return (master);
! }
}
! }
! closedir(dirp);
! return (-1);
! }
/*
* writestring()
--- 467,517 ----
* Modified by Norstad to remove assumptions about number of pty's allocated
* on this UNIX box.
*/
!
! /* static int findpty(char **slave) */
! int findpty(char **slave)
! {
! int master;
! #if defined(SVR4) || defined(SUNOS5)
! extern char *ptsname();
! #else /* defined(SVR4) || defined(SUNOS5) */
! static char line[12];
! void *dirp;
! /* char *dpname; */
struct dirent *dp;
! #endif /* defined(SVR4) || defined(SUNOS5) */
!
! #if defined(SVR4) || defined(SUNOS5)
! if ((master = open("/dev/ptmx", O_RDWR)) >= 1) {
! grantpt(master);
! unlockpt(master);
! *slave = ptsname(master);
! return (master);
! }
! #else /* defined(SVR4) || defined(SUNOS5) */
! safe_strcpy( line, "/dev/ptyXX", sizeof(line)-1 );
!
! dirp = opendir("/dev");
! if (!dirp) return(-1);
! while ((dp = readdir(dirp)) != NULL) {
! if (strncmp(dp->d_name, "pty", 3) == 0 && strlen(dp->d_name) == 5) {
! /* DEBUG(3,("pty: try to open %s, line was %s\n", dpname, line ) ); */
! line[8] = dp->d_name[3];
! line[9] = dp->d_name[4];
! if ((master = open(line, O_RDWR)) >= 0) {
! /* DEBUG(3,("pty: opened %s\n", line ) ); */
! line[5] = 't';
! *slave = line;
! closedir(dirp);
! return (master);
}
! }
! }
! closedir(dirp);
! #endif /* defined(SVR4) || defined(SUNOS5) */
! return (-1);
! }
/*
* writestring()
***************
*** 512,517 ****
--- 567,577 ----
if (!expect(master, P4, buf)) return FAILURE;
+ if (strcmp(buf, "\n") != 0) {
+ sprintf(pswd, "%s\n", newpass);
+ writestring(master, pswd);
+ if (!expect(master, P4, buf)) return FAILURE;
+ }
return SUCCESS;
}