00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
#include <stdio.h>
00036
#include <stdlib.h>
00037
#include <sys/types.h>
00038
#include <sys/stat.h>
00039
#include <fcntl.h>
00040
#include <string.h>
00041
#include <unistd.h>
00042
#include <sys/ioctl.h>
00043
#include "dazukoio_compat12.h"
00044
00045 int dazukoRegister_TS_compat12_wrapper(
struct dazuko_id **
dazuko_id,
const char *groupName)
00046 {
00047
int ret;
00048
struct dazuko_id *temp_id;
00049
00050
if (dazuko_id ==
NULL)
00051
return -1;
00052
00053 temp_id = (
struct dazuko_id *)malloc(
sizeof(*temp_id));
00054
if (temp_id ==
NULL)
00055
return -1;
00056
00057 memset(temp_id, 0,
sizeof(*temp_id));
00058
00059 temp_id->device = -1;
00060 temp_id->dev_major = -1;
00061
00062 ret =
dazukoRegister_TS_compat12(temp_id, groupName);
00063
00064
if (ret == 0)
00065 *dazuko_id = temp_id;
00066
else
00067 free(temp_id);
00068
00069
return ret;
00070 }
00071
00072 int dazukoRegister_TS_compat12(
struct dazuko_id *dazuko,
const char *groupName)
00073 {
00074
struct option_compat12 *opt;
00075
char buffer[10];
00076
int err = 0;
00077
00078
if (dazuko ==
NULL)
00079
return -1;
00080
00081
if (groupName ==
NULL)
00082 groupName =
"_GENERIC";
00083
00084
if (dazuko->
device < 0)
00085 {
00086
00087 dazuko->
device = open(
"/dev/dazuko", 0);
00088
if (dazuko->
device < 0)
00089
return -1;
00090
00091 memset(buffer, 0,
sizeof(buffer));
00092
if (read(dazuko->
device, buffer,
sizeof(buffer)-1) < 1)
00093 {
00094 close(dazuko->
device);
00095 dazuko->
device = -1;
00096
return -1;
00097 }
00098 dazuko->
dev_major = atoi(buffer);
00099 }
00100
00101 opt = (
struct option_compat12 *)malloc(
sizeof(
struct option_compat12));
00102
if (opt ==
NULL)
00103 {
00104 close(dazuko->
device);
00105 dazuko->
device = -1;
00106 dazuko->
dev_major = -1;
00107
return -1;
00108 }
00109
00110 memset(opt, 0,
sizeof(
struct option_compat12));
00111
00112 opt->command =
REGISTER;
00113 strncpy(opt->buffer, groupName,
sizeof(opt->buffer) - 1);
00114 opt->buffer_length = strlen(opt->buffer) + 1;
00115
00116
if (ioctl(dazuko->
device, _IOW(dazuko->
dev_major,
IOCTL_SET_OPTION,
void *), opt) != 0)
00117 {
00118
00119
00120
00121
00122
00123
00124
00125
00126 }
00127
00128 free(opt);
00129
00130
return err;
00131 }
00132
00133 int dazukoSetAccessMask_TS_compat12(
struct dazuko_id *dazuko,
unsigned long accessMask)
00134 {
00135
struct option_compat12 *opt;
00136
int err = 0;
00137
00138
if (dazuko ==
NULL)
00139
return -1;
00140
00141
if (dazuko->
device < 0 || dazuko->
dev_major < 0)
00142
return -1;
00143
00144 opt = (
struct option_compat12 *)malloc(
sizeof(
struct option_compat12));
00145
if (opt ==
NULL)
00146
return -1;
00147
00148 memset(opt, 0,
sizeof(
struct option_compat12));
00149
00150 opt->command =
SET_ACCESS_MASK;
00151 opt->buffer[0] = (
char)accessMask;
00152 opt->buffer_length = 1;
00153
00154
if (ioctl(dazuko->
device, _IOW(dazuko->
dev_major,
IOCTL_SET_OPTION,
void *), opt) != 0)
00155 err = -1;
00156
00157 free(opt);
00158
00159
return err;
00160 }
00161
00162 int dazuko_set_path_compat12(
struct dazuko_id *dazuko,
const char *
path,
int command)
00163 {
00164
struct option_compat12 *opt;
00165
int err = 0;
00166
00167
if (dazuko ==
NULL)
00168
return -1;
00169
00170
if (path ==
NULL)
00171
return -1;
00172
00173
if (dazuko->
device < 0 || dazuko->
dev_major < 0)
00174
return -1;
00175
00176 opt = (
struct option_compat12 *)malloc(
sizeof(
struct option_compat12));
00177
if (opt ==
NULL)
00178
return -1;
00179
00180 memset(opt, 0,
sizeof(
struct option_compat12));
00181
00182 opt->command = command;
00183 strncpy(opt->buffer, path,
sizeof(opt->buffer) - 1);
00184 opt->buffer_length = strlen(opt->buffer) + 1;
00185
00186
if (ioctl(dazuko->
device, _IOW(dazuko->
dev_major,
IOCTL_SET_OPTION,
void *), opt) != 0)
00187 err = -1;
00188
00189 free(opt);
00190
00191
return err;
00192 }
00193
00194 int dazukoAddIncludePath_TS_compat12(
struct dazuko_id *dazuko,
const char *
path)
00195 {
00196
return dazuko_set_path_compat12(dazuko, path,
ADD_INCLUDE_PATH);
00197 }
00198
00199 int dazukoAddExcludePath_TS_compat12(
struct dazuko_id *dazuko,
const char *
path)
00200 {
00201
return dazuko_set_path_compat12(dazuko, path,
ADD_EXCLUDE_PATH);
00202 }
00203
00204 int dazukoRemoveAllPaths_TS_compat12(
struct dazuko_id *dazuko)
00205 {
00206
struct option_compat12 *opt;
00207
int err = 0;
00208
00209
if (dazuko ==
NULL)
00210
return -1;
00211
00212
if (dazuko->
device < 0 || dazuko->
dev_major < 0)
00213
return -1;
00214
00215 opt = (
struct option_compat12 *)malloc(
sizeof(
struct option_compat12));
00216
if (opt ==
NULL)
00217
return -1;
00218
00219 memset(opt, 0,
sizeof(
struct option_compat12));
00220
00221 opt->command =
REMOVE_ALL_PATHS;
00222 opt->buffer_length = 0;
00223
00224
if (ioctl(dazuko->
device, _IOW(dazuko->
dev_major,
IOCTL_SET_OPTION,
void *), opt) != 0)
00225 err = -1;
00226
00227 free(opt);
00228
00229
return err;
00230
00231 }
00232
00233 int dazukoGetAccess_TS_compat12_wrapper(
struct dazuko_id *dazuko,
struct dazuko_access **acc)
00234 {
00235
struct access_compat12 acc_compat12;
00236
struct dazuko_access *temp_acc;
00237
int ret;
00238
00239
if (acc ==
NULL)
00240
return -1;
00241
00242 *acc =
NULL;
00243
00244 temp_acc = (
struct dazuko_access *)malloc(
sizeof(*temp_acc));
00245
if (temp_acc ==
NULL)
00246
return -1;
00247
00248 memset(temp_acc, 0,
sizeof(*temp_acc));
00249
00250 ret =
dazukoGetAccess_TS_compat12(dazuko, &acc_compat12);
00251
00252
if (ret == 0)
00253 {
00254 temp_acc->deny = acc_compat12.
deny;
00255 temp_acc->event = acc_compat12.
event;
00256 temp_acc->set_event = 1;
00257 temp_acc->flags = acc_compat12.
o_flags;
00258 temp_acc->set_flags = 1;
00259 temp_acc->mode = acc_compat12.
o_mode;
00260 temp_acc->set_mode = 1;
00261 temp_acc->uid = acc_compat12.
uid;
00262 temp_acc->set_uid = 1;
00263 temp_acc->pid = acc_compat12.
pid;
00264 temp_acc->set_pid = 1;
00265 temp_acc->filename = strdup(acc_compat12.
filename);
00266 temp_acc->set_filename = 1;
00267
00268 *acc = temp_acc;
00269 }
00270
else
00271 {
00272 free(temp_acc);
00273 }
00274
00275
return ret;
00276 }
00277
00278 int dazukoGetAccess_TS_compat12(
struct dazuko_id *dazuko,
struct access_compat12 *acc)
00279 {
00280
if (dazuko ==
NULL)
00281
return -1;
00282
00283
if (acc ==
NULL)
00284
return -1;
00285
00286
if (dazuko->
device < 0 || dazuko->
dev_major < 0)
00287
return -1;
00288
00289 memset(acc, 0,
sizeof(
struct access_compat12));
00290
00291
if (ioctl(dazuko->
device, _IOR(dazuko->
dev_major,
IOCTL_GET_AN_ACCESS,
struct access_compat12 *), acc) != 0)
00292
return -1;
00293
00294
return 0;
00295 }
00296
00297 int dazukoReturnAccess_TS_compat12_wrapper(
struct dazuko_id *dazuko,
struct dazuko_access **acc,
int return_access,
int free_access)
00298 {
00299
struct access_compat12 acc_compat12;
00300
int ret = 0;
00301
00302
if (acc ==
NULL)
00303
return -1;
00304
00305
if (*acc ==
NULL)
00306
return -1;
00307
00308
if (return_access)
00309 {
00310 memset(&acc_compat12, 0,
sizeof(acc_compat12));
00311
00312 acc_compat12.deny = (*acc)->deny;
00313 acc_compat12.event = (*acc)->event;
00314 acc_compat12.o_flags = (*acc)->flags;
00315 acc_compat12.o_mode = (*acc)->mode;
00316 acc_compat12.uid = (*acc)->uid;
00317 acc_compat12.pid = (*acc)->pid;
00318
if ((*acc)->filename !=
NULL)
00319 {
00320 strncpy(acc_compat12.filename, (*acc)->filename,
sizeof(acc_compat12.filename) - 1);
00321 acc_compat12.filename[
sizeof(acc_compat12.filename) - 1] = 0;
00322 }
00323
00324 ret =
dazukoReturnAccess_TS_compat12(dazuko, &acc_compat12);
00325 }
00326
00327
if (free_access && ret == 0)
00328 {
00329
if ((*acc)->filename !=
NULL)
00330 free((*acc)->filename);
00331 free(*acc);
00332 *acc =
NULL;
00333 }
00334
00335
return ret;
00336 }
00337
00338 int dazukoReturnAccess_TS_compat12(
struct dazuko_id *dazuko,
struct access_compat12 *acc)
00339 {
00340
if (dazuko ==
NULL)
00341
return -1;
00342
00343
if (acc ==
NULL)
00344
return -1;
00345
00346
if (dazuko->
device < 0 || dazuko->
dev_major < 0)
00347
return -1;
00348
00349
if (ioctl(dazuko->
device, _IOW(dazuko->
dev_major,
IOCTL_RETURN_ACCESS,
struct access_compat12 *), acc) != 0)
00350
return -1;
00351
00352
return 0;
00353 }
00354
00355 int dazukoUnregister_TS_compat12_wrapper(
struct dazuko_id **
dazuko_id)
00356 {
00357
int ret;
00358
00359
if (dazuko_id ==
NULL)
00360
return -1;
00361
00362 ret =
dazukoUnregister_TS_compat12(*dazuko_id);
00363
00364
if (ret == 0)
00365 {
00366 free(*dazuko_id);
00367 *dazuko_id =
NULL;
00368 }
00369
00370
return ret;
00371 }
00372
00373 int dazukoUnregister_TS_compat12(
struct dazuko_id *dazuko)
00374 {
00375
int error = -1;
00376
00377
if (dazuko ==
NULL)
00378
return -1;
00379
00380
if (dazuko->
device >= 0)
00381 error = close(dazuko->
device);
00382
00383 dazuko->
device = -1;
00384 dazuko->
dev_major = -1;
00385
00386
return error;
00387 }