* Dave Pare, 1986
* Steve McClure, 1998
* Ron Koenderink, 2004-2007
- * Markus Armbruster, 2005-2010
+ * Markus Armbruster, 2005-2015
* Tom Dickson-Hunt, 2010
+ * Martin Haukeli, 2015
*/
#include <config.h>
#include <string.h>
#ifdef _WIN32
#include <windows.h>
+#include <shlobj.h>
#include "sys/socket.h"
#else
#include <pwd.h>
struct passwd {
char *pw_name;
+ char *pw_dir;
};
static struct passwd *w32_getpw(void);
" -r Restricted mode, no redirections\n"
" -s [HOST:]PORT Specify server HOST and PORT\n"
" -u Use UTF-8\n"
+#ifdef HAVE_LIBREADLINE
+ " -H Save readline command history to file\n"
+#endif /* HAVE_LIBREADLINE */
" -h display this help and exit\n"
" -v display version information and exit\n",
program_name);
{
int opt;
char *auxfname = NULL;
+ int use_history_file = 0;
int send_kill = 0;
char *host = NULL;
char *port = NULL;
char *country;
char *passwd;
char *uname;
+ char *udir;
char *colon;
int sock;
+ char *history_file;
- while ((opt = getopt(argc, argv, "2:krs:uhv")) != EOF) {
+ while ((opt = getopt(argc, argv, "2:Hkrs:uhv")) != EOF) {
switch (opt) {
case '2':
auxfname = optarg;
break;
+#ifdef HAVE_LIBREADLINE
+ case 'H':
+ use_history_file = 1;
+ break;
+#endif /* HAVE_LIBREADLINE */
case 'k':
send_kill = 1;
break;
if (!host)
host = empirehost;
uname = getenv("LOGNAME");
- if (uname == NULL) {
+ udir = getenv("HOME");
+ if (!uname || !udir) {
struct passwd *pwd;
pwd = getpwuid(getuid());
fprintf(stderr, "You don't exist. Go away\n");
exit(1);
}
- uname = pwd->pw_name;
+ if (!uname)
+ uname = pwd->pw_name;
+ if (!udir)
+ udir = pwd->pw_dir;
}
if (*ap) {
fprintf(stderr, "%s: extra operand %s\n", argv[0], *ap);
sock = tcp_connect(host, port);
+ if (use_history_file) {
+ /* FIXME don't truncate udir */
+ history_file = malloc(1024);
+ strncpy(history_file, udir, 1000);
+ strcat(history_file, "/.empire.history");
+ }
+
if (!login(sock, uname, country, passwd, send_kill, utf8))
exit(1);
- if (play(sock) < 0)
+ if (play(sock, history_file) < 0)
exit(1);
return 0;
#ifdef _WIN32
/*
- * Get Windows user name
+ * Get Windows user name and directory
*/
static struct passwd *
w32_getpw(void)
{
static char unamebuf[128];
+ static char udirbuf[MAX_PATH];
static struct passwd pwd;
DWORD unamesize;
pwd.pw_name = "nobody";
} else
pwd.pw_name = "nobody";
+ if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_PROFILE, NULL, 0, udirbuf))
+ && strlen(udirbuf) == 0)
+ pwd.pw_dir = udirbuf;
return &pwd;
}