int init_shm() { int fd = 0; if(access(KEYFILE, F_OK) < 0){ if(errno == ENOENT){ create_keyfile("111111"); } } if((fd=open(KEYFILE, O_RDWR, 0666)) < 0){ return -1; } key_t key=SYSKEY; int shmid; char *shm = NULL; /* * * Create the segment. */ if ((shmid=shmget(key, sizeof(struct sys_key), IPC_CREAT | 0666)) < 0){ exit(1); } /* * * Now we attach the segment to our data space. */ if ((shm = shmat(shmid, NULL, 0)) == (char *) -1) { exit(1); } read(fd, shm, sizeof(struct sys_key)); close(fd); return 0; }
static void create_file_from_key(char *filename) { size_t size; char *akey = (char *) secrets_fetch("smb_traffic_analyzer_key", &size); if (akey == NULL) { printf("No key is installed! Can't create file.\n"); exit(1); } create_keyfile(filename, akey); free(akey); }