static int get_hash_via_username_and_inode(char *hash, char *passwd, size_t *passwd_len) { char tmp[MAX_LEN], tobehashed[MAX_LEN]; char mumps_ex[GTM_PATH_MAX], *user_ptr, *dist_ptr; size_t ilen; struct stat stat_info; memset(tobehashed, 0, MAX_LEN); memset(mumps_ex, 0, GTM_PATH_MAX); /* We need $USER and $gtm_dist to be defined to do the proper masking */ if (NULL == (user_ptr = (char *)getenv("USER"))) { printf("Environment variable USER not defined.\n"); return 1; } if (NULL == (dist_ptr = (char *)getenv(GTM_DIST))) { printf("Enivronment variable gtm_dist not defined.\n"); return 1; } snprintf(mumps_ex, GTM_PATH_MAX, "%s/%s", dist_ptr, "mumps"); if (0 != stat(mumps_ex, &stat_info)) { printf("Cannot stat %s\n", mumps_ex); return 1; } prompt_passwd(passwd); *passwd_len = strlen(passwd); strncpy(tobehashed, user_ptr, MIN(*passwd_len, MAX_LEN)); snprintf(tmp, MAX_LEN, "%ld", stat_info.st_ino); ilen = strlen(tmp); /* a potential simplification is to just concatenate the userid and inode */ if (ilen < *passwd_len) strncpy(tobehashed + (*passwd_len - ilen), tmp, ilen); else strncpy(tobehashed, tmp, *passwd_len); # ifdef USE_OPENSSL EVP_Digest(tobehashed, *passwd_len, (unsigned char *)hash, NULL, EVP_sha512(), NULL); # elif defined USE_GCRYPT gcry_md_hash_buffer(GCRY_MD_SHA512, hash, tobehashed, *passwd_len ); # endif return 0; }
int main() { char passwd[MAX_LEN], hash[HASH_LENGTH], out[MAX_LEN * 2]; size_t passwd_len; # ifdef USE_GCRYPT gcry_error_t err; /* Initialize libgcrypt so it does not put warning messages in the syslog. */ if (!gcry_check_version(GCRYPT_VERSION)) { printf("libgcrypt version mismatch. %s or higher is required.\n", GCRYPT_VERSION); exit(1); } /* Since we will just be hashing, secure memory is not needed. */ if (!(err = gcry_control(GCRYCTL_DISABLE_SECMEM,0))) err = gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0); if (GPG_ERR_NO_ERROR != err) { printf("Libgcrypt error: %s\n", gcry_strerror(err)); exit(1); } # endif passwd_len = -1; memset(passwd, 0, MAX_LEN); memset(out, 0, MAX_LEN * 2); if (get_hash_via_env_var(hash)) if (get_hash_via_username_and_inode(hash, passwd, &passwd_len)) exit(1); if (-1 == passwd_len) { prompt_passwd(passwd); passwd_len = strlen(passwd); } maskpass(passwd, passwd_len, hash, HASH_LENGTH); HEX(passwd, out, passwd_len * 2); printf("%s\n", out); return 0; }
int main(int argc, char** argv) { CURL *easy; CURLcode curl_res; char *tmp; int res; struct fuse_args args = FUSE_ARGS_INIT(argc, argv); /* Initialize curl library before we are a multithreaded program */ curl_global_init(CURL_GLOBAL_ALL); memset(&ftpfs, 0, sizeof ftpfs); /* Set some default values */ ftpfs.curl_version = curl_version_info(CURLVERSION_NOW); ftpfs.safe_nobody = ftpfs.curl_version->version_num > CURLFTPFS_BAD_NOBODY; ftpfs.blksize = 4096; ftpfs.disable_epsv = 1; ftpfs.multiconn = 1; ftpfs.attached_to_multi = 0; if (fuse_opt_parse(&args, &ftpfs, ftpfs_opts, ftpfs_opt_proc) == -1) return 1; if (!ftpfs.host) { fprintf(stderr, "missing host\n"); fprintf(stderr, "see `%s -h' for usage\n", argv[0]); return 1; } if (!ftpfs.iocharset) { ftpfs.iocharset = "UTF8"; } if (ftpfs.codepage) { convert_charsets(ftpfs.iocharset, ftpfs.codepage, &ftpfs.host); } easy = curl_easy_init(); if (easy == NULL) { fprintf(stderr, "Error initializing libcurl\n"); return 1; } res = cache_parse_options(&args); if (res == -1) return 1; if (!prompt_passwd("host", &ftpfs.user)) return 1; if (!prompt_passwd("proxy", &ftpfs.proxy_user)) return 1; if (ftpfs.transform_symlinks && !ftpfs.mountpoint) { fprintf(stderr, "cannot transform symlinks: no mountpoint given\n"); return 1; } if (!ftpfs.transform_symlinks) ftpfs.symlink_prefix_len = 0; else if (realpath(ftpfs.mountpoint, ftpfs.symlink_prefix) != NULL) ftpfs.symlink_prefix_len = strlen(ftpfs.symlink_prefix); else { fprintf(stderr, "unable to normalize mount path\n"); return 1; } set_common_curl_stuff(easy); curl_easy_setopt_or_die(easy, CURLOPT_WRITEDATA, NULL); curl_easy_setopt_or_die(easy, CURLOPT_NOBODY, ftpfs.safe_nobody); curl_res = curl_easy_perform(easy); if (curl_res != 0) ftpfs_curl_easy_perform_abort(); curl_easy_setopt_or_die(easy, CURLOPT_NOBODY, 0); ftpfs.multi = curl_multi_init(); if (ftpfs.multi == NULL) { fprintf(stderr, "Error initializing libcurl multi\n"); return 1; } ftpfs.connection = easy; pthread_mutex_init(&ftpfs.lock, NULL); /* Set the filesystem name to show the current server */ tmp = g_strdup_printf("-ofsname=curlftpfs#%s", ftpfs.host); fuse_opt_insert_arg(&args, 1, tmp); g_free(tmp); res = ftpfs_fuse_main(&args); cancel_previous_multi(); curl_multi_cleanup(ftpfs.multi); curl_easy_cleanup(easy); curl_global_cleanup(); fuse_opt_free_args(&args); pthread_mutex_destroy(&ftpfs.lock); cache_deinit(); return res; }