Bug 130518. Throw INVALID PARAMETER exception on null and empty strings

This commit is contained in:
Jim Norman 2005-10-31 20:26:21 +00:00
parent 4df26f8574
commit 16eff73590
3 changed files with 389 additions and 329 deletions

View File

@ -35,7 +35,7 @@ namespace Novell.CASA
{ {
public uint pwordType; public uint pwordType;
public uint pwordLen; // * enhanced protection len & pword to set public uint pwordLen; // * enhanced protection len & pword to set
// [MarshalAs(UnmanagedType.LPStr, SizeConst = 128)] // [MarshalAs(UnmanagedType.LPStr, SizeConst = 128)]
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string pword; // * should be passed in # of chars public string pword; // * should be passed in # of chars
} ; } ;
@ -166,7 +166,7 @@ namespace Novell.CASA
public string hint; //[NSSS_MAX_MP_PWORD_HINT_LEN]]; public string hint; //[NSSS_MAX_MP_PWORD_HINT_LEN]];
}; };
/* /*
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class SSCS_BASIC_CREDENTIAL public class SSCS_BASIC_CREDENTIAL
{ {
@ -178,7 +178,7 @@ namespace Novell.CASA
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string password; public string password;
} }
*/ */
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class SSCS_BASIC_CREDENTIAL_UTF8 public class SSCS_BASIC_CREDENTIAL_UTF8
{ {
@ -465,6 +465,12 @@ namespace Novell.CASA
// Methods start here // Methods start here
internal IntPtr openSecretStore(string sSecretStoreName) internal IntPtr openSecretStore(string sSecretStoreName)
{ {
//check params
if (sSecretStoreName == null || sSecretStoreName.Length==0)
throw new miCasaException(miCasaException.NSSCS_E_INVALID_PARAM);
SSCS_SECRET_STORE_ID_T SSid = new SSCS_SECRET_STORE_ID_T(); SSCS_SECRET_STORE_ID_T SSid = new SSCS_SECRET_STORE_ID_T();
SSid.id = sSecretStoreName; SSid.id = sSecretStoreName;
SSid.len = sSecretStoreName.Length; SSid.len = sSecretStoreName.Length;
@ -488,8 +494,12 @@ namespace Novell.CASA
string sSharedSecretID, string sSharedSecretID,
int iSecretType, int iSecretType,
string sEPPassword) string sEPPassword)
{ {
if (pHsc == IntPtr.Zero || sKeyChainID == null || sSharedSecretID == null
|| sKeyChainID.Length == 0 || sSharedSecretID.Length == 0)
throw new miCasaException(miCasaException.NSSCS_E_INVALID_PARAM);
// setup structures // setup structures
SSCS_KEYCHAIN_ID_T keyChainID = new SSCS_KEYCHAIN_ID_T(); SSCS_KEYCHAIN_ID_T keyChainID = new SSCS_KEYCHAIN_ID_T();
keyChainID.keychainID = sKeyChainID; keyChainID.keychainID = sKeyChainID;
@ -610,7 +620,7 @@ namespace Novell.CASA
return rcode; return rcode;
} }
/* /*
internal int setSecret( internal int setSecret(
IntPtr pHsc, IntPtr pHsc,
string sKeyChainID, string sKeyChainID,
@ -705,7 +715,7 @@ namespace Novell.CASA
Marshal.FreeHGlobal(ext.ext); Marshal.FreeHGlobal(ext.ext);
return rcode; return rcode;
} }
*/ */
internal bool KeyInNewList(NameValueCollection nvc, string key) internal bool KeyInNewList(NameValueCollection nvc, string key)
{ {
@ -720,7 +730,7 @@ namespace Novell.CASA
return true; return true;
} }
} }
Console.WriteLine("key = " + key + " is not present in nvc"); //Console.WriteLine("key = " + key + " is not present in nvc");
return false; return false;
} }
@ -734,6 +744,8 @@ namespace Novell.CASA
{ {
int rcode = 0; int rcode = 0;
if (sKeyChainID == null || sKeyChainID.Length == 0)
throw new miCasaException(miCasaException.NSSCS_E_INVALID_PARAM);
// now call miCASAWriteSecret // now call miCASAWriteSecret
SSCS_KEYCHAIN_ID_T keyChainID = new SSCS_KEYCHAIN_ID_T(); SSCS_KEYCHAIN_ID_T keyChainID = new SSCS_KEYCHAIN_ID_T();
@ -862,6 +874,11 @@ namespace Novell.CASA
string sSecretID, string sSecretID,
int iSecretType) int iSecretType)
{ {
if (context == IntPtr.Zero || sKeyChainID == null || sSecretID == null
|| sKeyChainID.Length==0 || sSecretID.Length==0)
return miCasaException.NSSCS_E_INVALID_PARAM;
int rcode = 0; int rcode = 0;
SSCS_KEYCHAIN_ID_T keyChainID = new SSCS_KEYCHAIN_ID_T(); SSCS_KEYCHAIN_ID_T keyChainID = new SSCS_KEYCHAIN_ID_T();
@ -903,6 +920,11 @@ namespace Novell.CASA
{ {
if (context == IntPtr.Zero || sKeyChainID==null || sSearchKey==null
|| sKeyChainID.Length==0)
throw new miCasaException(miCasaException.NSSCS_E_INVALID_PARAM);
// setup structures // setup structures
SSCS_KEYCHAIN_ID_T keyChainID = new SSCS_KEYCHAIN_ID_T(); SSCS_KEYCHAIN_ID_T keyChainID = new SSCS_KEYCHAIN_ID_T();
keyChainID.keychainID = sKeyChainID; keyChainID.keychainID = sKeyChainID;
@ -923,7 +945,7 @@ namespace Novell.CASA
idList.returnedIDs = (uint)numIDS; idList.returnedIDs = (uint)numIDS;
SSCS_SH_SECRET_ID_T secretId = new SSCS_SH_SECRET_ID_T(); SSCS_SH_SECRET_ID_T secretId = new SSCS_SH_SECRET_ID_T();
// secretId.name = new char[512]; // secretId.name = new char[512];
StringBuilder buffer3 = new StringBuilder( "content", 512 ); StringBuilder buffer3 = new StringBuilder( "content", 512 );
buffer3.Append( (char)0 ); buffer3.Append( (char)0 );
@ -953,7 +975,7 @@ namespace Novell.CASA
IntPtr temp = new IntPtr(idList.secretIDList.ToInt32() + (i * Marshal.SizeOf(secretId))); IntPtr temp = new IntPtr(idList.secretIDList.ToInt32() + (i * Marshal.SizeOf(secretId)));
secretId = (SSCS_SH_SECRET_ID_T)Marshal.PtrToStructure(temp, typeof(SSCS_SH_SECRET_ID_T)); secretId = (SSCS_SH_SECRET_ID_T)Marshal.PtrToStructure(temp, typeof(SSCS_SH_SECRET_ID_T));
// String st = new String(secretId.name,0,secretId.len - 1); // String st = new String(secretId.name,0,secretId.len - 1);
String st = secretId.name; String st = secretId.name;
sc.Add(st); sc.Add(st);
} }
@ -969,6 +991,10 @@ namespace Novell.CASA
uint ssFlags, uint ssFlags,
string sKeyChainID) string sKeyChainID)
{ {
if (context==IntPtr.Zero || sKeyChainID==null || sKeyChainID.Length==0)
throw new miCasaException(miCasaException.NSSCS_E_INVALID_PARAM);
SSCS_KEYCHAIN_ID_T keyChainID = new SSCS_KEYCHAIN_ID_T(); SSCS_KEYCHAIN_ID_T keyChainID = new SSCS_KEYCHAIN_ID_T();
keyChainID.keychainID = sKeyChainID; keyChainID.keychainID = sKeyChainID;
keyChainID.len = sKeyChainID.Length + 1; keyChainID.len = sKeyChainID.Length + 1;
@ -985,6 +1011,9 @@ namespace Novell.CASA
uint unFlag) uint unFlag)
{ {
if (sAppSecretID==null || sAppSecretID.Length == 0)
throw new miCasaException(miCasaException.NSSCS_E_INVALID_PARAM);
int rcode; int rcode;
BasicCredential bc = null; BasicCredential bc = null;
@ -1044,6 +1073,11 @@ namespace Novell.CASA
string sUsername, string sUsername,
string sPassword) string sPassword)
{ {
if (sAppSecretID==null || sUsername==null || sPassword==null
|| sAppSecretID.Length==0 || sUsername.Length==0 || sPassword.Length==0)
throw new miCasaException(miCasaException.NSSCS_E_INVALID_PARAM);
int rcode; int rcode;
SSCS_SECRET_ID_T appSecretID = new SSCS_SECRET_ID_T(); SSCS_SECRET_ID_T appSecretID = new SSCS_SECRET_ID_T();
@ -1092,6 +1126,9 @@ namespace Novell.CASA
string sSharedSecretID) string sSharedSecretID)
{ {
if (sAppSecretID == null || sAppSecretID.Length==0)
throw new miCasaException(miCasaException.NSSCS_E_INVALID_PARAM);
int rcode; int rcode;
SSCS_SECRET_ID_T appSecretID = new SSCS_SECRET_ID_T(); SSCS_SECRET_ID_T appSecretID = new SSCS_SECRET_ID_T();
appSecretID.id = sAppSecretID; appSecretID.id = sAppSecretID;
@ -1113,10 +1150,14 @@ namespace Novell.CASA
} }
public static int SetMasterPasscode( internal static int SetMasterPasscode(
uint ssFlags, uint ssFlags,
string passcodeStr) string passcodeStr)
{ {
if (passcodeStr==null || passcodeStr.Length==0)
throw new miCasaException(miCasaException.NSSCS_E_INVALID_PARAM);
int rcode = -1; int rcode = -1;
try try
{ {
@ -1124,10 +1165,10 @@ namespace Novell.CASA
SSCS_PASSWORD_T passwd = new SSCS_PASSWORD_T(); SSCS_PASSWORD_T passwd = new SSCS_PASSWORD_T();
passwd.pwordType = 1; passwd.pwordType = 1;
/* UTF8 ?? /* UTF8 ??
passwd.pword = GetUTF8FromString(passcodeStr,PASSWORD_LEN); passwd.pword = GetUTF8FromString(passcodeStr,PASSWORD_LEN);
passwd.pwordLen = GetUTF8ByteCount(passcodeStr); passwd.pwordLen = GetUTF8ByteCount(passcodeStr);
*/ */
passwd.pword = passcodeStr; passwd.pword = passcodeStr;
passwd.pwordLen = (uint)passcodeStr.Length; passwd.pwordLen = (uint)passcodeStr.Length;
@ -1151,6 +1192,10 @@ namespace Novell.CASA
uint ssFlags, uint ssFlags,
string mPasswd) string mPasswd)
{ {
if (mPasswd==null || mPasswd.Length==0)
return 1;
int rcode = -1; int rcode = -1;
try try
{ {
@ -1166,7 +1211,7 @@ namespace Novell.CASA
null, null,
new SSCS_EXT_T()); new SSCS_EXT_T());
} }
catch(Exception e) catch(Exception)
{ {
//Console.WriteLine(e.ToString()); //Console.WriteLine(e.ToString());
} }
@ -1175,7 +1220,9 @@ namespace Novell.CASA
public static bool IsSecretPersistent(uint ssFlags, string id) public static bool IsSecretPersistent(uint ssFlags, string id)
{ {
int rcode; int rcode = 0;
if (null != id && "" !=id)
{
SSCS_SECRET_ID_T secretID = new SSCS_SECRET_ID_T(); SSCS_SECRET_ID_T secretID = new SSCS_SECRET_ID_T();
if(ssFlags == 0) if(ssFlags == 0)
{ {
@ -1191,6 +1238,8 @@ namespace Novell.CASA
null, null,
new SSCS_EXT_T()); new SSCS_EXT_T());
} }
}
if(rcode == 1) if(rcode == 1)
return true; return true;
else else
@ -1234,6 +1283,9 @@ namespace Novell.CASA
string secretID, string secretID,
string keyID) string keyID)
{ {
if (sKeyChainID==null || secretID==null || keyID==null
|| sKeyChainID.Length==0 || secretID.Length==0 || keyID.Length==0)
throw new miCasaException(miCasaException.NSSCS_E_INVALID_PARAM);
int rcode = 0; int rcode = 0;
@ -1257,6 +1309,10 @@ namespace Novell.CASA
string sKeyChainID, string sKeyChainID,
string secretID) string secretID)
{ {
if (sKeyChainID==null || secretID==null
|| sKeyChainID.Length==0 || secretID.Length==0)
throw new miCasaException(miCasaException.NSSCS_E_INVALID_PARAM);
ArrayList keyList = null; ArrayList keyList = null;
try try
{ {
@ -1291,6 +1347,9 @@ namespace Novell.CASA
string secretID, string secretID,
string keyID) string keyID)
{ {
if (sKeyChainID==null || secretID==null || keyID==null
|| sKeyChainID.Length==0 || secretID.Length==0 || keyID.Length==0)
throw new miCasaException(miCasaException.NSSCS_E_INVALID_PARAM);
int rcode = 0; int rcode = 0;
string value = null; string value = null;
@ -1305,7 +1364,7 @@ namespace Novell.CASA
} }
catch (Exception e) catch (Exception e)
{ {
// rcode = -803; // rcode = -803;
Console.WriteLine(e.ToString()); Console.WriteLine(e.ToString());
} }
} }
@ -1314,6 +1373,9 @@ namespace Novell.CASA
private string EscapeReservedChars(string origString) private string EscapeReservedChars(string origString)
{ {
if (origString==null)
return origString;
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (int i=0; i<origString.Length; i++) for (int i=0; i<origString.Length; i++)
{ {

View File

@ -58,7 +58,6 @@ namespace Novell.CASA
} }
public static BasicCredential GetBasicCredential( public static BasicCredential GetBasicCredential(
string sAppSecretID, string sAppSecretID,
string sSharedSecretID) string sSharedSecretID)
@ -102,20 +101,14 @@ namespace Novell.CASA
{ {
NativeCalls.RemoveCredential(ssFlags, sAppSecretID, sSharedSecretID); NativeCalls.RemoveCredential(ssFlags, sAppSecretID, sSharedSecretID);
} }
/*
internal static int SetMasterPasscode(
uint ssFlags,
string passcodeStr)
{
return NativeCalls.SetMasterPasscode(ssFlags,passcodeStr);
}
*/
public static int SetMasterPassword( public static int SetMasterPassword(
uint ssFlags, uint ssFlags,
string mPasswd) string mPasswd)
{ {
return NativeCalls.SetMasterPassword(ssFlags,mPasswd); return NativeCalls.SetMasterPassword(ssFlags,mPasswd);
} }
public static bool IsSecretPersistent( public static bool IsSecretPersistent(
uint ssFlags, uint ssFlags,
string secretID) string secretID)

View File

@ -319,6 +319,11 @@ namespace Novell.CASA
return getMessage(m_iException); return getMessage(m_iException);
} }
public int getErrorCode()
{
return m_iException;
}
public string getMessage(int iException) public string getMessage(int iException)
{ {
switch (iException) switch (iException)