0
|
1 /*
|
|
2 * $Id: pwd.c,v 1.6 2004/07/12 17:53:02 hiroo Exp $
|
|
3 */
|
|
4
|
|
5 /*
|
|
6 * FreeWnn is a network-extensible Kana-to-Kanji conversion system.
|
|
7 * This file is part of FreeWnn.
|
|
8 *
|
|
9 * Copyright Kyoto University Research Institute for Mathematical Sciences
|
|
10 * 1987, 1988, 1989, 1990, 1991, 1992
|
|
11 * Copyright OMRON Corporation. 1987, 1988, 1989, 1990, 1991, 1992, 1999
|
|
12 * Copyright ASTEC, Inc. 1987, 1988, 1989, 1990, 1991, 1992
|
|
13 * Copyright FreeWnn Project 1999, 2000, 2002
|
|
14 *
|
|
15 * Maintainer: FreeWnn Project <freewnn@tomo.gr.jp>
|
|
16 *
|
|
17 * This program is free software; you can redistribute it and/or modify
|
|
18 * it under the terms of the GNU General Public License as published by
|
|
19 * the Free Software Foundation; either version 2 of the License, or
|
|
20 * (at your option) any later version.
|
|
21 *
|
|
22 * This program is distributed in the hope that it will be useful,
|
|
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
25 * GNU General Public License for more details.
|
|
26 *
|
|
27 * You should have received a copy of the GNU General Public License
|
|
28 * along with this program; if not, write to the Free Software
|
|
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
30 */
|
|
31
|
|
32 /*
|
|
33 eval(crypt(PWD, "HA")) routine.
|
|
34 */
|
|
35 #ifdef HAVE_CONFIG_H
|
|
36 # include <config.h>
|
|
37 #endif
|
|
38
|
|
39 #ifndef JS
|
|
40 #include <stdio.h>
|
|
41 #if STDC_HEADERS
|
|
42 # include <string.h>
|
|
43 #elif HAVE_STRINGS_H
|
|
44 # include <strings.h>
|
|
45 #endif /* STDC_HEADERS */
|
|
46 #if HAVE_UNISTD_H
|
|
47 # include <unistd.h>
|
|
48 #endif
|
|
49 #include "commonhd.h"
|
|
50 #include "jslib.h"
|
|
51 #include "wnn_os.h"
|
|
52 #endif /* !JS */
|
|
53
|
3
|
54 #include <time.h>
|
|
55
|
0
|
56 #ifdef JS
|
|
57 # define JS_STATIC static
|
|
58 #else /* !JS */
|
|
59 # define JS_STATIC
|
|
60 #endif /* !JS */
|
|
61
|
|
62 /* etc/pwd.c */
|
|
63 JS_STATIC void new_pwd (char* src, char* encd);
|
|
64 JS_STATIC int check_pwd (char* src, char* encd);
|
|
65
|
|
66 JS_STATIC void
|
|
67 new_pwd (char* src, char* encd)
|
|
68 {
|
|
69 int i, x, c;
|
|
70 char xx[3];
|
|
71 char *cr;
|
|
72
|
|
73 if (encd == NULL)
|
|
74 encd = src;
|
|
75 if (strcmp (src, "") == 0)
|
|
76 {
|
|
77 bzero (encd, WNN_PASSWD_LEN);
|
|
78 return;
|
|
79 }
|
|
80 x = time (NULL);
|
|
81 xx[0] = x & 0x3f;
|
|
82 xx[1] = (x & 0x3f00) >> 8;
|
|
83 xx[2] = '\0'; /* for MD5 (that requires terminator) */
|
|
84 for (i = 0; i < 2; i++)
|
|
85 {
|
|
86 c = xx[i] + '.';
|
|
87 if (c > '9')
|
|
88 c += 7;
|
|
89 if (c > 'Z')
|
|
90 c += 6;
|
|
91 xx[i] = c;
|
|
92 }
|
|
93 cr = crypt (src, xx);
|
|
94 bzero (encd, WNN_PASSWD_LEN);
|
|
95 strncpy (encd, cr, WNN_PASSWD_LEN);
|
|
96 }
|
|
97
|
|
98 JS_STATIC int
|
|
99 check_pwd (char* src, char* encd)
|
|
100 {
|
|
101 if (strcmp (encd, "") == 0)
|
|
102 return (1); /* No passwd */
|
|
103 return (!strncmp (encd, crypt (src, encd), WNN_PASSWD_LEN));
|
|
104 }
|