Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
10 | reyssat | 1 | /* Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis |
2 | * |
||
3 | * This program is free software; you can redistribute it and/or modify |
||
4 | * it under the terms of the GNU General Public License as published by |
||
5 | * the Free Software Foundation; either version 2 of the License, or |
||
6 | * (at your option) any later version. |
||
7 | * |
||
8 | * This program is distributed in the hope that it will be useful, |
||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
11 | * GNU General Public License for more details. |
||
12 | * |
||
13 | * You should have received a copy of the GNU General Public License |
||
14 | * along with this program; if not, write to the Free Software |
||
15 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
||
16 | */ |
||
17 | |||
18 | /* Crypt password as in /etc/shadow */ |
||
19 | |||
20 | #define MAX_LINELEN 1024 |
||
21 | |||
22 | #include <stdio.h> |
||
23 | #include <stdlib.h> |
||
24 | #include <string.h> |
||
25 | #include <unistd.h> |
||
26 | #include <sys/types.h> |
||
27 | #include <ctype.h> |
||
28 | #include "../config.h" |
||
29 | #ifdef HAVE_SYS_TIME_H |
||
30 | #include <sys/time.h> |
||
31 | #endif |
||
32 | #ifdef HAVE_CRYPT |
||
33 | #include <crypt.h> |
||
34 | #endif |
||
35 | |||
36 | int salt; |
||
37 | char schar[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./"; |
||
38 | |||
39 | void pcrypt(char *p) |
||
40 | { |
||
41 | #ifdef HAVE_CRYPT |
||
42 | char saltstr[4]; |
||
43 | char *pp, buf[MAX_LINELEN+1]; |
||
44 | saltstr[0]=schar[salt%64]; |
||
45 | saltstr[1]=schar[(salt/64)%64]; |
||
46 | saltstr[2]=0; |
||
47 | while(isspace(*p)) p++; |
||
48 | for(pp=p+strlen(p); pp>p && isspace(*(pp-1)); pp--); *pp=0; |
||
49 | snprintf(buf,sizeof(buf),"%s",crypt(p,saltstr)); |
||
50 | strcpy(p,buf); |
||
51 | #endif |
||
52 | } |
||
53 | |||
54 | int main(int argc,char *argv[]) |
||
55 | { |
||
56 | int salt1; |
||
57 | char p[MAX_LINELEN+1]; |
||
58 | |||
59 | #ifdef HAVE_GETTIMEOFDAY |
||
60 | struct timeval tv; |
||
61 | gettimeofday(&tv,NULL); salt1=tv.tv_sec+tv.tv_usec; |
||
62 | #else |
||
63 | salt1=3219; |
||
64 | #endif |
||
65 | if(argc<1) return 1; |
||
66 | srandom(salt1+getpid()); |
||
67 | salt=random()/101; |
||
68 | snprintf(p,sizeof(p),"%s",argv[1]); |
||
69 | pcrypt(p); printf("%s\n",p); |
||
70 | |||
71 | return 0; |
||
72 | } |
||
73 |