¿Es esta línea una mala práctica desde una postura de seguridad?
connect = mysql_real_connect(connection, "host", "user", "password", "database", 0, (const char *)NULL, 0);
Si es así, ¿qué solución utilizarías?
Editar
void get_credentials(char* host, char* name, char* passwd, char* db) {
char string_path[80] = "/etc/.acro";
struct stat sb;
stat(string_path, &sb);
int file_OK = FILE_OK;
if (sb.st_mode == 0644) {
fprintf(stderr, "Corrupt login file: permissions");
file_OK = FILE_BAD;
}
/* if(file_meta->st_uid != ???) {
fprintf(stderr, "Corrupt login file: owner");
file_OK = FILE_BAD;
} */
if(file_OK) {
FILE *login_file = fopen(string_path, "r");
fgets(host, 80, login_file);
fgets(name, 80, login_file);
fgets(passwd, 80, login_file);
fgets(db, 80, login_file);
host[strcspn (host, "\n")] = '// 33216 = 100700 in octal => rwx for owner only
if (sb.st_mode != 33216) {
printf("Corrupt login file: permissions");
file_OK = FILE_BAD;
}
';
name[strcspn (name, "\n")] = 'connect = mysql_real_connect(connection, "host", "user", "password", "database", 0, (const char *)NULL, 0);
';
passwd[strcspn (passwd, "\n")] = 'void get_credentials(char* host, char* name, char* passwd, char* db) {
char string_path[80] = "/etc/.acro";
struct stat sb;
stat(string_path, &sb);
int file_OK = FILE_OK;
if (sb.st_mode == 0644) {
fprintf(stderr, "Corrupt login file: permissions");
file_OK = FILE_BAD;
}
/* if(file_meta->st_uid != ???) {
fprintf(stderr, "Corrupt login file: owner");
file_OK = FILE_BAD;
} */
if(file_OK) {
FILE *login_file = fopen(string_path, "r");
fgets(host, 80, login_file);
fgets(name, 80, login_file);
fgets(passwd, 80, login_file);
fgets(db, 80, login_file);
host[strcspn (host, "\n")] = '// 33216 = 100700 in octal => rwx for owner only
if (sb.st_mode != 33216) {
printf("Corrupt login file: permissions");
file_OK = FILE_BAD;
}
';
name[strcspn (name, "\n")] = '%pre%';
passwd[strcspn (passwd, "\n")] = '%pre%';
db[strcspn (db, "\n")] = '%pre%';
fclose(login_file);
}
}
';
db[strcspn (db, "\n")] = '%pre%';
fclose(login_file);
}
}
Editar 2
La verificación de permisos debería tener este aspecto para un archivo 700:
%pre%