|
|
|
@ -13,10 +13,10 @@
|
|
|
|
|
#include <syslog.h>
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <dirent.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <iniparser.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_PATHS_H
|
|
|
|
@ -31,74 +31,16 @@
|
|
|
|
|
#include <security/pam_modutil.h>
|
|
|
|
|
#include <security/pam_ext.h>
|
|
|
|
|
|
|
|
|
|
#define INI_ENV "/etc/calculate/ini.env"
|
|
|
|
|
#define PROTECT_DIR "/etc"
|
|
|
|
|
#define UPDATES_MARK "/var/lib/calculate/calculate-update/updates.available"
|
|
|
|
|
|
|
|
|
|
#define HAVE_NO_UPDATE 0x0
|
|
|
|
|
#define HAVE_NEW_CONFIG 0x1
|
|
|
|
|
#define HAVE_NEW_PACKAGES 0x2
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
int has_cfg_files(char *pdir) {
|
|
|
|
|
DIR *dfd;
|
|
|
|
|
struct dirent *dp;
|
|
|
|
|
char filename[NAME_MAX];
|
|
|
|
|
int ret=0;
|
|
|
|
|
|
|
|
|
|
dfd = opendir(pdir);
|
|
|
|
|
if(!dfd) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
while( (dp=readdir(dfd)) != NULL) {
|
|
|
|
|
// skip internal name
|
|
|
|
|
if(strcmp(dp->d_name,".") == 0 ||
|
|
|
|
|
strcmp(dp->d_name,"..") == 0)
|
|
|
|
|
continue;
|
|
|
|
|
// found ._cfg files for dispatch-conf
|
|
|
|
|
if(strncmp(dp->d_name,"._cfg", 5) == 0) {
|
|
|
|
|
ret = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// recursive search in directories
|
|
|
|
|
if(dp->d_type == DT_DIR) {
|
|
|
|
|
if(strlen(pdir) + strlen(dp->d_name) + 1 < NAME_MAX) {
|
|
|
|
|
strcpy(filename,pdir);
|
|
|
|
|
strcat(filename,"/");
|
|
|
|
|
strcat(filename,dp->d_name);
|
|
|
|
|
if(has_cfg_files(filename)) {
|
|
|
|
|
ret = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
closedir(dfd);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
int has_new_packages() {
|
|
|
|
|
dictionary *ini;
|
|
|
|
|
char *value;
|
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
|
|
ini = iniparser_load(INI_ENV);
|
|
|
|
|
if(ini==NULL) {
|
|
|
|
|
fprintf(stderr, "wrong file: %s\n", INI_ENV);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
value = iniparser_getstring(ini, "update:updates", NULL);
|
|
|
|
|
if(value && strcmp(value,"on") == 0) {
|
|
|
|
|
ret = 1;
|
|
|
|
|
}
|
|
|
|
|
else if(!value) {
|
|
|
|
|
value = iniparser_getstring(ini, "update:packages", NULL);
|
|
|
|
|
if(value && strcmp(value,"on") == 0) {
|
|
|
|
|
ret = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
iniparser_freedict(ini);
|
|
|
|
|
return ret;
|
|
|
|
|
return (faccessat(0, UPDATES_MARK, F_OK, AT_SYMLINK_NOFOLLOW) == 0) ? 1 : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|