Skip to content

Commit ecccbba

Browse files
committed
Adding the possibility to notify a parent, via a file descriptor, that everything went fine. Useful in combination with PAM and forking.
1 parent b1f2cd7 commit ecccbba

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

src/fs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ crypt4gh_sqlite_read(fuse_req_t req, fuse_ino_t ino,
674674
data_fbuf = (struct fuse_buf *)calloc(1, sizeof(struct fuse_buf));
675675
if(!data_fbuf){ err = -ENOMEM; goto error; }
676676

677-
if(fh->header){ // Try Crypt4GH data
677+
if(config.seckeypath && fh->header){ // Try Crypt4GH data
678678

679679
data_fbuf->mem = calloc(data_size, sizeof(char));
680680
if(!data_fbuf->mem){ err = -ENOMEM; goto error; }

src/includes.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ struct fs_config {
139139
uint8_t seckey[crypto_kx_SECRETKEYBYTES]; /* unlocked secret key. TODO: better protect it */
140140
uint8_t pubkey[crypto_kx_PUBLICKEYBYTES];
141141

142+
/* PAM notify */
143+
int parent_fd;
144+
142145
/* SQLite database */
143146
char* db_path;
144147
sqlite3* db;

src/main.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ static struct fuse_opt fs_opts[] = {
8383
CRYPT4GH_SQLITE_OPT("seckey=%s" , seckeypath , 0),
8484
CRYPT4GH_SQLITE_OPT("passphrase_from_env=%s", passphrase_from_env, 0),
8585

86+
CRYPT4GH_SQLITE_OPT("parent_fd=%u", parent_fd, -1),
87+
8688
/* if multithreaded */
8789
CRYPT4GH_SQLITE_OPT("-s" , singlethread , 1),
8890
CRYPT4GH_SQLITE_OPT("clone_fd" , clone_fd , 1),
@@ -205,10 +207,16 @@ c4gh_init(void)
205207
{
206208
int res = 0;
207209

208-
D1("Initializing the file system");
210+
if(config.seckeypath == NULL){
211+
D1("Crypt4GH decryption disabled");
212+
return 0; // it's allowed
213+
}
214+
215+
D1("Initializing Crypt4GH");
216+
D1("Secret key path: %s", config.seckeypath);
209217

210-
if(!config.seckeypath || *config.seckeypath != '/'){
211-
E("Missing secret key path, or non-absolute path");
218+
if(*config.seckeypath != '/'){
219+
E("Secret key must be an absolute path");
212220
res ++;
213221
goto bailout;
214222
}
@@ -288,6 +296,7 @@ int main(int argc, char *argv[])
288296
config.singlethread = 0;
289297
config.foreground = 0;
290298
config.mounted_at = time(NULL);
299+
config.parent_fd = -1;
291300

292301
config.entry_timeout = DEFAULT_ENTRY_TIMEOUT;
293302
config.attr_timeout = DEFAULT_ATTR_TIMEOUT;
@@ -436,6 +445,19 @@ int main(int argc, char *argv[])
436445
config.fperm,
437446
config.dperm);
438447

448+
/* Notify the parent */
449+
if(config.parent_fd > 0){
450+
char data= '1';
451+
if(write(config.parent_fd, &data, 1) != 1){
452+
E("Error writing back to the parent: %s", strerror(errno));
453+
res = 7;
454+
/* should we close the parent_fd on error ? */
455+
goto bailout_unmount;
456+
}
457+
close(config.parent_fd);
458+
config.parent_fd = -1;
459+
}
460+
439461
if (config.singlethread){
440462
D2("Mode: single-threaded");
441463
res = fuse_session_loop(se);

0 commit comments

Comments
 (0)