You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

226 lines
10 KiB
C#

2 years ago
using System;
using System.Text;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace ocean
{
public enum EM_GROUP
{//权限类别
EUser_Level0 = 0, //未登录
EUser_Level1, //OP
EUser_Level2, //admin
EUser_Level3, //system
EUser_Level4, //root
};
public struct TUser
{//用户信息
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string name;
public uint group;
public uint limit;
};
public struct TUserLimit
{//用户权限
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string name;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string desc;
};
public class user
{
/****************************************************
*Function:
*Intput: NULL
*Output: NULL
*Return: 0,
******************************************************/
[DllImport(@"user.dll", EntryPoint = "user_init", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int init();
/****************************************************
*Function:
*Intput: NULL
*Output: NULL
*Return: 0,
******************************************************/
[DllImport(@"user.dll", EntryPoint = "user_deinit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int deinit();
/****************************************************
*Function: ,get_cur_limit
*Intput: lpUser
lpPwd
*Output: NULL
*Return: 0,
******************************************************/
[DllImport(@"user.dll", EntryPoint = "login", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int login(string lpUser, string lpPwd);
/****************************************************
*Function: 退
*Intput:
*Output: NULL
*Return: 0,
******************************************************/
[DllImport(@"user.dll", EntryPoint = "logout", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int logout();
/****************************************************
*Function: ,
*Intput: lpOldUser
lpNewUser
group admin/system
limit
*Output: NULL
*Return: 0,
******************************************************/
[DllImport(@"user.dll", EntryPoint = "change_user", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int update(string lpOldUser, string lpNewUser, uint group = 0, uint limit = 0);
/****************************************************
*Function:
*Intput: lpUser
lpOldPwd
lpNewPwd
*Output: NULL
*Return: 0,
******************************************************/
[DllImport(@"user.dll", EntryPoint = "change_pwd", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int change_pwd(string lpUser, string lpOldPwd, string lpNewPwd);
/****************************************************
*Function: ,
*Intput: lpUser
*Output: NULL
*Return: 0,
******************************************************/
[DllImport(@"user.dll", EntryPoint = "clear_pwd", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int clear_pwd(string lpUser);
/****************************************************
*Function:
*Intput: lpUser
lpPwd
group admin/system
limit
*Output: NULL
*Return: 0,
******************************************************/
[DllImport(@"user.dll", EntryPoint = "add_user", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int create(string lpUser, string lpPwd, uint group, uint limit);
/****************************************************
*Function:
*Intput: lpUser
*Output: NULL
*Return: 0,
******************************************************/
[DllImport(@"user.dll", EntryPoint = "del_user", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int remove(string lpUser);
/****************************************************
*Function:
*Intput: NULL
*Output: pszname
*Return: 0
******************************************************/
[DllImport(@"user.dll", EntryPoint = "get_cur_users", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int get_cur_users(StringBuilder pszname);
public static string cur_user()
{
StringBuilder pszname = new StringBuilder(32);
get_cur_users(pszname);
return pszname.ToString();
}
/****************************************************
*Function:
*Intput: NULL
*Output: NULL
*Return:
******************************************************/
[DllImport(@"user.dll", EntryPoint = "get_user_group", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern uint cur_group(uint lpuser = 0);
/****************************************************
*Function:
*Intput: NULL
*Output: NULL
*Return:
******************************************************/
[DllImport(@"user.dll", EntryPoint = "get_user_limit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern uint cur_limit(uint lpuser = 0);
/****************************************************
*Function:
*Intput: pstUser NULL
*Output: pstUser
*Return: 0, <0
******************************************************/
[DllImport(@"user.dll", EntryPoint = "get_user_list", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int get_user_list(IntPtr ptr);
public static int GetUserCount()
{
return get_user_list(IntPtr.Zero);
}
public static int GetAllUser(string []puser)
{
IntPtr ptr;
int len = 0;
int count = 0;
TUser info = new TUser();
count = get_user_list(IntPtr.Zero);
if (count > 0)
{
len = Marshal.SizeOf(info);
ptr = Marshal.AllocHGlobal(len * count);
get_user_list(ptr);
for (int i = 0; i < count; i++)
{
info = (TUser)Marshal.PtrToStructure(
ptr + len * i, typeof(TUser));
puser[i] = info.name;
}
Marshal.FreeHGlobal(ptr); //释放非托管内存
}
return count;
}
/****************************************************
*Function:
*Intput: pLimit
*Output: NULL
*Return: 10
******************************************************/
[DllImport(@"user.dll", EntryPoint = "chk_user_limit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int check(string pLimit, uint lpuser = 0);
/****************************************************
*Function: ,32
*Intput: index [0,32)
pszname
pszdesc
*Output: NULL
*Return: 0
*PS: 使chk_user_limit,
******************************************************/
[DllImport(@"user.dll", EntryPoint = "add_limit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int add_limit(string pLimit, string title);
/****************************************************
*Function:
*Intput: NULL
*Output: NULL
*Return: 0
******************************************************/
[DllImport(@"user.dll", EntryPoint = "del_last_limit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int del_limit();
}
}