99 lines
2.8 KiB
C
99 lines
2.8 KiB
C
#include <stdio.h>
|
|
#include <dirent.h>
|
|
#include <malloc.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/types.h>
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <errno.h>
|
|
#include <string.h>
|
|
#include <pwd.h>
|
|
#include <grp.h>
|
|
#include <sqlite3.h>
|
|
#include <stdlib.h>
|
|
#include "md5.h"
|
|
|
|
#define MAX 512
|
|
#define MAX_NAME 512
|
|
#define MAX_FILE 512
|
|
#define MAX_ACL 1024
|
|
#define MAX_ID 32
|
|
#define MAX_TYPE 10
|
|
#define MAX_MD5 33
|
|
#define MAX_MOD 16
|
|
#define MAX_PATH 4096
|
|
|
|
#define FILEISO 1
|
|
#define FILEPKG 2
|
|
#define FILEFIL 3
|
|
#define FILEMD5 4
|
|
#define FILEPER 5
|
|
#define FILEOWN 6
|
|
#define FILEGEN 7
|
|
#define FILETYP 8
|
|
|
|
#define FROM_PKGID 10
|
|
#define FROM_NOWISO 20
|
|
#define FROM_DATALIB 30
|
|
|
|
#define S_ISUGV 07000
|
|
|
|
#define md5_t char
|
|
|
|
#define DATALIB "./fileinfo.db"
|
|
#define PKGLIST "./pkglist"
|
|
#define FILEDIFF "./diff.log"
|
|
|
|
struct isoinfo{
|
|
char name[MAX_NAME]; //镜像名
|
|
char version[MAX_NAME];//镜像版本
|
|
int id; //镜像id
|
|
md5_t md5[MAX_NAME]; //镜像md5_t
|
|
char issue[MAX_NAME];
|
|
} ;
|
|
|
|
struct pkginfo{
|
|
char name[MAX_NAME]; //安装包名
|
|
char version[MAX_NAME];//安装包版本
|
|
int id; //安装包id
|
|
md5_t md5[MAX_MD5]; //安装包md5
|
|
} ;
|
|
|
|
struct fileinfo{
|
|
int id; //文件id
|
|
char name[MAX_NAME]; //文件名
|
|
char pathname[MAX_PATH];//文件绝对路径名
|
|
md5_t md5[MAX_MD5]; //文件md5值
|
|
char type[MAX_TYPE]; //文件类型
|
|
int owner; //文件属主
|
|
int genus; //文件属组
|
|
char permis[MAX_ID]; //文件权限
|
|
off_t size; //文件大小
|
|
char acl[MAX_ACL]; //文件acl
|
|
char capable[MAX]; //文件能力
|
|
char mac[MAX]; //文件mac
|
|
char level[MAX]; //文件等级
|
|
} ;
|
|
|
|
struct datalib{
|
|
int nrow;
|
|
int ncolumn;
|
|
char ** db_result;
|
|
} ;
|
|
|
|
int get_iso_info(struct isoinfo *iso); //获取当前镜像信息
|
|
int get_now_pkg(char *now_name,struct pkginfo *now_pkg); //处理当前安装包列表
|
|
int get_pkg_info(struct isoinfo *iso,struct pkginfo *now_pkg,struct pkginfo *data_pkg,int statu);//获取安装包信息
|
|
int get_datafile_list(struct pkginfo data_pkg,struct fileinfo *data_file,struct datalib *file_list);//根据安装包信息获取对应文件列表
|
|
int get_nowfile_info( struct fileinfo *now_file,struct fileinfo *data_file );//获取当前系统文件具体信息
|
|
int diff_file_info(struct fileinfo now_file,struct fileinfo data_file);//对比当前系统文件信息和数据库文件信息
|
|
void get_datafile_info(int i,struct datalib *file_list,struct fileinfo *data_file);//将获取的文件信息转入到文件信息结构体中
|
|
void get_cap(struct fileinfo *now_file);
|
|
void get_mac(struct fileinfo *now_file);
|
|
void get_acl(struct fileinfo *now_file);
|
|
|
|
int put_diff_log(char *content);
|
|
int myshell(char *command,char *buff,int num);//调用shell命令
|
|
|
|
void clean_n(char *log);
|