You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
132 lines
3.5 KiB
132 lines
3.5 KiB
#include "libublsettings.h"
|
|
|
|
// parsing functions
|
|
|
|
int yon_password_get_min_len(){
|
|
int leng=6;
|
|
int login_size;
|
|
config_str login_defs = yon_file_open("/etc/security/pwquiality.conf",&login_size);
|
|
for (int i=0;i<login_size;i++){
|
|
if (login_defs[i][0]!='#'){
|
|
char *copy = yon_char_new(login_defs[i]);
|
|
char *divided = yon_char_divide(copy,7);
|
|
if (divided){
|
|
if (!strcmp(divided,"minlen")){
|
|
leng = atol(strstr(login_defs[i],"\t"));
|
|
}
|
|
free(divided);
|
|
}
|
|
free(copy);
|
|
}
|
|
}
|
|
yon_char_parsed_free(login_defs,login_size);
|
|
return leng;
|
|
}
|
|
|
|
float yon_size_convert_automatic(int bytes, int *size){
|
|
float byte_float=bytes;
|
|
for (*size=-1;byte_float>1024;*size=*size+1){
|
|
byte_float=byte_float/1024;
|
|
}
|
|
if (*size==-1) {
|
|
*size=0;
|
|
byte_float=byte_float/1024;
|
|
}
|
|
return byte_float;
|
|
}
|
|
|
|
int yon_get_size_get_from_letter(char size){
|
|
switch (size){
|
|
case 'K': return 0;
|
|
break;
|
|
case 'M': return 1;
|
|
break;
|
|
case 'G': return 2;
|
|
break;
|
|
case 'T': return 3;
|
|
break;
|
|
default: return -1;
|
|
break;
|
|
}
|
|
}
|
|
|
|
char *yon_size_get_mod(int size){
|
|
char *size_modifier = NULL;
|
|
switch (size){
|
|
case 0: size_modifier = "K";
|
|
break;
|
|
case 1: size_modifier = "M";
|
|
break;
|
|
case 2: size_modifier = "G";
|
|
break;
|
|
case 3: size_modifier = "T";
|
|
break;
|
|
}
|
|
return size_modifier;
|
|
}
|
|
|
|
config_str yon_dir_get_contents(char *dir_path, int *size){
|
|
config_str dir = NULL;
|
|
*size=0;
|
|
if (!access(dir_path,F_OK)){
|
|
DIR *directory = opendir(dir_path);
|
|
struct dirent *de;
|
|
while ((de = readdir(directory))){
|
|
if (dir){ dir = yon_char_parsed_append(dir,size,yon_char_new(de->d_name));
|
|
} else dir = yon_char_parsed_new(size,yon_char_new(de->d_name),NULL);
|
|
}
|
|
closedir(directory);
|
|
}
|
|
return dir;
|
|
}
|
|
|
|
config_str yon_dir_get_by_mask(char *path, char *mask, int *size){
|
|
(*size)=0;
|
|
if (yon_char_count(mask,"*")<=1){
|
|
char *lpart;
|
|
char *rpart=yon_char_new(mask);
|
|
lpart = yon_char_divide_search(rpart,"*",-1);
|
|
config_str files = NULL;
|
|
int found_size;
|
|
config_str found_files = yon_dir_get_contents(path,&found_size);
|
|
if(found_size>0){
|
|
int found = 1;
|
|
int rfound = 0;
|
|
for (int i=0;i<found_size;i++){
|
|
int c;
|
|
for (c=0;c<strlen(found_files[i]);c++){
|
|
if (found_files[i][c]!=lpart[c]){
|
|
break;
|
|
}
|
|
if (c==strlen(lpart)) break;
|
|
}
|
|
if (found){
|
|
for (int l=c;l<strlen(found_files[i]);l++){
|
|
if (found_files[i][l]==rpart[l]) rfound++;
|
|
else rfound=0;
|
|
}
|
|
if (rfound==strlen(rpart)) {
|
|
yon_char_parsed_add_or_create_if_exists(files,size,found_files[i]);
|
|
}
|
|
}
|
|
}
|
|
free(found_files);
|
|
}
|
|
}
|
|
}
|
|
|
|
// terminal-using functions
|
|
|
|
int yon_launch_app_with_arguments(char *name, char *args)
|
|
{
|
|
char *path = yon_char_unite("/usr/bin/", name, " ", args,NULL);
|
|
pthread_t thread_id;
|
|
char *command = NULL;
|
|
command = path;
|
|
pthread_create(&thread_id, NULL, (void *)yon_launch, command);
|
|
};
|
|
|
|
void yon_launch(char *command)
|
|
{
|
|
int ansver = system(command);
|
|
} |