CASA/c_sharp/NSSCSWrapper/miCASA.cs

169 lines
4.2 KiB
C#

/***********************************************************************
*
* Copyright (C) 2005-2006 Novell, Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; version 2.1
* of the License.
*
* 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, Novell, Inc.
*
* To contact Novell about this file by physical or electronic mail,
* you may find current contact information at www.novell.com.
*
***********************************************************************/
using System;
using Novell.CASA;
namespace Novell.CASA
{
/// <summary>
/// Summary description for miCASA.
/// </summary>
public class miCASA
{
public static uint USERNAME_TYPE_CN_F = 0x00000000;
public static uint USERNAME_TYPE_NDS_DN_F = 0x00000001;
public static uint USERNAME_TYPE_NDS_FDN_F = 0x00000002;
public static uint USERNAME_TYPE_LDAP_DN_F = 0x00000004;
public static uint USERNAME_TYPE_EMAIL_F = 0x00000008;
public static uint USERNAME_TYPE_OTHER_F = 0x00000010;
public miCASA()
{
//
// TODO: Add constructor logic here
//
}
public static void SetBasicCredential(
string sAppSecretID,
string sSharedSecretID,
string sUsername,
string sPassword)
{
SetCredential(0, sAppSecretID, sSharedSecretID, 0, sUsername, sPassword);
}
public static string GetCredentialUsername(
string sAppSecretID,
string sSharedSecretID)
{
BasicCredential bc = GetBasicCredential(sAppSecretID, sSharedSecretID);
if (bc != null)
return bc.GetUsername();
else
return null;
}
public static string GetCredentialPassword(
string sAppSecretID,
string sSharedSecretID)
{
BasicCredential bc = GetBasicCredential(sAppSecretID, sSharedSecretID);
if (bc != null)
return bc.GetPassword();
else
return null;
}
public static BasicCredential GetBasicCredential(
string sAppSecretID,
string sSharedSecretID)
{
return GetCredential(0, sAppSecretID, sSharedSecretID, miCASA.USERNAME_TYPE_CN_F);
}
public static void RemoveBasicCredential(
string sAppSecretID,
string sSharedSecretID)
{
RemoveCredential(0, sAppSecretID, sSharedSecretID);
}
public static void SetCredential(
uint ssFlags,
string sAppSecretID,
string sSharedSecretID,
uint unFlag,
string sUsername,
string sPassword)
{
NativeCalls.SetCredential(ssFlags, sAppSecretID, sSharedSecretID, unFlag, sUsername, sPassword);
}
public static BasicCredential GetCredential(
uint ssFlags,
string sAppSecretID,
string sSharedSecretID,
uint unFlag)
{
return NativeCalls.GetCredential(ssFlags, sAppSecretID, sSharedSecretID, unFlag);
}
public static void RemoveCredential(
uint ssFlags,
string sAppSecretID,
string sSharedSecretID)
{
NativeCalls.RemoveCredential(ssFlags, sAppSecretID, sSharedSecretID);
}
public static int SetMasterPassword(
uint ssFlags,
string mPasswd)
{
return NativeCalls.SetMasterPassword(ssFlags,mPasswd);
}
public static bool IsSecretPersistent(
uint ssFlags,
string secretID)
{
return NativeCalls.IsSecretPersistent(ssFlags,secretID);
}
public static bool ChangeMasterPassword(string sCurrentPassword, string sNewPassword)
{
if (sCurrentPassword == null || sNewPassword == null)
{
throw new miCasaException(miCasaException.NSSCS_E_INVALID_PARAM);
}
if (sNewPassword.Length < 8)
throw new miCasaException(miCasaException.NSSCS_E_MP_PWORD_NOT_ALLOWED);
return NativeCalls.ResetMasterPassword(sCurrentPassword, sNewPassword);
}
public static bool ValidateDesktopPwd(string sPassword)
{
if (sPassword != null)
{
return NativeCalls.ValidateDesktopPwd(sPassword);
}
else
{
return false;
}
}
}
}