Novell Home

Another example of file system hooks (CLIB)

From Developer Community

This program installs 3 file system hooks with NWAddFSMonitorHook(): FSHOOK_PRE_MODIFY_DIRENTRY, FSHOOK_PRE_GEN_MODIFY_DOS_INFO, FSHOOK_PRE_GEN_MODIFY_NS_INFO

Sample Code

#include <nwfshook.h>
#include <nwthread.h>
#include <stdio.h>
#include <stdlib.h>

static int main_thread_group_id;

static int modify_direntry_callback_proc( ModifyDirEntryCallBackStruct const* cbs) {
  int saved_thread_group_id = SetThreadGroupID( main_thread_group_id);
  printf( "conn = %d, ModifyDirEntryCallBackStruct.modifyBits = %x\n", cbs -> connection, cbs -> modifyBits);
  SetThreadGroupID( saved_thread_group_id);
  return 0;
}
static int modify_dos_info_callback_proc( GenericModifyDOSInfoCBStruct const* cbs) {
  int saved_thread_group_id = SetThreadGroupID( main_thread_group_id);
  printf( "conn = %d, GenericModifyDOSInfoCBStruct.modifyBits = %x\n", cbs -> connection, cbs -> modifyMask);
  SetThreadGroupID( saved_thread_group_id);
  return 0;
}
static int modify_ns_info_callback_proc( GenericModifyNSInfoCBStruct const* cbs) {
  int saved_thread_group_id = SetThreadGroupID( main_thread_group_id);
  printf( "conn = %d, GenericModifyNSInfoCBStruct.modifyBits = %x\n", cbs -> connection, cbs -> modifyMask);
  SetThreadGroupID( saved_thread_group_id);
  return 0;
}
int main( void) {
  LONG modify_direntry_callback_handle;
  LONG modify_dos_info_callback_handle;
  LONG modify_ns_info_callback_handle;
  LONG ccode;
  main_thread_group_id = GetThreadGroupID();
  ccode = NWAddFSMonitorHook( FSHOOK_PRE_MODIFY_DIRENTRY, modify_direntry_callback_proc, &modify_direntry_callback_handle);
  if ( ccode != 0) {
    printf( "NWAddFSMonitorHook failed, ccode = %u\n", ccode);
    return EXIT_FAILURE;
  }
  ccode = NWAddFSMonitorHook( FSHOOK_PRE_GEN_MODIFY_DOS_INFO, modify_dos_info_callback_proc, &modify_dos_info_callback_handle);
  if ( ccode != 0) {
    NWRemoveFSMonitorHook( FSHOOK_PRE_MODIFY_DIRENTRY, modify_direntry_callback_handle);
    printf( "NWAddFSMonitorHook failed, ccode = %u\n", ccode);
    return EXIT_FAILURE;
  }
  ccode = NWAddFSMonitorHook( FSHOOK_PRE_GEN_MODIFY_NS_INFO, modify_ns_info_callback_proc, &modify_ns_info_callback_handle);
  if ( ccode != 0) {
    NWRemoveFSMonitorHook( FSHOOK_PRE_GEN_MODIFY_DOS_INFO, modify_dos_info_callback_handle);
    NWRemoveFSMonitorHook( FSHOOK_PRE_MODIFY_DIRENTRY, modify_direntry_callback_handle);
    printf( "NWAddFSMonitorHook failed, ccode = %u\n", ccode);
    return EXIT_FAILURE;
  }
  puts( "Press a key to exit");
  getch();
  NWRemoveFSMonitorHook( FSHOOK_PRE_GEN_MODIFY_NS_INFO, modify_ns_info_callback_handle);
  NWRemoveFSMonitorHook( FSHOOK_PRE_GEN_MODIFY_DOS_INFO, modify_dos_info_callback_handle);
  NWRemoveFSMonitorHook( FSHOOK_PRE_MODIFY_DIRENTRY, modify_direntry_callback_handle);
  return EXIT_SUCCESS;
}

--Dmitry Mityugov

Novell® Making IT Work As One

© 2008 Novell, Inc. All Rights Reserved.