#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
+#ifndef SUN_LEN
+#define SUN_LEN(su) (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path))
+#endif
#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
#ifdef HAVE_LIBREADLINE
+
#if defined(HAVE_READLINE_READLINE_H)
#include <readline/readline.h>
+#define USE_READLINE (1)
#elif defined(HAVE_READLINE_H)
#include <readline.h>
-#else /* !defined(HAVE_READLINE_H) */
-extern char *readline ();
+#define USE_READLINE (1)
#endif /* !defined(HAVE_READLINE_H) */
-char *cmdline = NULL;
-#else /* !defined(HAVE_READLINE_READLINE_H) */
- /* no readline */
+
#endif /* HAVE_LIBREADLINE */
#ifdef HAVE_READLINE_HISTORY
#if defined(HAVE_READLINE_HISTORY_H)
#include <readline/history.h>
+#define USE_READLINE_HISTORY (1)
#elif defined(HAVE_HISTORY_H)
#include <history.h>
-#else /* !defined(HAVE_HISTORY_H) */
-extern void add_history ();
-extern int write_history ();
-extern int read_history ();
+#define USE_READLINE_HISTORY (1)
#endif /* defined(HAVE_READLINE_HISTORY_H) */
- /* no history */
+
#endif /* HAVE_READLINE_HISTORY */
/*
* For configuration file stuff.
*/
-const char *radius_dir = RADDBDIR;
+char *radius_dir = RADDBDIR;
const char *progname = "radmin";
/*
socklen = SUN_LEN(&saremote);
if (connect(sockfd, (struct sockaddr *)&saremote, socklen) < 0) {
+ struct stat buf;
+
+ close(sockfd);
fprintf(stderr, "%s: Failed connecting to %s: %s\n",
progname, path, strerror(errno));
- close(sockfd);
+
+ /*
+ * The file doesn't exist. Tell the user how to
+ * fix it.
+ */
+ if ((stat(path, &buf) < 0) &&
+ (errno == ENOENT)) {
+ fprintf(stderr, " Perhaps you need to run the commands:\n\tcd /etc/raddb\n\tln -s sites-available/control-socket sites-enabled/control-socket\n and then re-start the server?\n");
+ }
+
return -1;
}
{
char *p;
ssize_t size, len;
- int flag = 1;
if (echo) {
fprintf(outputfp, "%s\n", command);
memset(buffer, 0, bufsize);
- while (flag == 1) {
+ while (1) {
int rcode;
fd_set readfds;
*p = '\0';
if (p[-1] == '\n') p[-1] = '\0';
-
- flag = 0;
break;
}
}
*/
if (input_file && !quiet && !isatty(STDIN_FILENO)) quiet = 1;
-#ifdef HAVE_LIBREADLINE
+#ifdef USE_READLINE
if (!quiet) {
+#ifdef USE_READLINE_HISTORY
using_history();
+#endif
rl_bind_key('\t', rl_insert);
}
#endif
buffer, sizeof(buffer));
if (size < 0) exit(1);
- fputs(buffer, outputfp);
- fprintf(outputfp, "\n");
- fflush(outputfp);
+ if (buffer[0]) {
+ fputs(buffer, outputfp);
+ fprintf(outputfp, "\n");
+ fflush(outputfp);
+ }
}
exit(0);
}
*/
while (1) {
-#ifndef HAVE_LIBREADLINE
+#ifndef USE_READLINE
if (!quiet) {
printf("radmin> ");
fflush(stdout);
continue;
}
+#ifdef USE_READLINE_HISTORY
add_history(line);
+#endif
} else /* quiet, or no readline */
#endif
{