diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index caee64332..d2ceb0fbd 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -37,7 +37,6 @@ #include #include #include -#include #include #ifdef HAVE_PTHREAD #include @@ -3282,7 +3281,7 @@ extern HAMLIB_EXPORT_VAR(char) debugmsgsave3[DEBUGMSGSAVE_SIZE]; // last-2 debu #ifndef __cplusplus #ifdef __GNUC__ // doing the debug macro with a dummy sprintf allows gcc to check the format string -#define rig_debug(debug_level,fmt,...) do { snprintf(debugmsgsave2,sizeof(debugmsgsave2),fmt,__VA_ARGS__);rig_debug(debug_level,fmt,##__VA_ARGS__); add2debugmsgsave(debugmsgsave2); } while(0); +#define rig_debug(debug_level,fmt,...) do { snprintf(debugmsgsave2,sizeof(debugmsgsave2),fmt,__VA_ARGS__);rig_debug(debug_level,fmt,##__VA_ARGS__); add2debugmsgsave(debugmsgsave2); } while(0) #endif #endif @@ -3389,6 +3388,8 @@ extern HAMLIB_EXPORT(int) hl_usleep(rig_useconds_t msec); extern HAMLIB_EXPORT(int) rig_cookie(RIG *rig, enum cookie_e cookie_cmd, char *cookie, int cookie_len); extern HAMLIB_EXPORT(int) rig_password(RIG *rig, const char *key1); +extern HAMLIB_EXPORT(void) rig_password_generate_secret(char *pass, + char result[HAMLIB_SECRET_LENGTH + 1]); //extern HAMLIB_EXPORT(int) int longlat2locator HAMLIB_PARAMS((double longitude, diff --git a/security/md5.c b/security/md5.c index 521821b91..36caef29a 100644 --- a/security/md5.c +++ b/security/md5.c @@ -293,7 +293,7 @@ unsigned char *make_hash(char *arg) char *rig_make_md5(char *pass) { - unsigned char *hash = make_hash("password"); + unsigned char *hash = make_hash(pass); char *md5str = make_digest(hash, 16); return md5str; } diff --git a/security/password.c b/security/password.c index e36dcedf4..5c3a74bdc 100644 --- a/security/password.c +++ b/security/password.c @@ -49,8 +49,8 @@ HAMLIB_EXPORT(void) rig_password_generate_secret(char *pass, srand(product); - snprintf(newpass, sizeof(newpass) - 1, "%s\t%lu\n", pass, (long)rand()); - printf("debug=%s\n", newpass); + snprintf(newpass, sizeof(newpass) - 1, "%s\t%lu\t%lu", pass, (long)rand(),time(NULL)); + //printf("debug=%s\n", newpass); char *md5str = rig_make_md5(newpass); strncpy(result, md5str, HAMLIB_SECRET_LENGTH); @@ -62,7 +62,7 @@ HAMLIB_EXPORT(void) rig_password_generate_secret(char *pass, printf("\nCan be used with rigctl --password [secret]\nOr can be place in ~/.hamlib_settings\n"); } -#define TESTPASSWORD +//#define TESTPASSWORD #ifdef TESTPASSWORD int main(int argc, char *argv[]) { diff --git a/src/settings.c b/src/settings.c index 68f8d68e4..d1d5167ba 100644 --- a/src/settings.c +++ b/src/settings.c @@ -1042,7 +1042,6 @@ HAMLIB_EXPORT(int) rig_settings_save(char *setting, void *value, int fd = mkstemp(template); close(fd); - printf("template=%s\n",template); fptmp = fopen(template, "w"); if (fptmp == NULL) @@ -1093,5 +1092,27 @@ HAMLIB_EXPORT(int) rig_settings_load(char *setting, void *value, return -RIG_ENIMPL; } +HAMLIB_EXPORT(int) rig_settings_load_all(char * settings_file) +{ + FILE *fp = fopen(settings_file, "r"); + char buf[4096]; + if (fp == NULL) + { + rig_debug(RIG_DEBUG_ERR, "%s: settings_file error(%s): %s\n", __func__, settings_file, strerror(errno)); + return -RIG_EINVAL; + } + while(fgets(buf,sizeof(buf),fp)) + { + char *s = strtok(buf,"="); + char *v = strtok(NULL, "\r\n"); + if (strcmp(s,"sharedkey")==0) + { + //sharedkey = strdup(v); + //rig_debug(RIG_DEBUG_TRACE, "%s: settings_file=%s, shared_key=%s\n", __func__, settings_file, sharedkey); + } + } + return RIG_OK; +} + /*! @} */ diff --git a/tests/rigctld.c b/tests/rigctld.c index 3e2efa3c6..7409c7477 100644 --- a/tests/rigctld.c +++ b/tests/rigctld.c @@ -305,7 +305,9 @@ int main(int argc, char *argv[]) case 'A': strncpy(rigctld_password, optarg, sizeof(rigctld_password) - 1); - char *md5 = rig_make_md5(rigctld_password); + //char *md5 = rig_make_m d5(rigctld_password); + char md5[HAMLIB_SECRET_LENGTH+1]; + rig_password_generate_secret(rigctld_password, md5); printf("Secret key: %s\n", md5); rig_settings_save("sharedkey", md5, e_CHAR); break; @@ -630,6 +632,7 @@ int main(int argc, char *argv[]) rig_debug(RIG_DEBUG_VERBOSE, "rigctld %s\n", hamlib_version2); rig_debug(RIG_DEBUG_VERBOSE, "%s", "Report bugs to \n\n"); + rig_debug(RIG_DEBUG_VERBOSE, "Max# of rigctld client services=%d\n", NI_MAXSERV); my_rig = rig_init(my_model); @@ -1221,7 +1224,7 @@ void *handle_socket(void *arg) if (retcode < 0 && !RIG_IS_SOFT_ERRCODE(-retcode)) { int retry = 3; - rig_debug(RIG_DEBUG_ERR, "%s: i/o error\n", __func__) + rig_debug(RIG_DEBUG_ERR, "%s: i/o error\n", __func__); do {