14 #define PWFILENAME "%s/.citadel.passwords"
16 void determine_pwfilename(char *pwfile) {
19 p = getpwuid(getuid());
20 if (p == NULL) strcpy(pwfile, "");
21 sprintf(pwfile, PWFILENAME, p->pw_dir);
26 * Check the password file for a host/port match; if found, stuff the user
27 * name and password into the user/pass buffers
29 void get_stored_password(
35 char pwfile[PATH_MAX];
39 char hostbuf[256], portbuf[256], ubuf[256], pbuf[256];
44 determine_pwfilename(pwfile);
45 if (strlen(pwfile)==0) return;
47 fp = fopen(pwfile, "r");
48 if (fp == NULL) return;
49 while (fgets(buf64, sizeof buf64, fp) != NULL) {
50 decode_base64(buf, buf64);
51 extract(hostbuf, buf, 0);
52 extract(portbuf, buf, 1);
53 extract(ubuf, buf, 2);
54 extract(pbuf, buf, 3);
56 if (!strcasecmp(hostbuf, host)) {
57 if (!strcasecmp(portbuf, port)) {
58 strcpy(username, ubuf);
59 strcpy(password, pbuf);
68 * Set (or clear) stored passwords.
70 void set_stored_password(
76 char pwfile[PATH_MAX];
80 char hostbuf[256], portbuf[256], ubuf[256], pbuf[256];
82 determine_pwfilename(pwfile);
83 if (strlen(pwfile)==0) return;
85 oldfp = fopen(pwfile, "r");
86 if (oldfp == NULL) oldfp = fopen("/dev/null", "r");
88 fp = fopen(pwfile, "w");
89 if (fp == NULL) fp = fopen("/dev/null", "w");
90 while (fgets(buf64, sizeof buf64, oldfp) != NULL) {
91 decode_base64(buf, buf64);
92 extract(hostbuf, buf, 0);
93 extract(portbuf, buf, 1);
94 extract(ubuf, buf, 2);
95 extract(pbuf, buf, 3);
97 if ( (strcasecmp(hostbuf, host))
98 || (strcasecmp(portbuf, port)) ) {
99 sprintf(buf, "%s|%s|%s|%s|",
100 hostbuf, portbuf, ubuf, pbuf);
101 encode_base64(buf64, buf);
102 fprintf(fp, "%s\n", buf64);
105 if (strlen(username) > 0) {
106 sprintf(buf, "%s|%s|%s|%s|",
107 host, port, username, password);
108 encode_base64(buf64, buf);
109 fprintf(fp, "%s\n", buf64);
118 * Set the password if the user wants to, clear it otherwise
120 void offer_to_remember_password(
126 if (rc_remember_passwords) {
127 if (boolprompt("Remember username/password for this site", 0)) {
128 set_stored_password(host, port, username, password);
131 set_stored_password(host, port, "", "");