]> andersk Git - moira.git/commitdiff
Win32 portability mods for Pismere.
authorrbasch <rbasch>
Wed, 15 Mar 2000 22:43:31 +0000 (22:43 +0000)
committerrbasch <rbasch>
Wed, 15 Mar 2000 22:43:31 +0000 (22:43 +0000)
27 files changed:
clients/addusr/addusr.c
clients/blanche/blanche.c
clients/lib/pobox.c
clients/mailmaint/mailmaint.c
clients/moira/acl.c
clients/moira/attach.c
clients/moira/cluster.c
clients/moira/lists.c
clients/moira/main.c
clients/moira/menu.c
clients/moira/misc.c
clients/moira/pobox.c
clients/moira/printer.c
clients/moira/user.c
clients/moira/utils.c
clients/mrcheck/mrcheck.c
clients/mrtest/mrtest.c
clients/passwd/chfn.c
clients/passwd/chpobox.c
clients/stella/stella.c
configure
configure.in
include/moira.h
lib/fixhost.c
lib/mr_call.c
lib/mr_connect.c
lib/mr_private.h

index eef20b87fe36bede1ba97115c704fe6fa770ab0d..fe1ffc1609fff080df4bb93ba8d1b20a6876f2e9 100644 (file)
@@ -46,7 +46,7 @@ int main(int argc, char **argv)
   int status, lineno;
   char **arg = argv, *qargv[U_END];
   char *p, *first, *middle, *last, *id, *login, *server;
-  char buf[BUFSIZ], idbuf[32];
+  char buf[BUFSIZ];
   FILE *input;
 
   /* clear all flags & lists */
index e573a4ef6778d4444ca38e76e027e2f425c32144..b6239bfaebe57526f967b78952521ceaa1342688 100644 (file)
@@ -826,39 +826,40 @@ int main(int argc, char **argv)
 
 void usage(char **argv)
 {
+#define USAGE_OPTIONS_FORMAT "  %-39s%s\n"
   fprintf(stderr, "Usage: %s listname [options]\n", argv[0]);
   fprintf(stderr, "Options are\n");
-  fprintf(stderr, "  %-39s%-39s\n", "-v  | -verbose",
+  fprintf(stderr, USAGE_OPTIONS_FORMAT, "-v  | -verbose",
          "-C  | -create");
-  fprintf(stderr, "  %-39s%-39s\n", "-m  | -members",
+  fprintf(stderr, USAGE_OPTIONS_FORMAT, "-m  | -members",
          "-R  | -rename newname");
-  fprintf(stderr, "  %-39s%-39s\n", "-u  | -users",
+  fprintf(stderr, USAGE_OPTIONS_FORMAT, "-u  | -users",
          "-P  | -public");
-  fprintf(stderr, "  %-39s%-39s\n", "-l  | -lists",
+  fprintf(stderr, USAGE_OPTIONS_FORMAT, "-l  | -lists",
          "-NP | -private");
-  fprintf(stderr, "  %-39s%-39s\n", "-s  | -strings",
+  fprintf(stderr, USAGE_OPTIONS_FORMAT, "-s  | -strings",
          "-A  | -active");
-  fprintf(stderr, "  %-39s%-39s\n", "-k  | -kerberos",
+  fprintf(stderr, USAGE_OPTIONS_FORMAT, "-k  | -kerberos",
          "-I  | -inactive");
-  fprintf(stderr, "  %-39s%-39s\n", "-i  | -info",
+  fprintf(stderr, USAGE_OPTIONS_FORMAT, "-i  | -info",
          "-V  | -visible");
-  fprintf(stderr, "  %-39s%-39s\n", "-r  | -recursive",
+  fprintf(stderr, USAGE_OPTIONS_FORMAT, "-r  | -recursive",
          "-H  | -hidden");
-  fprintf(stderr, "  %-39s%-39s\n", "-a  | -add member",
+  fprintf(stderr, USAGE_OPTIONS_FORMAT, "-a  | -add member",
          "-M  | -mail");
-  fprintf(stderr, "  %-39s%-39s\n", "-d  | -delete member",
+  fprintf(stderr, USAGE_OPTIONS_FORMAT, "-d  | -delete member",
          "-NM | -notmail");
-  fprintf(stderr, "  %-39s%-39s\n", "-al | -addlist filename",
+  fprintf(stderr, USAGE_OPTIONS_FORMAT, "-al | -addlist filename",
          "-G  | -group");
-  fprintf(stderr, "  %-39s%-39s\n", "-dl | -deletelist filename",
+  fprintf(stderr, USAGE_OPTIONS_FORMAT, "-dl | -deletelist filename",
          "-NG | -notgroup");
-  fprintf(stderr, "  %-39s%-39s\n", "-f  | -file filename",
+  fprintf(stderr, USAGE_OPTIONS_FORMAT, "-f  | -file filename",
          "-D  | -desc description");
-  fprintf(stderr, "  %-39s%-39s\n", "-at | -addtagged member tag",
+  fprintf(stderr, USAGE_OPTIONS_FORMAT, "-at | -addtagged member tag",
          "-O  | -owner owner");
-  fprintf(stderr, "  %-39s%-39s\n", "-ct | -changetag member tag",
+  fprintf(stderr, USAGE_OPTIONS_FORMAT, "-ct | -changetag member tag",
          "-t  | -tags");
-  fprintf(stderr, "  %-39s%-39s\n", "-n  | -noauth",
+  fprintf(stderr, USAGE_OPTIONS_FORMAT, "-n  | -noauth",
          "-db | -database host[:port]");
   exit(1);
 }
@@ -869,7 +870,6 @@ void usage(char **argv)
 void show_list_member(struct member *memberstruct)
 {
   char *s = "";
-  char *tag;
 
   switch (memberstruct->type)
     {
index c9c2c12426eafa53d4341999ec8f8c96e1ddb572..b8c9475920cef0cfacafacc85b8fb509a8062d84 100644 (file)
@@ -26,6 +26,10 @@ static int save_alias_value(int argc, char **argv, void *sq);
 
 extern char *whoami;
 
+#ifdef _WIN32
+#define strtok_r(s, tokens, resume) strtok(s, tokens)
+#endif /* _WIN32 */
+
 int mrcl_validate_pobox_smtp(char *user, char *address, char **ret)
 {
   char *addr, *retaddr, *p, *lasts = NULL;
index cc6bbb9b2a3b66be7deeb83b95e6fcbc611a0880..50afe3a95742a3817bf4fc0c5f1aa95452ec5558 100644 (file)
 
 #include <ctype.h>
 #ifdef HAVE_CURSES
+#ifdef _WIN32
+#include <conio.h>
+#ifdef MOUSE_MOVED
+#undef MOUSE_MOVED
+#endif
+#endif /*_WIN32*/
 #include <curses.h>
 #endif
-#include <pwd.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
 
 #include <krb.h>
 
+#ifdef _WIN32
+#define INPUT_MASK 0xff
+#ifdef getchar
+#undef getchar
+#endif
+#define getchar() _getch()
+#ifdef title
+#undef title
+#endif
+static void DELETE_A_CHAR(void)
+{
+    int x, y;
+    getsyx(&y, &x);
+    x -= 1;
+    mvdelch(y,x);
+}
+#else /* !_WIN32 */
+#define INPUT_MASK 0x7f
+#define DELETE_A_CHAR() printf("\b \b");
+#endif /* !_WIN32 */
+
 RCSID("$Header$");
 
 #define STARTCOL 0
@@ -90,6 +118,7 @@ void end_display(void);
 void display_menu(MENU *menu);
 void pack_main_menu(void);
 void pack_help_menu(void);
+void free_menu(MENU* menu);
 void highlight(MENU *menu);
 void title(char *buff);
 void center_text(int row, char *buff);
@@ -159,11 +188,13 @@ int main(int argc, char *argv[])
       display_buff("to at least 24 lines and 60 columns.\n");
       exit(0);
     }
+
   raw();
   noecho();
   old_hook = set_com_err_hook(menu_err_hook);
   position[0] = oldpos[0] = 1;
   level = 0;
+
   pack_main_menu();
   pack_help_menu();
   display_menu(main_menu);
@@ -171,6 +202,26 @@ int main(int argc, char *argv[])
   cls();
   endwin();
   set_com_err_hook(old_hook);
+
+  free_menu(main_menu);
+  free_menu(help_menu);
+
+  if (current_li->acl_type)
+    free(current_li->acl_type);
+  if (current_li->acl_name)
+    free(current_li->acl_name);
+  if (current_li->desc)
+    free(current_li->desc);
+  if (current_li->modtime)
+    free(current_li->modtime);
+  if (current_li->modby)
+    free(current_li->modby);
+  if (current_li->modwith)
+    free(current_li->modwith);
+  free(current_li);
+
+  mr_disconnect();
+
   exit(0);
 
 punt:
@@ -191,7 +242,7 @@ void get_main_input(void)
       currow = DISPROW + 2;
       page = 1;
       toggle = num_members = moreflg = 0;
-      c = getchar() & 0x7f;    /* mask parity bit */
+      c = getchar() & INPUT_MASK;      /* mask parity bit */
       if (c == '\r' || c == '\n')
        {
          if (position[level] == 7)
@@ -245,11 +296,12 @@ void get_main_input(void)
          if (retflg)
            delete_member();
          break;
+#ifndef _WIN32
        case 27:                /* escape */
-         c = getchar() & 0x7f;
+         c = getchar() & INPUT_MASK;
          if (c == 91)
            {
-             c = getchar() & 0x7f;
+             c = getchar() & INPUT_MASK;
              if (c == 65)      /* up arrow */
                {
                  position[level]--;
@@ -266,6 +318,25 @@ void get_main_input(void)
                    }
                }
            }
+#else /* _WIN32 */
+       case 0xe0:
+         c = getchar() & INPUT_MASK;
+         if (c == 0x48)        /* up arrow */
+           {
+             position[level]--;
+             if (!position[level])
+               position[level] = 7;
+           }
+         else
+           {
+             if (c == 0x50)    /* down arrow */
+               {
+                 position[level]++;
+                 if (position[level] > 7)
+                   position[level] = 1;
+               }
+           }
+#endif /* _WIN32 */
          break;
        default:
          printf("%c", 7);
@@ -311,6 +382,7 @@ void show_list_info(void)
       show_text(currow, STARTCOL, "Press any Key to continue...");
       getchar();
     }
+  free(buf);
   clrwin(DISPROW);
 }
 
@@ -318,14 +390,16 @@ void show_list_info(void)
 void display_buff(char *buf)
 {
   int i, cnt;
-  char *printbuf;
+  char *printbuf = NULL;
   int maxcol;
+  int len;
 
   maxcol = COLS;
 
   cnt = 0;
   printbuf = calloc(maxcol, 1);
-  for (i = 0; i <= strlen(buf); i++)
+  len = strlen(buf);
+  for (i = 0; i <= len; i++)
     {
       printbuf[cnt] = buf[i];
       cnt++;
@@ -337,11 +411,12 @@ void display_buff(char *buf)
          printbuf = calloc(maxcol, 1);
        }
     }
-  if (strlen(buf) % maxcol != 0)
+  if (len % maxcol != 0)
     {
       start_display_buff(printbuf);
-      free(printbuf);
     }
+  if (printbuf)
+    free(printbuf);
   return;
 }
 
@@ -404,6 +479,7 @@ void add_member(void)
       show_text(DISPROW + 4, STARTCOL, "Press any Key to continue...");
       getchar();
     }
+  free(buf);
   clrwin(DISPROW);
 }
 
@@ -434,7 +510,11 @@ void delete_member(void)
       currow = DISPROW + 4;
       show_text(DISPROW + 4, STARTCOL, "Press any Key to continue...");
       getchar();
+      free(argv[0]);
+      free(argv[1]);
+      free(argv[2]);
     }
+  free(buf);
   clrwin(DISPROW);
 }
 
@@ -460,6 +540,7 @@ void list_by_member(void)
   show_text(currow, STARTCOL, "Press any Key to continue...");
   getchar();
   clrwin(DISPROW);
+  free(buf);
 }
 
 /****************************************************/
@@ -468,7 +549,7 @@ void show_all(void)
   char c;
 
   show_text(DISPROW, STARTCOL, "This function may take a while... proceed? [n] ");
-  c = getchar() & 0x7f;
+  c = getchar() & INPUT_MASK;
   if (c == 'y' || c == 'Y')
     {
       move(DISPROW + 1, STARTCOL);
@@ -557,12 +638,14 @@ void list_members(void)
          show_text(currow, STARTCOL, "Press any key to continue...");
          getchar();
          clrwin(DISPROW);
-         return;
+         goto cleanup;
        }
       end_display();
-      return;
+      goto cleanup;
     }
   clrwin(DISPROW);
+ cleanup:
+  free(buf);
 }
 
 /****************************************************/
@@ -598,7 +681,7 @@ void start_display(char *buff)
          erase_line(currow, STARTCOL);
          show_text(currow, STARTCOL, "Flushing query...");
          moreflg = 1;
-         return;
+         goto cleanup;
        }
       clrwin(DISPROW + 2);
       currow = DISPROW + 2;
@@ -616,6 +699,8 @@ void start_display(char *buff)
       currow++;
     }
   toggle = !toggle;
+ cleanup:
+  free(buffer);
 }
 
 /****************************************************/
@@ -637,6 +722,7 @@ void end_display(void)
   show_text(currow, STARTCOL, "Press any key to continue...");
   getchar();
   clrwin(DISPROW);
+  free(buffer);
 }
 
 /****************************************************/
@@ -692,6 +778,7 @@ void pack_main_menu(void)
   main_menu->items[4] = strdup("5.  Add yourself to a mailing list.");
   main_menu->items[5] = strdup("6.  Delete yourself from a mailing list.");
   main_menu->items[6] = strdup("q.  Quit.");
+  free(buf);
 }
 
 /****************************************************/
@@ -709,6 +796,17 @@ void pack_help_menu(void)
   help_menu->items[4] = strdup("Press any key to continue.");
 }
 
+/****************************************************/
+void free_menu(MENU* menu)
+{
+  int i;
+  for (i = 0; i < menu->num_items; i++)
+    free(menu->items[i]);
+  free(menu->items);
+  free(menu->title);
+  free(menu);
+}
+
 /****************************************************/
 void highlight(MENU *menu)
 {
@@ -843,10 +941,11 @@ int Prompt(char *prompt, char *buf, int buflen, int crok)
 
   addstr(prompt);
   refresh();
+
   for (p = buf; abs(strlen(p) - strlen(buf)) <= buflen;)
     {
       refresh();
-      c = getchar() & 0x7f;
+      c = getchar() & INPUT_MASK;
       switch (c)
        {
        case CTL('C'):
@@ -871,16 +970,22 @@ int Prompt(char *prompt, char *buf, int buflen, int crok)
          if (p > buf)
            {
              p--;
-             printf("\b \b");
+             DELETE_A_CHAR();
            }
          break;
        case CTL('U'):
        case CTL('G'):
        case CTL('['):
          while (p-- > buf)
-           printf("\b \b");
+           DELETE_A_CHAR();
          p = buf;
          break;
+#ifdef _WIN32
+       case 0xe0:
+         c = getchar() & INPUT_MASK;
+         putchar(CTL('G'));
+         break;
+#endif /*_WIN32*/
        default:
          if (abs(strlen(p) - strlen(buf)) >= buflen)
            {
index 3009def2d01f19f45ff63af7b48e3a678312d6ef..dd2f9ff957ee30a6353d0e7591290864552b0727 100644 (file)
@@ -79,7 +79,6 @@ static char *PrintACLInfo(char **info)
 {
   static char name[BUFSIZ];
   char buf[BUFSIZ];
-  int status;
 
   if (!info)           /* If no informaion */
     {
@@ -109,9 +108,6 @@ static char *PrintACLInfo(char **info)
 static char **AskACLInfo(char **info)
 {
   char temp_buf[BUFSIZ];
-  char *args[3];
-  char *s, *d;
-  int status;
 
   Put_message("");
   info[ACL_HOST] = canonicalize_hostname(info[ACL_HOST]);
@@ -191,7 +187,7 @@ int DeleteACL(int argc, char **argv)
 
 int AddACL(int argc, char **argv)
 {
-  char *info[MAX_ARGS_SIZE], **args, *host;
+  char *info[MAX_ARGS_SIZE], **args;
   int stat;
 
   argv[1] = canonicalize_hostname(strdup(argv[1]));
index b70c39cdbf0829d8ae3ecd3a6e786b5901be7ef2..715ab681087f372fd3b19152c5dd3faf6fbf7ba8 100644 (file)
@@ -28,7 +28,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif /* HAVE_UNISTD_H */
 
 RCSID("$Header$");
 
@@ -234,9 +236,11 @@ static char *PrintFSInfo(char **info)
   return info[FS_NAME];
 }
 
-
 char *canonicalize_cell(char *c)
 {
+#ifdef _WIN32
+  return c;
+#else /* !_WIN32 */
   struct stat stbuf;
   char path[512];
   int count;
@@ -250,6 +254,7 @@ char *canonicalize_cell(char *c)
   path[count] = 0;
   free(c);
   return strdup(path);
+#endif /* _WIN32 */
 }
 
 
index b1c4fd636ecc741b9013b2a92f3afc3c4609b271..c4dbaa535b2955f024f10d47223c32d91c98873d 100644 (file)
 #include "globals.h"
 
 #include <sys/types.h>
+
+#ifdef HAVE_UNAME
 #include <sys/utsname.h>
+#endif
 
+#ifndef _WIN32
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <netdb.h>
+#endif /* _WIN32 */
 
 #include <ctype.h>
 #include <stdio.h>
@@ -584,7 +589,7 @@ char **AskMCDInfo(char **info, int type, Bool name)
        return NULL;
       if (GetAddressFromUser("Network mask", &info[SN_MASK]) == SUB_ERROR)
        return NULL;
-      if (atoi(info[SN_LOW]) == ntohl(inet_addr(S_DEFAULT_LOW)))
+      if (atoi(info[SN_LOW]) == (int)ntohl(inet_addr(S_DEFAULT_LOW)))
        {
          struct in_addr low;
          unsigned long mask, addr;
@@ -600,7 +605,7 @@ char **AskMCDInfo(char **info, int type, Bool name)
       if (GetAddressFromUser("Lowest assignable address", &info[SN_LOW]) ==
          SUB_ERROR)
        return NULL;
-      if (atoi(info[SN_HIGH]) == ntohl(inet_addr(S_DEFAULT_HIGH)))
+      if (atoi(info[SN_HIGH]) == (int)ntohl(inet_addr(S_DEFAULT_HIGH)))
        {
          struct in_addr high;
          unsigned long mask, addr;
@@ -997,10 +1002,16 @@ char *partial_canonicalize_hostname(char *s)
       else
        {
          struct hostent *hp;
+#ifdef HAVE_UNAME
          struct utsname name;
-
          uname(&name);
          hp = gethostbyname(name.nodename);
+#else
+         char  name[256];
+         gethostname(name, sizeof(name));
+         name[sizeof(name)-1] = 0;
+         hp = gethostbyname(name);
+#endif /* HAVE_UNAME */
          cp = strchr(hp->h_name, '.');
          if (cp)
            def_domain = strdup(++cp);
index 337c22fb9d8923107533718ebf25f35a77ec8736..6952a625c74a6432b1c039d402ba4350741a26d3 100644 (file)
@@ -732,7 +732,6 @@ int TagMember(int argc, char **argv)
 {
   char *args[10];
   int status;
-  char temp_buf[BUFSIZ];
 
   if (GetMemberInfo("tag", args) == SUB_ERROR)
     return DM_NORMAL;
index 1bb5e1f188e285444b3a63829360f54ec83e67d5..d63713990260d66d4fd86cb35ac37fd9235a5671 100644 (file)
 #include "f_defs.h"
 #include "globals.h"
 
-#include <pwd.h>
 #include <signal.h>
 #include <stdio.h>
 #include <string.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-
-#include <krb.h>
+#endif /* HAVE_UNISTD_H */
 
 RCSID("$Header$");
 
 static void ErrorExit(char *buf, int status);
 static void Usage(void);
-static void Signal_Handler(void);
-static void CatchInterrupt(void);
+static void Signal_Handler(int sig);
+static void CatchInterrupt(int sig);
+static void SetHandlers(void);
 
 char *whoami;                  /* used by menu.c ugh!!! */
 char *moira_server;
@@ -54,8 +54,7 @@ int main(int argc, char **argv)
 {
   int status;
   Menu *menu;
-  char **arg, pname[ANAME_SZ];
-  struct sigaction act;
+  char **arg;
 
   if (!(program_name = strrchr(argv[0], '/')))
     program_name = argv[0];
@@ -132,21 +131,7 @@ int main(int argc, char **argv)
    * These signals should not be set until just before we fire up the menu
    * system.
    */
-
-  sigemptyset(&act.sa_mask);
-  act.sa_flags = 0;
-  act.sa_handler = Signal_Handler;
-  sigaction(SIGHUP, &act, NULL);
-  sigaction(SIGQUIT, &act, NULL);
-#ifdef HAVE_CURSES
-  if (use_menu)
-    sigaction(SIGINT, &act, NULL);
-  else
-#endif
-    {
-      act.sa_handler = CatchInterrupt;
-      sigaction(SIGINT, &act, NULL);
-    }
+  SetHandlers();
 
   if (!strcmp(program_name, "listmaint"))
     menu = &list_menu;
@@ -205,7 +190,7 @@ static void Usage(void)
  *     Returns: doesn't
  */
 
-static void Signal_Handler(void)
+static void Signal_Handler(int sig)
 {
   Put_message("Signal caught - exiting");
 #ifdef HAVE_CURSES
@@ -217,8 +202,41 @@ static void Signal_Handler(void)
 }
 
 
-static void CatchInterrupt(void)
+static void CatchInterrupt(int sig)
 {
   Put_message("Interrupt! Press RETURN to continue");
   interrupt = 1;
 }
+
+#ifdef HAVE_POSIX_SIGNALS
+static void SetHandlers(void)
+{
+  struct sigaction act;
+
+  sigemptyset(&act.sa_mask);
+  act.sa_flags = 0;
+  act.sa_handler = Signal_Handler;
+  sigaction(SIGHUP, &act, NULL);
+  sigaction(SIGQUIT, &act, NULL);
+#ifdef HAVE_CURSES
+  if (use_menu)
+    sigaction(SIGINT, &act, NULL);
+  else
+#endif
+    {
+      act.sa_handler = CatchInterrupt;
+      sigaction(SIGINT, &act, NULL);
+    }
+}
+#else
+static void SetHandlers(void)
+{
+  signal(SIGTERM, Signal_Handler);
+#ifdef HAVE_CURSES
+  if (use_menu)
+    signal(SIGINT, Signal_Handler);
+  else
+#endif
+      signal(SIGINT, CatchInterrupt);
+}
+#endif
index e171f5443ce68aa7628e1ac38e5a7e7f30944947..e7ee80a684f367936913bbaa08f1f67b16c184e8 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
+
+#ifdef _WIN32
+#include <windows.h>
+#include <conio.h>
+#ifdef getchar
+#undef getchar
+#endif
+#define getchar() _getch()
+#define getpid _getpid
+#endif /* _WIN32 */
 
 RCSID("$Header$");
 
@@ -457,11 +469,11 @@ void refresh_screen(void)
 /* Prompt the user for input in the input window of cur_ms */
 int Prompt_input(char *prompt, char *buf, int buflen)
 {
+#ifdef HAVE_CURSES
   int c;
   char *p;
   int y, x, oldx, oldy;
 
-#ifdef HAVE_CURSES
   if (cur_ms != NULLMS)
     {
       more_flg = 1;
@@ -641,9 +653,6 @@ void Put_message(char *msg)
 /* Will be truncated to COLS characters.  */
 void Put_line(char *msg)
 {
-  int y, x, i;
-  char *msg1, chr;
-
   if (!more_flg)
     return;
 
@@ -655,6 +664,9 @@ void Put_line(char *msg)
 #ifdef HAVE_CURSES
          if (cur_ms != NULLMS)
            {
+              int x, y;
+              char chr;
+
              wstandout(cur_ms->ms_input);
              wprintw(cur_ms->ms_input, "---More---");
              wstandend(cur_ms->ms_input);
@@ -684,6 +696,9 @@ void Put_line(char *msg)
 #ifdef HAVE_CURSES
   if (cur_ms != NULLMS)
     {
+      int i;
+      char *msg1;
+
       msg1 = calloc(COLS, 1);
       strncpy(msg1, msg, COLS - 1);
       for (i = strlen(msg1); i < COLS - 1; i++)
@@ -766,13 +781,30 @@ struct menu_line *Find_command(Menu *m, char *command)
     return find_command_from(command, m, MAX_MENU_DEPTH);
 }
 
+static char *get_tmp_dir(void)
+{
+#ifdef _WIN32
+  static char tmp[BUFSIZ];
+  DWORD len;
+  if (!tmp[0])
+    {
+      len = GetTempPath(sizeof(tmp), tmp);
+      if (!len || (len > sizeof(tmp)))
+        strcpy(tmp, ".");
+    }
+  return tmp;
+#else
+  return "/var/tmp";
+#endif
+}
+
 int toggle_logging(int argc, char *argv[])
 {
   char buf[BUFSIZ];
 
   if (!log_file)
     {
-      sprintf(buf, "/var/tmp/%s-log.%ld", whoami, (long)getpid());
+      sprintf(buf, "%s/%s-log.%ld", get_tmp_dir(), whoami, (long)getpid());
 
       /* open the file */
       log_file = fopen(buf, "a");
index 64d923c6775171e08f3510ef7854ff9090a7455d..bba985f0ac63baf68658c71cd2bc5ed715d4d33f 100644 (file)
 #include "globals.h"
 
 #include <sys/types.h>
+#ifndef _WIN32
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <netdb.h>
+#endif /* _WIN32 */
 
 #include <stdio.h>
 #include <stdlib.h>
index ee86c403eea77c30f21d74c41afb51ffdee64640..4fc105a3434fefa2c489745ca1cc772dac9b4ddf 100644 (file)
@@ -395,7 +395,6 @@ int SetUserPOBox(int argc, char **argv)
 {
   int status;
   char *type, temp_buf[BUFSIZ], *local_user, *args[10], *box;
-  char *temp_box;
   struct mqelem *top = NULL;
 
   local_user = argv[1];
index 5637ef40656f3fdebee9afb973781bcbce557a87..8b0f031c805c5520ccb4326810482577c1f9042b 100644 (file)
@@ -207,7 +207,6 @@ static char **AskPrnInfo(char **info)
 {
   char temp_buf[BUFSIZ];
   char *args[3], *lpc_acl;
-  char *s, *d;
   int status;
 
   Put_message("");
@@ -526,7 +525,6 @@ int GetPrintSrv(int argc, char **argv)
 static char *PrintPrintSrvInfo(char **info)
 {
   char buf[BUFSIZ];
-  int status;
 
   if (!info)           /* If no informaion */
     {
@@ -575,9 +573,6 @@ static char **SetPrintSrvDefaults(char **info, char *name)
 static char **AskPrintSrvInfo(char **info)
 {
   char buf[BUFSIZ];
-  char *args[3], *lpc_acl;
-  char *s, *d;
-  int status;
 
   Put_message("");
   sprintf(buf, "Print Server entry for %s.", info[PRINTSERVER_HOST]);
@@ -644,7 +639,7 @@ int AddPrintSrv(int argc, char **argv)
 
 int ChangePrintSrv(int argc, char **argv)
 {
-  char *name, **args;
+  char *name;
   struct mqelem *elem = NULL;
   int stat;
 
index 4503c5e72acdb515e0cf6ccdb4bd0389b41a0319..56a42d4184340c2a92cbf110a8676cb779758dd0 100644 (file)
@@ -19,8 +19,6 @@
 #include "f_defs.h"
 #include "globals.h"
 
-#include <sys/time.h>
-
 #include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -188,7 +186,7 @@ void CorrectCapitalization(char **name)
 
 char **AskUserInfo(char **info, Bool name)
 {
-  int i, state;
+  int state;
   char temp_buf[BUFSIZ], *newname;
 
   if (name)
@@ -713,7 +711,7 @@ static void RealDeactivateUser(char **info, Bool one_item)
          FreeAndClear(&args[L_MODTIME], TRUE);
          FreeAndClear(&args[L_MODBY], TRUE);
          FreeAndClear(&args[L_MODWITH], TRUE);
-         SlipInNewName(args, args[L_NAME]);
+         SlipInNewName(args, strdup(args[L_NAME]));
          if ((status = do_mr_query("update_list", CountArgs(args), args,
                                    NULL, NULL)))
            {
@@ -749,7 +747,7 @@ static void RealDeactivateUser(char **info, Bool one_item)
       FreeAndClear(&args[FS_MODTIME], TRUE);
       FreeAndClear(&args[FS_MODBY], TRUE);
       FreeAndClear(&args[FS_MODWITH], TRUE);
-      SlipInNewName(args, args[FS_NAME]);
+      SlipInNewName(args, strdup(args[FS_NAME]));
       if ((status = do_mr_query("update_filesys", CountArgs(args), args,
                                NULL, NULL)))
        {
index 716ade7426ac0faf8cc75bc85161b28b73cbee2c..0a688e043e4fa842f3f407fc11cf34815b0b2aa2 100644 (file)
 
 #include <sys/types.h>
 
+#ifndef _WIN32
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <netdb.h>             /* for gethostbyname. */
+#endif /* _WIN32 */
 
 #include <ctype.h>
 #include <stdio.h>
@@ -777,11 +779,15 @@ int GetTypeFromUser(char *prompt, char *tname, char **pointer)
   strcat(buffer, " (");
   for (elem = GetTypeValues(tname); elem; elem = elem->q_forw)
     {
+      /* Make sure we don't blow up and get too long a prompt */
+      if (strlen(buffer) > 64)
+       break;
       strcat(buffer, elem->q_data);
       if (elem->q_forw)
        strcat(buffer, ", ");
     }
   strcat(buffer, ")");
+  /* Trim the prompt if it is too long */
   if (strlen(buffer) > 64)
     sprintf(buffer, "%s (? for help)", prompt);
   if (GetValueFromUser(buffer, pointer) == SUB_ERROR)
index 8d64a42fabf7e620b20f0845f6e821fd1c707f58..e82856880d9ce30520e51409453fef457b609e9f 100644 (file)
@@ -12,8 +12,6 @@
 #include <moira_site.h>
 #include <mrclient.h>
 
-#include <sys/time.h>
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -30,7 +28,7 @@ void usage(void);
 
 char *whoami;
 static int count = 0;
-static struct timeval now;
+static time_t now;
 
 struct service {
   char name[17];
@@ -78,7 +76,7 @@ int process_server(int argc, char **argv, void *sqv)
     disp_svc(argv, "Should this be enabled?\n");
   else if (atoi(argv[SVC_ENABLE]) &&
           60 * atoi(argv[SVC_INTERVAL]) + 86400 + atoi(argv[SVC_DFCHECK])
-          < now.tv_sec)
+          < now)
     disp_svc(argv, "Service has not been updated\n");
 
   return MR_CONT;
@@ -130,7 +128,7 @@ int process_host(int argc, char **argv, void *sqv)
     disp_sh(argv, "Should this be enabled?\n");
   else if (atoi(argv[SH_ENABLE]) && update_int &&
           60 * atoi(update_int) + 86400 + atoi(argv[SH_LASTSUCCESS])
-          < now.tv_sec)
+          < now)
     disp_sh(argv, "Host has not been updated\n");
 
   return MR_CONT;
@@ -187,7 +185,7 @@ int main(int argc, char *argv[])
       goto punt;
     }
 
-  gettimeofday(&now, 0);
+  now = time(NULL);
   sq = sq_create();
 
   /* Check services first */
index 268d784da2beb60bbe68a948730b62b82507111d..0f928875e4698089c40a24f6cef45ab0e106a83e 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
+
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#endif
+
+#ifdef _WIN32
+#include <windows.h>
+#include <io.h>
+#define dup    _dup
+#define dup2   _dup2
+#define isatty _isatty
+#define close  _close
+#define open   _open
+#define sigjmp_buf jmp_buf
+#define siglongjmp longjmp
+#define sigsetjmp(env, save) setjmp(env)
+#endif /* _WIN32 */
 
 #ifdef HAVE_READLINE
 #include "readline/readline.h"
@@ -29,11 +48,12 @@ RCSID("$Header$");
 int recursion = 0, quote_output = 0, interactive;
 int count, quit = 0, cancel = 0;
 char *whoami;
+
 sigjmp_buf jb;
 
 #define MAXARGS 20
 
-void discard_input(void);
+void discard_input(int sig);
 char *mr_gets(char *prompt, char *buf, size_t len);
 void execute_line(char *cmdbuf);
 int parse(char *buf, char *argv[MAXARGS]);
@@ -51,11 +71,12 @@ void test_dcm(void);
 void test_script(int argc, char **argv);
 void test_list_requests(void);
 void test_version(int argc, char **argv);
+void set_signal_handler(int, void (*handler)(int));
+void set_signal_blocking(int, int);
 
 int main(int argc, char **argv)
 {
   char cmdbuf[BUFSIZ];
-  struct sigaction action;
   int c;
 
   whoami = argv[0];
@@ -83,10 +104,7 @@ int main(int argc, char **argv)
   rl_bind_key('\t', rl_insert);
 #endif
 
-  action.sa_handler = discard_input;
-  action.sa_flags = 0;
-  sigemptyset(&action.sa_mask);
-  sigaction(SIGINT, &action, NULL);
+  set_signal_handler(SIGINT, discard_input);
   sigsetjmp(jb, 1);
 
   while (!quit)
@@ -99,7 +117,7 @@ int main(int argc, char **argv)
   exit(0);
 }
 
-void discard_input(void)
+void discard_input(int sig)
 {
   putc('\n', stdout);
 
@@ -432,7 +450,6 @@ int print_reply(int argc, char **argv, void *help)
 void test_query(int argc, char **argv)
 {
   int status, help;
-  sigset_t sigs;
 
   if (argc < 2)
     {
@@ -444,11 +461,9 @@ void test_query(int argc, char **argv)
   count = 0;
   /* Don't allow ^C during the query: it will confuse libmoira's
      internal state. (Yay static variables) */
-  sigemptyset(&sigs);
-  sigaddset(&sigs, SIGINT);
-  sigprocmask(SIG_BLOCK, &sigs, NULL);
+  set_signal_blocking(SIGINT, 1);
   status = mr_query(argv[1], argc - 2, argv + 2, print_reply, &help);
-  sigprocmask(SIG_UNBLOCK, &sigs, NULL);
+  set_signal_blocking(SIGINT, 0);
   printf("%d tuple%s\n", count, ((count == 1) ? "" : "s"));
   if (status)
     com_err("moira (query)", status, "");
@@ -520,3 +535,44 @@ void test_version(int argc, char **argv)
   if (status)
     com_err("moira (version)", status, "");
 }
+
+#ifdef HAVE_POSIX_SIGNALS
+
+void set_signal_handler(int sig, void (*handler)(int))
+{
+  struct sigaction action;
+
+  sigemptyset(&action.sa_mask);
+  action.sa_flags = 0;
+  action.sa_handler = handler;
+  sigaction(sig, &action, NULL);
+}
+
+void set_signal_blocking(int sig, int block)
+{
+  sigset_t sigs;
+  sigemptyset(&sigs);
+  sigaddset(&sigs, sig);
+  sigprocmask(block ? SIG_BLOCK : SIG_UNBLOCK, &sigs, NULL);
+}
+
+#else
+
+void set_signal_handler(int sig, void (*handler)(int))
+{
+  signal(sig, handler);
+}
+
+#ifdef _WIN32
+BOOL WINAPI blocking_handler(DWORD dwCtrlType)
+{
+  return(TRUE);
+}
+
+void set_signal_blocking(int sig, int block)
+{
+  SetConsoleCtrlHandler(blocking_handler, block ? TRUE : FALSE);
+}
+#endif /* _WIN32 */
+
+#endif /* HAVE_POSIX_SIGNALS */
index 5d6ac26093ec68726eb7f7f0fa4b4dfa503a7395..1943739a2a55abb75ff2240a3a78db5d36db4bc2 100644 (file)
@@ -75,7 +75,6 @@ int chfn(char *uname)
   int status;                  /* general purpose exit status */
   int q_argc;                  /* argc for mr_query */
   char *q_argv[F_END];         /* argv for mr_query */
-  char *motd;                  /* for Moira server status */
   int i;
 
   struct finger_info old_info;
@@ -175,6 +174,7 @@ char *ask(char *question, char *def_val, int phone_num)
   char *result;
   int i;
   int dashes = FALSE;
+  int len;
 
 #define BLANK "none"
 
@@ -192,7 +192,8 @@ char *ask(char *question, char *def_val, int phone_num)
       else
        result = buf;
 
-      for (i = 0; i < strlen(buf); i++)
+      len = strlen(buf);
+      for (i = 0; i < len; i++)
        {
          switch (buf[i])
            {
@@ -222,7 +223,8 @@ char *ask(char *question, char *def_val, int phone_num)
 
       if (phone_num && ok)
        {
-         for (i = 0; i < strlen(result); i++)
+         len = strlen(result);
+         for (i = 0; i < len; i++)
            {
              if (!isdigit(result[i]) && (result[i] != '-'))
                {
index 78a657da6b7d6fe72a70aaf159cff0f44fe05cfb..d76fffeb2b63e2985bbb26d5b2496463c0ed8fd4 100644 (file)
 #include <moira_site.h>
 #include <mrclient.h>
 
-#include <pwd.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#endif
 
 RCSID("$Header$");
 
@@ -43,7 +47,6 @@ static int match;
 
 int main(int argc, char *argv[])
 {
-  struct passwd *pwd;
   char *mrarg[3];
   char *address, *uname;
   int c, setflag, splitflag, prevflag, status;
index 1281c2dc287fa589446568ea0a8351946f51b4af..71b7ed1b4bd4b92c415bcf3bc83ffad45290c732 100644 (file)
@@ -78,7 +78,7 @@ int main(int argc, char **argv)
 {
   int status, success;
   char **arg = argv;
-  char *server = NULL, *p;
+  char *server = NULL;
 
   /* clear all flags & lists */
   info_flag = update_flag = create_flag = list_map_flag = update_map_flag = 0;
@@ -138,12 +138,14 @@ int main(int argc, char **argv)
          else if (argis("S", "status")) {
            if (arg - argv < argc - 1) {
              int i;
+             int len;
 
              arg++;
              update_flag++;
              h_status = *arg;
 
-             for(i=0; i<strlen(h_status); i++) {
+             len = strlen(h_status);
+             for(i = 0; i < len; i++) {
                if(!isdigit(h_status[i])) {
                  printf("Error: status code %s is not numeric.\n", h_status);
                  exit(1);
@@ -366,7 +368,6 @@ int main(int argc, char **argv)
       char *old_argv[30];
       char *argv[16];
       char *args[5];
-      int cnt;
 
       args[0] = canonicalize_hostname(strdup(hostname));
       args[1] = args[2] = args[3] = "*";
@@ -584,31 +585,32 @@ int main(int argc, char **argv)
 
 void usage(char **argv)
 {
+#define USAGE_OPTIONS_FORMAT "  %-39s%s\n"
   fprintf(stderr, "Usage: %s hostname [options]\n", argv[0]);
   fprintf(stderr, "Options are\n");
-  fprintf(stderr, "  %-39s%-39s\n", "-C   | -create",
+  fprintf(stderr, USAGE_OPTIONS_FORMAT, "-C   | -create",
          "-O   | -owner owner");
-  fprintf(stderr, "  %-39s%-39s\n", "-D   | -delete",
+  fprintf(stderr, USAGE_OPTIONS_FORMAT, "-D   | -delete",
          "-S   | -status status");
-  fprintf(stderr, "  %-39s%-39s\n", "-R   | -rename newname",
+  fprintf(stderr, USAGE_OPTIONS_FORMAT, "-R   | -rename newname",
          "-V   | -vendor vendor");
-  fprintf(stderr, "  %-39s%-39s\n", "-a   | -addalias alias",
+  fprintf(stderr, USAGE_OPTIONS_FORMAT, "-a   | -addalias alias",
          "-M   | -model model");
-  fprintf(stderr, "  %-39s%-39s\n", "-d   | -deletealias alias",
+  fprintf(stderr, USAGE_OPTIONS_FORMAT, "-d   | -deletealias alias",
          "-L   | -location location");
-  fprintf(stderr, "  %-39s%-39s\n", "-i   | -info",
+  fprintf(stderr, USAGE_OPTIONS_FORMAT, "-i   | -info",
          "-o   | -os os");
-  fprintf(stderr, "  %-39s%-39s\n", "-oc  | -opcmt op_cmt",
+  fprintf(stderr, USAGE_OPTIONS_FORMAT, "-oc  | -opcmt op_cmt",
          "-c   | -contact contact");
-  fprintf(stderr, "  %-39s%-39s\n", "-ac  | -admcmt adm_cmt",
+  fprintf(stderr, USAGE_OPTIONS_FORMAT, "-ac  | -admcmt adm_cmt",
          "-A   | -address address");
-  fprintf(stderr, "  %-39s%-39s\n", "-am  | -addmap cluster",
+  fprintf(stderr, USAGE_OPTIONS_FORMAT, "-am  | -addmap cluster",
          "-N   | -network network");
-  fprintf(stderr, "  %-39s%-39s\n", "-dm  | -deletemap cluster",
+  fprintf(stderr, USAGE_OPTIONS_FORMAT, "-dm  | -deletemap cluster",
          "-lm  | -listmap");
-  fprintf(stderr, "  %-39s%-39s\n", "-db  | -database host[:port]",
+  fprintf(stderr, USAGE_OPTIONS_FORMAT, "-db  | -database host[:port]",
          "-n   | -noauth");
-  fprintf(stderr, "  %-39s%-39s\n", "-v   | -verbose",
+  fprintf(stderr, USAGE_OPTIONS_FORMAT, "-v   | -verbose",
          "");
   exit(1);
 }
index 3490a4e5d5aa9d1f2d266a3b82c4491fdf8fcc13..13be8a455a2e1ddc55891c5dcee3e0f8d4fe2938 100755 (executable)
--- a/configure
+++ b/configure
@@ -2445,7 +2445,7 @@ fi
 
 
 
-for ac_func in getusershell strlcpy strlcat
+for ac_func in getusershell strlcpy strlcat uname
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
 echo "configure:2452: checking for $ac_func" >&5
@@ -2501,6 +2501,179 @@ fi
 done
 
 
+echo $ac_n "checking for sigaction""... $ac_c" 1>&6
+echo "configure:2506: checking for sigaction" >&5
+if eval "test \"`echo '$''{'ac_cv_func_sigaction'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  cat > conftest.$ac_ext <<EOF
+#line 2511 "configure"
+#include "confdefs.h"
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char sigaction(); below.  */
+#include <assert.h>
+/* Override any gcc2 internal prototype to avoid an error.  */
+/* We use char because int might match the return type of a gcc2
+    builtin and then its argument prototype would still apply.  */
+char sigaction();
+
+int main() {
+
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined (__stub_sigaction) || defined (__stub___sigaction)
+choke me
+#else
+sigaction();
+#endif
+
+; return 0; }
+EOF
+if { (eval echo configure:2534: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+  rm -rf conftest*
+  eval "ac_cv_func_sigaction=yes"
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  eval "ac_cv_func_sigaction=no"
+fi
+rm -f conftest*
+fi
+
+if eval "test \"`echo '$ac_cv_func_'sigaction`\" = yes"; then
+  echo "$ac_t""yes" 1>&6
+  cat >> confdefs.h <<\EOF
+#define HAVE_POSIX_SIGNALS 1
+EOF
+
+else
+  echo "$ac_t""no" 1>&6
+fi
+
+
+echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6
+echo "configure:2558: checking how to run the C preprocessor" >&5
+# On Suns, sometimes $CPP names a directory.
+if test -n "$CPP" && test -d "$CPP"; then
+  CPP=
+fi
+if test -z "$CPP"; then
+if eval "test \"`echo '$''{'ac_cv_prog_CPP'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+    # This must be in double quotes, not single quotes, because CPP may get
+  # substituted into the Makefile and "${CC-cc}" will confuse make.
+  CPP="${CC-cc} -E"
+  # On the NeXT, cc -E runs the code through the compiler's parser,
+  # not just through cpp.
+  cat > conftest.$ac_ext <<EOF
+#line 2573 "configure"
+#include "confdefs.h"
+#include <assert.h>
+Syntax Error
+EOF
+ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+{ (eval echo configure:2579: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
+if test -z "$ac_err"; then
+  :
+else
+  echo "$ac_err" >&5
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  CPP="${CC-cc} -E -traditional-cpp"
+  cat > conftest.$ac_ext <<EOF
+#line 2590 "configure"
+#include "confdefs.h"
+#include <assert.h>
+Syntax Error
+EOF
+ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+{ (eval echo configure:2596: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
+if test -z "$ac_err"; then
+  :
+else
+  echo "$ac_err" >&5
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  CPP="${CC-cc} -nologo -E"
+  cat > conftest.$ac_ext <<EOF
+#line 2607 "configure"
+#include "confdefs.h"
+#include <assert.h>
+Syntax Error
+EOF
+ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+{ (eval echo configure:2613: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
+if test -z "$ac_err"; then
+  :
+else
+  echo "$ac_err" >&5
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  CPP=/lib/cpp
+fi
+rm -f conftest*
+fi
+rm -f conftest*
+fi
+rm -f conftest*
+  ac_cv_prog_CPP="$CPP"
+fi
+  CPP="$ac_cv_prog_CPP"
+else
+  ac_cv_prog_CPP="$CPP"
+fi
+echo "$ac_t""$CPP" 1>&6
+
+for ac_hdr in unistd.h getopt.h
+do
+ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
+echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
+echo "configure:2641: checking for $ac_hdr" >&5
+if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  cat > conftest.$ac_ext <<EOF
+#line 2646 "configure"
+#include "confdefs.h"
+#include <$ac_hdr>
+EOF
+ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+{ (eval echo configure:2651: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
+if test -z "$ac_err"; then
+  rm -rf conftest*
+  eval "ac_cv_header_$ac_safe=yes"
+else
+  echo "$ac_err" >&5
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  eval "ac_cv_header_$ac_safe=no"
+fi
+rm -f conftest*
+fi
+if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
+  echo "$ac_t""yes" 1>&6
+    ac_tr_hdr=HAVE_`echo $ac_hdr | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'`
+  cat >> confdefs.h <<EOF
+#define $ac_tr_hdr 1
+EOF
+else
+  echo "$ac_t""no" 1>&6
+fi
+done
+
+
 
     case $PRO_C_INCLUDES in
        *INCLUDE='$(srcdir)'*) ;;
@@ -2771,6 +2944,7 @@ s%@READLINE_LIBS@%$READLINE_LIBS%g
 s%@CURSES_CPPFLAGS@%$CURSES_CPPFLAGS%g
 s%@CURSES_LIBS@%$CURSES_LIBS%g
 s%@CURSES_SUBDIRS@%$CURSES_SUBDIRS%g
+s%@CPP@%$CPP%g
 s%@KLIBS@%$KLIBS%g
 s%@MR_LIBDEP@%$MR_LIBDEP%g
 
index ab7605690b4678420319cba0b2052a8ea123f9fc..63c574600d70861e22e6193ff1501840a3ef684c 100755 (executable)
@@ -352,7 +352,11 @@ AC_SUBST(CURSES_LIBS)
 AC_SUBST(CURSES_SUBDIRS)
 
 
-AC_CHECK_FUNCS(getusershell strlcpy strlcat)
+AC_CHECK_FUNCS(getusershell strlcpy strlcat uname)
+
+AC_CHECK_FUNC(sigaction, AC_DEFINE(HAVE_POSIX_SIGNALS))
+
+AC_CHECK_HEADERS(unistd.h getopt.h)
 
 MR_EXTEND(PRO_C_INCLUDES, INCLUDE='$(srcdir)')
 MR_INCLUDE('$(SRCTOP)/include')
index 2563650af0d008491e45c6de263d36879846c449..47aba26a4c7b11d22159af111ed932e7e87ce6a9 100644 (file)
@@ -7,13 +7,20 @@
 #ifndef _moira_h_
 #define _moira_h_
 
-/* return values from queries (and error codes) */
+#ifdef _WIN32
+#include <windows.h>
+#ifndef strcasecmp
+#define strcasecmp      stricmp
+#endif
+#endif /*_WIN32 */
 
+/* return values from queries (and error codes) */
 #include <sys/types.h>
 #include <com_err.h>
 #include "mr_et.h"
 #include "krb_et.h"
 #include "ureg_err.h"
+
 #define MR_SUCCESS 0           /* Query was successful */
 
 #define MR_VERSION_1 1         /* Version in use from 7/87 to 4/88 */
@@ -125,6 +132,7 @@ void sq_destroy(struct save_queue *sq);
 char *strtrim(char *s);
 char *uppercase(char *s);
 char *lowercase(char *s);
+
 #ifndef HAVE_STRLCPY
 size_t strlcpy(char *dst, const char *src, size_t size);
 #endif
index 6bdb70f91dd4999620b2aa575e53f748c52e17ea..ae574ada446fc7fb96a86dc9e39ab7c54b96ffe1 100644 (file)
 #include <moira.h>
 
 #include <sys/types.h>
-#include <sys/socket.h>
+
+#ifdef HAVE_UNAME
 #include <sys/utsname.h>
+#endif
 
+#ifndef _WIN32
+#include <sys/socket.h>
 #include <netdb.h>
 #include <netinet/in.h>
+#endif /* _WIN32 */
 
 #include <ctype.h>
 #include <stdio.h>
 
 RCSID("$Header$");
 
+static struct hostent *local_gethostbyname(void)
+{
+#ifdef HAVE_UNAME
+  struct utsname name;
+  uname(&name);
+  return gethostbyname(name.nodename);
+#else
+  char hostname[128];
+  gethostname(hostname, sizeof(hostname));
+  hostname[sizeof(hostname)-1] = 0;
+  return gethostbyname(hostname);
+#endif
+}
+
 static char *local_domain(void)
 {
   static char *domain = NULL;
@@ -42,9 +61,7 @@ static char *local_domain(void)
        }
       else
        {
-         struct utsname name;
-         uname(&name);
-         hp = gethostbyname(name.nodename);
+         hp = local_gethostbyname();
          if (hp)
            {
              cp = strchr(hp->h_name, '.');
index f6f2bfd18945d2e94ab98d342d2a78bd3c6cd6d1..f226e68281cd7a798e3217d74aa17587270447c7 100644 (file)
 #include "mr_private.h"
 
 #include <errno.h>
-#include <netinet/in.h>
 #include <stdlib.h>
 #include <string.h>
+#ifndef _WIN32
+#include <netinet/in.h>
+#endif /* _WIN32 */
+
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
 
 RCSID("$Header$");
 
@@ -53,7 +58,8 @@ int mr_do_call(struct mr_params *params, struct mr_params *reply)
 
 int mr_send(int fd, struct mr_params *params)
 {
-  u_long length, written;
+  u_long length;
+  int written;
   int i, *argl;
   char *buf, *p;
 
@@ -99,12 +105,12 @@ int mr_send(int fd, struct mr_params *params)
   length = p - buf;
   putlong(buf, length);
 
-  written = write(fd, buf, length);
+  written = send(fd, buf, length, 0);
   free(buf);
   if (!params->mr_argl)
     free(argl);
 
-  if (written != length)
+  if (written != (int)length)
     return MR_ABORTED;
   else
     return MR_SUCCESS;
@@ -127,10 +133,11 @@ int mr_receive(int fd, struct mr_params *reply)
  * on failure, or -1 if the packet hasn't been completely received
  * yet.
  */
+
 int mr_cont_receive(int fd, struct mr_params *reply)
 {
   u_long length, data;
-  ssize_t size, more;
+  int size, more;
   char *p, *end;
   int i;
 
@@ -138,7 +145,7 @@ int mr_cont_receive(int fd, struct mr_params *reply)
     {
       char lbuf[4];
 
-      size = read(fd, lbuf, 4);
+      size = recv(fd, lbuf, 4, 0);
       if (size != 4)
        return size ? MR_ABORTED : MR_NOT_CONNECTED;
       getlong(lbuf, length);
@@ -155,8 +162,8 @@ int mr_cont_receive(int fd, struct mr_params *reply)
   else
     getlong(reply->mr_flattened, length);
 
-  more = read(fd, reply->mr_flattened + reply->mr_filled,
-             length - reply->mr_filled);
+  more = recv(fd, reply->mr_flattened + reply->mr_filled,
+             length - reply->mr_filled, 0);
   if (more == -1)
     {
       mr_destroy_reply(*reply);
@@ -177,7 +184,7 @@ int mr_cont_receive(int fd, struct mr_params *reply)
 
   getlong(reply->mr_flattened + 8, reply->u.mr_status);
   getlong(reply->mr_flattened + 12, reply->mr_argc);
-  if (reply->mr_argc > (length - 16) / 8)
+  if (reply->mr_argc > ((int)length - 16) / 8)
     {
       mr_destroy_reply(*reply);
       return MR_INTERNAL;
index 26aaf0ed25aaa1326d6bec2ff8f6396c29761c6a..5077a5ce6d58d037be6ff2b474b228166f2b85c4 100644 (file)
 #include "mr_private.h"
 
 #include <sys/types.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <netdb.h>
 
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
+
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
+
+#ifndef _WIN32
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#ifndef closesocket
+#define closesocket close
+#endif
+#ifndef SOCKET_ERROR
+#define SOCKET_ERROR -1
+#endif
+#endif
 
 #ifdef HAVE_HESIOD
 #include <hesiod.h>
@@ -30,6 +41,9 @@
 
 RCSID("$Header$");
 
+#define DEFAULT_SERV "moira_db"
+#define DEFAULT_PORT 775
+
 int _mr_conn = 0;
 static char *mr_server_host = NULL;
 
@@ -119,76 +133,80 @@ int mr_connect(char *server)
 
 int mr_connect_internal(char *server, char *port)
 {
-  int fd, size, more;
+  int size, more;
   struct sockaddr_in target;
   struct hostent *shost;
   char actualresponse[53];
+  char *host = NULL;
+  int fd = SOCKET_ERROR;
+  int ok = 0;
 
   shost = gethostbyname(server);
   if (!shost)
-    return 0;
+    goto cleanup;
+
+  /* Get the host info in case some library decides to clobber shost. */
+  memcpy(&target.sin_addr, shost->h_addr, shost->h_length);
+  target.sin_family = shost->h_addrtype;
+  host = strdup(shost->h_name);
 
   if (port[0] == '#')
-    target.sin_port = htons(atoi(port + 1));
+    target.sin_port = htons((unsigned short)atoi(port + 1));
   else
     {
       struct servent *s;
+      target.sin_port = 0;
       s = getservbyname(port, "tcp");
       if (s)
        target.sin_port = s->s_port;
-      else
 #ifdef HAVE_HESIOD
+      if (!target.sin_port)
         {
           s = hes_getservbyname(port, "tcp");
           if (s)
             target.sin_port = s->s_port;
-          else
-           return 0;
         }
-#else
-       return 0;
 #endif
+      if (!target.sin_port && !strcasecmp(port, DEFAULT_SERV))
+       target.sin_port = htons(DEFAULT_PORT);
+      if (!target.sin_port)
+       goto cleanup;
     }
 
-  memcpy(&target.sin_addr, shost->h_addr, shost->h_length);
-  target.sin_family = shost->h_addrtype;
-
   fd = socket(AF_INET, SOCK_STREAM, 0);
   if (fd < 0)
-    return 0;
+    goto cleanup;
 
   if (connect(fd, (struct sockaddr *)&target, sizeof(target)) < 0)
-    {
-      close(fd);
-      return 0;
-    }
+    goto cleanup;
 
   /* Do magic mrgdb initialization */
-  size = write(fd, challenge, sizeof(challenge));
+  size = send(fd, challenge, sizeof(challenge), 0);
   if (size != sizeof(challenge))
-    {
-      close(fd);
-      return 0;
-    }
+    goto cleanup;
   for (size = 0; size < sizeof(actualresponse); size += more)
     {
-      more = read(fd, actualresponse + size, sizeof(actualresponse) - size);
+      more = recv(fd, actualresponse + size, sizeof(actualresponse) - size, 0);
       if (more <= 0)
        break;
     }
   if (size != sizeof(actualresponse))
-    {
-      close(fd);
-      return 0;
-    }
+    goto cleanup;
   if (memcmp(actualresponse, response, sizeof(actualresponse)))
+    goto cleanup;
+
+  ok = 1;
+  mr_server_host = host;
+
+ cleanup:
+  if (!ok)
     {
-      close(fd);
+      if (host)
+       free(host);
+      if (fd != SOCKET_ERROR)
+       closesocket(fd);
       return 0;
     }
-
-  mr_server_host = strdup(shost->h_name);
-
   /* You win */
   return fd;
 }
@@ -196,7 +214,7 @@ int mr_connect_internal(char *server, char *port)
 int mr_disconnect(void)
 {
   CHECK_CONNECTED;
-  close(_mr_conn);
+  closesocket(_mr_conn);
   _mr_conn = 0;
   free(mr_server_host);
   mr_server_host = NULL;
@@ -258,17 +276,17 @@ int mr_listen(char *port)
     return -1;
   if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(int)) < 0)
     {
-      close(s);
+      closesocket(s);
       return -1;
     }
   if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0)
     {
-      close(s);
+      closesocket(s);
       return -1;
     }
   if (listen(s, 5) < 0)
     {
-      close(s);
+      closesocket(s);
       return -1;
     }
 
@@ -311,9 +329,9 @@ int mr_cont_accept(int conn, char **buf, int *nread)
   if (!*buf)
     {
       char lbuf[4];
-      if (read(conn, lbuf, 4) != 4)
+      if (recv(conn, lbuf, 4, 0) != 4)
        {
-         close(conn);
+         closesocket(conn);
          return 0;
        }
       getlong(lbuf, len);
@@ -322,7 +340,7 @@ int mr_cont_accept(int conn, char **buf, int *nread)
       *buf = malloc(len);
       if (!*buf || len < 58)
        {
-         close(conn);
+         closesocket(conn);
          free(*buf);
          return 0;
        }
@@ -333,11 +351,11 @@ int mr_cont_accept(int conn, char **buf, int *nread)
   else
     getlong(*buf, len);
 
-  more = read(conn, *buf + *nread, len - *nread);
+  more = recv(conn, *buf + *nread, len - *nread, 0);
 
   if (more == -1 && errno != EINTR)
     {
-      close(conn);
+      closesocket(conn);
       free(*buf);
       return 0;
     }
@@ -349,7 +367,7 @@ int mr_cont_accept(int conn, char **buf, int *nread)
 
   if (memcmp(*buf + 4, challenge + 4, 34))
     {
-      close(conn);
+      closesocket(conn);
       free(*buf);
       return 0;
     }
@@ -357,9 +375,9 @@ int mr_cont_accept(int conn, char **buf, int *nread)
   /* good enough */
   free(*buf);
 
-  if (write(conn, response, sizeof(response)) != sizeof(response))
+  if (send(conn, response, sizeof(response), 0) != sizeof(response))
     {
-      close(conn);
+      closesocket(conn);
       return 0;
     }
   return conn;
index 90a3b304edc44d3744852945f2331b0ba20668ec..0838b40e817f2a96815151f5797b7702a2cc3532 100644 (file)
 
 #include <sys/types.h>
 
+#ifndef _WIN32
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#endif /*_WIN32*/
 
 extern int _mr_conn, mr_inited;
 
@@ -32,7 +34,7 @@ typedef struct mr_params {
 #define CHECK_CONNECTED if (!_mr_conn) return MR_NOT_CONNECTED
 
 #define getlong(cp, l) do { l = ((((unsigned char *)cp)[0] * 256 + ((unsigned char *)cp)[1]) * 256 + ((unsigned char *)cp)[2]) * 256 + ((unsigned char *)cp)[3]; } while(0)
-#define putlong(cp, l) do { ((unsigned char *)cp)[0] = l >> 24; ((unsigned char *)cp)[1] = l >> 16; ((unsigned char *)cp)[2] = l >> 8; ((unsigned char *)cp)[3] = l; } while(0)
+#define putlong(cp, l) do { ((unsigned char *)cp)[0] = (unsigned char)(l >> 24); ((unsigned char *)cp)[1] = (unsigned char)(l >> 16); ((unsigned char *)cp)[2] = (unsigned char)(l >> 8); ((unsigned char *)cp)[3] = (unsigned char)(l); } while(0)
 
 /* prototypes from mr_call.h */
 int mr_do_call(struct mr_params *params, struct mr_params *reply);
This page took 0.166296 seconds and 5 git commands to generate.