X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fclient_passwords.c;h=4922a12490996279ae926e86dd8217c5604892b8;hb=4eb74b26380dfde31c86c685f0589e0c653aebf0;hp=d755f363b86067c56126a867ec27005b93de6054;hpb=9cfecc9db607a862e1220b96c1bec319bedecb8c;p=citadel.git diff --git a/citadel/client_passwords.c b/citadel/client_passwords.c index d755f363b..4922a1249 100644 --- a/citadel/client_passwords.c +++ b/citadel/client_passwords.c @@ -4,6 +4,21 @@ * Functions which allow the client to remember usernames and passwords for * various sites. * + * Copyright (c) 1987-2009 by the citadel.org team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "sysdep.h" @@ -16,14 +31,15 @@ #include #include #include +#include #include "citadel.h" #include "citadel_ipc.h" -#include "tools.h" #include "commands.h" +#include "client_passwords.h" #define PWFILENAME "%s/.citadel.passwords" -static void determine_pwfilename(char *pwfile, size_t n) { +void determine_pwfilename(char *pwfile, size_t n) { struct passwd *p; p = getpwuid(getuid()); @@ -46,22 +62,22 @@ void get_stored_password( FILE *fp; char buf[SIZ]; char buf64[SIZ]; - char hostbuf[SIZ], portbuf[SIZ], ubuf[SIZ], pbuf[SIZ]; + char hostbuf[256], portbuf[256], ubuf[256], pbuf[256]; strcpy(username, ""); strcpy(password, ""); determine_pwfilename(pwfile, sizeof pwfile); - if (strlen(pwfile)==0) return; + if (IsEmptyStr(pwfile)) return; fp = fopen(pwfile, "r"); if (fp == NULL) return; while (fgets(buf64, sizeof buf64, fp) != NULL) { CtdlDecodeBase64(buf, buf64, sizeof(buf64)); - extract(hostbuf, buf, 0); - extract(portbuf, buf, 1); - extract(ubuf, buf, 2); - extract(pbuf, buf, 3); + extract_token(hostbuf, buf, 0, '|', sizeof hostbuf); + extract_token(portbuf, buf, 1, '|', sizeof portbuf); + extract_token(ubuf, buf, 2, '|', sizeof ubuf); + extract_token(pbuf, buf, 3, '|', sizeof pbuf); if (!strcasecmp(hostbuf, host)) { if (!strcasecmp(portbuf, port)) { @@ -87,10 +103,10 @@ void set_stored_password( FILE *fp, *oldfp; char buf[SIZ]; char buf64[SIZ]; - char hostbuf[SIZ], portbuf[SIZ], ubuf[SIZ], pbuf[SIZ]; + char hostbuf[256], portbuf[256], ubuf[256], pbuf[256]; determine_pwfilename(pwfile, sizeof pwfile); - if (strlen(pwfile)==0) return; + if (IsEmptyStr(pwfile)) return; oldfp = fopen(pwfile, "r"); if (oldfp == NULL) oldfp = fopen("/dev/null", "r"); @@ -99,23 +115,23 @@ void set_stored_password( if (fp == NULL) fp = fopen("/dev/null", "w"); while (fgets(buf64, sizeof buf64, oldfp) != NULL) { CtdlDecodeBase64(buf, buf64, sizeof(buf64)); - extract(hostbuf, buf, 0); - extract(portbuf, buf, 1); - extract(ubuf, buf, 2); - extract(pbuf, buf, 3); + extract_token(hostbuf, buf, 0, '|', sizeof hostbuf); + extract_token(portbuf, buf, 1, '|', sizeof portbuf); + extract_token(ubuf, buf, 2, '|', sizeof ubuf); + extract_token(pbuf, buf, 3, '|', sizeof pbuf); if ( (strcasecmp(hostbuf, host)) || (strcasecmp(portbuf, port)) ) { snprintf(buf, sizeof buf, "%s|%s|%s|%s|", hostbuf, portbuf, ubuf, pbuf); - encode_base64(buf64, buf); + CtdlEncodeBase64(buf64, buf, strlen(buf), 0); fprintf(fp, "%s\n", buf64); } } - if (strlen(username) > 0) { + if (!IsEmptyStr(username)) { snprintf(buf, sizeof buf, "%s|%s|%s|%s|", host, port, username, password); - encode_base64(buf64, buf); + CtdlEncodeBase64(buf64, buf, strlen(buf), 0); fprintf(fp, "%s\n", buf64); } fclose(oldfp);