cozclient strange output format for ls -l month abbrev

Discussion of Co:Z sftp, a port of OpenSSH sftp for z/OS
Post Reply
Jeno
Posts: 23
Joined: Wed Oct 03, 2007 5:28 am

cozclient strange output format for ls -l month abbrev

Post by Jeno »

Hello,

We appreciate the coz version of sftp very much.
Found the following two minor minor problems while testing:

1) cozsftp client reports user ids in response to s 'ls -l' command. However, for the practically same 'ls -l *' command, the numeric gid values are included instead - this is at least a bit surprising ;)
(note that openssh client returns numeric values in both cases. I would rather prefer userids ;) )

2) for month abbreviations longer than 3 char (e.g. SZEPT for september in the hungarian locale), coz-client connecting to coz-server, 'ls -l' output completely ignores the date stamp. This leads to lthree less words reported, that may cause problems for scripts evaluating sftp output (e.g. delete old files on the remote host).
Note that openssh server seems to force C or POSIX locale for date.
  • Co:Z sftp version: 1.1.1-Beta (5.0p1) 2008-11-17 ------> openssh server
    -rw-r--r-- 1 CONTROLM OMVSGRP 2 SZEPT 5 00:55 syslog.pid

    ----- openssh client ---> openssh server
    -rw-r--r-- 1 0 1 2 Sep 5 00:55 syslog.pid

    Co:Z sftp version: 1.1.1-Beta (5.0p1) 2008-11-17 ----> coz server
    -rwxr-xr-x 1 jvago SYSADMIN 2523 rc

    ----- openssh client ---> coz server
    -rwxr-xr-x 0 213 65 2523 Sep 27 2005 rc
Compliments for the very good job done
Best regards Jenö
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail »

(1) Newer versions of Openssh will return a formatted "long name" for directory listings that use the "READDIR" packets. Since Co:Z SFTP is based on OpenSSH 5.0p1, it includes this feature. The difference that you are seeing is that for 'ls -l *' it is doing individual "STAT" packets, and sftp-server doesn't return a formatted "long name" for those. So, what you are seeing is unfortunately how it also works on other OpenSSH systems.
We will try to ask the OpenSSH upstream maintainers if this is by design or a bug, but we will wait to patch our port until we are sure that doing so will not affect other ssh clients.

(2) This is related somewhat to (1) - when the Co:Z sftp-server formats the date part of the long name it uses the "strftime()" function. Our port was using the wrong version of this function. This has been fixed in the latest release (1.2.1)
Jeno
Posts: 23
Joined: Wed Oct 03, 2007 5:28 am

Post by Jeno »

Sorry, but even after installing 1.2.1, I still get no date fields for 'ls -l' if the month name is longer than three characters. For me, it seems to be tha same as in my originalreport. Upon your reply, and upon the announcement to 1.2.1, this should have been fixed.
Best regards, Jenö
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail »

The sftp-server is where the name is formatted with strftime(). Are you sure that the process running the Co:Z sftp-server has it's locale setup the same way as the IBM openssh sftp-server?

We don't have a machine with Hungarian locale enabled/installed, so it is a little difficult for us to test this. We have verified, however, that the new release is calling IBM's strftime() from the C-library. The "%b" format code seems to be broken for long months.

Please double check your setup and let us know. If the problem can't be found, we might send you a test case that verifies that IBM's strftime() is broken (or why it works in IBM's OpenSSH port... they may have done something special other than calling the standard C-library routine)
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail »

One clarification: Are you saying that you see Hungarian month names if the are less than 3 chars?
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail »

We were able to test strftime() on a system that supported LANG=hu_HU and it seems to work. Can you test the following to see if strftime() is working in the server environment where you see the date fields disappear?

Code: Select all

#define _POSIX1_SOURCE 2
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <langinfo.h>
#include <locale.h>

int main(int argc, char** argv) {
	char dest[70];
	int ch;
	time_t temp;
	struct tm *timeptr;
	
	setlocale(LC_ALL, ""); /* sets locale to default */
	setenv("_EDC_ADD_ERRNO2", "1", 1); 
	
	temp = time(NULL);
	timeptr = localtime(&temp);
	ch = strftime(dest,sizeof(dest)-1,"Today is %A,"
			" %b %d. Time: %I:%M %p", timeptr);
	if (ch) {
		printf("%s \n", dest);
	} else {
		perror("strftime error");
	}

	timeptr->tm_mon = 8; 
	ch = strftime(dest,sizeof(dest)-1,"Sept day is %A,"
	             " %b %d. Time: %I:%M %p", timeptr);
	if (ch) {
		printf("%s \n", dest);
	} else {
		perror("strftime error");
	}

}
You can compile this with:

cc -o tstrftime tstrftime.c

If you don't have a C compiler, drop me an email at info@dovetail.com and I'll send you a binary.
Jeno
Posts: 23
Joined: Wed Oct 03, 2007 5:28 am

Post by Jeno »

Hello, thank you for the suggestions.

1) The code snipplet works fine.

2) Now I double-checked my tests. Now all four tests were using hungarian locale, on both the client and server side.
- Only coz-client to coz-server loses the three words for long month names, while three-char hungarian names still correctly appear.
- All other three combinations (non-coz client and/or non-coz server) correctly report also the long monthnames.

Best regards, Jenö
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail »

When listing a directory, both the IBM sftp-server and the Co:Z sftp-server generate "long names" in the response packets. Only the Co:Z sftp client actually displays this long name, whereas the IBM sftp client reformats the information, including the date.

What you seem to be seeing then, is the IBM sftp-server generating a "long name" that contains a nicely formatted date, whereas the Co:Z sftp-server is somehow failing. The strftime() is what seems to be going wrong, but it is hard to explain since it is using the same strftime() call as the code snippet.

Let me do a little more digging to see if I can reproduce what you are seeing. We did have some trouble getting our system to run a Hungarian locale, but I think that I have a fix for that.

Thanks for your patience.
Jeno
Posts: 23
Joined: Wed Oct 03, 2007 5:28 am

Post by Jeno »

Hello, please also note that connecting to coz-server using the openssh client, the date is also properly formatted. So for me, it does not seem a simple server-only issue ;)

Best regards, Jenö
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail »

Connecting the openssh-client to the coz sftp-server probably works because the IBM openssh client formats the date itself, and doesn't use the longname returned by the server.

I'm having problems getting the Co:Z sftp-server to run at all under Hungarian... can you please tell me how you have your locale related environment variables set? (LANG, LC_ALL, LC_SYNTAX, TZ, etc).
Jeno
Posts: 23
Joined: Wed Oct 03, 2007 5:28 am

Post by Jeno »

in SYS1.PARMLIB(CEEPRM00) , we use
ENVAR('LANG=C',
'LC_ALL=Hu_HU.IBM-1165',
'TZ=CET-1CEST,M3.5.0,M10.5.0/03:00:00'),
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail »

We found the problem! It turned out to be a bug in the base OpenSSH code (version 5.0p). strftime() wasn't the problem... the date buffer was too small. I should have seen that before :-)

If this is a big problem for you, we can make a new build, otherwise we will roll it into the next maintenance release.
Jeno
Posts: 23
Joined: Wed Oct 03, 2007 5:28 am

Post by Jeno »

Fine, I am glad you have found it. IMHO, in many cases, such errors reveal another problem of bigger importance ;) .
It is not that important for us, I can live with forcing sftp to run under LC_ALL=En_US .

Thank you and best regards, Jenö
Post Reply