50 const char *message, ...);
53 #define SHM_KEY (key_t)0x0d50d5ec
54 #define SEM_KEY (key_t)0x0d50d5ec
55 #define SHM_PERM S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP
56 #define SEM_PERM S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP
58 #ifndef HAVE_UNION_SEMUN
75 struct termios oldt, newt;
77 if (prompt == NULL)
return NULL;
82 if (isatty(fileno(stdin))) {
83 if (tcgetattr(fileno(stdin), &oldt) != 0)
return NULL;
85 newt.c_lflag &= ~ECHO;
86 if (tcsetattr(fileno(stdin), TCSAFLUSH, &newt) != 0)
return NULL;
98 if (isatty(fileno(stdin))) {
99 tcsetattr(fileno(stdin), TCSAFLUSH, &oldt);
119 "Could not access the semaphore: %s", strerror(errno));
125 if (semctl(semid, 0, SETVAL, arg) == -1) {
127 "Could not set value on the semaphore: %s", strerror(errno));
134 if (semctl(semid, 0, IPC_STAT, arg) != 0) {
136 "Could not stat the semaphore: %s", strerror(errno));
142 buf.sem_perm.gid != getegid())
145 "Bad permissions on the semaphore, please read Getting Help/Troubleshooting on OpenDNSSEC Wiki about this.");
155 struct sembuf sb = { 0, -1, 0 };
157 if (semop(semid, &sb, 1) == -1) {
159 "Could not lock the semaphore: %s", strerror(errno));
169 struct sembuf sb = { 0, 1, 0 };
171 if (semop(semid, &sb, 1) == -1) {
173 "Could not unlock the semaphore: %s", strerror(errno));
194 "Could not access the shared memory: %s", strerror(errno));
204 if (shmctl(shmid, IPC_STAT, &buf) != 0) {
206 "Could not stat the semaphore: %s", strerror(errno));
211 if (buf.shm_segsz != shmsize) {
213 "Bad memory size, please read Getting Help/Troubleshooting on OpenDNSSEC Wiki about this.");
219 buf.shm_perm.gid != getegid())
222 "Bad permissions on the shared memory, please read Getting Help/Troubleshooting on OpenDNSSEC Wiki about this.");
240 char *prompt_pin = NULL;
241 unsigned int size = 0;
245 if (repository == NULL)
return NULL;
250 if (semid == -1)
return NULL;
263 pins = (
char *)shmat(shmid, NULL, 0);
264 if (pins == (
char *)-1) {
274 size = strlen(&pins[index]);
276 memcpy(pin, &pins[index], size);
288 snprintf(prompt, 64,
"Enter PIN for token %s: ", repository);
290 if (prompt_pin == NULL) {
300 size = strlen(prompt_pin);
303 memcpy(pin, prompt_pin, size);
306 memset(prompt_pin,
'\0', strlen(prompt_pin));
335 unsigned int size = 0;
339 if (repository == NULL)
return NULL;
352 if (semid == -1)
return NULL;
365 pins = (
char *)shmat(shmid, NULL, 0);
366 if (pins == (
char *)-1) {
376 if (pins[index] ==
'\0') {
378 "No PIN in shared memory. "
379 "Please login with \"ods-hsmutil login\"");
390 "Removed bad PIN in shared memory. "
391 "Please login again with \"ods-hsmutil login\"");
399 size = strlen(&pins[index]);
401 memcpy(pin, &pins[index], size);
425 if (errno != ENOENT) {
427 "Could not access the semaphore: %s", strerror(errno));
432 if (semctl(semid, 0, IPC_RMID, arg) != 0) {
434 "Could not delete the semaphore: %s", strerror(errno));
442 if (errno != ENOENT) {
444 "Could not access the shared memory: %s", strerror(errno));
449 if (shmctl(shmid, IPC_RMID, &buf) != 0) {
451 "Could not stat the semaphore: %s", strerror(errno));