Main Page | Class List | Directories | File List | Class Members | File Members

cfkey.c File Reference

#include "cf.defs.h"
#include "cf.extern.h"

Go to the source code of this file.

Functions

void Initialize ARGLIST ((void))
int main ()
void Initialize ()
void AddMultipleClasses (char *classlist)
void ReleaseCurrentLock ()
int RecursiveTidySpecialArea (char *name, struct Tidy *tp, int maxrecurse, struct stat *sb)

Variables

char CFLOCK [bufsize]


Function Documentation

void AddMultipleClasses char *  classlist  ) 
 

Definition at line 164 of file cfkey.c.

Referenced by cfpclose_def(), CheckExistingFile(), CheckFileWrapper(), CheckForModule(), CheckRequired(), DisableFiles(), DoHardLink(), DoLink(), DoProcessCheck(), DoTidyFile(), FileObjectFilter(), HardLinkFiles(), ImageCopy(), KillOldLink(), LinkFiles(), MakeImages(), and ProcessFilter().

00168 {
00169 }

void Initialize ARGLIST (void)   ) 
 

void Initialize  ) 
 

Definition at line 146 of file cfkey.c.

References CheckWorkDirectories(), RandomSeed(), VLOCKDIR, and VLOGDIR.

00148 {
00149 umask(077);
00150 strcpy(VLOCKDIR,WORKDIR);
00151 strcpy(VLOGDIR,WORKDIR); 
00152 
00153 OpenSSL_add_all_algorithms();
00154 ERR_load_crypto_strings();
00155 
00156 CheckWorkDirectories();
00157 RandomSeed();
00158 }

int main  ) 
 

Definition at line 42 of file cfkey.c.

References bufsize, CFPRIVKEYFILE, CFPUBKEYFILE, errno, fp, Initialize(), NULL, snprintf(), strerror(), VBUFF, VERBOSE, and VLOGDIR.

00044 { unsigned long err;
00045   RSA *pair;
00046   FILE *fp;
00047   struct stat statbuf;
00048   int fd;
00049   static char *passphrase = "Cfengine passphrase";
00050   EVP_CIPHER *cipher = EVP_des_ede3_cbc();
00051 
00052 
00053 Initialize();
00054  
00055 if (stat(CFPRIVKEYFILE,&statbuf) != -1)
00056    {
00057    printf("A key file already exists at %s.\n",CFPRIVKEYFILE);
00058    return 1;
00059    }
00060 
00061 if (stat(CFPUBKEYFILE,&statbuf) != -1)
00062    {
00063    printf("A key file already exists at %s.\n",CFPUBKEYFILE);
00064    return 1;
00065    }
00066 
00067 printf("Making a key pair for cfengine, please wait, this could take a minute...\n"); 
00068 
00069 pair = RSA_generate_key(2048,35,NULL,NULL);
00070 
00071 if (pair == NULL)
00072    {
00073    err = ERR_get_error();
00074    printf("Error = %s\n",ERR_reason_error_string(err));
00075    return 1;
00076    }
00077 
00078 if (VERBOSE)
00079    {
00080    RSA_print_fp(stdout,pair,0);
00081    }
00082  
00083 fd = open(CFPRIVKEYFILE,O_WRONLY | O_CREAT | O_TRUNC, 0600);
00084 
00085 if (fd < 0)
00086    {
00087    printf("Ppen %s failed: %s.",CFPRIVKEYFILE,strerror(errno));
00088    return 0;
00089    }
00090  
00091 if ((fp = fdopen(fd, "w")) == NULL )
00092    {
00093    printf("fdopen %s failed: %s.",CFPRIVKEYFILE, strerror(errno));
00094    close(fd);
00095    return 0;
00096    }
00097 
00098 printf("Writing private key to %s\n",CFPRIVKEYFILE);
00099  
00100 if (!PEM_write_RSAPrivateKey(fp,pair,cipher,passphrase,strlen(passphrase),NULL,NULL))
00101     {
00102     err = ERR_get_error();
00103     printf("Error = %s\n",ERR_reason_error_string(err));
00104     return 1;
00105     }
00106  
00107 fclose(fp);
00108  
00109 fd = open(CFPUBKEYFILE,O_WRONLY | O_CREAT | O_TRUNC, 0600);
00110 
00111 if (fd < 0)
00112    {
00113    printf("open %s failed: %s.",CFPUBKEYFILE,strerror(errno));
00114    return 0;
00115    }
00116  
00117 if ((fp = fdopen(fd, "w")) == NULL )
00118    {
00119    printf("fdopen %s failed: %s.",CFPUBKEYFILE, strerror(errno));
00120    close(fd);
00121    return 0;
00122    }
00123 
00124 printf("Writing public key to %s\n",CFPUBKEYFILE);
00125  
00126 if(!PEM_write_RSAPublicKey(fp,pair))
00127    {
00128    err = ERR_get_error();
00129    printf("Error = %s\n",ERR_reason_error_string(err));
00130    return 1;
00131    }
00132 
00133 fclose(fp);
00134 
00135  
00136 snprintf(VBUFF,bufsize,"%s/randseed",VLOGDIR);
00137 RAND_write_file(VBUFF);
00138 chmod(VBUFF,0644); 
00139 return 0;
00140 }

int RecursiveTidySpecialArea char *  name,
struct Tidy tp,
int  maxrecurse,
struct stat *  sb
 

Definition at line 176 of file cfkey.c.

00183 {
00184  return true;
00185 }

void ReleaseCurrentLock  ) 
 

Definition at line 171 of file cfkey.c.

Referenced by AddToFstab(), CheckFileWrapper(), CheckProcesses(), CheckRequired(), ConfigureInterfaces(), DirectoriesWrapper(), DisableFiles(), DoEditFile(), DoExec(), DoTree(), ExitCleanly(), FatalError(), GetMountInfo(), HandleSignal(), MailCheck(), main(), MakeChildLinks(), MakeImages(), MakeLinks(), RecFileCheck(), RecHomeTidyWrapper(), Scripts(), StartServer(), TidyWrapper(), and Unmount().

00172 {
00173 }


Variable Documentation

char CFLOCK[bufsize]
 

Definition at line 35 of file cfkey.c.


© sourcejam.com 2005-2008