-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmain.c
More file actions
105 lines (81 loc) · 2.65 KB
/
main.c
File metadata and controls
105 lines (81 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <apr-1.0/apr_file_info.h>
#include <sqlite3.h>
int main(int argc, char **argv)
{
int rc, i, ncols; char *sql;
sqlite3 *db;
sqlite3_stmt *stmt;
char buffer[256];
const char *tail;
apr_initialize();
/* Arrange to have it cleaned up at exit. */
atexit(apr_terminate);
/* Open an in-memory database */
if(sqlite3_open(":memory:", &db) != SQLITE_OK) {
exit(1);
}
/* Enable loadable modules (DSOs) */
sqlite3_enable_load_extension(db, 1);
/* Load the fs virtual table. */
char* msg;
const char* lib = "libvtable";
rc = sqlite3_load_extension(db, lib, "fs_register", &msg);
if(rc != SQLITE_OK) {
printf("ERROR: %s\n", msg);
exit(1);
}
/* Create it. */
sql = "create virtual table f using filesystem";
rc = sqlite3_exec(db, sql, NULL, NULL, &msg);
if(rc != SQLITE_OK) {
printf("ERROR: %s\n", msg);
exit(1);
}
/* Query it. */
/*
sql = "select inode,name,path,size,prot,uid,gid from f "
"where path match '/var/log, /usr/lib, /usr/local, /var/lib' "
"and name like '%.so'";
*/
sql = "select inode,name,path,size,prot,uid,gid from f "
"where path match '/var/log, /usr/lib, /usr/local, /var/lib'";
rc = sqlite3_prepare(db, sql, (int)strlen(sql), &stmt, &tail);
if(rc != SQLITE_OK) {
printf("ERROR: %s\n", msg);
exit(1);
}
/* Iterate over results */
ncols = sqlite3_column_count(stmt);
rc = sqlite3_step(stmt);
/* Print column information
for(i=0; i < ncols; i++) {
fprintf(stdout, "Column: name=%s, storage class=%i, declared=%s\n",
sqlite3_column_name(stmt, i),
sqlite3_column_type(stmt, i),
sqlite3_column_decltype(stmt, i));
}
fprintf(stdout, "\n");
*/
while(rc == SQLITE_ROW)
{
int inode = sqlite3_column_int(stmt, 0);
const char* name = sqlite3_column_text(stmt, 1);
const char* path = sqlite3_column_text(stmt, 2);
int size = sqlite3_column_int(stmt, 3);
int prot = sqlite3_column_int(stmt, 4);
int uid = sqlite3_column_int(stmt, 6);
int gid = sqlite3_column_int(stmt, 7);
if(name != NULL) {
fprintf( stderr,
"%6i %-35s %-45s %-9i %5X %-5i %-5i\n",
inode,name,path,size,prot,uid,gid );
}
rc = sqlite3_step(stmt);
}
sqlite3_finalize(stmt);
sqlite3_close(db);
return 0;
}