5 * Author: ppessi <Pekka.Pessi@hut.fi>
6 * Pavel Fedin <sonic_amiga@rambler.ru>
8 * Copyright © 1994 AmiTCP/IP Group, <amitcp-group@hut.fi>,
9 * Helsinki University of Technology, Finland.
10 * All rights reserved.
11 * Copyright © 2005 Pavel Fedin
13 * Created : Wed Jan 12 01:40:38 1994 ppessi
14 * Last modified: Thu Sep 29 22:29:20 2005 sonic
17 //#include "whoami_rev.h"
19 static const char version
[] = "$VER: whoami 1.3 (29.09.2005)\n"
20 "Copyright © 1994 AmiTCP/IP Group, <amitcp-group@hut.fi>\n"
21 "Helsinki University of Technology, Finland.\n"
22 "Copyright © 2005 Pavel Fedin\n";
24 /****** utilities/whoami ***************************************************
27 whoami - prints effective current user id
36 Whoami prints your effective user id. It works even if you are
40 Whoami return WARN, if the user id has got no user name associated.
45 *****************************************************************************
49 #define USE_INLINE_STDARG
51 #include <exec/types.h>
52 #include <exec/ports.h>
53 #include <exec/semaphores.h>
54 #include <exec/memory.h>
55 #include <exec/execbase.h>
58 #include <dos/dosextens.h>
61 #include <clib/exec_protos.h>
62 extern struct ExecBase
* SysBase
;
63 #include <pragmas/exec_sysbase_pragmas.h>
65 #include <proto/exec.h>
67 #include <proto/dos.h>
68 #include <proto/usergroup.h>
69 #include <libraries/usergroup.h>
71 #include <devices/sana2.h>
72 #include <net/sana2errno.h>
75 #define USERGROUPVERSION 1 /* minimum version to use */
78 #define MAXLINELENGTH 1024
88 struct DosLibrary
*DOSBase
;
89 struct ExecBase
*SysBase
;
91 SysBase
= *(struct ExecBase
**)4;
92 DOSBase
= (struct DosLibrary
*)OpenLibrary("dos.library", 37L);
95 struct Library
*UserGroupBase
=
96 OpenLibrary("usergroup.library", USERGROUPVERSION
);
98 if (UserGroupBase
!= NULL
) {
99 uid_t uid
= geteuid();
100 struct passwd
*pw
= getpwuid(uid
);
103 Printf("%s\n", (ULONG
)pw
->pw_name
);
106 Printf("whoami: no login associated with uid %lu.\n", uid
);
107 retval
= RETURN_WARN
;
110 // CloseLibrary(UserGroupBase);
112 Printf("whoami: cannot open usergroup.library\n");
115 CloseLibrary((struct Library
*)DOSBase
);