0677 nwnss: wrap NDP shared idbroker providers
This commit is contained in:
@@ -213,7 +213,11 @@ add_library(nwnss SHARED
|
||||
library/misc/dbginit.c
|
||||
library/misc/nssErrorTable.c
|
||||
library/debug/otherErrorTables.c
|
||||
comn/common/ndpComnShared.c
|
||||
comn/common/ndpGuidsShared.c
|
||||
comn/common/ndpMessageHandlerShared.c
|
||||
comn/common/ndpIdBrokerShared.c
|
||||
comn/common/ndpNcpUserlandBoundary.c
|
||||
library/misc/sysimp.c
|
||||
comn/main/comnCmdline.c
|
||||
comn/authsys/authorize.c
|
||||
|
||||
18
src/nwnss/comn/common/ndpComnShared.c
Normal file
18
src/nwnss/comn/common/ndpComnShared.c
Normal file
@@ -0,0 +1,18 @@
|
||||
/****************************************************************************
|
||||
| MARS-NWE libnwnss import wrapper for NSS shared NDP common source.
|
||||
+-------------------------------------------------------------------------*/
|
||||
|
||||
#include <semaphore.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include <ndp_app.h>
|
||||
|
||||
ndpContext_t *ndpContext = NULL;
|
||||
int ndpSyslogFacility = LOG_USER;
|
||||
int ndp_debug = 0;
|
||||
long ndpMsgQueueID = -1;
|
||||
long ndpmsg_multipleID = 0;
|
||||
int daemonize = 0;
|
||||
sem_t ndpmsg_multipleIDsem;
|
||||
|
||||
#include <sharedsrc/ndp_comn.c.h>
|
||||
5
src/nwnss/comn/common/ndpGuidsShared.c
Normal file
5
src/nwnss/comn/common/ndpGuidsShared.c
Normal file
@@ -0,0 +1,5 @@
|
||||
/****************************************************************************
|
||||
| MARS-NWE libnwnss import wrapper for NSS shared NDP GUID source.
|
||||
+-------------------------------------------------------------------------*/
|
||||
|
||||
#include <sharedsrc/ndp_guids.c.h>
|
||||
@@ -2,4 +2,20 @@
|
||||
| MARS-NWE libnwnss import wrapper for NSS shared NDP idbroker source.
|
||||
+-------------------------------------------------------------------------*/
|
||||
|
||||
#include <semaphore.h>
|
||||
|
||||
#include <schedule.h>
|
||||
#include <library/que.h>
|
||||
#include <evs.h>
|
||||
#include <ndp_comn.h>
|
||||
#include <ndp_app.h>
|
||||
|
||||
extern long ndpmsg_multipleID;
|
||||
extern sem_t ndpmsg_multipleIDsem;
|
||||
extern int daemonize;
|
||||
|
||||
STATUS COMN_GenerateVolumeCrypto(VolumeKey_s *key, unicode_t *password);
|
||||
STATUS COMN_ProcessVolumeCrypto(VolumeKey_s *key, unicode_t *password);
|
||||
|
||||
#define BUILD_NDP_IDBROKER 1
|
||||
#include <sharedsrc/ndp_idbroker.c.h>
|
||||
|
||||
5
src/nwnss/comn/common/ndpMessageHandlerShared.c
Normal file
5
src/nwnss/comn/common/ndpMessageHandlerShared.c
Normal file
@@ -0,0 +1,5 @@
|
||||
/****************************************************************************
|
||||
| MARS-NWE libnwnss import wrapper for NSS shared NDP message handler source.
|
||||
+-------------------------------------------------------------------------*/
|
||||
|
||||
#include <sharedsrc/ndp_messagehandler.c.h>
|
||||
130
src/nwnss/comn/common/ndpNcpUserlandBoundary.c
Normal file
130
src/nwnss/comn/common/ndpNcpUserlandBoundary.c
Normal file
@@ -0,0 +1,130 @@
|
||||
/****************************************************************************
|
||||
| MARS-NWE libnwnss userspace NDP/NCP dynamic boundary.
|
||||
|
|
||||
| The NSS shared management sources call a small NCP/NSSAdmin surface directly.
|
||||
| Novell's NDP idbroker side binds these providers dynamically instead of
|
||||
| linking the module hard to libncpid/libnssadmin. Keep the same boundary for
|
||||
| libnwnss: resolve the optional providers at runtime and return an error when
|
||||
| the external service is unavailable.
|
||||
+-------------------------------------------------------------------------*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include <public/zOmni.h>
|
||||
#include <library/xUnicode.h>
|
||||
#include <schedule.h>
|
||||
#include <ncpIDAPI.h>
|
||||
#include <nssAdminLib.h>
|
||||
#include <support/ndssdkINC_kern/dconst.h>
|
||||
#include <support/ndssdkINC_kern/nwdserr.h>
|
||||
#include <ndp_idbroker.h>
|
||||
|
||||
static void *mars_nwnss_ncpid_handle;
|
||||
static void *mars_nwnss_nssadmin_handle;
|
||||
|
||||
static void *mars_nwnss_open_optional_library(void **handle, const char *name)
|
||||
{
|
||||
if (*handle == NULL) {
|
||||
*handle = dlopen(name, RTLD_NOW | RTLD_LOCAL);
|
||||
}
|
||||
return *handle;
|
||||
}
|
||||
|
||||
static void *mars_nwnss_ncpid_symbol(const char *name)
|
||||
{
|
||||
void *handle = mars_nwnss_open_optional_library(&mars_nwnss_ncpid_handle,
|
||||
"libncpid.so");
|
||||
return handle ? dlsym(handle, name) : NULL;
|
||||
}
|
||||
|
||||
static void *mars_nwnss_nssadmin_symbol(const char *name)
|
||||
{
|
||||
void *handle = mars_nwnss_open_optional_library(&mars_nwnss_nssadmin_handle,
|
||||
"libnssadmin.so");
|
||||
return handle ? dlsym(handle, name) : NULL;
|
||||
}
|
||||
|
||||
int OpenNCPServLib(void)
|
||||
{
|
||||
int (*fn)(void) = (int (*)(void))mars_nwnss_ncpid_symbol("OpenNCPServLib");
|
||||
return fn ? fn() : -1;
|
||||
}
|
||||
|
||||
void CloseNCPServLib(void)
|
||||
{
|
||||
void (*fn)(void) = (void (*)(void))mars_nwnss_ncpid_symbol("CloseNCPServLib");
|
||||
if (fn) {
|
||||
fn();
|
||||
}
|
||||
}
|
||||
|
||||
int NCPMapGUIDToDN(const char *guid, const size_t dnSize, unsigned short *dn)
|
||||
{
|
||||
int (*fn)(const char *, const size_t, unsigned short *) =
|
||||
(int (*)(const char *, const size_t, unsigned short *))
|
||||
mars_nwnss_ncpid_symbol("NCPMapGUIDToDN");
|
||||
return fn ? fn(guid, dnSize, dn) : -1;
|
||||
}
|
||||
|
||||
int OpenNSSAdminLib(void)
|
||||
{
|
||||
int (*fn)(void) = (int (*)(void))mars_nwnss_nssadmin_symbol("OpenNSSAdminLib");
|
||||
return fn ? fn() : -1;
|
||||
}
|
||||
|
||||
void CloseNSSAdminLib(void)
|
||||
{
|
||||
void (*fn)(void) = (void (*)(void))mars_nwnss_nssadmin_symbol("CloseNSSAdminLib");
|
||||
if (fn) {
|
||||
fn();
|
||||
}
|
||||
}
|
||||
|
||||
int NCPLoginAsNSSAdmin(int context)
|
||||
{
|
||||
int (*fn)(int) = (int (*)(int))mars_nwnss_nssadmin_symbol("NCPLoginAsNSSAdmin");
|
||||
return fn ? fn(context) : -1;
|
||||
}
|
||||
|
||||
int NCPCloseAdminIdentity(int context)
|
||||
{
|
||||
int (*fn)(int) = (int (*)(int))mars_nwnss_nssadmin_symbol("NCPCloseAdminIdentity");
|
||||
return fn ? fn(context) : -1;
|
||||
}
|
||||
|
||||
STATUS MNSS_FindUserIDByDN(unsigned char *context, unsigned char *dn,
|
||||
UserID_t *userID)
|
||||
{
|
||||
STATUS status;
|
||||
NINT offset = 0;
|
||||
unicode_t uniName[MAX_DN_CHARS];
|
||||
utf8_t tempName[MAX_DN_CHARS];
|
||||
|
||||
if ((dn == NULL) || (userID == NULL)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dn[0] != '.') {
|
||||
tempName[0] = '.';
|
||||
offset = 1;
|
||||
}
|
||||
if (context != NULL) {
|
||||
strcpy(&tempName[offset], dn);
|
||||
strcat(tempName, ".");
|
||||
strcat(tempName, context);
|
||||
} else {
|
||||
strcpy(&tempName[offset], dn);
|
||||
}
|
||||
|
||||
utf2uni(tempName, uniName, sizeof(uniName));
|
||||
status = ndp_NCPMapDNToGUID(1, uniName, userID);
|
||||
if ((status == ERR_ILLEGAL_DS_NAME) &&
|
||||
(tempName[strlen(tempName) - 1] != '.')) {
|
||||
strcat(tempName, ".");
|
||||
utf2uni(tempName, uniName, sizeof(uniName));
|
||||
status = ndp_NCPMapDNToGUID(1, uniName, userID);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
1603
src/nwnss/sharedsrc/ndp_comn.c.h
Normal file
1603
src/nwnss/sharedsrc/ndp_comn.c.h
Normal file
File diff suppressed because it is too large
Load Diff
50
src/nwnss/sharedsrc/ndp_guids.c.h
Normal file
50
src/nwnss/sharedsrc/ndp_guids.c.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/****************************************************************************
|
||||
|
|
||||
| (C) Copyright 2004 Novell, Inc.
|
||||
| All Rights Reserved.
|
||||
|
|
||||
| This program is free software; you can redistribute it and/or
|
||||
| modify it under the terms of version 2 of the GNU General Public
|
||||
| License as published by the Free Software Foundation.
|
||||
|
|
||||
| This program is distributed in the hope that it will be useful,
|
||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
| GNU General Public License for more details.
|
||||
|
|
||||
| You should have received a copy of the GNU General Public License
|
||||
| along with this program; if not, contact Novell, Inc.
|
||||
|
|
||||
| To contact Novell about this file by physical or electronic mail,
|
||||
| you may find current contact information at www.novell.com
|
||||
|
|
||||
|***************************************************************************
|
||||
|
|
||||
| Novell's User/Kernel Data Portal (NDP) GUIDs file.
|
||||
|
|
||||
|---------------------------------------------------------------------------
|
||||
|
|
||||
| $Author: taysom $
|
||||
| $Date: 2004-12-31 01:10:58 +0530 (Fri, 31 Dec 2004) $
|
||||
|
|
||||
| $RCSfile$
|
||||
| $Revision: 465 $
|
||||
|
|
||||
|---------------------------------------------------------------------------
|
||||
| This file is used to:
|
||||
| ...
|
||||
+-------------------------------------------------------------------------*/
|
||||
|
||||
#include <ndp_guids.h>
|
||||
|
||||
/******************************************************************************
|
||||
*******************************************************************************
|
||||
* Declare the NDP Application & Module GUID Values
|
||||
*******************************************************************************
|
||||
******************************************************************************/
|
||||
|
||||
/* DD698A15-9E44-4317-9195-5B0499873F26 */
|
||||
GUID_t ndpAppGuid = { 0xdd698a15, 0x9e44, 0x4317, 0x91, 0x95, { 0x5b, 0x04, 0x99, 0x87, 0x3f, 0x26 } };
|
||||
|
||||
/* 4B1F2770-DE5E-4482-8E52-70D86EFE990C */
|
||||
GUID_t ndpModGuid = { 0x4b1f2770, 0xde5e, 0x4482, 0x8e, 0x52, { 0x70, 0xd8, 0x6e, 0xfe, 0x99, 0x0c } };
|
||||
@@ -299,7 +299,7 @@ static ndpIdBrokerInfo_t ndpIdBrokerInfo[] =
|
||||
* The NDP ID Broker Message Handling Routine
|
||||
* These routines run in their own threads...
|
||||
******************************************************************************/
|
||||
#ifdef __KERNEL__
|
||||
#if defined(__KERNEL__) || defined(MARS_NWE_NWNSS_USERSPACE)
|
||||
void *ndp_idBroker_messagehandler(
|
||||
THREAD thread,
|
||||
void *_threadContext)
|
||||
@@ -840,7 +840,7 @@ int ndp_init_idBroker(void)
|
||||
sts = pthread_create(
|
||||
&ndpIdBrokerInfo[g].thread,
|
||||
NULL,
|
||||
ndp_idBroker_messagehandler,
|
||||
(void *(*)(void *))ndp_idBroker_messagehandler,
|
||||
&ndpIdBrokerInfo[g].threadContext);
|
||||
// if (sts) {
|
||||
// /* Thread Creation Error */
|
||||
@@ -908,7 +908,7 @@ int ndp_cleanup_idBroker(void)
|
||||
* K2U <uidtofdn><uid>nnn</uid></uidtofdn>
|
||||
* U2K <uidtofdn><sts>nnn</sts><uid>nnn</uid><fdn>ccc</fdn></uidtofdn>
|
||||
*****************************************************************************/
|
||||
#ifdef __KERNEL__
|
||||
#if defined(__KERNEL__) || defined(MARS_NWE_NWNSS_USERSPACE)
|
||||
int ndp_namGetUserFDNfromUID(
|
||||
int uid,
|
||||
unicode_t **userFDN)
|
||||
@@ -1223,7 +1223,7 @@ int ndp_namGetUserFDNfromUID_handler(
|
||||
* K2U <dntoguid><create>nnn</create><dn>ccc</dn></dntoguid>
|
||||
* U2K <dntoguid><sts>nnn</sts><dn>ccc</dn><guid>hex</guid></dntoguid>
|
||||
*****************************************************************************/
|
||||
#ifdef __KERNEL__
|
||||
#if defined(__KERNEL__) || defined(MARS_NWE_NWNSS_USERSPACE)
|
||||
int ndp_NCPMapDNToGUID(
|
||||
int create,
|
||||
unicode_t *dn,
|
||||
@@ -1400,7 +1400,7 @@ SendResponse:
|
||||
* K2U <localtreename><namesize>nnn</namesize></localtreename>
|
||||
* U2K <localtreename><sts>nnn</sts><name>ccc</name></localtreename>
|
||||
*****************************************************************************/
|
||||
#ifdef __KERNEL__
|
||||
#if defined(__KERNEL__) || defined(MARS_NWE_NWNSS_USERSPACE)
|
||||
int ndp_NCPLocalTreeName(
|
||||
size_t treeNameSize, /* This is buffer size in bytes */
|
||||
unicode_t *treeName)
|
||||
@@ -1579,7 +1579,7 @@ SendResponse:
|
||||
* U2K <dntosev><sts>nnn</sts><dn>ccc</dn><guidsevcount>nnn</guidsevcount>
|
||||
* <guidsev>hex,...</guidsev></dntosev>
|
||||
*****************************************************************************/
|
||||
#ifdef __KERNEL__
|
||||
#if defined(__KERNEL__) || defined(MARS_NWE_NWNSS_USERSPACE)
|
||||
int ndp_NCPMapDNToSEV(
|
||||
unicode_t *dn,
|
||||
size_t *_guidSEVCount,
|
||||
@@ -1848,7 +1848,7 @@ SendResult:
|
||||
* U2K <guidtomgtlevel><sts>nnn</sts><objid>hex</objid>
|
||||
* <managementLevel>nnn</managementLevel></guidtomgtlevel>
|
||||
*****************************************************************************/
|
||||
#ifdef __KERNEL__
|
||||
#if defined(__KERNEL__) || defined(MARS_NWE_NWNSS_USERSPACE)
|
||||
int ndp_NCPMapGUIDToMgtLevel(
|
||||
size_t numAuthenticatedIDs,
|
||||
GUID_t *authenticatedIDs,
|
||||
@@ -2081,7 +2081,7 @@ SendResult:
|
||||
* K2U <guidtodn><guid>hex</guid><dnsize>nnn</dnsize></guidtodn>
|
||||
* U2K <guidtodn><sts>nnn</sts><guid>hex</guid><dn>ccc</dn></guidtodn>
|
||||
*****************************************************************************/
|
||||
#ifdef __KERNEL__
|
||||
#if defined(__KERNEL__) || defined(MARS_NWE_NWNSS_USERSPACE)
|
||||
int ndp_NCPMapGUIDToDN(
|
||||
GUID_t *guid,
|
||||
size_t dnSize,
|
||||
@@ -2274,7 +2274,7 @@ SendResult:
|
||||
* K2U <guidtouid><guid>hex</guid></guidtouid>
|
||||
* U2K <guidtouid><sts>nnn</sts><guid>hex</guid><uid>nnn</uid></guidtouid>
|
||||
*****************************************************************************/
|
||||
#ifdef __KERNEL__
|
||||
#if defined(__KERNEL__) || defined(MARS_NWE_NWNSS_USERSPACE)
|
||||
int ndp_NCPMapGUIDToUID(
|
||||
GUID_t *guid,
|
||||
LONG *uid)
|
||||
@@ -2417,7 +2417,7 @@ int ndp_NCPMapGUIDToUID_handler(
|
||||
* K2U <uidtoguid><uid>nnn</uid></uidtoguid>
|
||||
* U2K <uidtoguid><sts>nnn</sts><uid>nnn</uid><guid>hex</guid></uidtoguid>
|
||||
*****************************************************************************/
|
||||
#ifdef __KERNEL__
|
||||
#if defined(__KERNEL__) || defined(MARS_NWE_NWNSS_USERSPACE)
|
||||
int ndp_NCPMapUIDToGUID(
|
||||
LONG uid,
|
||||
GUID_t *guid)
|
||||
@@ -2551,7 +2551,7 @@ int ndp_NCPMapUIDToGUID_handler(
|
||||
* K2U <getuidfromname><name>ccc</name></getuidfromname>
|
||||
* U2K <getuidfromname><sts>nnn</sts><name>ccc</name><uid>nnn</uid></getuidfromname>
|
||||
*****************************************************************************/
|
||||
#ifdef __KERNEL__
|
||||
#if defined(__KERNEL__) || defined(MARS_NWE_NWNSS_USERSPACE)
|
||||
int ndp_GetUIDFromName(
|
||||
unsigned char *name,
|
||||
LONG *uid)
|
||||
@@ -2788,7 +2788,7 @@ utf8_t *ndp_UnManglePassword(
|
||||
* U2K <generatedata><sts>nnn</sts><w>ccc</w><y>hex</y><p>hex</p>
|
||||
* </generatedata>
|
||||
*****************************************************************************/
|
||||
#ifdef __KERNEL__
|
||||
#if defined(__KERNEL__) || defined(MARS_NWE_NWNSS_USERSPACE)
|
||||
int ndp_GenerateVolumeKeyInfo(
|
||||
unicode_t *volumePassword,
|
||||
BYTE *retKey, /* ptr to 16 byte buffer to receive the new key */
|
||||
@@ -2995,7 +2995,7 @@ SendResult:
|
||||
* K2U <extractdata><w>ccc</w><p>hex</p></extractdata>
|
||||
* U2K <extractdata><sts>nnn</sts><w>ccc</w><y>hex</y></extractdata>
|
||||
*****************************************************************************/
|
||||
#ifdef __KERNEL__
|
||||
#if defined(__KERNEL__) || defined(MARS_NWE_NWNSS_USERSPACE)
|
||||
int ndp_ExtractVolumeKeyInfo(
|
||||
unicode_t *volumePassword,
|
||||
BYTE *volP, /* ptr to 128 byte persistent portion of VolumeKey_s */
|
||||
@@ -3215,7 +3215,7 @@ SendResult:
|
||||
* if already registered (-2)
|
||||
* if invalid function pointer (-1)
|
||||
*****************************************************************************/
|
||||
#ifdef __KERNEL__
|
||||
#if defined(__KERNEL__) || defined(MARS_NWE_NWNSS_USERSPACE)
|
||||
void (*ndp_NCPNotifyDNChange)(unicode_t *oldDN, unicode_t *newDN) = NULL;
|
||||
|
||||
int ndp_register_NCPNotifyDNChange(
|
||||
@@ -3246,7 +3246,7 @@ EXPORT_SYMBOL(ndp_register_NCPNotifyDNChange);
|
||||
* K2U ... N/A (no return value) ...
|
||||
* U2K <notifyofdnchange><olddn>ccc</olddn><newdn>ccc</newdn></notifyofdnchange>
|
||||
*****************************************************************************/
|
||||
#ifdef __KERNEL__
|
||||
#if defined(__KERNEL__) || defined(MARS_NWE_NWNSS_USERSPACE)
|
||||
int ndp_NCPNotifyDNChange_handler(
|
||||
GUID_t *srcGuid,
|
||||
LONG length,
|
||||
@@ -3313,7 +3313,7 @@ int ndp_NCPNotifyDNChange_handler(
|
||||
* if already registered (-2)
|
||||
* if invalid function pointer (-1)
|
||||
*****************************************************************************/
|
||||
#ifdef __KERNEL__
|
||||
#if defined(__KERNEL__) || defined(MARS_NWE_NWNSS_USERSPACE)
|
||||
void (*ndp_NCPNotifySEVChange)(GUID_t *changedGUID) = NULL;
|
||||
|
||||
int ndp_register_NCPNotifySEVChange(
|
||||
@@ -3343,7 +3343,7 @@ EXPORT_SYMBOL(ndp_register_NCPNotifySEVChange);
|
||||
* K2U ... N/A (no return value) ...
|
||||
* U2K <notifyofsevchange><guid>hex</guid></notifyofsevchange>
|
||||
*****************************************************************************/
|
||||
#ifdef __KERNEL__
|
||||
#if defined(__KERNEL__) || defined(MARS_NWE_NWNSS_USERSPACE)
|
||||
int ndp_NCPNotifySEVChange_handler(
|
||||
GUID_t *srcGuid,
|
||||
LONG length,
|
||||
|
||||
356
src/nwnss/sharedsrc/ndp_messagehandler.c.h
Normal file
356
src/nwnss/sharedsrc/ndp_messagehandler.c.h
Normal file
@@ -0,0 +1,356 @@
|
||||
/****************************************************************************
|
||||
|
|
||||
| (C) Copyright 2004 Novell, Inc.
|
||||
| All Rights Reserved.
|
||||
|
|
||||
| This program is free software; you can redistribute it and/or
|
||||
| modify it under the terms of version 2 of the GNU General Public
|
||||
| License as published by the Free Software Foundation.
|
||||
|
|
||||
| This program is distributed in the hope that it will be useful,
|
||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
| GNU General Public License for more details.
|
||||
|
|
||||
| You should have received a copy of the GNU General Public License
|
||||
| along with this program; if not, contact Novell, Inc.
|
||||
|
|
||||
| To contact Novell about this file by physical or electronic mail,
|
||||
| you may find current contact information at www.novell.com
|
||||
|
|
||||
|***************************************************************************
|
||||
|
|
||||
| Novell's User/Kernel Data Portal (NDP) Common Message Handling program file.
|
||||
|
|
||||
|---------------------------------------------------------------------------
|
||||
|
|
||||
| $Author: blarsen $
|
||||
| $Date: 2006-02-09 05:04:41 +0530 (Thu, 09 Feb 2006) $
|
||||
|
|
||||
| $RCSfile$
|
||||
| $Revision: 1325 $
|
||||
|
|
||||
|---------------------------------------------------------------------------
|
||||
| This file is used to:
|
||||
| ...
|
||||
+-------------------------------------------------------------------------*/
|
||||
|
||||
#include <ndp_comn.h>
|
||||
#include <ndp_messagehandler.h>
|
||||
|
||||
#ifndef __KERNEL__
|
||||
#include <xmlNSS.h>
|
||||
#endif /* __KERNEL__ */
|
||||
|
||||
extern ndpContext_t *ndpContext;
|
||||
|
||||
/******************************************************************************
|
||||
* Declare and initialize NDP Application "Globals"
|
||||
******************************************************************************/
|
||||
#ifndef __KERNEL__
|
||||
extern long ndpMsgQueueID; /* See ndp_app.c */
|
||||
#endif /* __KERNEL__ */
|
||||
|
||||
/******************************************************************************
|
||||
* Function Pre-Declarations (not in ndp_messagehandler.h, or static)
|
||||
******************************************************************************/
|
||||
|
||||
static int ndp_messagehandler_echo(
|
||||
GUID_t *ndpGuid,
|
||||
GUID_t *ndpGuidPrime,
|
||||
GUID_t *ndpOtherGuid,
|
||||
GUID_t *msgSrcGuid,
|
||||
LONG length,
|
||||
unsigned char *data);
|
||||
|
||||
static int ndp_messagehandler_register(
|
||||
GUID_t *ndpGuid,
|
||||
GUID_t *ndpGuidPrime,
|
||||
GUID_t *ndpOtherGuid,
|
||||
GUID_t *msgSrcGuid,
|
||||
LONG length,
|
||||
unsigned char *data);
|
||||
|
||||
static int ndp_messagehandler_deregister(
|
||||
GUID_t *ndpGuid,
|
||||
GUID_t *ndpGuidPrime,
|
||||
GUID_t *ndpOtherGuid,
|
||||
GUID_t *msgSrcGuidPrime,
|
||||
LONG length,
|
||||
unsigned char *data);
|
||||
|
||||
/******************************************************************************
|
||||
* <Echo> Message Handler Action for the NDP Message Handler
|
||||
* Returns 1 if handled by this handler
|
||||
*******************************************************************************
|
||||
* NOTE: As a saftey mechanism against an infinite loop, the echoed data
|
||||
* is shortend by one character each time it is echoed...
|
||||
******************************************************************************/
|
||||
static int ndp_messagehandler_echo(
|
||||
GUID_t *ndpGuid,
|
||||
GUID_t *ndpGuidPrime,
|
||||
GUID_t *ndpOtherGuid,
|
||||
GUID_t *msgSrcGuid,
|
||||
LONG length,
|
||||
unsigned char *data)
|
||||
{
|
||||
int messageHandled = 0;
|
||||
static unsigned char cmdString[] = "<echo>";
|
||||
int cmdStringLength = sizeof(cmdString) - 1; /* Don't count '\0' */
|
||||
|
||||
if ((length >= cmdStringLength) && (data)) {
|
||||
if (ndp_strncasecmp(data, cmdString, cmdStringLength) == 0) {
|
||||
unsigned char *dp = NULL;
|
||||
ndpDbgPrintf(1, "ndp_messagehandler_echo(Start)\n");
|
||||
dp = ndpMalloc(((size_t)length+1), GFP_KERNEL);
|
||||
if (dp) {
|
||||
memcpy(dp, data, (size_t)length);
|
||||
dp[(size_t)length] = '\0';
|
||||
ndpDbgPrintf(2, "ndp_messagehandler_echo:%ld=\"%s\"\n",
|
||||
length, dp);
|
||||
ndpFree(dp);
|
||||
}
|
||||
messageHandled = 1;
|
||||
/* No need to get sts, we will just ignore the results */
|
||||
(void) ndp_writeToGuid(1,
|
||||
ndpGuidPrime, /* *srcGuidPrime */
|
||||
msgSrcGuid, /* *dstGuid */
|
||||
length - 1, /* length shortened by a count of 1 */
|
||||
data);
|
||||
ndpDbgPrintf(1, "ndp_messagehandler_echo(Stop)\n");
|
||||
}
|
||||
}
|
||||
return(messageHandled);
|
||||
} /* ndp_messagehandler_echo() */
|
||||
|
||||
/******************************************************************************
|
||||
* <Register> Message Handler Action for the NDP Message Handler
|
||||
* Returns 1 if handled by this handler
|
||||
******************************************************************************/
|
||||
static int ndp_messagehandler_register(
|
||||
GUID_t *ndpGuid,
|
||||
GUID_t *ndpGuidPrime,
|
||||
GUID_t *ndpOtherGuid,
|
||||
GUID_t *msgSrcGuid,
|
||||
LONG length,
|
||||
unsigned char *data)
|
||||
{
|
||||
int messageHandled = 0;
|
||||
#ifndef __KERNEL__
|
||||
/* This is currently only allowed (useful) in the application world */
|
||||
static unsigned char cmdString[] = "<register>";
|
||||
int cmdStringLength = sizeof(cmdString) - 1; /* Don't count '\0' */
|
||||
|
||||
if ((length >= cmdStringLength) && (data)) {
|
||||
if (ndp_strncasecmp(data, cmdString, cmdStringLength) == 0) {
|
||||
XML_ElementInfo_s xmlInfo;
|
||||
ndp_guidmsgcontext_t *guidmsgcontext;
|
||||
unsigned char msgReply[] =
|
||||
"<RegisterReply>1234567890123456</RegisterReply>";
|
||||
|
||||
GUID_t *msgSrcGuidPrime = (GUID_t *)&msgReply[15];
|
||||
char *name = NULL;
|
||||
pid_t pid = -1;
|
||||
int connectionType = NDPCONN_unknown;
|
||||
STATUS sts;
|
||||
|
||||
ndpDbgPrintf(10, "ndp_messagehandler_register(Start): data=%s\n", data);
|
||||
messageHandled = 1;
|
||||
/*
|
||||
* Parse the contents of the <Register>...</Register> tag set
|
||||
* Recognized tags:
|
||||
* <Name>...</Name>
|
||||
* <Pid>...</Pid>
|
||||
* <ConnectionType>...</ConnectionType>
|
||||
* Recognized values:
|
||||
* "link" - routines are linked in
|
||||
* "msgop" - msgget, msgsnd, msgrcv, ...
|
||||
*/
|
||||
sts = XML_GetTagElement("name",
|
||||
(utf8_t *)&data[0], (utf8_t *)&data[length-1], &xmlInfo);
|
||||
if (sts == zOK) {
|
||||
/* Get the value and add a '\0' terminator */
|
||||
*(xmlInfo.dataEnd + 1) = '\0';
|
||||
name = xmlInfo.dataStart;
|
||||
}
|
||||
sts = XML_GetTagElement("pid",
|
||||
(utf8_t *)&data[0], (utf8_t *)&data[length-1], &xmlInfo);
|
||||
if (sts == zOK) {
|
||||
/* Get the value */
|
||||
*(xmlInfo.dataEnd + 1) = '\0';
|
||||
pid = (pid_t)ndp_atoi(xmlInfo.dataStart);
|
||||
}
|
||||
sts = XML_GetTagElement("connectiontype",
|
||||
(utf8_t *)&data[0], (utf8_t *)&data[length-1], &xmlInfo);
|
||||
if (sts == zOK) {
|
||||
utf8_t *connectionTypeString;
|
||||
/* Get the string value and convert it to a number */
|
||||
*(xmlInfo.dataEnd + 1) = '\0';
|
||||
connectionTypeString = xmlInfo.dataStart;
|
||||
if (ndp_strncasecmp((unsigned char *)connectionTypeString,
|
||||
(unsigned char *)NDPCONNSTR_linked,
|
||||
strlen(NDPCONNSTR_linked)) == 0) {
|
||||
connectionType = NDPCONN_linked;
|
||||
} else if (ndp_strncasecmp((unsigned char *)connectionTypeString,
|
||||
(unsigned char *)NDPCONNSTR_msgop,
|
||||
strlen(NDPCONNSTR_msgop)) == 0) {
|
||||
connectionType = NDPCONN_msgop;
|
||||
}
|
||||
}
|
||||
/* Do the actual register */
|
||||
ndp_registerGuid(msgSrcGuid, msgSrcGuidPrime, name);
|
||||
/* Fill in connection information */
|
||||
guidmsgcontext = find_ndp_guidmsgcontext(
|
||||
ndpContext->guidListContext, msgSrcGuid);
|
||||
guidmsgcontext->pid = pid;
|
||||
guidmsgcontext->connection = connectionType;
|
||||
guidmsgcontext->ndpMsgQueueID = ndpMsgQueueID;
|
||||
/* Send the guidPrime back as a packet */
|
||||
(void) ndp_writeToGuid(10,
|
||||
ndpGuidPrime, /* *srcGuidPrime */
|
||||
msgSrcGuid, /* *dstGuid */
|
||||
sizeof(msgReply), /* length */
|
||||
msgReply);
|
||||
ndpDbgPrintf(10, "ndp_messagehandler_register(Stop)\n");
|
||||
}
|
||||
}
|
||||
#endif /* __KERNEL__ */
|
||||
return(messageHandled);
|
||||
} /* ndp_messagehandler_register() */
|
||||
|
||||
/******************************************************************************
|
||||
* <DeRegister> Message Handler Action for the NDP Message Handler
|
||||
* Returns 1 if handled by this handler
|
||||
******************************************************************************/
|
||||
static int ndp_messagehandler_deregister(
|
||||
GUID_t *ndpGuid,
|
||||
GUID_t *ndpGuidPrime,
|
||||
GUID_t *ndpOtherGuid,
|
||||
GUID_t *msgSrcGuidPrime,
|
||||
LONG length,
|
||||
unsigned char *data)
|
||||
{
|
||||
int messageHandled = 0;
|
||||
static unsigned char cmdString[] = "<deregister>";
|
||||
int cmdStringLength = sizeof(cmdString) - 1; /* Don't count '\0' */
|
||||
|
||||
if ((length >= cmdStringLength) && (data)) {
|
||||
if (ndp_strncasecmp(data, cmdString, cmdStringLength) == 0) {
|
||||
ndpDbgPrintf(10, "ndp_messagehandler_deregister(Start)\n");
|
||||
messageHandled = 1;
|
||||
ndp_deregisterGuid(msgSrcGuidPrime);
|
||||
ndpDbgPrintf(10, "ndp_messagehandler_deregister(Stop)\n");
|
||||
}
|
||||
}
|
||||
return(messageHandled);
|
||||
} /* ndp_messagehandler_deregister() */
|
||||
|
||||
/******************************************************************************
|
||||
* The NDP Application Message Handling Routine
|
||||
* This routine is called whenever a message is received for the NDP Application
|
||||
*******************************************************************************
|
||||
* if (srcGuidPrime) {
|
||||
* Use srcGuidPrime, dstGuid, length, and data values passed in.
|
||||
* Try <Register> message handler.
|
||||
* else if (ndpContext) {
|
||||
* Call ndp_readFromGuid() to get the data.
|
||||
* Try all message handlers except <Register>.
|
||||
* } else {
|
||||
* Error ... Ignore
|
||||
* }
|
||||
*******************************************************************************
|
||||
* NOTE: <Register> is the ONLY case that comes here using (srcGuidPrime,
|
||||
* dstGuid, length, data), all others ALWAYS come here * using (ndpContext).
|
||||
******************************************************************************/
|
||||
void ndp_messagehandler(
|
||||
ndpContext_t *ndpContext,
|
||||
GUID_t *srcGuidPrime,
|
||||
GUID_t *dstGuid,
|
||||
LONG length, /* 32 bit unsigned value */
|
||||
unsigned char *data)
|
||||
{
|
||||
int sts = 0;
|
||||
GUID_t _srcGuid;
|
||||
GUID_t *srcGuid = &_srcGuid;
|
||||
GUID_t _srcGuidPrime;
|
||||
|
||||
ndpDbgPrintf(13, "ndp_messagehandler(Enter)\n");
|
||||
if (srcGuidPrime) {
|
||||
/* Skip past any white space */
|
||||
data = ndp_SkipWhitespace(data, &length);
|
||||
if ((length > 0) && (*data == '<')) {
|
||||
ndpDbgDumpDataInHex(13, "ndp_messagehandler(srcGuid)",
|
||||
sizeof(GUID_t), (unsigned char *)srcGuidPrime);
|
||||
ndpDbgDumpDataInHex(13, "ndp_messagehandler(data)",
|
||||
length, data);
|
||||
/* <Register> is the only message we allow to come in this way */
|
||||
/* No need to get sts, no other handlers will be tried */
|
||||
(void) ndp_messagehandler_register(
|
||||
&THISGUID,
|
||||
&THISGUIDPRIME,
|
||||
&OTHERGUID,
|
||||
srcGuidPrime,
|
||||
length,
|
||||
data);
|
||||
}
|
||||
} else if (ndpContext) {
|
||||
sts = ndp_readFromGuid(13, &THISGUIDPRIME, srcGuid, &length, &data);
|
||||
if (sts == 0) {
|
||||
/* Skip past any white space */
|
||||
data = ndp_SkipWhitespace(data, &length);
|
||||
if (length > 0) {
|
||||
ndpDbgDumpDataInHex(13, "ndp_messagehandler(srcGuid)",
|
||||
sizeof(GUID_t), (unsigned char *)srcGuid);
|
||||
ndpDbgDumpDataInHex(13, "ndp_messagehandler(data)",
|
||||
length, data);
|
||||
/* get the srcGuidPrime using the guid */
|
||||
srcGuidPrime = &_srcGuidPrime;
|
||||
sts = ndp_exchangeGuidForGuidPrime(
|
||||
ndpContext->guidListContext, srcGuid, srcGuidPrime);
|
||||
/*
|
||||
* All message to the NDP message handler are in XML format.
|
||||
* Thus, all messages start with '<' and the next character
|
||||
* will be a quick indicator as to which handlers to try...
|
||||
* All the handlers examine the data to see if they are
|
||||
* supposed to deal with the data, and return 1 if they do
|
||||
* and 0 if they don't. This way, we can try several
|
||||
* handlers that start with the same character until one
|
||||
* of them handles the message. Non-handled messages
|
||||
* are ignored.
|
||||
*/
|
||||
if (data[0] == '<') switch (data[1]) {
|
||||
case 'd':
|
||||
case 'D':
|
||||
{
|
||||
/* (D) Possibly == DeRegister, ... */
|
||||
sts = ndp_messagehandler_deregister(
|
||||
&THISGUID,
|
||||
&THISGUIDPRIME,
|
||||
&OTHERGUID,
|
||||
srcGuidPrime,
|
||||
length,
|
||||
data);
|
||||
}
|
||||
case 'e':
|
||||
case 'E':
|
||||
{
|
||||
/* (E) Possibly == Echo, ... */
|
||||
sts = ndp_messagehandler_echo(
|
||||
&THISGUID,
|
||||
&THISGUIDPRIME,
|
||||
&OTHERGUID,
|
||||
srcGuid,
|
||||
length,
|
||||
data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (data) {
|
||||
ndpFree(data);
|
||||
}
|
||||
//IGNORE// } else {
|
||||
}
|
||||
ndpDbgPrintf(13, "ndp_messagehandler(Leave)\n");
|
||||
return;
|
||||
} /* ndp_messagehandler() */
|
||||
Reference in New Issue
Block a user