Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / network / common / C / whoami.c
bloba36fedd19ddb44ea9fb2cf51fbc0bda7670e39b2
1 /* $Id$
2 /*
3 * whoami.c ---
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 ***************************************************
26 NAME
27 whoami - prints effective current user id
29 VERSION
30 $Id$
32 TEMPLATE
33 whoami
35 FUNCTION
36 Whoami prints your effective user id. It works even if you are
37 su'd.
39 RETURN VALUE
40 Whoami return WARN, if the user id has got no user name associated.
42 SEE ALSO
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>
57 #include <dos/dos.h>
58 #include <dos/dosextens.h>
60 #ifdef __SASC
61 #include <clib/exec_protos.h>
62 extern struct ExecBase* SysBase;
63 #include <pragmas/exec_sysbase_pragmas.h>
64 #else
65 #include <proto/exec.h>
66 #endif
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>
73 #include <string.h>
75 #define USERGROUPVERSION 1 /* minimum version to use */
77 #ifndef MAXLINELENGTH
78 #define MAXLINELENGTH 1024
79 #endif
81 #ifdef __MORPHOS__
82 ULONG __abox__ = 1;
83 #endif
85 LONG whoami(void)
87 LONG retval = 128;
88 struct DosLibrary *DOSBase;
89 struct ExecBase *SysBase;
91 SysBase = *(struct ExecBase**)4;
92 DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 37L);
94 if (DOSBase) {
95 struct Library *UserGroupBase =
96 OpenLibrary("usergroup.library", USERGROUPVERSION);
98 if (UserGroupBase != NULL) {
99 uid_t uid = geteuid();
100 struct passwd *pw = getpwuid(uid);
102 if (pw != NULL) {
103 Printf("%s\n", (ULONG)pw->pw_name);
104 retval = RETURN_OK;
105 } else {
106 Printf("whoami: no login associated with uid %lu.\n", uid);
107 retval = RETURN_WARN;
110 // CloseLibrary(UserGroupBase);
111 } else {
112 Printf("whoami: cannot open usergroup.library\n");
115 CloseLibrary((struct Library *)DOSBase);
118 return retval;