{"action":"created","comment":{"url":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/comments/80094258","id":80094258,"diff_hunk":"@@ -0,0 +1,388 @@\n+/**\n+ * @file\n+ *\n+ * @brief filter plugin providing cryptographic operations\n+ *\n+ * @copyright BSD License (see doc/COPYING or http://www.libelektra.org)\n+ *\n+ */\n+\n+#ifndef HAVE_KDBCONFIG\n+#include \"kdbconfig.h\"\n+#endif\n+#include \"fcrypt.h\"\n+#include <gpg.h>\n+#include <kdb.h>\n+#include <kdberrors.h>\n+#include <kdbtypes.h>\n+#include <stdlib.h>\n+#include <string.h>\n+#include <errno.h>\n+#include <fcntl.h>\n+#include <sys/stat.h>\n+#include <sys/types.h>\n+#include <unistd.h>\n+\n+enum fcryptGetState\n+{\n+\tPREGETSTORAGE = 0,\n+\tPOSTGETSTORAGE = 1\n+};\n+\n+struct _fcryptState\n+{\n+\tenum fcryptGetState getState;\n+};\n+typedef struct _fcryptState fcryptState;\n+\n+/**\n+ * @brief Allocates a new string holding the name of the temporary file.\n+ * @param file holds the path to the original file\n+ * @returns an allocated string holding the name of the encrypted file. Must be freed by the caller.\n+ */\n+static char * getTemporaryFileName (const char * file)\n+{\n+\tconst size_t newFileAllocated = strlen (file) + 7;\n+\tchar * newFile = elektraMalloc (newFileAllocated);\n+\tif (!newFile) return NULL;\n+\tsnprintf (newFile, newFileAllocated, \"%sXXXXXX\", file);\n+\tmkstemp (newFile);\n+\treturn newFile;\n+}\n+\n+/**\n+ * @brief lookup if the test mode for unit testing is enabled.\n+ * @param conf KeySet holding the plugin configuration.\n+ * @retval 0 test mode is not enabled\n+ * @retval 1 test mode is enabled\n+ */\n+static int inTestMode (KeySet * conf)\n+{\n+\tKey * k = ksLookupByName (conf, ELEKTRA_CRYPTO_PARAM_GPG_UNIT_TEST, 0);\n+\tif (k && !strcmp (keyString (k), \"1\"))\n+\t{\n+\t\treturn 1;\n+\t}\n+\treturn 0;\n+}\n+\n+/**\n+ * @brief Read number of total GPG recipient keys from the plugin configuration.\n+ * @param config holds the plugin configuration\n+ * @returns the number of GPG recipient keys.\n+ */\n+static size_t getRecipientCount (KeySet * config)\n+{\n+\tKey * k;\n+\tsize_t recipientCount = 0;\n+\tKey * root = ksLookupByName (config, ELEKTRA_CRYPTO_PARAM_GPG_KEY, 0);\n+\n+\tif (!root) return 0;\n+\n+\t// toplevel\n+\tif (strlen (keyString (root)) > 0)\n+\t{\n+\t\trecipientCount++;\n+\t}\n+\n+\tksRewind (config);\n+\twhile ((k = ksNext (config)) != 0)\n+\t{\n+\t\tif (keyIsBelow (k, root))\n+\t\t{\n+\t\t\trecipientCount++;\n+\t\t}\n+\t}\n+\treturn recipientCount;\n+}\n+\n+/**\n+ * @brief encrypt the file speicied at parentKey\n+ * @param pluginConfig holds the plugin configuration\n+ * @pararm parentKey holds the path to the file to be encrpted. Will hold an error description in case of failure.\n+ * @retval 1 on success\n+ * @retval -1 on error, errorKey holds an error description\n+ */\n+static int encrypt (KeySet * pluginConfig, Key * parentKey)\n+{\n+\tconst size_t recipientCount = getRecipientCount (pluginConfig);\n+\tif (recipientCount == 0)\n+\t{\n+\t\tELEKTRA_SET_ERRORF (ELEKTRA_ERROR_CRYPTO_CONFIG_FAULT, parentKey,\n+\t\t\t\t    \"Missing GPG key (specified as %s) in plugin configuration.\", ELEKTRA_CRYPTO_PARAM_GPG_KEY);\n+\t\treturn -1;\n+\t}\n+\n+\tconst size_t testMode = inTestMode (pluginConfig);\n+\n+\tchar * tmpFile = getTemporaryFileName (keyString (parentKey));","path":"src/plugins/fcrypt/fcrypt.c","position":118,"original_position":118,"commit_id":"63e302c72ea0d7ce23a8e982810ebcb7adeca297","original_commit_id":"628f297f56c0397564adf2415a65b12d3c301c27","user":{"login":"petermax2","id":2538677,"avatar_url":"https://avatars.githubusercontent.com/u/2538677?v=3","gravatar_id":"","url":"https://api.github.com/users/petermax2","html_url":"https://github.com/petermax2","followers_url":"https://api.github.com/users/petermax2/followers","following_url":"https://api.github.com/users/petermax2/following{/other_user}","gists_url":"https://api.github.com/users/petermax2/gists{/gist_id}","starred_url":"https://api.github.com/users/petermax2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petermax2/subscriptions","organizations_url":"https://api.github.com/users/petermax2/orgs","repos_url":"https://api.github.com/users/petermax2/repos","events_url":"https://api.github.com/users/petermax2/events{/privacy}","received_events_url":"https://api.github.com/users/petermax2/received_events","type":"User","site_admin":false},"body":"fixed - I used `mktemp()` instead, which does not return a file descriptor.","created_at":"2016-09-22T17:35:03Z","updated_at":"2016-09-22T17:35:03Z","html_url":"https://github.com/ElektraInitiative/libelektra/pull/945#discussion_r80094258","pull_request_url":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/945","_links":{"self":{"href":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/comments/80094258"},"html":{"href":"https://github.com/ElektraInitiative/libelektra/pull/945#discussion_r80094258"},"pull_request":{"href":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/945"}}},"pull_request":{"url":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/945","id":85455960,"html_url":"https://github.com/ElektraInitiative/libelektra/pull/945","diff_url":"https://github.com/ElektraInitiative/libelektra/pull/945.diff","patch_url":"https://github.com/ElektraInitiative/libelektra/pull/945.patch","issue_url":"https://api.github.com/repos/ElektraInitiative/libelektra/issues/945","number":945,"state":"open","locked":false,"title":"Fcrypt file encryption plugin","user":{"login":"petermax2","id":2538677,"avatar_url":"https://avatars.githubusercontent.com/u/2538677?v=3","gravatar_id":"","url":"https://api.github.com/users/petermax2","html_url":"https://github.com/petermax2","followers_url":"https://api.github.com/users/petermax2/followers","following_url":"https://api.github.com/users/petermax2/following{/other_user}","gists_url":"https://api.github.com/users/petermax2/gists{/gist_id}","starred_url":"https://api.github.com/users/petermax2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petermax2/subscriptions","organizations_url":"https://api.github.com/users/petermax2/orgs","repos_url":"https://api.github.com/users/petermax2/repos","events_url":"https://api.github.com/users/petermax2/events{/privacy}","received_events_url":"https://api.github.com/users/petermax2/received_events","type":"User","site_admin":false},"body":"# Purpose\r\n\r\nThe `fcrypt` plugin enables file based encryption and decryption.\r\n\r\nSee #914 for full discussion.\r\n\r\n# Checklist\r\n\r\nPlease only check relevant points.\r\nFor docu fixes, spell checking and similar nothing\r\nneeds to be checked.\r\n\r\n- [x] commit messages are fine (with references to issues)\r\n- [x] I ran all tests and everything went fine\r\n- [x] I added unit tests\r\n- [x] affected documentation is fixed\r\n- [x] I added code comments, logging, and assertions\r\n- [ ] meta data is updated (e.g. README.md of plugins)\r\n\r\n# TODO\r\n\r\n- [x] add unit tests\r\n\r\n@markus2330 please review my pull request\r\n","created_at":"2016-09-15T18:32:14Z","updated_at":"2016-09-22T17:35:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cf5b9510bcfaf493b2fb1511c2df423c00b475f6","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/945/commits","review_comments_url":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/945/comments","review_comment_url":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ElektraInitiative/libelektra/issues/945/comments","statuses_url":"https://api.github.com/repos/ElektraInitiative/libelektra/statuses/63e302c72ea0d7ce23a8e982810ebcb7adeca297","head":{"label":"petermax2:fcrypt","ref":"fcrypt","sha":"63e302c72ea0d7ce23a8e982810ebcb7adeca297","user":{"login":"petermax2","id":2538677,"avatar_url":"https://avatars.githubusercontent.com/u/2538677?v=3","gravatar_id":"","url":"https://api.github.com/users/petermax2","html_url":"https://github.com/petermax2","followers_url":"https://api.github.com/users/petermax2/followers","following_url":"https://api.github.com/users/petermax2/following{/other_user}","gists_url":"https://api.github.com/users/petermax2/gists{/gist_id}","starred_url":"https://api.github.com/users/petermax2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petermax2/subscriptions","organizations_url":"https://api.github.com/users/petermax2/orgs","repos_url":"https://api.github.com/users/petermax2/repos","events_url":"https://api.github.com/users/petermax2/events{/privacy}","received_events_url":"https://api.github.com/users/petermax2/received_events","type":"User","site_admin":false},"repo":{"id":30610180,"name":"libelektra","full_name":"petermax2/libelektra","owner":{"login":"petermax2","id":2538677,"avatar_url":"https://avatars.githubusercontent.com/u/2538677?v=3","gravatar_id":"","url":"https://api.github.com/users/petermax2","html_url":"https://github.com/petermax2","followers_url":"https://api.github.com/users/petermax2/followers","following_url":"https://api.github.com/users/petermax2/following{/other_user}","gists_url":"https://api.github.com/users/petermax2/gists{/gist_id}","starred_url":"https://api.github.com/users/petermax2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petermax2/subscriptions","organizations_url":"https://api.github.com/users/petermax2/orgs","repos_url":"https://api.github.com/users/petermax2/repos","events_url":"https://api.github.com/users/petermax2/events{/privacy}","received_events_url":"https://api.github.com/users/petermax2/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/petermax2/libelektra","description":"Elektra provides a universal and secure framework to store configuration parameters in a global, hierarchical key database.","fork":true,"url":"https://api.github.com/repos/petermax2/libelektra","forks_url":"https://api.github.com/repos/petermax2/libelektra/forks","keys_url":"https://api.github.com/repos/petermax2/libelektra/keys{/key_id}","collaborators_url":"https://api.github.com/repos/petermax2/libelektra/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/petermax2/libelektra/teams","hooks_url":"https://api.github.com/repos/petermax2/libelektra/hooks","issue_events_url":"https://api.github.com/repos/petermax2/libelektra/issues/events{/number}","events_url":"https://api.github.com/repos/petermax2/libelektra/events","assignees_url":"https://api.github.com/repos/petermax2/libelektra/assignees{/user}","branches_url":"https://api.github.com/repos/petermax2/libelektra/branches{/branch}","tags_url":"https://api.github.com/repos/petermax2/libelektra/tags","blobs_url":"https://api.github.com/repos/petermax2/libelektra/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/petermax2/libelektra/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/petermax2/libelektra/git/refs{/sha}","trees_url":"https://api.github.com/repos/petermax2/libelektra/git/trees{/sha}","statuses_url":"https://api.github.com/repos/petermax2/libelektra/statuses/{sha}","languages_url":"https://api.github.com/repos/petermax2/libelektra/languages","stargazers_url":"https://api.github.com/repos/petermax2/libelektra/stargazers","contributors_url":"https://api.github.com/repos/petermax2/libelektra/contributors","subscribers_url":"https://api.github.com/repos/petermax2/libelektra/subscribers","subscription_url":"https://api.github.com/repos/petermax2/libelektra/subscription","commits_url":"https://api.github.com/repos/petermax2/libelektra/commits{/sha}","git_commits_url":"https://api.github.com/repos/petermax2/libelektra/git/commits{/sha}","comments_url":"https://api.github.com/repos/petermax2/libelektra/comments{/number}","issue_comment_url":"https://api.github.com/repos/petermax2/libelektra/issues/comments{/number}","contents_url":"https://api.github.com/repos/petermax2/libelektra/contents/{+path}","compare_url":"https://api.github.com/repos/petermax2/libelektra/compare/{base}...{head}","merges_url":"https://api.github.com/repos/petermax2/libelektra/merges","archive_url":"https://api.github.com/repos/petermax2/libelektra/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/petermax2/libelektra/downloads","issues_url":"https://api.github.com/repos/petermax2/libelektra/issues{/number}","pulls_url":"https://api.github.com/repos/petermax2/libelektra/pulls{/number}","milestones_url":"https://api.github.com/repos/petermax2/libelektra/milestones{/number}","notifications_url":"https://api.github.com/repos/petermax2/libelektra/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/petermax2/libelektra/labels{/name}","releases_url":"https://api.github.com/repos/petermax2/libelektra/releases{/id}","deployments_url":"https://api.github.com/repos/petermax2/libelektra/deployments","created_at":"2015-02-10T19:27:08Z","updated_at":"2016-03-17T18:11:49Z","pushed_at":"2016-09-22T12:51:34Z","git_url":"git://github.com/petermax2/libelektra.git","ssh_url":"git@github.com:petermax2/libelektra.git","clone_url":"https://github.com/petermax2/libelektra.git","svn_url":"https://github.com/petermax2/libelektra","homepage":"","size":33892,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ElektraInitiative:master","ref":"master","sha":"ceb8d1da84efb70606563b9a4a0552923702ac97","user":{"login":"ElektraInitiative","id":7949092,"avatar_url":"https://avatars.githubusercontent.com/u/7949092?v=3","gravatar_id":"","url":"https://api.github.com/users/ElektraInitiative","html_url":"https://github.com/ElektraInitiative","followers_url":"https://api.github.com/users/ElektraInitiative/followers","following_url":"https://api.github.com/users/ElektraInitiative/following{/other_user}","gists_url":"https://api.github.com/users/ElektraInitiative/gists{/gist_id}","starred_url":"https://api.github.com/users/ElektraInitiative/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ElektraInitiative/subscriptions","organizations_url":"https://api.github.com/users/ElektraInitiative/orgs","repos_url":"https://api.github.com/users/ElektraInitiative/repos","events_url":"https://api.github.com/users/ElektraInitiative/events{/privacy}","received_events_url":"https://api.github.com/users/ElektraInitiative/received_events","type":"Organization","site_admin":false},"repo":{"id":21063580,"name":"libelektra","full_name":"ElektraInitiative/libelektra","owner":{"login":"ElektraInitiative","id":7949092,"avatar_url":"https://avatars.githubusercontent.com/u/7949092?v=3","gravatar_id":"","url":"https://api.github.com/users/ElektraInitiative","html_url":"https://github.com/ElektraInitiative","followers_url":"https://api.github.com/users/ElektraInitiative/followers","following_url":"https://api.github.com/users/ElektraInitiative/following{/other_user}","gists_url":"https://api.github.com/users/ElektraInitiative/gists{/gist_id}","starred_url":"https://api.github.com/users/ElektraInitiative/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ElektraInitiative/subscriptions","organizations_url":"https://api.github.com/users/ElektraInitiative/orgs","repos_url":"https://api.github.com/users/ElektraInitiative/repos","events_url":"https://api.github.com/users/ElektraInitiative/events{/privacy}","received_events_url":"https://api.github.com/users/ElektraInitiative/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ElektraInitiative/libelektra","description":"Elektra serves as a universal and secure framework to access configuration parameters in a global, hierarchical key database.","fork":false,"url":"https://api.github.com/repos/ElektraInitiative/libelektra","forks_url":"https://api.github.com/repos/ElektraInitiative/libelektra/forks","keys_url":"https://api.github.com/repos/ElektraInitiative/libelektra/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ElektraInitiative/libelektra/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ElektraInitiative/libelektra/teams","hooks_url":"https://api.github.com/repos/ElektraInitiative/libelektra/hooks","issue_events_url":"https://api.github.com/repos/ElektraInitiative/libelektra/issues/events{/number}","events_url":"https://api.github.com/repos/ElektraInitiative/libelektra/events","assignees_url":"https://api.github.com/repos/ElektraInitiative/libelektra/assignees{/user}","branches_url":"https://api.github.com/repos/ElektraInitiative/libelektra/branches{/branch}","tags_url":"https://api.github.com/repos/ElektraInitiative/libelektra/tags","blobs_url":"https://api.github.com/repos/ElektraInitiative/libelektra/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ElektraInitiative/libelektra/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ElektraInitiative/libelektra/git/refs{/sha}","trees_url":"https://api.github.com/repos/ElektraInitiative/libelektra/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ElektraInitiative/libelektra/statuses/{sha}","languages_url":"https://api.github.com/repos/ElektraInitiative/libelektra/languages","stargazers_url":"https://api.github.com/repos/ElektraInitiative/libelektra/stargazers","contributors_url":"https://api.github.com/repos/ElektraInitiative/libelektra/contributors","subscribers_url":"https://api.github.com/repos/ElektraInitiative/libelektra/subscribers","subscription_url":"https://api.github.com/repos/ElektraInitiative/libelektra/subscription","commits_url":"https://api.github.com/repos/ElektraInitiative/libelektra/commits{/sha}","git_commits_url":"https://api.github.com/repos/ElektraInitiative/libelektra/git/commits{/sha}","comments_url":"https://api.github.com/repos/ElektraInitiative/libelektra/comments{/number}","issue_comment_url":"https://api.github.com/repos/ElektraInitiative/libelektra/issues/comments{/number}","contents_url":"https://api.github.com/repos/ElektraInitiative/libelektra/contents/{+path}","compare_url":"https://api.github.com/repos/ElektraInitiative/libelektra/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ElektraInitiative/libelektra/merges","archive_url":"https://api.github.com/repos/ElektraInitiative/libelektra/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ElektraInitiative/libelektra/downloads","issues_url":"https://api.github.com/repos/ElektraInitiative/libelektra/issues{/number}","pulls_url":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls{/number}","milestones_url":"https://api.github.com/repos/ElektraInitiative/libelektra/milestones{/number}","notifications_url":"https://api.github.com/repos/ElektraInitiative/libelektra/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ElektraInitiative/libelektra/labels{/name}","releases_url":"https://api.github.com/repos/ElektraInitiative/libelektra/releases{/id}","deployments_url":"https://api.github.com/repos/ElektraInitiative/libelektra/deployments","created_at":"2014-06-21T08:01:04Z","updated_at":"2016-09-17T08:00:03Z","pushed_at":"2016-09-22T14:15:38Z","git_url":"git://github.com/ElektraInitiative/libelektra.git","ssh_url":"git@github.com:ElektraInitiative/libelektra.git","clone_url":"https://github.com/ElektraInitiative/libelektra.git","svn_url":"https://github.com/ElektraInitiative/libelektra","homepage":"http://libelektra.org","size":34580,"stargazers_count":35,"watchers_count":35,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":26,"mirror_url":null,"open_issues_count":159,"forks":26,"open_issues":159,"watchers":35,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/945"},"html":{"href":"https://github.com/ElektraInitiative/libelektra/pull/945"},"issue":{"href":"https://api.github.com/repos/ElektraInitiative/libelektra/issues/945"},"comments":{"href":"https://api.github.com/repos/ElektraInitiative/libelektra/issues/945/comments"},"review_comments":{"href":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/945/comments"},"review_comment":{"href":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/945/commits"},"statuses":{"href":"https://api.github.com/repos/ElektraInitiative/libelektra/statuses/63e302c72ea0d7ce23a8e982810ebcb7adeca297"}}}}
{"actor":{"display_login":"petermax2"}}