}
if ((passwd = _app2sd_get_password_from_db(pkgid, uid)) == NULL) {
- passwd = (char *)_app2sd_generate_password(pkgid);
+ passwd = (char *)_app2sd_generate_password();
if (NULL == passwd) {
_E("unable to generate password");
return NULL;
_E("no password found for (%s)", pkgid);
return APP2EXT_ERROR_SQLITE_REGISTRY;
}
- passwd = (char *)_app2sd_generate_password(pkgid);
+ passwd = (char *)_app2sd_generate_password();
if (NULL == passwd) {
_E("unable to generate password\n");
return APP2EXT_ERROR_PASSWD_GENERATION;
}
if ((passwd = _app2sd_get_password_from_db(pkgid, uid)) == NULL) {
- passwd = (char *)_app2sd_generate_password(pkgid);
+ passwd = (char *)_app2sd_generate_password();
if (NULL == passwd) {
_E("unable to generate password");
return APP2EXT_ERROR_PASSWD_GENERATION;
*/
#include <dirent.h>
-#include <time.h>
+#include <glib.h>
#include <storage-internal.h>
#include "app2sd_internals.h"
* This is a simple password generator
* return: On success, it will return the password, else NULL.
*/
-char *_app2sd_generate_password(const char *pkgid)
+char *_app2sd_generate_password(void)
{
- char passwd[PASSWD_LEN + 1] = { 0, };
- char *ret_result = NULL;
- char set[ASCII_PASSWD_CHAR + 1] =
+ char *passwd;
+ static const char charset[ASCII_PASSWD_CHAR + 1] =
"!\"#$%&()*+,-./0123456789:;<=>?@ABCDE" \
"FGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
- unsigned char char_1;
- unsigned char char_2;
- int i = 0;
- int appname_len = strlen(pkgid);
- int j = appname_len;
- unsigned int seed;
-
- /* length of the password */
- ret_result = (char *)malloc(PASSWD_LEN + 1);
- if (NULL == ret_result) {
+ int i;
+
+ /* include null byte */
+ passwd = (char *)malloc(sizeof(char) * (PASSWD_LEN + 1));
+ if (passwd == NULL) {
_E("unable to allocate memory");
return NULL;
}
- memset((void *)ret_result, '\0', PASSWD_LEN + 1);
-
- while (i < PASSWD_LEN) {
- seed = time(NULL);
- if (j > 0) j--;
- char_1 = (rand_r(&seed) + pkgid[j]) % ASCII_PASSWD_CHAR;
- char_2 = rand_r(&seed) % ASCII_PASSWD_CHAR;
- passwd[i] = set[char_1];
- if (j > 0) j--;
- passwd[i + 1] = set[((pkgid[j]) * 2) % ASCII_PASSWD_CHAR];
- if (i < PASSWD_LEN - 3)
- passwd[i + 2] = set[char_2];
- i++;
- }
- memcpy(ret_result, passwd, PASSWD_LEN + 1);
+ for (i = 0; i < PASSWD_LEN; i++)
+ passwd[i] = charset[g_random_int() % ASCII_PASSWD_CHAR];
+ passwd[i] = '\0';
- return ret_result;
+ return passwd;
}
#ifdef TIZEN_FEATURE_APP2SD_DMCRYPT_ENCRYPTION