Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2044993
  • 博文数量: 519
  • 博客积分: 10070
  • 博客等级: 上将
  • 技术积分: 3985
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-29 14:05
个人简介

只问耕耘

文章分类

全部博文(519)

文章存档

2016年(1)

2013年(5)

2011年(46)

2010年(220)

2009年(51)

2008年(39)

2007年(141)

2006年(16)

我的朋友

分类: 数据库开发技术

2007-06-22 12:20:37

Lotus C API 创建DSAPI实现Web端超级用户访问
 
    The Domino Web Server Application Programming Interface (DSAPI) 是能够扩展Domino Web Server功能的C API。本文实现用户super可以Web端登陆任何一个数据库,用户super并不在Domino地址本里也不在数据库的ACL里。
 
一,演示
1,访问Domino地址本,
2,使用用户名super, 密码password登陆,登陆成功,Domino Console显示如下
2007-06-22 11:48:09   super logged in successful
 

二,实现

1VC++ 创建Win32 Dynamic-Link Library工程

 

2,修改工程设置

--工程->设置->C/C++->General->添加W32到预处理程序定义,如:WIN32,_DEBUG,_CONSOLE,_MBCS,W32

--工程->设置->C/C++->Code Generation->Struct member alignment->选择"1 Byte"

--工程->添加工程->文件,把notes.lib添加到工程里

3,添加代码如下:

 

//dsapi.c

/* Input and output include files */
#include
/* Notes SDK include files */
#include "global.h"
#include "osmem.h"
#include "addin.h"
#include "dsapi.h"

unsigned int FilterInit(FilterInitData* filterInitData)
{
/*
 * Description:  Filter initialization is performed when the filter
 *               shared library is dynamically loaded.
 *
 * Input:  filterInitData     dsapi specification controls the format
 *                            of data
 * Output: filterInitData     several fields are filled in
 *
 * Return: kFilterHandledEvent
 */

   /*Required*/
   filterInitData->appFilterVersion = kInterfaceVersion;

   /* Modify the following code to set the flags you want */
   filterInitData->eventFlags = kFilterAuthenticate;

   /* Set a short description for your filter */
   strcpy(filterInitData->filterDesc,
               "Superuser Authentication sample Filter");

        /* insert any global initialization code here...       */

   /* Output sent to stdout and stderr is displayed on the
    * server console, but is not written to the server log file.
    */
   printf("\nDSAPI Authentication filter initialized\n");
   return kFilterHandledEvent;
}
unsigned int TerminateFilter(unsigned int reserved)
{
   return kFilterHandledEvent;
}


/*---
*      filter notification handling
*/
unsigned int HttpFilterProc(FilterContext* context,
         unsigned int eventType, void* eventData)
{
/*
 * Description:  This routine is called for all dsapi filter events.
 *
 * Input:  reserved     currently unused (dsapi spec controls the
 *                      format of data)
 * Output: none
 *
 * Return: kFilterNotHandled for all events that we don't customize,
 *         otherwise allow our filter routine to provide a return
 *         value.
 */

   /* Include only those events we want to handle */
 FilterAuthenticate* authData;
 char string1[] = "\n user is found in the cache \n";
 char string2[] = "\nERROR: Username and password must be specified\n";
    switch (eventType) {
    case kFilterAuthenticate:
 authData=(FilterAuthenticate *)eventData;
   /* If the user is found in the cache, then we don't need to do
 * anything further.
 */
 if (!authData || authData->foundInCache) {
  //AddInLogMessageText (string1, NOERROR);
  return kFilterNotHandled;
 }
  if (authData->userName==NULL || authData->password==NULL)
  {
   AddInLogMessageText (string2, NOERROR);
   return kFilterNotHandled; 

  }
  else
  {
    if (strcmp(authData->userName,"super")==0 && strcmp(authData->password,"password" )==0)
    {  
       AddInLogMessageText ("super logged in successful", NOERROR);
     authData->authType = kAuthenticBasic;
    authData->foundInCache = TRUE;
    return kFilterHandledEvent;
    }   
    
   }
  
      return kFilterNotHandled;
   default:
      break;
   }

   return kFilterNotHandled;
}

4,添加dsapi.def文件如下:

 

LIBRARY dsapi
DESCRIPTION "Web Server API"

EXPORTS
    FilterInit      @1
    TerminateFilter @2
    HttpFilterProc  @3


5,把编译好的dsapi.dll拷贝到Domino程序目录

6,打开Domino地址本names.nsf,从Server - Servers视图, 打开server document,

From Notes UI, open the Directory database of the Lotus Domino server
   (the names.nsf database).
7. From the Server - Servers view, open this server's server document. 在Internet Protocols tab, DSAPI filter file names: 输入dsapi.dll, 保存。

8,当http服务起动的时候,dsapi.dll会被调用。

 

 

阅读(1697) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~