source: trunk/third/moira/update/smskey.c @ 24319

Revision 24319, 1.3 KB checked in by broder, 15 years ago (diff)
New Moira snapshot from SVN.
Line 
1/* $Id: smskey.c 3956 2010-01-05 20:56:56Z zacheiss $
2 *
3 * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology.
4 * For copying and distribution information, please see the file
5 * <mit-copyright.h>.
6 */
7
8#include <mit-copyright.h>
9#include <moira.h>
10
11#include <fcntl.h>
12#include <stdio.h>
13#include <string.h>
14#include <unistd.h>
15
16#include <des.h>
17
18RCSID("$HeadURL: svn+ssh://svn.mit.edu/moira/trunk/moira/update/smskey.c $ $Id: smskey.c 3956 2010-01-05 20:56:56Z zacheiss $");
19
20int debug = 0;                  /* goddamn des library breakage */
21char string[] = "sms\0\0Athena\0\1";
22char srvtab[] = "/etc/srvtab";
23char insecure[] =
24    "\7\7\7This program MUST be run on the console, for security reasons.\n";
25
26int main(int argc, char **argv)
27{
28  int fd;
29  des_cblock key;
30  char *tty;
31  tty = ttyname(0);
32  if (!tty || strcmp(tty, "/dev/console"))
33    {
34      fprintf(stderr, insecure);
35      exit(1);
36    }
37  fd = open(srvtab, O_WRONLY|O_APPEND, 0);
38  if (!fd)
39    {
40      perror(srvtab);
41      exit(1);
42    }
43  if (sizeof(string) - 1 != 13)
44    {
45      fprintf(stderr, "string size bad\n");
46      exit(1);
47    }
48  des_read_password(key, "Enter SMS update password: ", 0);
49  write(fd, string, sizeof(string) - 1);
50  write(fd, key, sizeof(C_Block));
51  if (fsync(fd))
52    perror(srvtab);
53  close(fd);
54  printf("\nKey written.\n");
55  exit(0);
56}
Note: See TracBrowser for help on using the repository browser.