#include "dazuko_linux.h"#include "dazuko_core.h"Go to the source code of this file.
Defines | |
| #define | DAZUKO_DM 0 |
| #define | __wait_event_interruptible(wq, condition, ret) |
| #define | wait_event_interruptible(wq, condition) |
| #define | wait_event(wq, condition) |
| #define | DAZUKO_HOOK(syscall_func) |
| #define | DAZUKO_UNHOOK(syscall_func) |
Functions | |
| int | linux_dazuko_device_read (struct file *file, char *buffer, size_t length, loff_t *pos) |
| int | linux_dazuko_device_write (struct file *file, const char *buffer, size_t length, loff_t *pos) |
| int | linux_dazuko_device_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long param) |
| int | linux_dazuko_device_open (struct inode *inode, struct file *file) |
| int | linux_dazuko_device_release (struct inode *inode, struct file *file) |
| void | xp_init_mutex (struct xp_mutex *mutex) |
| void | xp_down (struct xp_mutex *mutex) |
| void | xp_up (struct xp_mutex *mutex) |
| void | xp_destroy_mutex (struct xp_mutex *mutex) |
| void | xp_init_rwlock (struct xp_rwlock *rwlock) |
| void | xp_write_lock (struct xp_rwlock *rwlock) |
| void | xp_write_unlock (struct xp_rwlock *rwlock) |
| void | xp_read_lock (struct xp_rwlock *rlock) |
| void | xp_read_unlock (struct xp_rwlock *rlock) |
| void | xp_destroy_rwlock (struct xp_rwlock *rwlock) |
| int | xp_init_queue (struct xp_queue *queue) |
| int | xp_wait_until_condition (struct xp_queue *queue, int(*cfunction)(void *), void *cparam, int allow_interrupt) |
| int | xp_notify (struct xp_queue *queue) |
| int | xp_destroy_queue (struct xp_queue *queue) |
| void * | xp_malloc (size_t size) |
| int | xp_free (void *ptr) |
| int | xp_copyin (const void *user_src, void *kernel_dest, size_t size) |
| int | xp_copyout (const void *kernel_src, void *user_dest, size_t size) |
| int | xp_verify_user_writable (const void *user_ptr, size_t size) |
| int | xp_verify_user_readable (const void *user_ptr, size_t size) |
| int | xp_is_absolute_path (const char *path) |
| int | xp_atomic_set (struct xp_atomic *atomic, int value) |
| int | xp_atomic_inc (struct xp_atomic *atomic) |
| int | xp_atomic_dec (struct xp_atomic *atomic) |
| int | xp_atomic_read (struct xp_atomic *atomic) |
| static int | dazuko_get_filename_dentry (struct xp_file_struct *xfs, int follow_symlinks, const char *local_filename, int user_ptr) |
| static int | dazuko_get_fd_dentry (struct xp_file_struct *xfs) |
| static char * | __d_path (struct dentry *dentry, struct dentry *root, char *buffer, int buflen) |
| static int | dazuko_get_full_filename (struct xp_file_struct *xfs) |
| static int | dazuko_fill_file_struct_cleanup (struct dazuko_file_struct *dfs) |
| int | xp_fill_file_struct (struct dazuko_file_struct *dfs) |
| static int | dazuko_file_struct_cleanup (struct dazuko_file_struct **dfs) |
| static int | check_parent (struct task_struct *parent, struct task_struct *child) |
| int | xp_id_compare (struct xp_daemon_id *id1, struct xp_daemon_id *id2, int check_related) |
| int | xp_id_free (struct xp_daemon_id *id) |
| xp_daemon_id * | xp_id_copy (struct xp_daemon_id *id) |
| int | xp_set_event_properties (struct event_properties *event_p, struct xp_daemon_id *xp_id) |
| int | xp_init_cache (unsigned long ttl) |
| static int | linux_dazuko_sys_generic (int event, const char *user_pathname, int daemon_is_allowed) |
| int | xp_sys_hook () |
| int | xp_sys_unhook () |
| int | xp_print (const char *fmt,...) |
| int __init | linux_dazuko_init (void) |
| void | linux_dazuko_exit (void) |
| module_init (linux_dazuko_init) | |
| module_exit (linux_dazuko_exit) | |
Variables | |
| void * | sys_call_table [] |
| xp_atomic | active |
| static struct dentry * | orig_root = NULL |
| static int | dev_major = -1 |
| static struct file_operations | fops |
|
|
Value: do { \ struct wait_queue __wait; \ \ __wait.task = current; \ add_wait_queue(&wq, &__wait); \ for (;;) { \ current->state = TASK_INTERRUPTIBLE; \ mb(); \ if (condition) \ break; \ if (!signal_pending(current)) { \ schedule(); \ continue; \ } \ ret = -ERESTARTSYS; \ break; \ } \ current->state = TASK_RUNNING; \ remove_wait_queue(&wq, &__wait); \ } while (0) Definition at line 99 of file dazuko_linux.c. |
|
|
Definition at line 35 of file dazuko_linux.c. Referenced by xp_sys_hook(). |
|
|
Value: do \ { \ original_sys_##syscall_func = sys_call_table[__NR_##syscall_func]; \ sys_call_table[__NR_##syscall_func] = linux_dazuko_sys_##syscall_func; \ DPRINT(("dazuko: hooked sys_" #syscall_func "\n")); \ } \ while (0) Definition at line 1602 of file dazuko_linux.c. Referenced by xp_sys_hook(). |
|
|
Value: do \ { \ if (sys_call_table[__NR_##syscall_func] != linux_dazuko_sys_##syscall_func) \ xp_print("dazuko: " #syscall_func " system call has been changed (system may be left in an unstable state!)\n"); \ sys_call_table[__NR_##syscall_func] = original_sys_##syscall_func; \ DPRINT(("dazuko: unhooked sys_" #syscall_func "\n")); \ } \ while (0) Definition at line 1723 of file dazuko_linux.c. Referenced by xp_sys_unhook(). |
|
|
Value: ({ \
int __ret = 0; \
if (!(condition)) \
__wait_event_interruptible(wq, condition, __ret);\
__ret; \
})
Definition at line 130 of file dazuko_linux.c. Referenced by xp_wait_until_condition(). |
|
|
Value: ({ \
int __ret = 0; \
if (!(condition)) \
__wait_event_interruptible(wq, condition, __ret);\
__ret; \
})
Definition at line 123 of file dazuko_linux.c. Referenced by xp_wait_until_condition(). |
|
||||||||||||||||||||
|
Definition at line 489 of file dazuko_linux.c. Referenced by dazuko_get_full_filename(). 00490 {
00491 /* Copy of d_path from linux/dcache.c but using
00492 * a given root instead of the current root. */
00493
00494 char * end = buffer+buflen;
00495 char * retval;
00496
00497 *--end = '\0';
00498 buflen--;
00499 if (dentry->d_parent != dentry && list_empty(&dentry->d_hash)) {
00500 buflen -= 10;
00501 end -= 10;
00502 memcpy(end, " (deleted)", 10);
00503 }
00504
00505 /* Get '/' right */
00506 retval = end-1;
00507 *retval = '/';
00508
00509 for (;;) {
00510 struct dentry * parent;
00511 int namelen;
00512
00513 if (dentry == root)
00514 break;
00515 dentry = dentry->d_covers;
00516 parent = dentry->d_parent;
00517 if (dentry == parent)
00518 break;
00519 namelen = dentry->d_name.len;
00520 buflen -= namelen + 1;
00521 if (buflen < 0)
00522 break;
00523 end -= namelen;
00524 memcpy(end, dentry->d_name.name, namelen);
00525 *--end = '/';
00526 retval = end;
00527 dentry = parent;
00528 }
00529 return retval;
00530 }
|
|
||||||||||||
|
Definition at line 900 of file dazuko_linux.c. References NULL. 00901 {
00902 struct task_struct *ts = child;
00903
00904 if (parent == NULL || child == NULL)
00905 return -1;
00906
00907 while (1)
00908 {
00909 if (ts == parent)
00910 return 0;
00911
00912 #ifdef TASKSTRUCT_USES_PARENT
00913 if (ts->parent == NULL)
00914 break;
00915
00916 if (ts == ts->parent)
00917 break;
00918
00919 ts = ts->parent;
00920 #else
00921 if (ts->p_pptr == NULL)
00922 break;
00923
00924 if (ts == ts->p_pptr)
00925 break;
00926
00927 ts = ts->p_pptr;
00928 #endif
00929 }
00930
00931 return -1;
00932 }
|
|
|
Definition at line 866 of file dazuko_linux.c. References dazuko_file_listnode::filename, dazuko_file_listnode::next, NULL, and xp_free(). 00867 {
00868 struct dazuko_file_listnode *cur;
00869
00870 if (dfs == NULL)
00871 return 0;
00872
00873 if (*dfs == NULL)
00874 return 0;
00875
00876 while ((*dfs)->aliases != NULL)
00877 {
00878 cur = (*dfs)->aliases;
00879 (*dfs)->aliases = cur->next;
00880
00881 if (cur->filename != NULL)
00882 xp_free(cur->filename);
00883
00884 xp_free(cur);
00885 }
00886
00887 if ((*dfs)->extra_data != NULL)
00888 xp_free((*dfs)->extra_data);
00889
00890 xp_free(*dfs);
00891
00892 *dfs = NULL;
00893
00894 return 0;
00895 }
|
|
|
Definition at line 612 of file dazuko_linux.c. References xp_file_struct::buffer, xp_file_struct::dentry, xp_file_struct::dput_dentry, dazuko_file_struct::extra_data, xp_file_struct::free_page_buffer, xp_file_struct::mntput_vfsmount, xp_file_struct::nd, NULL, and xp_file_struct::vfsmount. Referenced by xp_fill_file_struct(). 00613 {
00614 /* Delete all the flagged structures from the
00615 * given dazuko_file_struct and reset all critical
00616 * values back to 0. */
00617
00618 if (dfs->extra_data == NULL)
00619 return 0;
00620
00621 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
00622 {
00623 if (dfs->extra_data->mntput_vfsmount)
00624 {
00625 mntput(dfs->extra_data->vfsmount);
00626 dfs->extra_data->mntput_vfsmount = 0;
00627 }
00628 }
00629 #endif
00630
00631 if (dfs->extra_data->free_page_buffer)
00632 {
00633 free_page((unsigned long)dfs->extra_data->buffer);
00634 dfs->extra_data->free_page_buffer = 0;
00635 }
00636
00637 if (dfs->extra_data->dput_dentry)
00638 {
00639 dput(dfs->extra_data->dentry);
00640 dfs->extra_data->dput_dentry = 0;
00641 }
00642
00643 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
00644 {
00645 if (dfs->extra_data->path_release_nd)
00646 {
00647 path_release(&(dfs->extra_data->nd));
00648 dfs->extra_data->path_release_nd = 0;
00649 }
00650 }
00651 #endif
00652
00653 return 0;
00654 }
|
|
|
Definition at line 432 of file dazuko_linux.c. References xp_file_struct::dentry, xp_file_struct::dput_dentry, xp_file_struct::mntput_vfsmount, NULL, and xp_file_struct::vfsmount. Referenced by xp_fill_file_struct(). 00433 {
00434 if (current->files != NULL)
00435 {
00436 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
00437 {
00438 read_lock(¤t->files->file_lock);
00439 }
00440 #endif
00441
00442 if (current->files->fd != NULL)
00443 {
00444 if (current->files->fd[xfs->fd] != NULL)
00445 {
00446 if (current->files->fd[xfs->fd]->f_dentry != NULL)
00447 {
00448 xfs->dentry = dget(current->files->fd[xfs->fd]->f_dentry);
00449 xfs->dput_dentry = 1;
00450
00451 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
00452 {
00453 if (current->files->fd[xfs->fd]->f_vfsmnt != NULL)
00454 {
00455 xfs->vfsmount = mntget(current->files->fd[xfs->fd]->f_vfsmnt);
00456 xfs->mntput_vfsmount = 1;
00457 }
00458 else
00459 {
00460 dput(xfs->dentry);
00461 xfs->dentry = NULL;
00462 xfs->dput_dentry = 0;
00463 }
00464 }
00465 #endif
00466 }
00467 }
00468 }
00469
00470 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
00471 {
00472 read_unlock(¤t->files->file_lock);
00473 }
00474 #endif
00475 }
00476
00477 /* check if we got the dentry */
00478 if (xfs->dentry == NULL)
00479 return 0;
00480
00481 /* check if this file has no inode */
00482 if (xfs->dentry->d_inode == NULL)
00483 return 0;
00484
00485 return 1;
00486 }
|
|
||||||||||||||||||||
|
Definition at line 333 of file dazuko_linux.c. References dazuko_bzero(), dazuko_get_filename_length(), xp_file_struct::dentry, xp_file_struct::dput_dentry, xp_file_struct::nd, and NULL. Referenced by xp_fill_file_struct(). 00334 {
00335 /* We get the appropriate structures in order
00336 * to acquire the inode and store them in the
00337 * dazuko_file_struct structure. */
00338
00339 const char *filename = NULL;
00340 int putname_filename = 0;
00341 int filename_length = 0;
00342 int rc = 0;
00343
00344 /* make sure we really need to get the filename */
00345 if (user_ptr)
00346 {
00347 /* grab filename from filename cache */
00348 filename = (char *)getname(local_filename);
00349
00350 /* make sure it is a valid name */
00351 if (IS_ERR(filename))
00352 {
00353 filename = NULL;
00354 return 0;
00355 }
00356
00357 /* the name will need to be put back */
00358 putname_filename = 1;
00359 }
00360 else
00361 {
00362 filename = local_filename;
00363 }
00364
00365 filename_length = dazuko_get_filename_length(filename);
00366
00367 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
00368 {
00369 dazuko_bzero(&(xfs->nd), sizeof(struct nameidata));
00370
00371 /* initialize nameidata structure for finding file data */
00372 if (!path_init(filename, (follow_symlinks ? LOOKUP_FOLLOW : 0) | LOOKUP_POSITIVE, &(xfs->nd)))
00373 goto dentry_exit;
00374
00375 if (!xfs->path_release_nd)
00376 {
00377 /* find file data and fill it in nameidata structure */
00378 if (path_walk(filename, &(xfs->nd))) /* !=0 -> error */
00379 goto dentry_exit;
00380
00381 /* the nameidata will need to be released */
00382 xfs->path_release_nd = 1;
00383 }
00384
00385 /* get a local copy of the dentry to make kernel version
00386 * compatibility code eaiser to read */
00387
00388 /* make sure we don't already have a dentry */
00389 if (!xfs->dput_dentry)
00390 {
00391 xfs->dentry = dget(xfs->nd.dentry);
00392
00393 /* the dentry will need to be put back */
00394 xfs->dput_dentry = 1;
00395 }
00396 }
00397 #else
00398 {
00399 if (!xfs->dput_dentry)
00400 {
00401 xfs->dentry = lookup_dentry(filename, NULL, (follow_symlinks ? LOOKUP_FOLLOW : 0));
00402 if (IS_ERR(xfs->dentry))
00403 {
00404 xfs->dentry = NULL;
00405 goto dentry_exit;
00406 }
00407
00408 /* the dentry will need to be put back */
00409 xfs->dput_dentry = 1;
00410 }
00411 }
00412 #endif
00413
00414 /* check if this file has no inode */
00415 if (xfs->dentry->d_inode == NULL)
00416 {
00417 goto dentry_exit;
00418 }
00419 else
00420 {
00421 /* if we made it this far, we got the inode */
00422 rc = 1;
00423 }
00424
00425 dentry_exit:
00426 if (putname_filename)
00427 putname(filename);
00428
00429 return rc;
00430 }
|
|
|
Definition at line 533 of file dazuko_linux.c. References __d_path(), xp_file_struct::buffer, dazuko_get_filename_length(), xp_file_struct::dentry, xp_file_struct::free_full_filename, xp_file_struct::free_page_buffer, xp_file_struct::full_filename, xp_file_struct::full_filename_length, xp_file_struct::mntput_vfsmount, xp_file_struct::nd, NULL, orig_root, orig_rootmnt, xp_file_struct::vfsmount, and xp_malloc(). Referenced by xp_fill_file_struct(). 00534 {
00535 /* Get the filename with the full path appended
00536 * to the beginning. */
00537
00538 char *temp;
00539 struct dentry *root;
00540
00541 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
00542 struct vfsmount *rootmnt;
00543 #endif
00544
00545 /* check if we need to allocate a buffer */
00546 if (!xfs->free_page_buffer)
00547 {
00548 /* get pre-requisites for d_path function */
00549 xfs->buffer = (char *)__get_free_page(GFP_USER);
00550
00551 /* the buffer will need to be freed */
00552 xfs->free_page_buffer = 1;
00553 }
00554
00555 root = dget(orig_root);
00556
00557 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
00558 {
00559 /* make sure we don't already have a vfsmount */
00560 if (!xfs->mntput_vfsmount)
00561 {
00562 xfs->vfsmount = mntget(xfs->nd.mnt);
00563
00564 /* the vfsmount will need to be put back */
00565 xfs->mntput_vfsmount = 1;
00566 }
00567
00568 /* build new filename with path included, using temp */
00569
00570 rootmnt = mntget(orig_rootmnt);
00571
00572 spin_lock(&dcache_lock);
00573 temp = __d_path(xfs->dentry, xfs->vfsmount, root, rootmnt, xfs->buffer, PAGE_SIZE);
00574 spin_unlock(&dcache_lock);
00575
00576 mntput(rootmnt);
00577 }
00578 #else
00579 {
00580 /* build new filename with path included, using temp */
00581
00582 temp = __d_path(xfs->dentry, root, xfs->buffer, PAGE_SIZE);
00583 }
00584 #endif
00585
00586 dput(root);
00587
00588 /* make sure we really got a new filename */
00589 if (temp == NULL)
00590 return 0;
00591
00592 /* make sure we don't already have a full_filename */
00593 if (!xfs->free_full_filename)
00594 {
00595 xfs->full_filename_length = dazuko_get_filename_length(temp);
00596
00597 xfs->full_filename = (char *)xp_malloc(xfs->full_filename_length + 1);
00598 if (!xfs->full_filename)
00599 return 0;
00600
00601 /* the char array will need to be freed */
00602 xfs->free_full_filename = 1;
00603
00604 memcpy(xfs->full_filename, temp, xfs->full_filename_length + 1);
00605 }
00606
00607 /* we have a filename with the full path */
00608
00609 return 1;
00610 }
|
|
||||||||||||||||||||
|
|
|
||||||||||||
|
|
|
||||||||||||||||||||
|
Definition at line 1137 of file dazuko_linux26.c. 01138 {
01139 /* Reading from the dazuko device simply
01140 * returns the device number. This is to
01141 * help out the daemon. */
01142
01143 char tmp[20];
01144 size_t dev_major_len;
01145
01146 DPRINT(("dazuko: linux_dazuko_device_read() [%d]\n", current->pid));
01147
01148 if (*pos != 0)
01149 return 0;
01150
01151 if (dev_major < 0)
01152 return XP_ERROR_NODEVICE;
01153
01154 /* print dev_major to a string
01155 * and get length (with terminator) */
01156 dazuko_bzero(tmp, sizeof(tmp));
01157
01158 dev_major_len = dazuko_snprintf(tmp, sizeof(tmp), "%d", dev_major) + 1;
01159
01160 if (tmp[sizeof(tmp)-1] != 0)
01161 {
01162 xp_print("dazuko: failing device_read, device number overflow for dameon %d (dev_major=%d)\n", current->pid, dev_major);
01163 return XP_ERROR_FAULT;
01164 }
01165
01166 if (length < dev_major_len)
01167 return XP_ERROR_INVALID;
01168
01169 /* copy dev_major string to userspace */
01170 if (xp_copyout(tmp, buffer, dev_major_len) != 0)
01171 return XP_ERROR_FAULT;
01172
01173 *pos += dev_major_len;
01174
01175 return dev_major_len;
01176 }
|
|
||||||||||||
|
|
|
||||||||||||||||||||
|
Definition at line 1178 of file dazuko_linux26.c. 01179 {
01180 struct xp_daemon_id xp_id;
01181 char tmpbuffer[32];
01182 int size;
01183
01184 size = length;
01185 if (length >= sizeof(tmpbuffer))
01186 size = sizeof(tmpbuffer) -1;
01187
01188 /* copy request pointer string to kernelspace */
01189 if (xp_copyin(buffer, tmpbuffer, size) != 0)
01190 return XP_ERROR_FAULT;
01191
01192 tmpbuffer[size] = 0;
01193
01194 xp_id.pid = current->pid;
01195 xp_id.file = file;
01196 xp_id.current_p = current;
01197 xp_id.files = current->files;
01198
01199 if (dazuko_handle_user_request(tmpbuffer, &xp_id) == 0)
01200 return size;
01201
01202 return XP_ERROR_INTERRUPT;
01203 }
|
|
|
Definition at line 1964 of file dazuko_linux.c. References dazuko_exit(). 01966 {
01967 dazuko_exit();
01968 }
|
|
|
Definition at line 1956 of file dazuko_linux.c. References dazuko_init(). 01957 {
01958 return dazuko_init();
01959 }
|
|
||||||||||||||||
|
Definition at line 1500 of file dazuko_linux.c. References dazuko_bzero(), dazuko_check_access(), dazuko_file_struct_cleanup(), dazuko_process_access(), xp_daemon_id::file, NULL, xp_daemon_id::pid, xp_free(), and xp_malloc(). 01501 {
01502 struct dazuko_file_struct *dfs = NULL;
01503 int error = 0;
01504 int check_error = 0;
01505 struct event_properties event_p;
01506 struct xp_daemon_id xp_id;
01507 struct slot_list *sl = NULL;
01508
01509 xp_id.pid = current->pid;
01510 xp_id.file = NULL;
01511 xp_id.current_p = current;
01512 xp_id.files = current->files;
01513
01514 check_error = dazuko_check_access(event, daemon_is_allowed, &xp_id, &sl);
01515
01516 if (!check_error)
01517 {
01518 dfs = (struct dazuko_file_struct *)xp_malloc(sizeof(struct dazuko_file_struct));
01519 if (dfs)
01520 {
01521 dazuko_bzero(dfs, sizeof(struct dazuko_file_struct));
01522
01523 dfs->extra_data = (struct xp_file_struct *)xp_malloc(sizeof(struct xp_file_struct));
01524 if (dfs->extra_data != NULL)
01525 {
01526 dazuko_bzero(dfs->extra_data, sizeof(struct xp_file_struct));
01527
01528 dfs->extra_data->user_filename = user_pathname;
01529
01530 dazuko_bzero(&event_p, sizeof(event_p));
01531 event_p.pid = current->pid;
01532 event_p.set_pid = 1;
01533 event_p.uid = current->uid;
01534 event_p.set_uid = 1;
01535
01536 error = dazuko_process_access(event, dfs, &event_p, sl);
01537
01538 dazuko_file_struct_cleanup(&dfs);
01539 }
01540 else
01541 {
01542 xp_free(dfs);
01543 dfs = NULL;
01544 }
01545 }
01546 }
01547
01548 return error;
01549 }
|
|
|
|
|
|
|
|
|
Definition at line 314 of file dazuko_linux.c. References xp_atomic::atomic. 00315 {
00316 #ifdef MODULE
00317 if (atomic == &active)
00318 MOD_DEC_USE_COUNT;
00319 #endif
00320
00321 atomic_dec(&(atomic->atomic));
00322 return 0;
00323 }
|
|
|
Definition at line 303 of file dazuko_linux.c. References xp_atomic::atomic. 00304 {
00305 #ifdef MODULE
00306 if (atomic == &active)
00307 MOD_INC_USE_COUNT;
00308 #endif
00309
00310 atomic_inc(&(atomic->atomic));
00311 return 0;
00312 }
|
|
|
Definition at line 325 of file dazuko_linux.c. References xp_atomic::atomic. 00326 {
00327 return atomic_read(&(atomic->atomic));
00328 }
|
|
||||||||||||
|
Definition at line 297 of file dazuko_linux.c. References xp_atomic::atomic. 00298 {
00299 atomic_set(&(atomic->atomic), value);
00300 return 0;
00301 }
|
|
||||||||||||||||
|
Definition at line 258 of file dazuko_linux.c. 00259 {
00260 return copy_from_user(kernel_dest, user_src, size);
00261 }
|
|
||||||||||||||||
|
Definition at line 263 of file dazuko_linux.c. 00264 {
00265 return copy_to_user(user_dest, kernel_src, size);
00266 }
|
|
|
Definition at line 163 of file dazuko_linux.c. 00164 {
00165 }
|
|
|
Definition at line 239 of file dazuko_linux.c. 00240 {
00241 return 0;
00242 }
|
|
|
Definition at line 199 of file dazuko_linux.c. 00200 {
00201 }
|
|
|
Definition at line 153 of file dazuko_linux.c. References xp_mutex::mutex. 00154 {
00155 down(&(mutex->mutex));
00156 }
|
|
|
Definition at line 656 of file dazuko_linux.c. References dazuko_file_struct::aliases, dazuko_bzero(), DAZUKO_DIRECTORY, dazuko_fill_file_struct_cleanup(), dazuko_get_fd_dentry(), dazuko_get_filename_dentry(), dazuko_get_filename_length(), dazuko_get_full_filename(), DAZUKO_LINK, DAZUKO_REGULAR, xp_file_struct::dentry, file_properties::device_type, dazuko_file_struct::extra_data, dazuko_file_struct::file_p, xp_file_struct::free_full_filename, xp_file_struct::full_filename, xp_file_struct::full_filename_length, file_properties::gid, file_properties::mode, dazuko_file_listnode::next, NULL, file_properties::set_device_type, file_properties::set_gid, file_properties::set_mode, file_properties::set_size, file_properties::set_type, file_properties::set_uid, file_properties::size, file_properties::type, file_properties::uid, xp_file_struct::user_filename, xp_free(), and xp_malloc(). 00657 {
00658 struct dazuko_file_listnode *listnode;
00659 int follow_symlinks = 0;
00660 int error = -1;
00661 int loopcount = 0;
00662 char *freeparentpath = NULL;
00663 char *parentpath = NULL;
00664 char *rawfilename = NULL;
00665 int i;
00666
00667 if (dfs == NULL)
00668 return error;
00669
00670 /* check if filenames have already been filled in */
00671 if (dfs->aliases != NULL)
00672 return 0;
00673
00674 if (dfs->extra_data == NULL)
00675 return error;
00676
00677 /* make sure we can get an inode */
00678 while (1)
00679 {
00680 loopcount++;
00681
00682 if (dfs->extra_data->user_filename != NULL)
00683 {
00684 if (!dazuko_get_filename_dentry(dfs->extra_data, follow_symlinks, dfs->extra_data->user_filename, 1))
00685 {
00686 /* we will try to build a "fake" name from the parent directory */
00687
00688 freeparentpath = getname(dfs->extra_data->user_filename);
00689 /* make sure it is a valid name */
00690 if (IS_ERR(freeparentpath))
00691 {
00692 freeparentpath = NULL;
00693 break;
00694 }
00695
00696 parentpath = freeparentpath;
00697
00698 i = dazuko_get_filename_length(parentpath);
00699 if (i == 0)
00700 break;
00701
00702 while (i > 0)
00703 {
00704 if (parentpath[i] == '/')
00705 {
00706 rawfilename = parentpath + i + 1;
00707 parentpath[i] = 0;
00708 break;
00709 }
00710
00711 i--;
00712 }
00713 if (i == 0)
00714 {
00715 if (parentpath[i] == '/')
00716 {
00717 rawfilename = parentpath + 1;
00718 parentpath = "/";
00719 }
00720 else
00721 {
00722 rawfilename = parentpath;
00723 parentpath = ".";
00724 }
00725 }
00726
00727 if (!dazuko_get_filename_dentry(dfs->extra_data, follow_symlinks, parentpath, 0))
00728 {
00729 putname(freeparentpath);
00730 freeparentpath = NULL;
00731 break;
00732 }
00733 }
00734 }
00735 else
00736 {
00737 if (!dazuko_get_fd_dentry(dfs->extra_data))
00738 {
00739 break;
00740 }
00741 else
00742 {
00743 /* make sure we don't loop a 2nd time */
00744 loopcount++;
00745 }
00746 }
00747
00748 /* make sure we can get the full path */
00749 if (!dazuko_get_full_filename(dfs->extra_data))
00750 break;
00751
00752 if (freeparentpath != NULL)
00753 {
00754 /* we are working with a "fake" name */
00755
00756 parentpath = dfs->extra_data->full_filename;
00757 i = dazuko_get_filename_length(rawfilename);
00758
00759 dfs->extra_data->full_filename = (char *)xp_malloc(dfs->extra_data->full_filename_length + 1 + i + 1);
00760 if (dfs->extra_data->full_filename == NULL)
00761 {
00762 /* put things back how they were and get out */
00763 dfs->extra_data->full_filename = parentpath;
00764 break;
00765 }
00766
00767 /* copy parent path */
00768 memcpy(dfs->extra_data->full_filename, parentpath, dfs->extra_data->full_filename_length);
00769
00770 /* possibly copy "/" */
00771 if (dfs->extra_data->full_filename[dfs->extra_data->full_filename_length - 1] != '/')
00772 {
00773 dfs->extra_data->full_filename[dfs->extra_data->full_filename_length] = '/';
00774 dfs->extra_data->full_filename_length++;
00775 }
00776
00777 /* copy filename */
00778 memcpy(dfs->extra_data->full_filename + dfs->extra_data->full_filename_length, rawfilename, i + 1);
00779 dfs->extra_data->full_filename_length += i;
00780
00781 /* free allocated parent path */
00782 xp_free(parentpath);
00783 }
00784 else
00785 {
00786 dfs->file_p.size = dfs->extra_data->dentry->d_inode->i_size;
00787 dfs->file_p.set_size = 1;
00788 dfs->file_p.uid = dfs->extra_data->dentry->d_inode->i_uid;
00789 dfs->file_p.set_uid = 1;
00790 dfs->file_p.gid = dfs->extra_data->dentry->d_inode->i_gid;
00791 dfs->file_p.set_gid = 1;
00792 dfs->file_p.mode = dfs->extra_data->dentry->d_inode->i_mode;
00793 dfs->file_p.set_mode = 1;
00794 dfs->file_p.device_type = dfs->extra_data->dentry->d_inode->i_dev;
00795 dfs->file_p.set_device_type = 1;
00796 }
00797
00798 if (S_ISREG(dfs->extra_data->dentry->d_inode->i_mode))
00799 {
00800 dfs->file_p.type = DAZUKO_REGULAR;
00801 dfs->file_p.set_type = 1;
00802 }
00803 else if (S_ISLNK(dfs->extra_data->dentry->d_inode->i_mode))
00804 {
00805 dfs->file_p.type = DAZUKO_LINK;
00806 dfs->file_p.set_type = 1;
00807 }
00808 else if (S_ISDIR(dfs->extra_data->dentry->d_inode->i_mode))
00809 {
00810 dfs->file_p.type = DAZUKO_DIRECTORY;
00811 dfs->file_p.set_type = 1;
00812 }
00813
00814 listnode = (struct dazuko_file_listnode *)xp_malloc(sizeof(struct dazuko_file_listnode));
00815 if (listnode == NULL)
00816 break;
00817
00818 dazuko_bzero(listnode, sizeof(struct dazuko_file_listnode));
00819
00820 listnode->filename = dfs->extra_data->full_filename;
00821 listnode->filename_length = dfs->extra_data->full_filename_length; /* the string length */
00822
00823 dfs->extra_data->free_full_filename = 0;
00824 dfs->extra_data->full_filename = NULL;
00825 dfs->extra_data->full_filename_length = 0;
00826
00827 if (dfs->aliases == NULL)
00828 {
00829 listnode->next = dfs->aliases;
00830 dfs->aliases = listnode;
00831 }
00832 else
00833 {
00834 listnode->next = dfs->aliases->next;
00835 dfs->aliases->next = listnode;
00836 }
00837
00838 /* we successfully got the file information */
00839 error = 0;
00840
00841 if (!follow_symlinks && dfs->file_p.set_type && dfs->file_p.type == DAZUKO_LINK && loopcount < 2)
00842 {
00843 /* this is a link, we will grab the real path now */
00844
00845 follow_symlinks = 1;
00846
00847 /* clean up because we are going to fill it again */
00848 dazuko_fill_file_struct_cleanup(dfs);
00849 }
00850 else
00851 {
00852 /* we've grabbed the real path (or we already have 2 paths), so we are done */
00853
00854 break;
00855 }
00856 }
00857
00858 if (freeparentpath != NULL)
00859 putname(freeparentpath);
00860
00861 dazuko_fill_file_struct_cleanup(dfs);
00862
00863 return error;
00864 }
|
|
|
Definition at line 252 of file dazuko_linux.c. 00253 {
00254 kfree(ptr);
00255 return 0;
00256 }
|
|
||||||||||||||||
|
Definition at line 934 of file dazuko_linux.c. References check_parent, DAZUKO_CHILD, DAZUKO_DIFFERENT, DAZUKO_SAME, DAZUKO_SUSPICIOUS, xp_daemon_id::file, NULL, and xp_daemon_id::pid. 00935 {
00936 if (id1 == NULL || id2 == NULL)
00937 return DAZUKO_DIFFERENT;
00938
00939 /* if file's are available and they match,
00940 * then we say that the id's match
00941 * ("file" is only used to unregister daemons and
00942 * here we allow other processes to do this)
00943 * Note: this is a Linux-only "hack" */
00944 if (id1->file != NULL && id1->file == id2->file)
00945 return DAZUKO_SAME;
00946
00947 if (id1->pid == id2->pid && id1->current_p == id2->current_p && id1->files == id2->files)
00948 return DAZUKO_SAME;
00949
00950 if (check_related)
00951 {
00952 if (check_parent(id1->current_p, id2->current_p) == 0)
00953 {
00954 return DAZUKO_CHILD;
00955 }
00956 else if (id1->pid == id2->pid || id1->current_p == id2->current_p || id1->files == id2->files)
00957 {
00958 return DAZUKO_SUSPICIOUS;
00959 }
00960 }
00961
00962 return DAZUKO_DIFFERENT;
00963 }
|
|
|
Definition at line 972 of file dazuko_linux.c. References xp_daemon_id::file, NULL, xp_daemon_id::pid, and xp_malloc(). 00973 {
00974 struct xp_daemon_id *ptr;
00975
00976 if (id == NULL)
00977 return NULL;
00978
00979 ptr = (struct xp_daemon_id *)xp_malloc(sizeof(struct xp_daemon_id));
00980
00981 if (ptr != NULL)
00982 {
00983 ptr->pid = id->pid;
00984 ptr->file = id->file;
00985 ptr->current_p = id->current_p;
00986 ptr->files = id->files;
00987 }
00988
00989 return ptr;
00990 }
|
|
|
Definition at line 965 of file dazuko_linux.c. References xp_free(). 00966 {
00967 xp_free(id);
00968
00969 return 0;
00970 }
|
|
|
Definition at line 1006 of file dazuko_linux.c. 01007 {
01008 return -1;
01009 }
|
|
|
Definition at line 144 of file dazuko_linux.c. References xp_mutex::mutex. 00145 {
00146 #ifdef init_MUTEX
00147 init_MUTEX(&(mutex->mutex));
00148 #else
00149 sema_init(&(mutex->mutex), 1);
00150 #endif
00151 }
|
|
|
Definition at line 206 of file dazuko_linux.c. References NULL, and xp_queue::queue. 00207 {
00208 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
00209 init_waitqueue_head(&(queue->queue));
00210 #else
00211 queue = NULL;
00212 #endif
00213
00214 return 0;
00215 }
|
|
|
Definition at line 170 of file dazuko_linux.c. References xp_rwlock::rwlock. 00171 {
00172 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
00173 rwlock_init(&(rwlock->rwlock));
00174 #else
00175 rwlock->rwlock = RW_LOCK_UNLOCKED;
00176 #endif
00177 }
|
|
|
Definition at line 289 of file dazuko_linux.c. 00290 {
00291 return (path[0] == '/');
00292 }
|
|
|
Definition at line 247 of file dazuko_linux.c. 00248 {
00249 return kmalloc(size, GFP_KERNEL);
00250 }
|
|
|
Definition at line 233 of file dazuko_linux.c. References xp_queue::queue. 00234 {
00235 wake_up(&(queue->queue));
00236 return 0;
00237 }
|
|
||||||||||||
|
Definition at line 1791 of file dazuko_linux.c. References dazuko_vsnprintf(), xp_free(), and xp_malloc(). 01792 {
01793 va_list args;
01794 char *p;
01795 size_t size = 1024;
01796
01797 p = (char *)xp_malloc(size);
01798 if (!p)
01799 return -1;
01800
01801 va_start(args, fmt);
01802 dazuko_vsnprintf(p, size-1, fmt, args);
01803 va_end(args);
01804
01805 p[size-1] = 0;
01806
01807 printk(p);
01808
01809 xp_free(p);
01810
01811 return 0;
01812 }
|
|
|
Definition at line 189 of file dazuko_linux.c. References xp_rwlock::rwlock. 00190 {
00191 read_lock(&(rlock->rwlock));
00192 }
|
|
|
Definition at line 194 of file dazuko_linux.c. References xp_rwlock::rwlock. 00195 {
00196 read_unlock(&(rlock->rwlock));
00197 }
|
|
||||||||||||
|
Definition at line 995 of file dazuko_linux.c. References xp_daemon_id::pid.
|
|
|
Definition at line 1610 of file dazuko_linux.c. References DAZUKO_DM, DAZUKO_HOOK, dev_major, DEVICE_NAME, fops, NULL, orig_root, orig_rootmnt, sys_call_table, and xp_print(). 01611 {
01612 /* Called insmod when inserting the module. */
01613
01614 #ifdef HIDDEN_SCT
01615 sys_call_table = dazuko_get_sct();
01616 if (sys_call_table == NULL)
01617 {
01618 xp_print("dazuko: panic (sys_call_table == NULL)\n");
01619 return -1;
01620 }
01621 #endif
01622
01623 /* Make sure we have a valid task_struct. */
01624
01625 if (current == NULL)
01626 {
01627 xp_print("dazuko: panic (current == NULL)\n");
01628 return -1;
01629 }
01630 if (current->fs == NULL)
01631 {
01632 xp_print("dazuko: panic (current->fs == NULL)\n");
01633 return -1;
01634 }
01635 if (current->fs->root == NULL)
01636 {
01637 xp_print("dazuko: panic (current->fs->root == NULL)\n");
01638 return -1;
01639 }
01640 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
01641 {
01642 if (current->fs->rootmnt == NULL)
01643 {
01644 xp_print("dazuko: panic (current->fs->rootmnt == NULL)\n");
01645 return -1;
01646 }
01647 }
01648 #endif
01649
01650 /* register the dazuko device */
01651 #ifdef DEVFS_SUPPORT
01652 dev_major = devfs_register_chrdev(0, DEVICE_NAME, &fops);
01653 devfs_register(NULL, DEVICE_NAME, DEVFS_FL_DEFAULT,
01654 dev_major, 0, S_IFCHR | S_IRUSR | S_IWUSR,
01655 &fops, NULL);
01656 #else
01657 dev_major = register_chrdev(DAZUKO_DM, DEVICE_NAME, &fops);
01658 #endif
01659 if (dev_major < 0)
01660 {
01661 xp_print("dazuko: unable to register device chrdev, err=%d\n", dev_major);
01662 return dev_major;
01663 }
01664
01665 /* Grab the current root. This is assumed to be the real.
01666 * If it is not the real root, we could have problems
01667 * looking up filenames. */
01668
01669 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
01670 {
01671 read_lock(¤t->fs->lock);
01672 orig_rootmnt = current->fs->rootmnt;
01673 }
01674 #endif
01675
01676 orig_root = current->fs->root;
01677
01678 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
01679 read_unlock(¤t->fs->lock);
01680 #endif
01681
01682 /* do a file syncronization on all devices (IMPORTANT!) and replace system calls */
01683 #ifdef __SMP__
01684 lock_kernel();
01685 #endif
01686
01687 fsync_dev(0);
01688
01689 #if defined(ON_OPEN_SUPPORT)
01690 DAZUKO_HOOK(open);
01691 DAZUKO_HOOK(dup);
01692 #endif
01693 #if defined(ON_OPEN_SUPPORT) || defined(ON_CLOSE_SUPPORT) || defined(ON_CLOSE_MODIFIED_SUPPORT)
01694 DAZUKO_HOOK(dup2);
01695 #endif
01696
01697 #if defined(ON_CLOSE_SUPPORT) || defined(ON_CLOSE_MODIFIED_SUPPORT)
01698 DAZUKO_HOOK(close);
01699 #endif
01700
01701 #ifdef ON_EXEC_SUPPORT
01702 DAZUKO_HOOK(execve);
01703 #endif
01704
01705 #ifdef ON_UNLINK_SUPPORT
01706 DAZUKO_HOOK(unlink);
01707 #endif
01708
01709 #ifdef ON_RMDIR_SUPPORT
01710 DAZUKO_HOOK(rmdir);
01711 #endif
01712
01713 #ifdef __SMP__
01714 unlock_kernel();
01715 #endif
01716 /* done syncing and replacing */
01717
01718 /* initialization complete */
01719
01720 return 0;
01721 }
|
|
|
Definition at line 1732 of file dazuko_linux.c. References DAZUKO_UNHOOK, dev_major, DEVICE_NAME, NULL, and xp_print(). 01733 {
01734 /* Called by rmmod when removing the module. */
01735
01736 int error;
01737
01738 /* do a file syncronization on all devices (IMPORTANT!) and replace system calls */
01739 #ifdef __SMP__
01740 lock_kernel();
01741 #endif
01742
01743 fsync_dev(0);
01744
01745 #if defined(ON_OPEN_SUPPORT)
01746 DAZUKO_UNHOOK(open);
01747 DAZUKO_UNHOOK(dup);
01748 #endif
01749 #if defined(ON_OPEN_SUPPORT) || defined(ON_CLOSE_SUPPORT) || defined(ON_CLOSE_MODIFIED_SUPPORT)
01750 DAZUKO_UNHOOK(dup2);
01751 #endif
01752
01753 #if defined(ON_CLOSE_SUPPORT) || defined(ON_CLOSE_MODIFIED_SUPPORT)
01754 DAZUKO_UNHOOK(close);
01755 #endif
01756
01757 #ifdef ON_EXEC_SUPPORT
01758 DAZUKO_UNHOOK(execve);
01759 #endif
01760
01761 #ifdef ON_UNLINK_SUPPORT
01762 DAZUKO_UNHOOK(unlink);
01763 #endif
01764
01765 #ifdef ON_RMDIR_SUPPORT
01766 DAZUKO_UNHOOK(rmdir);
01767 #endif
01768
01769 #ifdef __SMP__
01770 unlock_kernel();
01771 #endif
01772 /* done syncing and replacing */
01773
01774 #ifdef DEVFS_SUPPORT
01775 error = devfs_unregister_chrdev(dev_major, DEVICE_NAME);
01776 devfs_unregister(devfs_find_handle(NULL, DEVICE_NAME, dev_major, 0, DEVFS_SPECIAL_CHR, 0));
01777 #else
01778 error = unregister_chrdev(dev_major, DEVICE_NAME);
01779 #endif
01780 if (error < 0)
01781 {
01782 xp_print("dazuko: error unregistering chrdev, err=%d\n", error);
01783 }
01784
01785 return 0;
01786 }
|
|
|
Definition at line 158 of file dazuko_linux.c. References xp_mutex::mutex. 00159 {
00160 up(&(mutex->mutex));
00161 }
|
|
||||||||||||
|
Definition at line 277 of file dazuko_linux.c. 00278 {
00279 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
00280 return verify_area(VERIFY_READ, user_ptr, size);
00281 #else
00282 return 0;
00283 #endif
00284 }
|
|
||||||||||||
|
Definition at line 268 of file dazuko_linux.c. 00269 {
00270 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
00271 return verify_area(VERIFY_WRITE, user_ptr, size);
00272 #else
00273 return 0;
00274 #endif
00275 }
|
|
||||||||||||||||||||
|
Definition at line 217 of file dazuko_linux.c. References xp_queue::queue, wait_event, and wait_event_interruptible. 00218 {
00219 /* wait until cfunction(cparam) != 0 (condition is true) */
00220
00221 if (allow_interrupt)
00222 {
00223 return wait_event_interruptible(queue->queue, cfunction(cparam) != 0);
00224 }
00225 else
00226 {
00227 wait_event(queue->queue, cfunction(cparam) != 0);
00228 }
00229
00230 return 0;
00231 }
|
|
|
Definition at line 179 of file dazuko_linux.c. References xp_rwlock::rwlock. 00180 {
00181 write_lock(&(rwlock->rwlock));
00182 }
|
|
|
Definition at line 184 of file dazuko_linux.c. References xp_rwlock::rwlock. 00185 {
00186 write_unlock(&(rwlock->rwlock));
00187 }
|
|
|
|
|
|
Definition at line 63 of file dazuko_linux.c. |
|
|
Initial value: {
read: linux_dazuko_device_read,
write: linux_dazuko_device_write,
ioctl: linux_dazuko_device_ioctl,
open: linux_dazuko_device_open,
release: linux_dazuko_device_release,
}
Definition at line 85 of file dazuko_linux.c. |
|
|
Definition at line 62 of file dazuko_linux.c. Referenced by dazuko_get_full_filename(), and xp_sys_hook(). |
|
|
Referenced by xp_sys_hook(). |
1.4.2