X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=textclient%2Fclient_passwords.c;h=522ec882564c674f0de8f0b18bbd74eac4e3b0d6;hb=HEAD;hp=6187a7cd3c4ddd3ef3aa5bf6ae75610d24bff1ac;hpb=633eabfc5820a6cc3b3c45793243928d0fa9c099;p=citadel.git diff --git a/textclient/client_passwords.c b/textclient/client_passwords.c index 6187a7cd3..21b0906c7 100644 --- a/textclient/client_passwords.c +++ b/textclient/client_passwords.c @@ -1,22 +1,14 @@ -// Functions which allow the client to remember usernames and passwords for -// various sites. +// Functions which allow the client to remember usernames and passwords for various sites. // -// Copyright (c) 1987-2016 by the citadel.org team +// Copyright (c) 1987-2023 by the citadel.org team // -// This program is open source software. Use, duplication, and/or -// disclosure are subject to the GNU General Purpose License version 3. -// -// 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. +// This program is open source software. Use, duplication, or disclosure is subject to the GNU General Public License version 3. #include "textclient.h" #define PWFILENAME "%s/.citadel.passwords" -void determine_pwfilename(char *pwfile, size_t n) -{ +void determine_pwfilename(char *pwfile, size_t n) { struct passwd *p; p = getpwuid(getuid()); @@ -26,12 +18,9 @@ void determine_pwfilename(char *pwfile, size_t n) } -/* - * Check the password file for a host/port match; if found, stuff the user - * name and password into the user/pass buffers - */ -void get_stored_password(char *host, char *port, char *username, char *password) -{ +// Check the password file for a host/port match; if found, stuff the user +// name and password into the user/pass buffers +void get_stored_password(char *host, char *port, char *username, char *password) { char pwfile[PATH_MAX]; FILE *fp; @@ -47,8 +36,9 @@ void get_stored_password(char *host, char *port, char *username, char *password) return; fp = fopen(pwfile, "r"); - if (fp == NULL) + if (fp == NULL) { return; + } while (fgets(buf64, sizeof buf64, fp) != NULL) { CtdlDecodeBase64(buf, buf64, sizeof(buf64)); extract_token(hostbuf, buf, 0, '|', sizeof hostbuf); @@ -67,11 +57,8 @@ void get_stored_password(char *host, char *port, char *username, char *password) } -/* - * Set (or clear) stored passwords. - */ -void set_stored_password(char *host, char *port, char *username, char *password) -{ +// Set (or clear) stored passwords. +void set_stored_password(char *host, char *port, char *username, char *password) { char pwfile[PATH_MAX]; FILE *fp, *oldfp; @@ -84,12 +71,14 @@ void set_stored_password(char *host, char *port, char *username, char *password) return; oldfp = fopen(pwfile, "r"); - if (oldfp == NULL) + if (oldfp == NULL) { oldfp = fopen("/dev/null", "r"); + } unlink(pwfile); fp = fopen(pwfile, "w"); - if (fp == NULL) + if (fp == NULL) { fp = fopen("/dev/null", "w"); + } while (fgets(buf64, sizeof buf64, oldfp) != NULL) { CtdlDecodeBase64(buf, buf64, sizeof(buf64)); extract_token(hostbuf, buf, 0, '|', sizeof hostbuf); @@ -97,16 +86,15 @@ void set_stored_password(char *host, char *port, char *username, char *password) extract_token(ubuf, buf, 2, '|', sizeof ubuf); extract_token(pbuf, buf, 3, '|', sizeof pbuf); - if ((strcasecmp(hostbuf, host)) - || (strcasecmp(portbuf, port))) { + if ((strcasecmp(hostbuf, host)) || (strcasecmp(portbuf, port))) { snprintf(buf, sizeof buf, "%s|%s|%s|%s|", hostbuf, portbuf, ubuf, pbuf); - CtdlEncodeBase64(buf64, buf, strlen(buf), 0); + CtdlEncodeBase64(buf64, buf, strlen(buf), BASE64_NO_LINEBREAKS); fprintf(fp, "%s\n", buf64); } } if (!IsEmptyStr(username)) { snprintf(buf, sizeof buf, "%s|%s|%s|%s|", host, port, username, password); - CtdlEncodeBase64(buf64, buf, strlen(buf), 0); + CtdlEncodeBase64(buf64, buf, strlen(buf), BASE64_NO_LINEBREAKS); fprintf(fp, "%s\n", buf64); } fclose(oldfp); @@ -115,16 +103,14 @@ void set_stored_password(char *host, char *port, char *username, char *password) } -/* - * Set the password if the user wants to, clear it otherwise - */ -void offer_to_remember_password(CtdlIPC * ipc, char *host, char *port, char *username, char *password) -{ +// Set the password if the user wants to, clear it otherwise +void offer_to_remember_password(CtdlIPC * ipc, char *host, char *port, char *username, char *password) { if (rc_remember_passwords) { if (boolprompt("Remember username/password for this site", 0)) { set_stored_password(host, port, username, password); - } else { + } + else { set_stored_password(host, port, "", ""); } }