3 // Copyright 2010 Micke Nordin <micke@hal>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 // MA 02110-1301, USA.
20 #include <sys/types.h>
32 #include "password.hpp"
34 std::string remove_char(std::string str, char c) {
35 std::string::size_type k = 0;
36 while((k=str.find(c,k))!=str.npos) {
42 std::string remove_chars(std::string str) {
43 std::string chars = " \t\n\b\a-?+\\{[]}'*'";
44 for(int i = 0; i < (signed) chars.size(); i++) {
45 str = remove_char(str, chars[i]);
51 std::string make_filename(std::string user, std::string app) {
52 return remove_chars(app + user);
54 std::string get_password(std::string masterpasswd, std::string user, std::string app) {
56 menc.genkey(masterpasswd);
57 std::string key = menc.get_key();
58 password pw = password("", "", key);
59 pw.from_file(make_filename(user, app));
60 return menc.decrypt(key, pw.get_enc());
63 void put_password(std::string masterpasswd, std::string passwd, std::string user, std::string app) {
65 menc.genkey(masterpasswd);
66 std::string key = menc.get_key();
67 password pw = password(menc.encrypt(key, passwd ), "", key);
68 pw.to_file(make_filename(user, app));
71 std::string do_something(std::string str) {
76 std::string m_read() {
78 std::ifstream is("fife");
84 void m_send(std::string message) {
85 std::ofstream os("fife");
91 int main(int argc, char** argv) {
92 /* Our process ID and Session ID */
95 /* Fork off the parent process */
100 /* If we got a good PID, then
101 we can exit the parent process. */
106 /* Change the file mode mask */
109 /* Open any logs here */
111 /* Create a new SID for the child process */
114 /* Log the failure */
120 /* Change the current working directory */
121 if ((chdir("/home/micke/.fifo")) < 0) {
122 /* Log the failure */
126 /* Close out the standard file descriptors */
128 close(STDOUT_FILENO);
129 close(STDERR_FILENO);
131 /* Daemon-specific initialization goes here */
133 mkfifo("./fife", 0777);
137 m_send(do_something(m_read()));
138 sleep(1); /* wait 1 second*/