From: 諏訪子 <suwako@076.moe> Date: Fri, 2 Feb 2024 03:15:58 +0000 (+0900) Subject: 英訳の追加 X-Git-Tag: sp-1.3.0~32 X-Git-Url: http://10.11.0.4:5575/?a=commitdiff_plain;h=461b952da7a4ae014850936d06bf4b2c5f043b6b;p=sp.git 英訳の追加 --- diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c8d8e7..3339f36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 1.3.0 +* è±è¨³ã®è¿½å + # 1.2.0 * ãã£ã¨TOTPæ©è½æ§ãä¿®æ£ãã * makeãå®è¡ãããããã¤ããªããã£ã¨å°ãããªã diff --git a/addpass.c b/addpass.c index b25f1ee..cd5c72a 100644 --- a/addpass.c +++ b/addpass.c @@ -74,10 +74,13 @@ void getpasswd(char* prompt, char*pw, size_t pwlen) { } void addpass(char* file) { + char *lang = getenv("SP_LANG"); + // ãã¹ãæºå char* homedir = getenv("HOME"); if (homedir == NULL) { - perror("ãã¼ã ãã£ã¬ã¯ããªãååã«å¤±æã"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to retrieving home directory"); + else perror("ãã¼ã ãã£ã¬ã¯ããªãååã«å¤±æ"); return; } @@ -90,28 +93,33 @@ void addpass(char* file) { int alllen = snprintf(NULL, 0, "%s%s%s%s", homedir, basedir, file, ext) + 1; char* gpgpathchk = malloc(alllen); if (gpgpathchk == NULL) { - perror("ã¡ã¢ãªãå²å½ã«å¤±æã"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to allocating memory"); + else perror("ã¡ã¢ãªãå²å½ã«å¤±æ"); return; } // ãã¡ã¤ã«ãæ¢ã«åå¨ãããã©ããç¢ºèª snprintf(gpgpathchk, alllen, "%s%s%s%s", homedir, basedir, file, ext); if (access(gpgpathchk, F_OK) != -1) { - fprintf(stderr, "ãã¹ã¯ã¼ããæ¢ã«åå¨ãã¦ãã¾ãã\nå¤æ´ããã«ã¯ãã sp -e %s ããå®è¡ãã¦ä¸ããã\n", file); + if (lang != NULL && strncmp(lang, "en", 2) == 0) fprintf(stderr, "Password already exist.\nFor edit, please run ' sp -e %s '.\n", file); + else fprintf(stderr, "ãã¹ã¯ã¼ããæ¢ã«åå¨ãã¦ãã¾ãã\nå¤æ´ããã«ã¯ãã sp -e %s ããå®è¡ãã¦ä¸ããã\n", file); free(gpgpathchk); return; } free(gpgpathchk); // ãã¹ã¯ã¼ããåãåã - getpasswd("ãã¹ã¯ã¼ãï¼ ", pass, sizeof(pass)); + if (lang != NULL && strncmp(lang, "en", 2) == 0) getpasswd("Password: ", pass, sizeof(pass)); + else getpasswd("ãã¹ã¯ã¼ãï¼ ", pass, sizeof(pass)); puts(""); - getpasswd("ãã¹ã¯ã¼ãï¼ç¢ºèªç¨ï¼ï¼ ", knin, sizeof(knin)); + if (lang != NULL && strncmp(lang, "en", 2) == 0) getpasswd("Password (for verification): ", knin, sizeof(knin)); + else getpasswd("ãã¹ã¯ã¼ãï¼ç¢ºèªç¨ï¼ï¼ ", knin, sizeof(knin)); puts(""); // ãã¹ã¯ã¼ããä¸è´ãããã©ããç¢ºèª if (strcmp(pass, knin) != 0) { - fprintf(stderr, "ãã¹ã¯ã¼ããä¸è´ãã¦ãã¾ãããçµäºâ¦\n"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Password does not match. Ending..."); + else perror("ãã¹ã¯ã¼ããä¸è´ãã¦ãã¾ãããçµäºâ¦"); return; } @@ -130,14 +138,16 @@ void addpass(char* file) { // GPGMEãåµä½ err = gpgme_new(&ctx); if (err) { - fprintf(stderr, "GPGMEãåµä½ã«å¤±æï¼%s\n", gpgme_strerror(err)); + if (lang != NULL && strncmp(lang, "en", 2) == 0) fprintf(stderr, "Failed to generating GPGME: %s\n", gpgme_strerror(err)); + else fprintf(stderr, "GPGMEãåµä½ã«å¤±æï¼%s\n", gpgme_strerror(err)); return; } // GPGMEã¯é対話çã¢ã¼ãã«è¨å® err = gpgme_set_pinentry_mode(ctx, GPGME_PINENTRY_MODE_LOOPBACK); if (err) { - fprintf(stderr, "pinentryã¢ã¼ããè¨å®ã«å¤±æï¼ %s\n", gpgme_strerror(err)); + if (lang != NULL && strncmp(lang, "en", 2) == 0) fprintf(stderr, "Failed to setting pinentry mode: %s\n", gpgme_strerror(err)); + else fprintf(stderr, "pinentryã¢ã¼ããè¨å®ã«å¤±æï¼ %s\n", gpgme_strerror(err)); gpgme_release(ctx); return; } @@ -145,7 +155,8 @@ void addpass(char* file) { // ãã¹ã¯ã¼ããããã¼ã¿ãªãã¸ã§ã¯ããåµä½ err = gpgme_data_new_from_mem(&in, pass, strlen(pass), 0); if (err) { - fprintf(stderr, "ãã¼ã¿ãªãã¸ã§ã¯ããåµä½ã«å¤±æï¼ %s\n", gpgme_strerror(err)); + if (lang != NULL && strncmp(lang, "en", 2) == 0) fprintf(stderr, "Failed to making data object: %s\n", gpgme_strerror(err)); + else fprintf(stderr, "ãã¼ã¿ãªãã¸ã§ã¯ããåµä½ã«å¤±æï¼ %s\n", gpgme_strerror(err)); gpgme_release(ctx); return; } @@ -159,14 +170,20 @@ void addpass(char* file) { FILE* keyfile = fopen(keypath, "rb"); if (keyfile == NULL) { - perror(".gpg-idãã¡ã¤ã«ãéãã«å¤±æã"); - printf("失æãããã¹ï¼ %s\n", keypath); + if (lang != NULL && strncmp(lang, "en", 2) == 0) { + perror("Failed to opening .gpg-id file"); + fprintf(stderr, "Failed path: %s\n", keypath); + } else { + perror(".gpg-idãã¡ã¤ã«ãéãã«å¤±æ"); + fprintf(stderr, "失æãããã¹ï¼ %s\n", keypath); + } return; } char* keyid = malloc(256); if (!fgets(keyid, 256, keyfile)) { - perror("éµIDãèªè¾¼ã«å¤±æã"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to reading key ID"); + else perror("éµIDãèªè¾¼ã«å¤±æ"); fclose(keyfile); free(keyid); return; @@ -177,13 +194,15 @@ void addpass(char* file) { err = gpgme_get_key(ctx, keyid, &key[0], 0); if (err) { - fprintf(stderr, "éµãååã«å¤±æï¼ %s\n", gpgme_strerror(err)); + if (lang != NULL && strncmp(lang, "en", 2) == 0) fprintf(stderr, "Failed to getting key: %s\n", gpgme_strerror(err)); + else fprintf(stderr, "éµãååã«å¤±æï¼ %s\n", gpgme_strerror(err)); free(keyid); return; } if (key[0] == NULL) { - fprintf(stderr, "ã¨ã©ã¼ï¼éµã¯NULLã§ãã\n"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Error: Key is NULL"); + else perror("ã¨ã©ã¼ï¼éµã¯NULLã§ã"); free(keyid); return; } @@ -193,7 +212,8 @@ void addpass(char* file) { // æå·å err = gpgme_op_encrypt(ctx, &key[0], GPGME_ENCRYPT_ALWAYS_TRUST, in, out); if (err) { - fprintf(stderr, "æå·åã«å¤±æï¼ %s\n", gpgme_strerror(err)); + if (lang != NULL && strncmp(lang, "en", 2) == 0) fprintf(stderr, "Failed to encrypt: %s\n", gpgme_strerror(err)); + else fprintf(stderr, "æå·åã«å¤±æï¼ %s\n", gpgme_strerror(err)); cleanup(ctx, key[0], in, out); return; } @@ -202,7 +222,8 @@ void addpass(char* file) { char* gpgpath = malloc(alllen); if (gpgpath == NULL) { cleanup(ctx, key[0], in, out); - perror("ã¡ã¢ãªãå²å½ã«å¤±æã"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to allocating memory"); + else perror("ã¡ã¢ãªãå²å½ã«å¤±æ"); return; } @@ -217,7 +238,8 @@ void addpass(char* file) { if (mkdir_r(dirpath, 0755) != 0) { free(gpgpath); cleanup(ctx, key[0], in, out); - perror("ãã£ã¬ã¯ããªãåµä½ã«å¤±æã"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to constructing directory"); + else perror("ãã£ã¬ã¯ããªãåµä½ã«å¤±æ"); return; } } @@ -227,14 +249,20 @@ void addpass(char* file) { if (stat(gpgpath, &statbuf) == 0) { free(gpgpath); cleanup(ctx, key[0], in, out); - fprintf(stderr, "ãã¹ã¯ã¼ãã¯æ¢ã«åå¨ãã¦ãã¾ãã\n"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Password is already exist"); + else perror("ãã¹ã¯ã¼ãã¯æ¢ã«åå¨ãã¦ãã¾ã"); return; } gpgfile = fopen(gpgpath, "wb"); if (gpgfile == NULL) { - perror("ãã¡ã¤ã«ãéãã«å¤±æã"); - printf("失æãããã¹ï¼ %s\n", gpgpath); + if (lang != NULL && strncmp(lang, "en", 2) == 0) { + perror("Failed to opening file."); + fprintf(stderr, "Failed path: %s\n", gpgpath); + } else { + perror("ãã¡ã¤ã«ãéãã«å¤±æã"); + fprintf(stderr, "失æãããã¹ï¼ %s\n", gpgpath); + } free(gpgpath); cleanup(ctx, key[0], in, out); return; @@ -243,7 +271,8 @@ void addpass(char* file) { // ãã¼ã¿ãä¿åãããã©ããç¢ºèª ssize_t encrypted_data_size = gpgme_data_seek(out, 0, SEEK_END); if (encrypted_data_size <= 0) { - fprintf(stderr, "ãã¼ã¿ãä¿åã«å¤±æã\n"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to saving the data"); + else perror("ãã¼ã¿ãä¿åã«å¤±æ"); fclose(gpgfile); free(gpgpath); cleanup(ctx, key[0], in, out); @@ -258,7 +287,8 @@ void addpass(char* file) { while ((read_bytes = gpgme_data_read(out, buffer, sizeof(buffer))) > 0) { if (fwrite(buffer, 1, (size_t)read_bytes, gpgfile) != (size_t)read_bytes) { - perror("ãã¹ã¯ã¼ããæ¸ãè¾¼ã¿ã«å¤±æ"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to writing password"); + else perror("ãã¹ã¯ã¼ããæ¸ãè¾¼ã¿ã«å¤±æ"); free(gpgpath); cleanup(ctx, key[0], in, out); return; @@ -270,5 +300,6 @@ void addpass(char* file) { free(gpgpath); cleanup(ctx, key[0], in, out); - printf("ãã¹ã¯ã¼ããä¿ååºæ¥ã¾ããã\n"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) puts("I could save the password"); + else puts("ãã¹ã¯ã¼ããä¿ååºæ¥ã¾ãã"); } diff --git a/base32.c b/base32.c index 6a8ce6d..ee36ab6 100644 --- a/base32.c +++ b/base32.c @@ -1,3 +1,5 @@ +#include <string.h> + #include "base32.h" int char_to_val(char c) { diff --git a/base32.h b/base32.h index 6e2561f..4023054 100644 --- a/base32.h +++ b/base32.h @@ -2,7 +2,6 @@ #define BASE32_H #include <stdlib.h> -#include <string.h> unsigned char *base32_decode(const char *encoded, size_t *out_len); diff --git a/delpass.c b/delpass.c index f64d0bc..2f20ed0 100644 --- a/delpass.c +++ b/delpass.c @@ -1,15 +1,19 @@ #include <unistd.h> #include <stdlib.h> #include <stdio.h> +#include <string.h> #include "delpass.h" int delpass(char* file, int force) { + char *lang = getenv("SP_LANG"); + // ãã¹ãæºå char pwfile[512]; char* homedir = getenv("HOME"); if (homedir == NULL) { - perror("ãã¼ã ãã£ã¬ã¯ããªãååã«å¤±æã"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to getting home directory"); + else perror("ãã¼ã ãã£ã¬ã¯ããªãååã«å¤±æ"); return -1; } @@ -19,14 +23,16 @@ int delpass(char* file, int force) { int alllen = snprintf(NULL, 0, "%s%s%s%s", homedir, basedir, file, ext) + 1; char* gpgpathchk = malloc(alllen); if (gpgpathchk == NULL) { - perror("ã¡ã¢ãªãå²å½ã«å¤±æã"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to allocating memory"); + else perror("ã¡ã¢ãªãå²å½ã«å¤±æ"); return -1; } // ãã¡ã¤ã«ãæ¢ã«åå¨ãããã©ããç¢ºèª snprintf(gpgpathchk, alllen, "%s%s%s%s", homedir, basedir, file, ext); if (access(gpgpathchk, F_OK) != 0) { - fprintf(stderr, "ãã¹ã¯ã¼ããåå¨ãã¾ããã\n"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Password does not exist"); + else perror("ãã¹ã¯ã¼ããåå¨ãã¾ãã"); free(gpgpathchk); return -1; } @@ -34,16 +40,19 @@ int delpass(char* file, int force) { int needed = snprintf(pwfile, sizeof(pwfile), "%s%s%s%s", homedir, basedir, file, ext); if (needed >= (int)sizeof(pwfile)) { - fprintf(stderr, "ã¨ã©ã¼ï¼ãã¹ãé·ãããã\n"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Error: Path is too long"); + else perror("ã¨ã©ã¼ï¼ãã¹ãé·ããã"); return -1; } // åé¤ã確èªãã if (force == 0) { // ãã¹ã¯ã¼ãã®å¤æ´ã®ã°ããã確èªã¯ä¸è¦ + if (lang != NULL && strncmp(lang, "en", 2) == 0) printf("Is it really good if I delete the password '%s'? (y/N): ", file); printf("ãã¹ã¯ã¼ãã%sããæ¬å½ã«åé¤ããäºãå®ããã§ããããï¼ (y/N): ", file); int confirm = getchar(); if (confirm != 'y' && confirm != 'Y') { - printf("åé¤ãã¾ããã§ããã\n"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) puts("Not deleted"); + else puts("åé¤ãã¾ããã§ãã"); return -1; } @@ -52,12 +61,14 @@ int delpass(char* file, int force) { } if (unlink(pwfile) == -1) { - perror("ãã¹ã¯ã¼ããåé¤åºæ¥ã¾ããã§ããã"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Password cannot be delete"); + else perror("ãã¹ã¯ã¼ããåé¤åºæ¥ã¾ããã§ãã"); return -1; } if (force == 1) return 0; - printf("ãã¹ã¯ã¼ããåé¤ãã¾ããã\n"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) puts("Deleted password"); + else puts("ãã¹ã¯ã¼ããåé¤ãã¾ãã"); return 0; } diff --git a/genpass.c b/genpass.c index 3d862b6..ac7617b 100644 --- a/genpass.c +++ b/genpass.c @@ -5,13 +5,16 @@ #include "genpass.h" void genpass(int count, bool issecure) { + char *lang = getenv("SP_LANG"); + const char* charset_risky = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; const char* charset_secure = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()=~-^\\|_@`[{]};:+*<>,./?"; const char* charset = issecure ? charset_secure : charset_risky; FILE *fp = fopen("/dev/random", "rb"); if (fp == NULL) { - perror("/dev/randomãéãããã¾ããã§ããã"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Could not opening /dev/random"); + else perror("/dev/randomãéãããã¾ããã§ãã"); exit(EXIT_FAILURE); } diff --git a/initpass.c b/initpass.c index 6a5679d..b073559 100644 --- a/initpass.c +++ b/initpass.c @@ -8,9 +8,12 @@ #include "addpass.h" void initpass(char* gpgid) { + char *lang = getenv("SP_LANG"); + char* homedir = getenv("HOME"); if (homedir == NULL) { - perror("ãã¼ã ãã£ã¬ã¯ããªãååã«å¤±æã"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to getting home directory."); + else perror("ãã¼ã ãã£ã¬ã¯ããªãååã«å¤±æã"); return; } @@ -19,7 +22,8 @@ void initpass(char* gpgid) { snprintf(dirpath, sizeof(dirpath), "%s%s", homedir, basedir); if (mkdir_r(dirpath, 0755) != 0 && errno != EEXIST) { - perror("ãã£ã¬ã¯ããªãä½æã«å¤±æã"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to creating directory."); + else perror("ãã£ã¬ã¯ããªãä½æã«å¤±æã"); return; } @@ -28,23 +32,27 @@ void initpass(char* gpgid) { struct stat statbuf; if (stat(gpgidpath, &statbuf) == 0) { - fprintf(stderr, ".gpg-idãã¡ã¤ã«ã¯æ¢ã«åå¨ãã¾ãã\n"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror(".gpg-id file is already exist."); + else perror(".gpg-idãã¡ã¤ã«ã¯æ¢ã«åå¨ãã¾ãã"); return; } FILE* gpgidfile = fopen(gpgidpath, "w"); if (gpgidfile == NULL) { - perror(".gpg-idãã¡ã¤ã«ãæ¸ãè¾¼ãã¾ããã"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to writing .gpg-id file."); + else perror(".gpg-idãã¡ã¤ã«ãæ¸ãè¾¼ãã¾ããã"); fclose(gpgidfile); return; } if (fputs(gpgid, gpgidfile) == EOF) { - fprintf(stderr, ".gpg-idãã¡ã¤ã«ã¸ã®æ¸ãè¾¼ã¿ã«å¤±æãã¾ããã\n"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to writing .gpg-id file."); + else perror(".gpg-idãã¡ã¤ã«ã¸ã®æ¸ãè¾¼ã¿ã«å¤±æãã¾ããã"); fclose(gpgidfile); return; } fclose(gpgidfile); - printf("åæè¨å®ã«å®äºãã¾ããã"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) puts("First time setup was complete."); + else puts("åæè¨å®ã«å®äºãã¾ããã"); } diff --git a/listpass.c b/listpass.c index a5e5932..93429e8 100644 --- a/listpass.c +++ b/listpass.c @@ -7,10 +7,13 @@ #include "listpass.h" void listpass(char* basePath, int level) { + char *lang = getenv("SP_LANG"); + struct dirent* entry; DIR* dir = opendir(basePath); if (!dir) { - perror("ãã£ã¬ã¯ããªãéãããã¾ããã"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Could not opening directory"); + else perror("ãã£ã¬ã¯ããªãéãããã¾ãã"); return; } @@ -19,13 +22,15 @@ void listpass(char* basePath, int level) { char path[1000]; int needed = snprintf(path, sizeof(path), "%s/%s", basePath, entry->d_name); if (needed >= (int)sizeof(path) || needed < 0) { - fprintf(stderr, "ã¨ã©ã¼ï¼ãã¹ãé·ããããåã¯é·ããååã«å¤±æã"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Error: Path is too long, or failed to getting lenth"); + else perror("ã¨ã©ã¼ï¼ãã¹ãé·ããããåã¯é·ããååã«å¤±æ"); continue; } struct stat statbuf; if (stat(path, &statbuf) == -1) { - perror("ãã¡ã¤ã«ç¶æ³ãèªè¾¼ã«å¤±æã"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to reading file status"); + else perror("ãã¡ã¤ã«ç¶æ³ãèªè¾¼ã«å¤±æ"); continue; } diff --git a/main.c b/main.c index 42b0bd5..5ade13f 100644 --- a/main.c +++ b/main.c @@ -13,7 +13,6 @@ #include "delpass.h" #include "genpass.h" #include "otppass.h" -void helpme(); const char* sofname = "sp"; const char* version = "1.2.0"; @@ -21,7 +20,7 @@ const char* version = "1.2.0"; void helpme() { printf("ï¼ï¼ï¼ %s %s - ã·ã³ãã«ãªãã¹ã¯ã¼ãããã¼ã¸ã£ã¼\n", sofname, version); printf("https://076.moe/ | https://gitler.moe/suwako/%s\n\n", sofname); - puts ("使ãæ¹ï¼\n"); + puts ("使ãæ¹ï¼"); printf("%s -i <gpg-id> ï¼GPGã¨ä½¿ã£ã¦ãã¹ã¯ã¼ãã¹ãã¬ã¼ã¸ãåæè¨å®\n", sofname); printf("%s -s <ãã¹ã¯ã¼ãå> ï¼ãã¹ã¯ã¼ãã表示\n", sofname); printf("%s -y <ãã¹ã¯ã¼ãå> ï¼ãã¹ã¯ã¼ãã表示ããã¯ãªãããã¼ãã«ã³ãã¼ãã\n", sofname); @@ -30,14 +29,35 @@ void helpme() { printf("%s -d <ãã¹ã¯ã¼ãå> ï¼ãã¹ã¯ã¼ããåé¤\n", sofname); printf("%s -e <ãã¹ã¯ã¼ãå> ï¼ãã¹ã¯ã¼ããå¤æ´\n", sofname); printf("%s -g <æåæ°> [risk|secure] ï¼å¸ææåæ°ã§ãã¹ã¯ã¼ããã©ã³ãã ã«ä½æãããriskï¼è±æ°åã®ã¿ï¼ä¸å®ï¼ãsecureï¼è±æ°åï¼ç¹å¥æåï¼ããã©ã«ãï¼ã使ç¨\n", sofname); - printf("%s -o <ãã¹ã¯ã¼ãå>\n ï¼ã¯ã³ã¿ã¤ã ãã¹ã¯ã¼ãï¼TOTPï¼ã表示ãåå¨ããªããã°ãåµä½ãã\n", sofname); + printf("%s -o <ãã¹ã¯ã¼ãå> ï¼ã¯ã³ã¿ã¤ã ãã¹ã¯ã¼ãï¼TOTPï¼ã表示ãåå¨ããªããã°ãåµä½ãã\n", sofname); printf("%s -h ï¼ãã«ãã表示\n", sofname); printf("%s -v ï¼ãã¼ã¸ã§ã³ã表示\n", sofname); } +void helpme_en() { + printf("076 %s %s - Simple Password Manager\n", sofname, version); + printf("https://076.moe/ | https://gitler.moe/suwako/%s\n", sofname); + puts ("When reporting issues, please report in Japanese.\n"); + puts ("Usage:"); + printf("%s -i <gpg-id> : First setting for using GPG and password storage\n", sofname); + printf("%s -s <Password name> : Show password\n", sofname); + printf("%s -y <Password name> : Copy password to clipboard without show\n", sofname); + printf("%s -l : Show me list of password\n", sofname); + printf("%s -a <Password name> : Add password\n", sofname); + printf("%s -d <Password name> : Delete password\n", sofname); + printf("%s -e <Password name> : Edit password\n", sofname); + printf("%s -g <Characters amount> [risk|secure] : Randomly make password with hoped amount. Using risk = only english letter and number (abnoxious), secure = english letter and digit + special character (default)\n", sofname); + printf("%s -o <Password name> : Show one time password. If not exist, construct\n", sofname); + printf("%s -h : Show help\n", sofname); + printf("%s -v : Show version\n", sofname); +} + int main (int argc, char* argv[]) { + char *lang = getenv("SP_LANG"); + if (argc < 2) { - helpme(); + if (lang != NULL && strncmp(lang, "en", 2) == 0) helpme_en(); + else helpme(); return 0; } @@ -48,7 +68,8 @@ int main (int argc, char* argv[]) { char basePath[512]; char* homedir = getenv("HOME"); if (homedir == NULL) { - perror("ãã¼ã ãã£ã¬ã¯ããªãååã«å¤±æã"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to getting home directory"); + else perror("ãã¼ã ãã£ã¬ã¯ããªãååã«å¤±æ"); return -1; } @@ -67,13 +88,17 @@ int main (int argc, char* argv[]) { if (argc == 3) genpass(atoi(argv[2]), true); else if (argc == 4 && strcmp(argv[3], "risk") == 0) genpass(atoi(argv[2]), false); else if (argc == 4 && strcmp(argv[3], "secure") == 0) genpass(atoi(argv[2]), true); - else helpme(); + else { + if (lang != NULL && strncmp(lang, "en", 2) == 0) helpme_en(); + else helpme(); + } } else if (argc == 3 && strcmp(argv[1], "-o") == 0) { char fullPath[512]; char* homedir = getenv("HOME"); if (homedir == NULL) { - perror("ãã¼ã ãã£ã¬ã¯ããªãååã«å¤±æã"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to getting home directory"); + else perror("ãã¼ã ãã£ã¬ã¯ããªãååã«å¤±æ"); return -1; } @@ -83,7 +108,10 @@ int main (int argc, char* argv[]) { otppass(fullPath); } else if (argc == 2 && strcmp(argv[1], "-v") == 0) printf("%s-%s\n", sofname, version); - else helpme(); + else { + if (lang != NULL && strncmp(lang, "en", 2) == 0) helpme_en(); + else helpme(); + } return 0; } diff --git a/otppass.c b/otppass.c index 1630f47..a6a3148 100644 --- a/otppass.c +++ b/otppass.c @@ -1,4 +1,5 @@ #include <stdio.h> +#include <string.h> #include <openssl/hmac.h> #include <openssl/sha.h> #include <gpgme.h> @@ -7,9 +8,12 @@ #include "otppass.h" unsigned char* extract_secret(const char* otpauth_url, size_t* decoded_len) { + char *lang = getenv("SP_LANG"); + const char* secret_start = strstr(otpauth_url, "secret="); if (!secret_start) { - fprintf(stderr, "OTPAuth URLã®ä¸ã«ãã·ã¼ã¯ã¬ãããè¦ã¤ãããã¾ããã§ããã\n"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("In the middle of the OTPAuth URL, could not found secret"); + else perror("OTPAuth URLã®ä¸ã«ãã·ã¼ã¯ã¬ãããè¦ã¤ãããã¾ããã§ãã"); return NULL; } secret_start += 7; @@ -24,7 +28,8 @@ unsigned char* extract_secret(const char* otpauth_url, size_t* decoded_len) { } if (secret_end < secret_start) { - fprintf(stderr, "ä¸æ£ãªã·ã¼ã¯ã¬ããã®è·é¢ã\n"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Illegal secret range"); + else perror("ä¸æ£ãªã·ã¼ã¯ã¬ããã®è·é¢"); return NULL; } @@ -32,7 +37,8 @@ unsigned char* extract_secret(const char* otpauth_url, size_t* decoded_len) { char* secret_encoded = (char*)malloc(secret_len + 1); if (secret_encoded == NULL) { - fprintf(stderr, "ã¡ã¢ãªã®å½¹å²ã«å¤±æã\n"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to allocating memory"); + else perror("ã¡ã¢ãªã®å½¹å²ã«å¤±æ"); return NULL; } @@ -43,7 +49,8 @@ unsigned char* extract_secret(const char* otpauth_url, size_t* decoded_len) { free(secret_encoded); if (!secret_decoded) { - fprintf(stderr, "BASE32ã®å¾©å·åã«å¤±æã\n"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to decrypting of the BASE32"); + else perror("BASE32ã®å¾©å·åã«å¤±æ"); return NULL; } @@ -67,6 +74,8 @@ uint32_t generate_totp(const char *secret, uint64_t counter) { } void otppass(char* file) { + char *lang = getenv("SP_LANG"); + gpgme_ctx_t ctx; gpgme_error_t err; gpgme_data_t in, out; @@ -75,38 +84,44 @@ void otppass(char* file) { gpgme_check_version(NULL); err = gpgme_new(&ctx); if (err) { - fprintf(stderr, "GPGMEãåµä½ã«å¤±æ\n"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to generating the GPG"); + else perror("GPGMEãåµä½ã«å¤±æ"); exit(1); } err = gpgme_data_new_from_file(&in, file, 1); if (err) { - fprintf(stderr, "GPGãã¡ã¤ã«ãèªè¾¼ã«å¤±æ\n"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to reading the GPG file"); + else perror("GPGãã¡ã¤ã«ãèªè¾¼ã«å¤±æ"); exit(1); } err = gpgme_data_new(&out); if (err) { - fprintf(stderr, "GPGãã¼ã¿ãèªè¾¼ã«å¤±æ\n"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to reading the GPG data"); + else perror("GPGãã¼ã¿ãèªè¾¼ã«å¤±æ"); exit(1); } err = gpgme_op_decrypt(ctx, in, out); if (err) { - fprintf(stderr, "GPGã復å·åã«å¤±æ\n"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to decrypting the GPG"); + else perror("GPGã復å·åã«å¤±æ"); exit(1); } char* secret = gpgme_data_release_and_get_mem(out, &secret_len); if (!secret) { - fprintf(stderr, "GPGãååã«å¤±æ\n"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to getting the GPG"); + else perror("GPGãååã«å¤±æ"); exit(1); } size_t decoded_len; unsigned char* secret_decoded = extract_secret(secret, &decoded_len); if (!secret_decoded) { - fprintf(stderr, "ã·ã¼ã¯ã¬ããã®æ½åºã¾ãã¯ãã³ã¼ãã«å¤±æãã¾ãã\n"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to decoding or exporting secret"); + else perror("ã·ã¼ã¯ã¬ããã®æ½åºåã¯ãã³ã¼ãã«å¤±æãã¾ãã"); free(secret); exit(1); } diff --git a/showpass.c b/showpass.c index 9355521..1262775 100644 --- a/showpass.c +++ b/showpass.c @@ -4,6 +4,7 @@ #include <locale.h> #include <gpgme.h> +#include <string.h> #include "showpass.h" @@ -16,6 +17,8 @@ void clean_up(gpgme_ctx_t ctx, gpgme_data_t in, gpgme_data_t out, FILE* gpgfile, } void showpass(char* file) { + char *lang = getenv("SP_LANG"); + gpgme_ctx_t ctx; gpgme_error_t err; gpgme_data_t in = NULL, out = NULL; @@ -29,7 +32,8 @@ void showpass(char* file) { // GPGMEãåµä½ err = gpgme_new(&ctx); if (err) { - fprintf(stderr, "GPGMEãåµä½ã«å¤±æï¼%s\n", gpgme_strerror(err)); + if (lang != NULL && strncmp(lang, "en", 2) == 0) fprintf(stderr, "Failed to generating GPGME: %s\n", gpgme_strerror(err)); + else fprintf(stderr, "GPGMEãåµä½ã«å¤±æï¼%s\n", gpgme_strerror(err)); return; } @@ -39,7 +43,8 @@ void showpass(char* file) { // æå·åããã¿ã¤ã«ãéã char* homedir = getenv("HOME"); if (homedir == NULL) { - perror("ãã¼ã ãã£ã¬ã¯ããªãååã«å¤±æã"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to getting home directory"); + else perror("ãã¼ã ãã£ã¬ã¯ããªãååã«å¤±æ"); return; } @@ -48,29 +53,37 @@ void showpass(char* file) { int alllen = snprintf(NULL, 0, "%s%s%s%s", homedir, basedir, file, ext) + 1; char* gpgpath = malloc(alllen); if (gpgpath == NULL) { - perror("ã¡ã¢ãªãå²å½ã«å¤±æã"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to allocating memeory"); + else perror("ã¡ã¢ãªãå²å½ã«å¤±æ"); return; } snprintf(gpgpath, alllen, "%s%s%s%s", homedir, basedir, file, ext); gpgfile = fopen(gpgpath, "rb"); if (gpgfile == NULL) { - perror("ãã¡ã¤ã«ãéãã«å¤±æã"); - printf("失æãããã¹ï¼ %s\n", gpgpath); + if (lang != NULL && strncmp(lang, "en", 2) == 0) { + perror("Failed to opening file"); + fprintf(stderr, "Failing path: %s\n", gpgpath); + } else { + perror("ãã¡ã¤ã«ãéãã«å¤±æ"); + fprintf(stderr, "失æãããã¹ï¼ %s\n", gpgpath); + } free(gpgpath); return; } // ãã¡ã¤ã«ããinãã¼ã¿ãªãã¸ã§ã¯ããåµä½ if (gpgme_data_new_from_stream(&in, gpgfile) != GPG_ERR_NO_ERROR) { - fprintf(stderr, "GPGMEãã¼ã¿ãªãã¸ã§ã¯ããåµä½ã«å¤±æã\n"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to generating the GPGME data object"); + else perror("GPGMEãã¼ã¿ãªãã¸ã§ã¯ããåµä½ã«å¤±æ"); clean_up(ctx, in, out, gpgfile, gpgpath); return; } // outãã¼ã¿ãªãã¸ã§ã¯ããåµä½ if (gpgme_data_new(&out) != GPG_ERR_NO_ERROR) { - fprintf(stderr, "GPGMEãã¼ã¿ãªãã¸ã§ã¯ããåµä½ã«å¤±æã\n"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to generating the GPGME data object"); + else perror("GPGMEãã¼ã¿ãªãã¸ã§ã¯ããåµä½ã«å¤±æ"); clean_up(ctx, in, out, gpgfile, gpgpath); return; } @@ -81,7 +94,8 @@ void showpass(char* file) { // 復å·åã㦠err = gpgme_op_decrypt(ctx, in, out); if (err) { - fprintf(stderr, "復å·åã«å¤±æï¼ %s\n", gpgme_strerror(err)); + if (lang != NULL && strncmp(lang, "en", 2) == 0) fprintf(stderr, "Failed to decrypting: %s\n", gpgme_strerror(err)); + else fprintf(stderr, "復å·åã«å¤±æï¼ %s\n", gpgme_strerror(err)); // æé¤ clean_up(ctx, in, out, gpgfile, gpgpath); diff --git a/yankpass.c b/yankpass.c index cf0af8c..6f67aba 100644 --- a/yankpass.c +++ b/yankpass.c @@ -2,6 +2,7 @@ #include <stdlib.h> #include <locale.h> #include <unistd.h> +#include <string.h> #include <gpgme.h> @@ -9,9 +10,12 @@ #include "showpass.h" void yankpass(char* file) { + char *lang = getenv("SP_LANG"); + // Xã»ãã·ã§ã³ã§ã¯ãªãå ´åï¼ä¾ãã°ãSSHãTTYãGaylandçï¼ãshowpass()ãå®è¡ã㦠- if (getenv("DISPLAY") == NULL) { - printf("Xã»ãã·ã§ã³ã§ã¯ããã¾ããã®ã§ããsp -sããå®è¡ãã¾ãã\n"); + if (getenv("DISPLAY") == NULL) { + if (lang != NULL && strncmp(lang, "en", 2) == 0) puts("There is no X session, so executing 'sp -s'."); + else puts("Xã»ãã·ã§ã³ã§ã¯ããã¾ããã®ã§ããsp -sããå®è¡ãã¾ãã"); showpass(file); return; } @@ -29,7 +33,8 @@ void yankpass(char* file) { // GPGMEãåµä½ err = gpgme_new(&ctx); if (err) { - fprintf(stderr, "GPGMEãåµä½ã«å¤±æï¼%s\n", gpgme_strerror(err)); + if (lang != NULL && strncmp(lang, "en", 2) == 0) fprintf(stderr, "Failed to generating GPGME: %s\n", gpgme_strerror(err)); + else fprintf(stderr, "GPGMEãåµä½ã«å¤±æï¼%s\n", gpgme_strerror(err)); return; } @@ -39,7 +44,8 @@ void yankpass(char* file) { // æå·åããã¿ã¤ã«ãéã char* homedir = getenv("HOME"); if (homedir == NULL) { - perror("ãã¼ã ãã£ã¬ã¯ããªãååã«å¤±æã"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to getting home directory"); + else perror("ãã¼ã ãã£ã¬ã¯ããªãååã«å¤±æ"); return; } @@ -48,15 +54,21 @@ void yankpass(char* file) { int alllen = snprintf(NULL, 0, "%s%s%s%s", homedir, basedir, file, ext) + 1; char* gpgpath = malloc(alllen); if (gpgpath == NULL) { - perror("ã¡ã¢ãªãå²å½ã«å¤±æã"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to allocating memory"); + else perror("ã¡ã¢ãªãå²å½ã«å¤±æ"); return; } snprintf(gpgpath, alllen, "%s%s%s%s", homedir, basedir, file, ext); gpgfile = fopen(gpgpath, "rb"); if (gpgfile == NULL) { - perror("ãã¡ã¤ã«ãéãã«å¤±æã"); - printf("失æãããã¹ï¼ %s\n", gpgpath); + if (lang != NULL && strncmp(lang, "en", 2) == 0) { + perror("Failed to opening the file"); + fprintf(stderr, "Failed path: %s\n", gpgpath); + } else { + perror("ãã¡ã¤ã«ãéãã«å¤±æ"); + fprintf(stderr, "失æãããã¹ï¼ %s\n", gpgpath); + } free(gpgpath); return; } @@ -68,7 +80,8 @@ void yankpass(char* file) { // 復å·åã㦠err = gpgme_op_decrypt(ctx, in, out); if (err) { - fprintf(stderr, "復å·åã«å¤±æï¼ %s\n", gpgme_strerror(err)); + if (lang != NULL && strncmp(lang, "en", 2) == 0) fprintf(stderr, "Failed to decryption: %s\n", gpgme_strerror(err)); + else fprintf(stderr, "復å·åã«å¤±æï¼ %s\n", gpgme_strerror(err)); // æé¤ fclose(gpgfile); @@ -89,7 +102,8 @@ void yankpass(char* file) { gpgme_data_release(in); gpgme_data_release(out); gpgme_release(ctx); - perror("ã¯ãªãããã¼ããè¦ã¤ãããã¾ããã§ããã"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Could not found a clipboard"); + else perror("ã¯ãªãããã¼ããè¦ã¤ãããã¾ããã§ãã"); return; } @@ -109,7 +123,8 @@ void yankpass(char* file) { pclose(pipe); // 45ç§å¾ãã¯ãªãããã¼ãããåé¤ãã - printf("ãã¹ã¯ã¼ããã¯ãªãããã¼ãã«è¿½å ãã¾ããã\n45ç§å¾ã¯ã¯ãªãããã¼ãããåãæ¶ããã¾ãã\n"); + if (lang != NULL && strncmp(lang, "en", 2) == 0) puts("Added password to the clipboard.\nI will take it away from the clipboard after 45 second"); + else puts("ãã¹ã¯ã¼ããã¯ãªãããã¼ãã«è¿½å ãã¾ããã\n45ç§å¾ã¯ã¯ãªãããã¼ãããåãæ¶ããã¾ã"); sleep(45); system("echo -n | xclip -selection clipboard");