/* * Author: Lubomir Host 'rajo' * $Log: passwd.c,v $ * Revision 1.6 2001/11/14 16:00:08 host8 * Changed some debug messages. * Improvements in cookies (still not works fine). * * Revision 1.5 2001/11/12 20:19:10 host8 * http_connect() probably works fine. * Some problems with http_requests for www.mtnsms.com. * * Revision 1.4 2001/11/12 16:08:00 host8 * Big improvements in http. connect() doesn't work correctly yet. * * Revision 1.3 2001/10/30 17:24:02 host8 * New implementation of http request. * * Revision 1.2 2001/10/27 20:32:43 host8 * mail2sms.c splited to multiple files. * Little improvements in Makefile.in. * * Revision 1.1 2001/10/25 20:05:28 host8 * First implementation of login with password. * */ #include #include #include #include #ifdef HAVE_CONFIG_H # include "config.h" #endif #include "passwd.h" #include "strings.h" #include "mail2sms.h" #define MAX_LOGIN_LEN 1024 // static char *get_string(int what) {{{ static char *get_string(int what, int silence) { int i, idx = -1; FILE *f; char *site, *home_env, *filename, *str; for (i=0; servers[i].desc != NULL; i++) { if (servers[i].id == id) { idx = i; break; } } if (idx == -1) { fprintf(stderr, "Id %d not found in servers[] !\n", id); exit(1); } site = servers[idx].desc; #ifdef DEBUG if (silence) { if (what) { fprintf(stderr, "PASSWD: Looking for passwd for site %s...\n", site); } else { fprintf(stderr, "PASSWD: Looking for login for site %s...\n", site); } } #endif home_env = strdup(getenv("HOME")); if (home_env == NULL) { fprintf(stderr, "getenv(HOME) failed!\n"); my_free(home_env); return (""); } filename = (char *) malloc((strlen(home_env) + strlen(site) + strlen("/.mail2sms/")) * sizeof(char)); strcpy(filename, home_env); strcat(filename, "/.mail2sms/"); strcat(filename, site); if ((f = fopen(filename, "r")) == NULL) { fprintf(stderr, "%s: %s\n", filename, strerror(errno)); my_free(home_env); my_free(filename); return (""); } str = (char *) malloc((MAX_LOGIN_LEN +1)*sizeof(char)); if (fgets(str, MAX_LOGIN_LEN, f) == NULL) { fprintf(stderr, "Can't read login from %s!\n", filename); my_free(str); my_free(home_env); my_free(filename); return (""); } #ifdef DEBUG else if (debug > 7) fprintf(stderr, "PASSWD: Login readed successfully (%d chars).\n", strlen(str)); #endif if (what == 0) { str[strlen(str) - 1] = '\0'; my_free(home_env); my_free(filename); return (strrmeol(str)); } else { if (fgets(str, MAX_LOGIN_LEN, f) == NULL) { fprintf(stderr, "Can't read password from %s!\n", filename); my_free(str); my_free(home_env); my_free(filename); return (""); } #ifdef DEBUG else if (debug > 7) fprintf(stderr, "PASSWD: Password readed successfully (%d chars).\n", strlen(str)); #endif return (strrmeol(str)); } return (""); } // }}} char *my_getlogin(int silence) { return (get_string(0, silence)); } char *my_getpass(int silence) { return (get_string(1, silence)); } /* Modeline for ViM {{{1 * vim:set ts=4: * vim600:fdm=marker fdl=0 fdc=3: * }}}1 */