[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#4666: popclient argument/poprc processing



Package: popclient
Version: 3.05-3

While trying out popclient 3.05 I found some bugs in the command line
argument / poprc processing. The patches I made are included at the
bottom of this mail. Some items addressed there:

o poprc options nokeep, noflush, nofetchall:
	These options didn't change the (true) defaults because bison
	silently ignores a 0 value of a token, and so flex returned a
	non-0 value for ``FALSE'' (token in poprc_y.y). 

o --norewrite (command line):
	The default was _not_ to rewrite sender's addresses because it's
	impossible in the current program structure to implement a
	non-zero default for a flag. I changed this flag to --rewrite
	(unset by default), so one can enable rewriting if desired.

o poprc option mda:
	The internal variable char *mda_argv[] is limited to 32 entries,
	but there was no test for index overflow while parsing the mda
	option. While it's unlike to need as much arguments, it's of
	potential danger for a program that may be installed setuid
	root.
	There are some more problems with mda mentioned in the BUGS
	section of the man page now. 
	The arguments are printed now on --version.

Regards
	Herbert.

diff -u --recursive popclient-3.05-org/Makefile.in popclient-3.05/Makefile.in
--- popclient-3.05-org/Makefile.in	Thu Aug 29 00:34:41 1996
+++ popclient-3.05/Makefile.in	Tue Oct  1 18:38:08 1996
@@ -156,7 +156,8 @@
 .PHONY: clean realclean distclean mostlyclean
 clean: 
 	-rm -f popclient *.o core popclient.dvi \
-	       poprc_l.c poprc_y.h poprc_y.c popclient.tar popclient.tar.gz
+	       poprc_l.c poprc_y.h poprc_y.c popclient.tar popclient.tar.gz \
+	       y.output
 
 distclean: clean 
 	-rm -f Makefile config.h
diff -u --recursive popclient-3.05-org/options.c popclient-3.05/options.c
--- popclient-3.05-org/options.c	Thu Aug 29 00:34:41 1996
+++ popclient-3.05/options.c	Tue Oct  1 16:23:38 1996
@@ -40,10 +40,10 @@
 #define LA_MDA		17
 #define LA_LOGFILE	18
 #define LA_QUIT		19
-#define LA_NOREWRITE	20
+#define LA_REWRITE	20
 #define LA_YYDEBUG	21
  
-static char *shortoptions = "23VaKkvscl:Fd:f:u:r:o:m:L:qN";
+static char *shortoptions = "23VaKkvscl:Fd:f:u:r:o:m:L:qR";
 static struct option longoptions[] = {
   {"version",   no_argument,       (int *) 0, LA_VERSION    },
   {"all",	no_argument,       (int *) 0, LA_ALL        },
@@ -66,7 +66,7 @@
   {"logfile",	required_argument, (int *) 0, LA_LOGFILE    },
   {"idfile",	required_argument, (int *) 0, LA_IDFILE     },
   {"quit",	no_argument,	   (int *) 0, LA_QUIT       },
-  {"norewrite",	no_argument,	   (int *) 0, LA_NOREWRITE  },
+  {"rewrite",	no_argument,	   (int *) 0, LA_REWRITE    },
   {"yydebug",	no_argument,	   (int *) 0, LA_YYDEBUG    },
   {(char *) 0,  no_argument,       (int *) 0, 0             }
 };
@@ -227,9 +227,9 @@
       case LA_QUIT:
         quitmode = 1;
         break;
-      case 'N':
-      case LA_NOREWRITE:
-	queryctl->rewrite = 0;
+      case 'R':
+      case LA_REWRITE:
+	queryctl->rewrite = 1;
 	break;
       case LA_YYDEBUG:
 	yydebug = 1;
@@ -265,6 +265,8 @@
     fputs("  -o, --local      specify filename for received mail\n", stderr);
     fputs("  -r, --remote     specify remote folder name\n", stderr);
     fputs("  -L, --logfile    specify logfile name\n", stderr);
+    fputs("  -R, --rewrite    rewrite local sender's addresses (POP3 only)\n",
+	    stderr);
     return(-1);
   }
   else {
@@ -311,7 +313,7 @@
 #else
   queryctl->keep = 0;
 #endif
-  queryctl->rewrite = 1;
+  queryctl->rewrite = 0;
 
   strcpy(queryctl->localname,pw->pw_name);
   strcpy(queryctl->remotename,pw->pw_name);
diff -u --recursive popclient-3.05-org/popclient.c popclient-3.05/popclient.c
--- popclient-3.05-org/popclient.c	Thu Aug 29 00:34:41 1996
+++ popclient-3.05/popclient.c	Tue Oct  1 16:25:47 1996
@@ -16,6 +16,7 @@
 #include <config.h>
 
 #include <stdio.h>
+#include <assert.h>
 
 #if defined(STDC_HEADERS)
 #include <stdlib.h>
@@ -39,7 +40,7 @@
 #include "popclient.h"
 
 /* release info */
-#define         RELEASE_TAG	"3.05"
+#define         RELEASE_TAG	"3.05ht"
 
 #ifdef HAVE_PROTOTYPES
 /* prototypes for internal functions */
@@ -66,7 +67,8 @@
 int versioninfo;	/* emit only version info */
 
 /* args for the MDA, parsed out in the usual fashion by parseMDAargs() */
-char *mda_argv [32];
+#define MDA_ARG_MAX 31
+char *mda_argv [MDA_ARG_MAX+1];
 
 /*********************************************************************
   function:      main
@@ -234,8 +236,11 @@
 	   * consistently bombs after the first delivery.
 	   */
 	  if (hostp->output == TO_MDA
-			&& strncmp("/usr/lib/sendmail", hostp->mda, 18) == 0)
+			&& strncmp("/usr/lib/sendmail", hostp->mda, 18) == 0) {
 	      hostp->output = TO_FOLDER;
+	      fprintf(stderr,
+"popclient: writing directly to folder instead of using /usr/lib/sendmail\n");
+	  }
 
 	  popstatus = query_host(hostp);
       }
@@ -327,6 +332,8 @@
 int dump_params (queryctl)
 struct hostrec *queryctl;
 {
+  int i;
+
   printf("  Username = '%s'\n", queryctl->remotename);
   printf("  Password = '%s'\n", queryctl->password);
 
@@ -341,6 +348,9 @@
   default: printf("unknown?!?\n"); break;
   }
 
+  printf("  Local POP host mail adresses will%s be expanded (--rewrite %s).\n",
+	 queryctl->rewrite ? "" : " not",
+	 queryctl->rewrite ? "on" : "off");
   printf("  Fetched messages will%s be kept on the server (--keep %s).\n",
 	 queryctl->keep ? "" : " not",
 	 queryctl->keep ? "on" : "off");
@@ -358,6 +368,12 @@
     break;
   case TO_MDA:
     printf("  Messages will be delivered with %s\n", queryctl->mda);
+    printf("    MDA arguments: ");
+    for( i=0; mda_argv[i]!=0; i++ ) {
+      assert(i < MDA_ARG_MAX);
+      printf("%s ", mda_argv[i]);
+    }
+    printf("\n");
     break;
   case TO_STDOUT:
     printf("  Messages will be dumped to standard output\n");
@@ -459,7 +475,7 @@
       exit(1);
     }
 
-    execv(queryctl->mda, mda_argv+1);
+    execv(queryctl->mda, mda_argv);
 
     /* if we got here, an error occurred */
     perror("popclient: openmailpipe: exec");
@@ -559,18 +575,30 @@
   mda_argv[0] = argp ? (argp + 1) : queryctl->mda;
   
   argp = queryctl->mda;
-  while (*argp != '\0' && isspace(*argp))	/* skip null first arg */
-    argp++;					
+  while (*argp != '\0' && !isspace(*argp))	/* skip first arg */
+    argp++;
+  if (*argp != '\0')				/* punch in a null terminator */
+    *(argp++) = '\0';
 
   /* now punch nulls into the delimiting whitespace in the args */
   for (argi = 1;  
        *argp != '\0';
        argi++) {
 
+    if (argi == MDA_ARG_MAX) {
+	fprintf(stderr, "popclient: more than %d MDA arguments, aborting\n",
+	        MDA_ARG_MAX-1);
+	exit(PS_SYNTAX);
+    }
+
+    /* find start of this argument */
+    while (*argp != '\0' && isspace(*argp))
+      argp++;
+
     mda_argv[argi] = argp;     /* store pointer to this argument */
 
     /* find end of this argument */
-    while (!(*argp == '\0' || isspace(*argp)))
+    while (*argp != '\0' && !isspace(*argp))
       argp++;
 
     /* punch in a null terminator */
@@ -586,13 +614,11 @@
   description:   hack message headers so replies will work properly
 
   arguments:
-    after        where to put the hacked header
-    before       header to hack
+    buf          buffer with message header to modify
     host         name of the pop header
 
   return value:  none.
   calls:         none.
-  globals:       writes mda_argv.
  *********************************************************************/
 
 void reply_hack(buf, host)
diff -u --recursive popclient-3.05-org/popclient.man popclient-3.05/popclient.man
--- popclient-3.05-org/popclient.man	Thu Aug 29 00:34:41 1996
+++ popclient-3.05/popclient.man	Tue Oct  1 18:33:19 1996
@@ -171,15 +171,13 @@
 causes normal progress/status messages which would be redundant or meaningless
 to be modified or omitted.
 .TP
-.B \-N, --norewrite
-Normally,
-.I popclient
-edits RFC-822 address headers (To, From, Cc, Bcc, and Reply-To) in
+.B \-R, --rewrite
+Edit RFC-822 address headers (To, From, Cc, Bcc, and Reply-To) in
 fetched mail so that any mail IDs local to the host are expanded to
 full addresses (@ and the POP host name are appended).  This enables 
 replies on the client to get addressed correctly (otherwise your
 mailer might think they should be addressed to local users on the
-client machine).  This option disables the rewrite.
+client machine).  Default is not to rewrite address headers.
 .TP
 .B \-V, --version
 Displays the version information for your copy of 
@@ -542,15 +540,23 @@
 (used only with newer RFC1725-compliant servers supporting the UIDL command).
 .SH BUGS
 .PP
-The --version option doesn't display MDA arguments.
+The
+.B \--rewrite
+option works for POP3 only.
+.PP
+The arguments of the last MDA defined are used for all MDA's.  This needs
+to be fixed.
+.PP
+%s doesn't get expanded in MDA arguments.
 .PP
 Delivery via
 .IR sendmail (8)
 doesn't work in daemon mode;
 .I popmail
 dies after the first delivery.  To cope with this, in daemon mode the
-delivery mode is automatically switched to append-and-lock if sendmail
-is the selected delivery agent.  This needs to be fixed.
+delivery mode is automatically switched to append-and-lock if /usr/lib/sendmail
+is the selected delivery agent, and a warning is written to stderr.
+This needs to be fixed.
 .PP
 The UIDL support for RFC1725-compliant servers is not yet well tested.
 .PP
diff -u --recursive popclient-3.05-org/poprc.c popclient-3.05/poprc.c
--- popclient-3.05-org/poprc.c	Thu Aug 29 00:34:41 1996
+++ popclient-3.05/poprc.c	Tue Oct  1 16:19:07 1996
@@ -468,9 +468,7 @@
 #undef STR_OPTION_MERGE
 
       /* merge in options */
-#define FLAG_OPTION_MERGE(fld)	\
-				if (!mrg_opts->fld && sp_node->fld) \
-				  mrg_opts->fld = 1;
+#define FLAG_OPTION_MERGE(fld)	mrg_opts->fld |= sp_node->fld;
       FLAG_OPTION_MERGE(keep);
       FLAG_OPTION_MERGE(flush);
       FLAG_OPTION_MERGE(fetchall);
diff -u --recursive popclient-3.05-org/poprc_l.l popclient-3.05/poprc_l.l
--- popclient-3.05-org/poprc_l.l	Thu Aug 29 00:34:42 1996
+++ popclient-3.05/poprc_l.l	Tue Oct  1 10:25:07 1996
@@ -32,14 +32,14 @@
 remote(folder)? { return KW_REMOTEFOLDER; }
 local(folder)?	{ return KW_LOCALFOLDER; }
 mda		{ return KW_MDA; }
-keep		{ yylval.flag = TRUE; return KW_KEEP; }
-flush		{ yylval.flag = TRUE; return KW_FLUSH; }
-fetchall	{ yylval.flag = TRUE; return KW_FETCHALL; }
-rewrite		{ yylval.flag = TRUE; return KW_REWRITE; }
-nokeep		{ yylval.flag = FALSE; return KW_KEEP; }
-noflush		{ yylval.flag = FALSE; return KW_FLUSH; }
-nofetchall	{ yylval.flag = FALSE; return KW_FETCHALL; }
-norewrite	{ yylval.flag = FALSE; return KW_REWRITE; }
+keep		{ yylval.flag = PARAM_TRUE; return KW_KEEP; }
+flush		{ yylval.flag = PARAM_TRUE; return KW_FLUSH; }
+fetchall	{ yylval.flag = PARAM_TRUE; return KW_FETCHALL; }
+rewrite		{ yylval.flag = PARAM_TRUE; return KW_REWRITE; }
+nokeep		{ yylval.flag = PARAM_FALSE; return KW_KEEP; }
+noflush		{ yylval.flag = PARAM_FALSE; return KW_FLUSH; }
+nofetchall	{ yylval.flag = PARAM_FALSE; return KW_FETCHALL; }
+norewrite	{ yylval.flag = PARAM_FALSE; return KW_REWRITE; }
 
 (pop2)|(POP2)	{ yylval.proto = P_POP2;  return PROTO_POP2; }
 (pop3)|(POP3)	{ yylval.proto = P_POP3;  return PROTO_POP3; }
diff -u --recursive popclient-3.05-org/poprc_y.y popclient-3.05/poprc_y.y
--- popclient-3.05-org/poprc_y.y	Thu Aug 29 00:34:42 1996
+++ popclient-3.05/poprc_y.y	Tue Oct  1 16:19:24 1996
@@ -37,8 +37,8 @@
 %type <proto> proto;
 
 /* these are actually used by the lexer */
-%token TRUE	1
-%token FALSE	0
+%token PARAM_TRUE
+%token PARAM_FALSE
 
 %%
 
@@ -69,10 +69,10 @@
 	|	KW_REMOTEFOLDER PARAM_STRING	{prc_setremote($2);}
 	|	KW_LOCALFOLDER PARAM_STRING	{prc_setlocal($2);}
 	|	KW_MDA PARAM_STRING		{prc_setmda($2);}
-	|	KW_KEEP				{prc_setkeep($1);}
-	|	KW_FLUSH			{prc_setflush($1);}
-	|	KW_FETCHALL			{prc_setfetchall($1);}
-	|	KW_REWRITE			{prc_setrewrite($1);}
+	|	KW_KEEP				{prc_setkeep($1==PARAM_TRUE);}
+	|	KW_FLUSH			{prc_setflush($1==PARAM_TRUE);}
+	|	KW_FETCHALL		{prc_setfetchall($1==PARAM_TRUE);}
+	|	KW_REWRITE		{prc_setrewrite($1==PARAM_TRUE);}
   ;
 
 proto:		PROTO_POP2
diff -u --recursive popclient-3.05-org/sample.poprc popclient-3.05/sample.poprc
--- popclient-3.05-org/sample.poprc	Thu Aug 29 00:34:41 1996
+++ popclient-3.05/sample.poprc	Tue Oct  1 18:38:30 1996
@@ -29,9 +29,11 @@
 #   keep
 #   flush
 #   fetchall
+#   rewrite
 #   nokeep
 #   noflush
 #   nofetchall
+#   norewrite
 #
 # Legal protocol identifiers are
 #   pop2 (or POP2)

--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-devel-REQUEST@lists.debian.org . Trouble? e-mail to Bruce@Pixar.com


Reply to: