Insert or remove a USM user profile on the manager.
The list of users are persistent and will not be lost when the device is reset.
Input:
Index : SINT (1..25)
The index of the user.
User : snmpUser
The information about the user. See snmpUser.
Leave the username empty to remove a user.
Returns: INT
1
|
- Success.
|
0
|
- This function is not supported.
|
-2
|
- Illegal parameter
|
-4
|
- Another user with this name is already present.
|
Declaration
FUNCTION snmpUserSet : INT;
VAR_INPUT
index : MANDATORY SINT;
user : ACCESS snmpUser;
END_VAR;
Example:
INCLUDE rtcu.inc
VAR
user : snmpUser;
iface : SINT := 2;
END_VAR;
FUNCTION show_user
VAR_INPUT
index : SINT;
END_VAR;
VAR
str : STRING;
rc : INT;
END_VAR;
rc := snmpUserGet(index := index, user := user);
IF rc < 1 THEN
DebugFmt(message := " snmpUserGet=\1", v1 := rc);
RETURN;
END_IF;
DebugMsg(message := "--------------------------------------------------");
DebugFmt(message := "User \1:", v1 := index);
IF strLen(str := user.username) = 0 THEN
DebugMsg(message := " <EMPTY>");
ELSE
DebugMsg(message := " Name = " + user.username);
DebugMsg(message := " Password = " + user.password);
DebugMsg(message := " Encrypt key = " + user.cryptkey);
DebugMsg(message := " Engine ID = " + user.engineid);
CASE user.level OF
0: DebugMsg(message := " Level = None");
1: DebugMsg(message := " Level = Authenticate");
2: DebugMsg(message := " Level = Encrypt");
END_CASE;
IF user.authentication = _SNMP_USM_MD5 THEN
DebugMsg(message := " Authentication = MD5");
ELSE
DebugMsg(message := " Authentication = SHA");
END_IF;
IF user.encryption = _SNMP_USM_AES THEN
DebugMsg(message := " Encryption = AES");
ELSE
DebugMsg(message := " Encryption = DES");
END_IF;
END_IF;
END_FUNCTION;
PROGRAM example;
VAR
i : SINT;
rc : INT;
handle : SYSHANDLE;
END_VAR;
FOR i := 1 TO 10 DO
show_user(index := i);
END_FOR;
user.username := "Administrator";
user.password := "Pass phrase";
user.cryptkey := "Pass phrase";
user.engineid := "8000000001020304";
user.level := _SNMP_SEC_ENC;
user.authentication := _SNMP_USM_MD5;
user.encryption := _SNMP_USM_AES;
rc := snmpUserSet(index := 1, user := user);
IF rc < 1 THEN
DebugFmt(message := "snmpUserSet=\1", v1 := rc);
END_IF;
rc := netOpen(iface := iface);
DebugFmt(Message := "netOpen (rc=\1)", v1 := rc);
WHILE NOT netConnected(iface := iface) DO
Sleep(Delay := 2000);
END_WHILE;
rc := snmpStartListen(
handle := handle,
community := "public"
);
IF rc < 1 THEN
DebugFmt(message := "snmpStartListen=\1", v1 := rc);
END_IF;
rc := snmpRegisterTrap(oid := "1.3.6.1.4.1.6101.1.8.8.2.6");
IF rc < 1 THEN
DebugFmt(message := "snmpRegisterTrap=\1", v1 := rc);
END_IF;
BEGIN
END;
END_PROGRAM;
|