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 
54 #ifdef JS
55 # define JS_STATIC static
56 #else  /* !JS */
57 # define JS_STATIC
58 #endif /* !JS */
59 
60 /* etc/pwd.c */
61 JS_STATIC void new_pwd (char* src, char* encd);
62 JS_STATIC int check_pwd (char* src, char* encd);
63 
64 JS_STATIC void
new_pwd(char * src,char * encd)65 new_pwd(char *src, char *encd)
66 {
67 	int i, x, c;
68 	char xx[3];
69 	char *cr;
70 
71 	if (encd == NULL)
72 		encd = src;
73 
74 	if (strcmp (src, "") == 0) {
75 		bzero (encd, WNN_PASSWD_LEN);
76 		return;
77 	}
78 
79 	x = time (NULL);
80 	xx[0] = x & 0x3f;
81 	xx[1] = (x & 0x3f00) >> 8;
82 
83 	/* for MD5 (that requires terminator) */
84 	xx[2] = '\0';
85 
86 	for (i = 0; i < 2; i++) {
87 		c = xx[i] + '.';
88 		if (c > '9')
89 			c += 7;
90 		if (c > 'Z')
91 			c += 6;
92 		xx[i] = c;
93 	}
94 
95 	cr = crypt(src, xx);
96 	bzero(encd, WNN_PASSWD_LEN);
97 	strncpy(encd, cr, WNN_PASSWD_LEN);
98 }
99 
100 JS_STATIC int
check_pwd(char * src,char * encd)101 check_pwd(char* src, char* encd)
102 {
103 	if (strcmp (encd, "") == 0)
104 		/* No passwd */
105 		return (1);
106 
107 	return (!strncmp(encd, crypt(src, encd), WNN_PASSWD_LEN));
108 }
109