home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3250 < prev    next >
Encoding:
Internet Message Format  |  1991-04-29  |  5.7 KB

  1. From: dowjones@imp.com (Joachim Astel)
  2. Newsgroups: comp.unix.xenix.sco,alt.sources
  3. Subject: Workaround for SCO UNIX "ct"
  4. Message-ID: <1991Apr29.005233.21495@impch.imp.com>
  5. Date: 29 Apr 91 00:52:33 GMT
  6.  
  7. This is a workaround for the SCO UNIX SysV R3.2 ct-bug. The following program
  8. "callback" takes a phone number as an argument and calls back the specified
  9. number at a fixed speed. Note my WARNING in callback.c, which reads that EVERY
  10. person on the system can do a callback (because the system runs setuid root).
  11. It uses /etc/init which can handle the correct permissions and so on.
  12.  
  13. You may feel free to modify the sources, but don't blame me with them. :-)
  14. The program was a quick one, so I do not make gurantees for anything.
  15.  
  16. To make it run, you must do the following:
  17.  
  18. 1. Unshar the following shar-archive
  19.  
  20. 2. edit the Makefile to your personal needs
  21.  
  22. 3. read the comments at the beginning of callback.c, and modify the "#defines"
  23.    to your personal needs (baudrate in CT_CMDSTRING, etc.)
  24.  
  25. 4. type ("make" and) "make install" at your shell-prompt
  26.  
  27. 5. edit the /etc/inittab file and add an entry for /usr/bin/callout (this
  28.    is mentioned in 'detail' at the beginning of callback.c)
  29.  
  30. Here we go...
  31. --------------------------------- cut here ------------------------------------
  32. :
  33. # This is a shell archive, meaning:
  34. # 1. Remove everything above the : line.
  35. # 2. Save the resulting text in a file.
  36. # 3. Execute the file with /bin/sh (not csh) to create:
  37. #    callback.c
  38. #    Makefile
  39. # This archive created: Mon Apr 29 02:12:26 1991 by dowjones@impch.imp.com
  40. export PATH; PATH=/bin:/usr/bin:$PATH
  41. if test -f 'callback.c'
  42. then
  43.     echo shar: "will not over-write existing file 'callback.c'"
  44. else
  45. sed 's/^X//' << \SHAR_EOF > 'callback.c'
  46. X/*
  47. X * callback.c - Copyright (C) 1991 by Joachim Astel (dowjones@jattmp.imp.com)
  48. X *
  49. X * WARNING: the program runs as -rws--x--x root (suid-bit set for root),
  50. X *          so EVERY person on the system can make the unix system to call
  51. X *          him/her back. USE IT ON YOUR OWN RISK.
  52. X * 
  53. X * This program fetches superuser-permissions and creates a temporary
  54. X * shell-script "CALL_FILE" with a "sleep 10" and "ct" command in it.
  55. X * Afterwards, an "init"-command is executed, and the shell script is
  56. X * activated from init as far as there is an appropriate line entry in
  57. X * /etc/inittab, like the following:
  58. X *
  59. X * "cbc:c:once:/usr/bin/callout" (without quotation marks, of course)
  60. X *      ^      ^^^^^^^^^^^^^^^^ Must be the same as in #define CALL_FILE
  61. X *      ^
  62. X *      if you have already an entry "c" in use, change the defined
  63. X *    INITTAB_ID (see below) to "a" or "b"
  64. X *
  65. X * It works under SCO UNIX SysV R3.2, which has problems with its C2-system
  66. X * if you try to execute "ct" directly.
  67. X *
  68. X * BUGS: the error handling could be better. All in all, the program was a
  69. X *       a quick hack. I got reports from some users that this programm did
  70. X *       not call back at some time. But that effect was non-reproduceable.
  71. X */
  72. X
  73. X#include <stdio.h>
  74. X#include <signal.h>
  75. X#include <time.h>
  76. X#include <pwd.h>
  77. X
  78. X/* You may feel free to change the following defines */
  79. X
  80. X#define LOG_FILE "/usr/adm/callback"
  81. X#define CT_CMDSTRING "ct -s 2400 %s\n" /* (%s: phone-number.) */
  82. X#define CALL_FILE "/usr/bin/callout" /* must be mentioned in /etc/inittab */
  83. X#define INITTAB_ID "c" /* "slot" in /etc/inittab */
  84. X#define NOTE \
  85. X    "Please hang up now and reconfigure your modem to auto-answer mode."
  86. X
  87. X#ifndef GETLUID
  88. X#define getluid getuid
  89. X#endif
  90. X
  91. Xchar *Prgrm;
  92. X
  93. X#define SAME 0 /* for strcmp */
  94. X
  95. X/* return username of specific id */
  96. Xchar *username(id)
  97. X    int id;
  98. X{
  99. X    struct passwd *pwd;
  100. X
  101. X    setpwent(); /* rewind passwd file */
  102. X    if ((pwd = getpwuid(id)) == NULL) {
  103. X        fprintf(stderr, "%s: Unknown user-id: %d\n", Prgrm, id);
  104. X        exit(1);
  105. X    }
  106. X    endpwent(); /* close passwd file */
  107. X    return pwd->pw_name;
  108. X}
  109. X
  110. Xmain(argc, argv)
  111. X    int argc;
  112. X    char **argv;
  113. X{
  114. X    FILE *call_file, *log_file;
  115. X    char *phone_number;
  116. X    int pid;
  117. X
  118. X    Prgrm = *argv;
  119. X
  120. X    if (argc != 2) {
  121. X        fprintf(stderr, "Usage: %s phone-number\n", Prgrm);
  122. X        exit(0);
  123. X    }
  124. X    phone_number = argv[1];
  125. X
  126. X    if (!(pid = fork())) { /* Child-process */
  127. X        setgid(0); setuid(0); /* get root permissions */
  128. X
  129. X        if ((call_file = fopen(CALL_FILE, "w")) == NULL) {
  130. X            fprintf(stderr, "Error: Cannot open %s\n", CALL_FILE);
  131. X            kill(pid, 9); /* don't let parent process hangup */
  132. X            exit(1); /* abort program */
  133. X        }
  134. X        fprintf(call_file, "sleep 10\n");
  135. X        fprintf(call_file, CT_CMDSTRING, phone_number);
  136. X        fclose(call_file);
  137. X          chmod(CALL_FILE, 0755);
  138. X
  139. X        close(0); close(1); close(2); /* ignore signals etc. */
  140. X        signal(SIGHUP, SIG_IGN);
  141. X
  142. X        if ((log_file = fopen(LOG_FILE, "w+")) != NULL) {
  143. X            time_t t;
  144. X            time(&t);
  145. X            fprintf(log_file, "%s: %s %s\n", username(getluid()),
  146. X                phone_number, ctime(&t));
  147. X            fclose(log_file);
  148. X        }
  149. X        execl("/etc/init", "call-back", INITTAB_ID, NULL);
  150. X    /* on error... */
  151. X        fprintf(stderr, "Error: Cannot execute init\n");
  152. X        kill(pid, 9); /* don't let parent-process hangup the line */
  153. X        exit(1); /* abort program */
  154. X    }
  155. X}
  156. SHAR_EOF
  157. fi
  158. if test -f 'Makefile'
  159. then
  160.     echo shar: "will not over-write existing file 'Makefile'"
  161. else
  162. sed 's/^X//' << \SHAR_EOF > 'Makefile'
  163. X# Makefile for "callback.c"
  164. X
  165. XCC = cc
  166. XBINFILE = callback
  167. XINSTALLPATH = /usr/bin
  168. X
  169. XOBJECTS = callback.o
  170. X
  171. Xall: $(BINFILE)
  172. X    @echo "Now start \"make install\""
  173. X
  174. X$(BINFILE): $(OBJECTS)
  175. X    $(CC) $(CFLAGS) -o $(@) $(OBJECTS)
  176. X
  177. Xinstall: $(BINFILE)
  178. X    cp $(BINFILE) $(INSTALLPATH)
  179. X    strip $(INSTALLPATH)/$(BINFILE)
  180. X    chmod 4111 $(INSTALLPATH)/$(BINFILE)
  181. X    chgrp bin $(INSTALLPATH)/$(BINFILE)
  182. X    chown root $(INSTALLPATH)/$(BINFILE)
  183. X
  184. Xclean:
  185. X    -rm -f *.o core
  186. X
  187. Xclobber:
  188. X    -rm -f *.o core $(BINFILE)
  189. SHAR_EOF
  190. fi
  191. exit 0
  192. #    End of shell archive
  193. -- 
  194. Joachim Astel, E-MAIL: dowjones@jattmp.imp.com, dowjones@jattmp.nbg.sub.org
  195.