2 Copyright (c) 2004, Devin Watson <dmwatson@comcast.net>
3 and 2010 Micke Nordin <mickewiki@gmail.com>
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
8 * Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 * Neither the name of mnenc nor the
14 names of its contributors may be used to endorse or promote products
15 derived from this software without specific prior written permission.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL Devin Watson BE LIABLE FOR ANY
21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/types.h>
42 #include "password.hpp"
44 std::string remove_char(std::string str, char c) {
45 std::string::size_type k = 0;
46 while((k=str.find(c,k))!=str.npos) {
52 std::string remove_chars(std::string str) {
53 std::string chars = " \t\n\b\a-?+\\{[]}'*'";
54 for(int i = 0; i < (signed) chars.size(); i++) {
55 str = remove_char(str, chars[i]);
61 std::string make_filename(std::string user, std::string app) {
62 return remove_chars(app + user);
64 std::string get_password(std::string masterpasswd, std::string user, std::string app) {
66 menc.genkey(masterpasswd);
67 std::string key = menc.get_key();
68 password pw = password("", "", key);
69 pw.from_file(make_filename(user, app));
70 return menc.decrypt(key, pw.get_enc());
73 void put_password(std::string masterpasswd, std::string passwd, std::string user, std::string app) {
75 menc.genkey(masterpasswd);
76 std::string key = menc.get_key();
77 password pw = password(menc.encrypt(key, passwd ), "", key);
78 pw.to_file(make_filename(user, app));
81 std::string do_something(std::string str) {
86 std::string m_read() {
88 std::ifstream is("fife");
94 void m_send(std::string message) {
95 std::ofstream os("fife");
101 int main(int argc, char** argv) {
102 /* Our process ID and Session ID */
105 /* Fork off the parent process */
110 /* If we got a good PID, then
111 we can exit the parent process. */
116 /* Change the file mode mask */
119 /* Open any logs here */
121 /* Create a new SID for the child process */
124 /* Log the failure */
128 /* Change the current working directory */
129 if ((chdir("/home/micke/.fifo")) < 0) {
130 /* Log the failure */
134 /* Close out the standard file descriptors */
136 close(STDOUT_FILENO);
137 close(STDERR_FILENO);
139 /* Daemon-specific initialization goes here */
141 mkfifo("./fife", 0777);
145 m_send(do_something(m_read()));
146 sleep(1); /* wait 1 second*/