eyedbcrypt.cc

00001 /* 
00002    EyeDB Object Database Management System
00003    Copyright (C) 1994-2008 SYSRA
00004    
00005    EyeDB is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009    
00010    EyeDB is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014    
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with this library; if not, write to the Free Software
00017    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA 
00018 */
00019 
00020 /*
00021    Author: Eric Viara <viara@sysra.com>
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 }

Generated on Mon Dec 22 18:15:54 2008 for eyedb by  doxygen 1.5.3