Client login files

This commit is contained in:
Jim Norman 2005-10-21 01:16:41 +00:00
parent 7d98f95064
commit a76d92a334
3 changed files with 392 additions and 0 deletions

106
c_clientlogin/Makefile Normal file
View File

@ -0,0 +1,106 @@
#/******************************************************************************
#
# %name: Makefile %
# %version: %
# %date_modified: %
# $Copyright:
#
# Copyright (c) 2004 Novell, Inc. All Rights Reserved.
#
# THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND
# TREATIES. NO PART OF THIS WORK MAY BE USED, PRACTICED, PERFORMED
# COPIED, DISTRIBUTED, REVISED, MODIFIED, TRANSLATED, ABRIDGED, CONDENSED,
# EXPANDED, COLLECTED, COMPILED, LINKED, RECAST, TRANSFORMED OR ADAPTED
# WITHOUT THE PRIOR WRITTEN CONSENT OF NOVELL, INC. ANY USE OR EXPLOITATION
# OF THIS WORK WITHOUT AUTHORIZATION COULD SUBJECT THE PERPETRATOR TO
# CRIMINAL AND CIVIL LIABILITY.$
#
# *****************************************************************************/
.PHONY: all rebuild clean
# Source directory name, library name and library directory name
APP_NAME = nwautologin
# Output Paths
ifdef DEBUG
OBJ_ROOT = ./Debug
FINAL_ROOT = ./Debug
else
OBJ_ROOT = ./Release
FINAL_ROOT = ./Release
endif
OBJ_DIR := $(OBJ_ROOT)
FINAL_DIR := $(FINAL_ROOT)
OBJS := $(foreach obj,$(basename $(wildcard *.c)),$(addsuffix .o, $(obj)))
# Target file
FINAL_TARGET := $(FINAL_DIR)/$(APP_NAME)
# Library paths and files
# Please note: lib CLN has a circular dependency. In the case of a clean
# build, lib NCP must be built first. lib NCP cannot be fully built until
# until lib CLN has been built. Build order is NCP, CLN, NCP (or CLN, NCP, CLN)
NWLIB_PATH := /opt/novell/lib
NWLIB_LIST := clxlnx callnx netlnx ncplnx clnlnx loclnx
EXTLIB_PATH :=
EXTLIB_LIST :=
# Compiler specific include paths
INC_PATH = /opt/novell/include/xplat /opt/novell/CASA_devel/include
# Compiler flagsEXTLIB_LIST
CFLAGS := -Wall -O2 -D N_PLAT_UNIX -D N_USE_CRT -fshort-wchar \
$(foreach path,$(INC_PATH),-I $(path))
ifdef DEBUG
CFLAGS += -g
endif
# Linker flags
#LDFLAGS := $(foreach path,$(NWLIB_PATH) $(EXTLIB_PATH),-L$(path)) \
# $(foreach lib, $(NWLIB_LIST) $(EXTLIB_LIST),-l$(lib)) \
# -Wl,$(foreach path,$(NWLIB_PATH),-rpath $(path))
LDFLAGS := $(foreach path,$(NWLIB_PATH) $(EXTLIB_PATH),-L$(path)) \
$(foreach lib, $(NWLIB_LIST) $(EXTLIB_LIST),-l$(lib))
ifdef DEBUG
LDFLAGS += -g
endif
# Prerequisite and target search paths
vpath %.h /opt/novell/include/xplat
vpath %.o $(OBJ_DIR)
# Main target is library file in final area
all: $(FINAL_TARGET)
# Helper target/source defines
SILENT = @
IGNORE = -
_Target = $@
_Source = $<
_Sources = $^
_Root = $*
# Final target
$(FINAL_TARGET): $(OBJS)
@echo Linking $(_Target)
gcc -o $(_Target) $(LDFLAGS) $(foreach obj,$(OBJS),$(OBJ_DIR)/$(obj))
# build .c files
%.o: %.c
@echo Compiling $(_Source)
gcc -c $(CFLAGS) $(INC_PATHS) $(_Source) -o $(OBJ_DIR)/$(_Target)
# Rebuild this project
rebuild: clean all
# Clean this project
clean:
@-rm $(FINAL_TARGET)
@-rm $(OBJ_DIR)/*.o

285
c_clientlogin/alogin.c Normal file
View File

@ -0,0 +1,285 @@
/***********************************************************************
* File: alogin.c
* Author: (tthrone@novell.com)
*
* Copyright (C) 2005 Novell, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
***********************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dlfcn.h>
#include <errno.h>
#include <syslog.h>
#include <nwcalls.h>
#include <nwnet.h>
#include <micasa_mgmd.h>
#define NCL_CONFIG_FILE "/etc/opt/novell/ncl/login.conf"
#define DEFAULT_TREE_VARIABLE_NAME "Default_Tree"
typedef
int
(*PGETCREDENTIAL)(
unsigned long ssFlags, // IN
SSCS_SECRET_ID_T * appSecretID, // IN
SSCS_SECRET_ID_T * sharedSecretID, // Optional IN
int * credentialType, // OUT
void * credential, // IN
SSCS_EXT_T * ext // Reserved
);
extern int errno;
//++=======================================================================
int
GetConfigValue(
char *pConfigFile,
char *pName,
int nameSize,
char *pValue,
int *pValueSize)
//
// Arguments In: pConfigFile - name of configuration file to use
// pName - pointer to name of configuration option
// nameSize - size of configuration option name
// pValueSize - size of the buffer pointed to by pValue
//
// Arguments Out: pValue - contains the value of name
// pValueSize - contains the size of value
//
// Returns: 0 - success, errno - failure
//
// Abstract: Method to obtain the value of a named configuration variable
// within a configuration file.
//
// L2
//=======================================================================--
{
int ccode = -1;
// Open the configuration file
FILE *stream = fopen(pConfigFile, "r");
if (stream != NULL)
{
// Configuration file opened, now seek to
// the beginning and go through each line until
// we find the configuration variable or reach
// the end of the line.
fseek(stream, 0, SEEK_SET);
char line[258] = {0};
while (fgets(line, 258, stream) != NULL)
{
// Check if the configuration variable name is at the beginning
// of the line.
char *p = strstr(line, pName);
if (p == line)
{
// Configuration variable found
//
// Get past the configuration variable and
// try to get its value.
p += nameSize;
int charsLeft = strlen(line) - (p - line);
// Skip any spaces, tabs, or equal signs that may be ahead of the
// value.
for ( ; charsLeft > 0; charsLeft--, p++)
{
if (*p != ' '
&& *p != '\t'
&& *p != '=')
break;
}
// Skip any spaces, tabs, or the newline that may be after the value.
// NULL terminate the value if necessary
char *currLocation = p;
for ( ; charsLeft > 0; charsLeft--, currLocation++)
{
if (*currLocation == ' '
|| *currLocation == '\t'
|| *currLocation == '\n')
{
*currLocation = '\0';
break;
}
}
// Try to obtain the value
if ((currLocation - p) < (*pValueSize - 1))
{
strcpy(pValue, p);
*pValueSize = (currLocation - p);
ccode = 0;
}
else
{
printf("Buffer overflow reading configuration value.\n");
ccode = -1;
}
break;
}
}
// Close configuration file
fclose(stream);
}
else
{
printf("Error opening %s.conf file, error = %d\n", pConfigFile, errno);
ccode = errno;
}
return ccode;
}
int main(int argc, char* argv[])
{
int ccode;
NWDSContextHandle hContext = 0;
char defaultTree[NW_MAX_TREE_NAME_LEN + 1];
int defaultTreeSize;
int authenticated = 0;
SSCS_BASIC_CREDENTIAL basicCredential;
// Get ready to log
openlog("nwautologin", LOG_CONS | LOG_NOWAIT | LOG_ODELAY| LOG_PID, LOG_USER);
setlogmask(LOG_UPTO(LOG_INFO));
syslog(LOG_USER | LOG_INFO, "Attempting Novell client auto login.");
defaultTreeSize = sizeof(defaultTree);
ccode = GetConfigValue(
NCL_CONFIG_FILE,
DEFAULT_TREE_VARIABLE_NAME,
sizeof(DEFAULT_TREE_VARIABLE_NAME) - 1,
defaultTree,
&defaultTreeSize);
if (ccode != SUCCESS)
{
syslog(LOG_USER | LOG_ERR, "Error reading configuration value \"Default_Tree=\" from /etc/opt/novell/ncl/login.conf file.");
exit (1);
}
// printf("Default tree returned from GetConfigValue [%s], tree length %d\n", defaultTree, defaultTreeSize);
authenticated = 0;
ccode = NWDSCreateContextHandle(&hContext);
if (ccode == SUCCESS)
{
// Set tree name in context handle.
ccode = NWDSSetContext(hContext, DCK_TREE_NAME, defaultTree);
if (ccode == SUCCESS)
{
// Do we already have a identity for this tree (logged in to tree)?
if (NWDSCanDSAuthenticate(hContext) == TRUE)
{
syslog(LOG_USER | LOG_INFO, "Novell client is already authenticated to %s.", defaultTree);
authenticated = 1;
}
}
NWDSFreeContext(hContext);
}
ccode = -1;
if (authenticated == 0)
{
SSCS_SECRET_ID_T tree;
void * hModule;
PGETCREDENTIAL pfnGetCredential;
int credentialType;
//
// Set the new credentials in miCASA
//
if ((hModule = dlopen("libmicasa.so", RTLD_LAZY)) != NULL)
{
if ((pfnGetCredential =
(PGETCREDENTIAL)dlsym(hModule, "miCASAGetCredential")) != NULL)
{
strcpy((char *)&tree.id, defaultTree);
tree.len = defaultTreeSize + 1;
// printf("tree name passed to miCASAGetCredential [%s], length %d\n", tree.id, tree.len);
basicCredential.unFlags = USERNAME_TYPE_NDS_FDN_F;
basicCredential.unLen = 0;
basicCredential.pwordLen = 0;
credentialType = SSCS_CRED_TYPE_BASIC_F;
ccode = (*pfnGetCredential)(
0,
&tree,
NULL,
&credentialType,
&basicCredential,
NULL);
// printf("miCASAGetCredential returned %d\n", ccode);
if (ccode != SUCCESS)
{
syslog(LOG_USER | LOG_INFO, "miCASAGetCredential failed with %d.", ccode);
}
/*
else
{
printf("Credential type %d\n", credentialType);
printf("Credential - username [%s], password [%s]\n", basicCredential.username, basicCredential.password);
}
*/
}
dlclose(hModule);
}
else
{
syslog(LOG_USER | LOG_INFO, "dlopen on libmicasa.so failed, errno - %d.", errno);
}
}
if (ccode == SUCCESS)
{
char command[258] = {0};
sprintf(command, "/opt/novell/ncl/bin/nwlogin -t %s -u %s -p %s -r", defaultTree, basicCredential.username, basicCredential.password);
ccode = system(command);
syslog(LOG_USER | LOG_INFO, "/opt/novell/ncl/bin/nwlogin returned %d.", ccode);
}
closelog();
return ccode;
}

View File

@ -0,0 +1 @@
/opt/novell/CASA/bin/nwautologin