Dr A Olowofoyeku wrote:
On 23 Jan 00, at 2:17, Frank Heckenbach wrote:
J. David Bryan wrote:
On 21 Jan 00, at 9:58, Dr A Olowofoyeku wrote:
Your problem is probably due to things that are missing in the gcc Mingw libraries (and there are many of them).
I have tracked my specific problem down to the lack of a "pwd.h" file in Mingw (thanks, Chief!). The trouble is that "_p_pwl2c" in "rts.c" references the "passwd" struct, which is defined in "pwd.h", but "pwd.h" isn't part of Mingw. This is detected by the Pascal "configure", which sets "#undef HAVE_PWD_H" in "rts-config.h" but is not covered by alternate code in "rts.c". The result is a syntax error when compiling.
As I said, the current code (to be released as a snapshot soon) contains such a check. However, no alternate code (just a failure result) -- if there's equivalent functionality on other systems (which I don't know about), I'll have to leave it to you to add it...
Can you please let me know what the code is actually supposed to do? Perhaps there is a way to write an implementation for it, which we can include in 'os-hacks.h'.
It returns information about the user accounts on the system (i.e., not the users currently logged in, but all users who are allowed to log in). I guess on MS-Windows 95/98, there's not much point to it, but on NT, there might be...
The relevant functions and data types are:
---
NAME getpwnam, getpwuid - get password file entry
SYNOPSIS #include <pwd.h> #include <sys/types.h>
struct passwd *getpwnam(const char * name);
struct passwd *getpwuid(uid_t uid);
DESCRIPTION The getpwnam() function returns a pointer to a structure containing the broken out fields of a line from /etc/passwd for the entry that matches the user name name.
The getpwuid() function returns a pointer to a structure containing the broken out fields of a line from /etc/passwd for the entry that matches the user uid uid.
The passwd structure is defined in <pwd.h> as follows:
struct passwd { char *pw_name; /* user name */ char *pw_passwd; /* user password */ uid_t pw_uid; /* user id */ gid_t pw_gid; /* group id */ char *pw_gecos; /* real name */ char *pw_dir; /* home directory */ char *pw_shell; /* shell program */ };
RETURN VALUE The getpwnam() and getpwuid() functions return the passwd structure, or NULL if the matching entry is not found or an error occurs.
---
NAME getpwent, setpwent, endpwent - get password file entry
SYNOPSIS #include <pwd.h> #include <sys/types.h>
struct passwd *getpwent(void);
void setpwent(void);
void endpwent(void);
DESCRIPTION The getpwent() function returns a pointer to a structure containing the broken out fields of a line from /etc/passwd. The first time it is called it returns the first entry; thereafter, it returns successive entries.
The setpwent() function rewinds the file pointer to the beginning of the /etc/passwd file.
The endpwent() function closes the /etc/passwd file.
The passwd structure is defined in <pwd.h> as follows:
struct passwd { char *pw_name; /* user name */ char *pw_passwd; /* user password */ uid_t pw_uid; /* user id */ gid_t pw_gid; /* group id */ char *pw_gecos; /* real name */ char *pw_dir; /* home directory */ char *pw_shell; /* shell program */ };
RETURN VALUE The getpwent() function returns the passwd structure, or NULL if there are no more entries or an error occurs.
---
So, getpwnam and getpwuid find an entry by user name or user ID, resp., while getpwent returns all entries successively. Of course, the former to can be implemented on top of the latter, so if only the latter is available, that'll be fine.
BTW, the pw_passwd contains the password in encrypted form, of course! And on systems that use shadow, it doesn't contain anything interesting (at least for normal programs), but usually `*' or `x'. That's better security-wise, so you probably shouldn't even try to put something interesting in this field...
If it's not possible to implement them, don't worry. These functions will by marked as optional (i.e., not returning meaningful information on all systems), and programs are expected to cope with that (which will appear to them like a system with no accounts).
Frank
Hi Peter, Frank,
Here is the fsync function. I get compile errors when converting it to a macro in os-hacks.h - so please convert it for me.
int fsync (int __fd) { return FlushFileBuffers ((HANDLE) _get_osfhandle (__fd)); }
On 25 Jan 00, at 10:22, Frank Heckenbach wrote:
The relevant functions and data types are:
NAME getpwnam, getpwuid - get password file entry
SYNOPSIS #include <pwd.h> #include <sys/types.h>
struct passwd *getpwnam(const char * name);
[...]
Here is my implementation. The WinAPI calls are correct, but I am clearly not doing things correctly as far as the return values for pointers to the passwd structure is concerned - I get garbabe in the fields when I call the functions that return pointers to the passwd structure (but inside the functions themselves, when I do "printf" of the return values from the WinAPI functions, I get correct values). So the problem is how to assign the values returned by WinAPI to the fields of the structure, and how to return correctly.
The source file is attached.
Yours, Bimbo. -- Dr Abimbola A Olowofoyeku School of Law Keele University Keele ST5 5BG England. Email: laa12@keele.ac.uk
Tel: +44 (0)1782 584 363 Fax: +44 (0)1782 583 228 http://www.keele.ac.uk/depts/la/home.htm
The following section of this message contains a file attachment prepared for transmission using the Internet MIME message format. If you are using Pegasus Mail, or any another MIME-compliant system, you should be able to save it or view it from within your mailer. If you cannot, please ask your system administrator for assistance.
---- File information ----------- File: passwd.c Date: 4 Feb 2000, 17:17 Size: 5600 bytes. Type: Program-source