Re: [patch] netcat: support --crlf

2023-08-25 Thread Andrea Biscuola
Hi op.

On Fri, 25 Aug 2023 20:14:37 +0200
Omar Polo  wrote:

> On 2023/08/25 09:07:35 -0600, "Theo de Raadt"  wrote:
> > Pietro Cerutti  wrote:
> > 
> > > The motivation is that several network protocols are line oriented
> > > with CRLF as line terminators. SMTP and HTTP are among the most
> > > popular.
> > 
> > Yet, all servers of those protocols and and will accept the simpler 1-byte
> > line terminator.
> 
> Not http at least.  Try nc www.openbsd.org 80 and type an http
> request, httpd(8) will be happily waiting for a \r.
> 
> opensmtpd is less picky and is happy with just a line feed.
> 
> (I don't have any opinion on adding a flag.  To be fair, even if it
> were added I would probably forget and just use ^V^M^M instead of RET
> to terminate the lines when manually testing something.)
> 

I don't have any skin in this game. However, It's obvious to me that nc 
shouldn't
deal with protocol-specific things and adding flags to it to accomodate such 
behaviour
just feels wrong.

Netcat is, purely, a transport tool, it is not netcat business if a bunch of 
bytes
written in it's stdin, or whatever, terminates with '\r\n', or just '\n'.



chmod(1) -f flag is still used?

2015-11-12 Thread Andrea Biscuola
Hi tech.

Digging around the tree (Yes, i want try to contribute if possible),
i found this small piece of code:


>case 'f':  /* no longer documented. */
>   fflag = 1;
>   break;

And the usage of this flag in two conditional statement in a logic
OR:

>if (ischmod) {
>   if (!fchmodat(AT_FDCWD, p->fts_accpath, oct ? omode :
>   getmode(set, p->fts_statp->st_mode), atflags)
>   || fflag)
>   continue;
>} else if (!ischflags) {
>   if (!fchownat(AT_FDCWD, p->fts_accpath, uid, gid,
>   atflags) || fflag)
>   continue;

I checked the man pages related to chmod(1), chgrp(1), chflags(1) and
chown(8) and as the comment stated, nowhere the option is mentioned.
There is a motivation why the unused -f option is still there? As the
option is not documented anymore, this mean that fflag will be false
in every documented use case.
Anyway, attached a diff usable if the option can be removed.

Regards
Index: chmod.c
===
RCS file: /cvs/src/bin/chmod/chmod.c,v
retrieving revision 1.38
diff -u -p -r1.38 chmod.c
--- chmod.c 9 Oct 2015 01:37:06 -   1.38
+++ chmod.c 12 Nov 2015 20:51:28 -
@@ -62,7 +62,7 @@ main(int argc, char *argv[])
unsigned long val;
int oct;
mode_t omode;
-   int Hflag, Lflag, Rflag, ch, fflag, fts_options, hflag, rval, atflags;
+   int Hflag, Lflag, Rflag, ch, fts_options, hflag, rval, atflags;
uid_t uid;
gid_t gid;
u_int32_t fclear, fset;
@@ -79,8 +79,8 @@ main(int argc, char *argv[])
 
uid = (uid_t)-1;
gid = (gid_t)-1;
-   Hflag = Lflag = Rflag = fflag = hflag = 0;
-   while ((ch = getopt(argc, argv, "HLPRXfghorstuwx")) != -1)
+   Hflag = Lflag = Rflag = hflag = 0;
+   while ((ch = getopt(argc, argv, "HLPRXghorstuwx")) != -1)
switch (ch) {
case 'H':
Hflag = 1;
@@ -96,9 +96,6 @@ main(int argc, char *argv[])
case 'R':
Rflag = 1;
break;
-   case 'f':   /* no longer documented. */
-   fflag = 1;
-   break;
case 'h':
hflag = 1;
break;
@@ -261,12 +258,11 @@ done:
 
if (ischmod) {
if (!fchmodat(AT_FDCWD, p->fts_accpath, oct ? omode :
-   getmode(set, p->fts_statp->st_mode), atflags)
-   || fflag)
+   getmode(set, p->fts_statp->st_mode), atflags))
continue;
} else if (!ischflags) {
if (!fchownat(AT_FDCWD, p->fts_accpath, uid, gid,
-   atflags) || fflag)
+   atflags))
continue;
} else {
if (!chflagsat(AT_FDCWD, p->fts_accpath, oct ? fset :


Small cat(1) style(9) diff

2015-11-08 Thread Andrea Biscuola
Hi tech

Here a small diff for cat(1).

1 - Added the argc decrement (as normal in the majority of the tree).
2 - Removed args name from function prototypes as stated in style(9).
3 - Enclosed a while in braces (this will be a bit more readeable).

Regards
Index: cat.c
===
RCS file: /cvs/src/bin/cat/cat.c,v
retrieving revision 1.24
diff -u -p -r1.24 cat.c
--- cat.c   4 Nov 2015 21:28:01 -   1.24
+++ cat.c   8 Nov 2015 15:51:48 -
@@ -54,9 +54,9 @@ int bflag, eflag, nflag, sflag, tflag, v
 int rval;
 char *filename;
 
-void cook_args(char *argv[]);
+void cook_args(char **);
 void cook_buf(FILE *);
-void raw_args(char *argv[]);
+void raw_args(char **);
 void raw_cat(int);
 
 int
@@ -69,7 +69,7 @@ main(int argc, char *argv[])
if (pledge("stdio rpath", NULL) == -1)
err(1, "pledge");
 
-   while ((ch = getopt(argc, argv, "benstuv")) != -1)
+   while ((ch = getopt(argc, argv, "benstuv")) != -1) {
switch (ch) {
case 'b':
bflag = nflag = 1;  /* -b implies -n */
@@ -98,6 +98,8 @@ main(int argc, char *argv[])
exit(1);
/* NOTREACHED */
}
+   }
+   argc -= optind;
argv += optind;
 
if (bflag || eflag || nflag || sflag || tflag || vflag)