00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <eyedbconfig.h>
00025
00026 #include <stdio.h>
00027 #include <stdlib.h>
00028 #include <string.h>
00029 #include <fcntl.h>
00030 #include <unistd.h>
00031 #include <sys/types.h>
00032 #include <sys/stat.h>
00033 #ifdef HAVE_CRYPT_H
00034 #include <crypt.h>
00035 #endif
00036
00037 int
00038 main(int argc, char *argv[])
00039 {
00040 char s[64];
00041
00042 if (argc != 3)
00043 {
00044 fprintf(stderr, "usage: %s cryptfile passwd\n", argv[0]);
00045 return 1;
00046 }
00047
00048 int fd = creat(argv[1], 0600);
00049
00050 if (fd < 0)
00051 {
00052 fprintf(stderr, "%s: cannot create file '%s'\n", argv[0], argv[1]);
00053 return 1;
00054 }
00055
00056 if (strlen(argv[2]) > 8)
00057 argv[2][8] = 0;
00058
00059 strcpy(s, crypt(argv[2], "r8"));
00060 s[13] = 0;
00061
00062 if (write(fd, s, 14) != 14)
00063 {
00064 fprintf(stderr, "%s: cannot write file '%s'\n", argv[0], argv[1]);
00065 return 1;
00066 }
00067
00068 fchmod(fd, 0400);
00069
00070 close(fd);
00071
00072 return 0;
00073 }