source: trunk/third/moira/reg_svr/genwords.pc @ 23740

Revision 23740, 1.9 KB checked in by broder, 16 years ago (diff)
In moira: * New CVS snapshot (Trac: #195) * Drop patches that have been incorporated upstream. * Update to build without krb4 on systems that no longer have it. This doesn't build yet on squeeze, which lacks a krb4 library, but I'm committing now before I start hacking away at a patch to fix that.
Line 
1/* $Id: genwords.pc,v 1.2 2000-08-25 23:38:35 zacheiss Exp $
2 *
3 * Utility program to generate magic words for a given ID
4 *
5 * Copyright (C) 1998 by the Massachusetts Institute of Technology
6 * For copying and distribution information, please see the file
7 * <mit-copyright.h>.
8 *
9 */
10
11#include <mit-copyright.h>
12#include <moira.h>
13#include <moira_schema.h>
14#include "reg_svr.h"
15
16#include <stdio.h>
17#include <stdlib.h>
18
19EXEC SQL INCLUDE sqlca;
20
21RCSID("$Header: /afs/athena.mit.edu/astaff/project/moiradev/repository/moira/reg_svr/genwords.pc,v 1.2 2000-08-25 23:38:35 zacheiss Exp $");
22
23int main(int argc, char **argv)
24{
25  char *words[6];
26  int verb;
27
28  if (argc > 1 && !strcmp(argv[1], "-v"))
29    {
30      verb++;
31      argv++;
32      argc--;
33    }
34
35  if (argc != 2)
36    {
37      fprintf(stderr, "Usage: genwords [-v] id\n");
38      exit(1);
39    }
40
41  if (!read_hmac_key())
42    {
43      fprintf(stderr, "Couldn't read hmac key\n");
44      exit(1);
45    }
46
47  getwordlist(argv[1], words);
48  if (verb)
49    {
50      EXEC SQL BEGIN DECLARE SECTION;
51      char first[USERS_FIRST_SIZE], middle[USERS_MIDDLE_SIZE];
52      char last[USERS_LAST_SIZE], *id, *database = "moira";
53      EXEC SQL END DECLARE SECTION;
54
55      EXEC SQL CONNECT :database IDENTIFIED BY :database;
56
57      id = argv[1];
58      EXEC SQL SELECT first, middle, last INTO :first, :middle, :last
59        FROM users WHERE clearid = :id;
60      if (sqlca.sqlcode)
61        {
62          sprintf(first, "%d", sqlca.sqlcode);
63          *middle = *last = '\0';
64        }
65      else
66        {
67          strtrim(first);
68          strtrim(middle);
69          strtrim(last);
70        }
71
72      printf("(%s%s%s %s) (%s) (%s) (%s) (%s) (%s) (%s) (%s) dopage\n",
73             first, *middle ? " " : "", middle, last, id,
74             words[0], words[1], words[2], words[3], words[4], words[5]);
75    }
76  else
77    {
78      printf("%s %s %s %s %s %s\n", words[0], words[1], words[2],
79             words[3], words[4], words[5]);
80    }
81}
82
83/* used by words.c */
84void *xmalloc(size_t size)
85{
86  /* we won't run out of memory here */
87  return malloc(size);
88}
Note: See TracBrowser for help on using the repository browser.