|
|
@@ -1828,40 +1828,32 @@ void* ntp_thread(void *arg)
|
|
|
|
|
|
int snmp_config(SNMPManager *m)
|
|
|
{
|
|
|
- char *pass_tok="createUser";
|
|
|
- char *pass_conf="/var/net-snmp/snmpd.conf";
|
|
|
- char *user_tok="rouser";
|
|
|
- char *user_conf="/root/run/app/snmp/conf/snmpd.conf";
|
|
|
+ char *path_conf="/root/run/app/snmp/conf/snmpd.conf";
|
|
|
+ //char *path_conf="/root/snmpd.conf";
|
|
|
char user[100],pass[200],cmd[400];
|
|
|
-return 0;
|
|
|
+
|
|
|
if(strlen(m->crypt.auth.alg)<=1) {
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
- sprintf(user, "%s %s", user_tok, m->crypt.user);
|
|
|
- sprintf(pass, "%s %s \"%s\"", pass_tok, m->crypt.auth.alg, m->crypt.auth.passwd);
|
|
|
- if(strlen(m->crypt.priv.alg)>1) {
|
|
|
- sprintf(cmd, " %s \"%s\"", m->crypt.priv.alg, m->crypt.priv.passwd);
|
|
|
- strcat(pass, cmd);
|
|
|
- }
|
|
|
-
|
|
|
- snprintf(cmd, sizeof(cmd), "sed -i '/^%s/ { s/%s.*/%s/; t; a\\%s; }' %s", pass_tok, pass_tok, pass, pass, pass_conf);
|
|
|
- system(cmd);
|
|
|
-
|
|
|
- snprintf(cmd, sizeof(cmd), "sed -i '/^%s/ { s/%s.*/%s/; t; a\\%s; }' %s", user_tok, user_tok, user, user, user_conf);
|
|
|
- system(cmd);
|
|
|
-
|
|
|
- system("/etc/init.d/S90PDUApp stop snmpd");
|
|
|
- //snprintf(tmp, sizeof(tmp), "net-snmp-create-v3-user -ro -a -A <auth_password> -x <priv_protocol> -X <priv_password> usernmae");
|
|
|
+ //createUser afafafaf MD5 "md5123456" DES "des123456
|
|
|
|
|
|
-
|
|
|
- printf("___snmp: %s\n", cmd);
|
|
|
+ //delete
|
|
|
+ sprintf(cmd, "sed -e /^createUser.*$/d -e /^rouser.*$/d -i %s", path_conf);
|
|
|
system(cmd);
|
|
|
|
|
|
- system("/etc/init.d/S90PDUApp start snmpd");
|
|
|
+ if(m->version==2) {
|
|
|
+ sprintf(user, "rouser \"%s\"", m->crypt.user);
|
|
|
+ sprintf(pass, "createUser \"%s\" %s \"%s\"", m->crypt.user, m->crypt.auth.alg, m->crypt.auth.passwd);
|
|
|
+ if(strlen(m->crypt.priv.alg)>1) {
|
|
|
+ sprintf(cmd, " %s \"%s\"", m->crypt.priv.alg, m->crypt.priv.passwd);
|
|
|
+ strcat(pass, cmd);
|
|
|
+ }
|
|
|
|
|
|
- thread_stop(THREAD_ID_SNMP);
|
|
|
- thread_restart(THREAD_ID_SNMP);
|
|
|
+ sprintf(cmd, "sed -e \"$ a %s\" -e \"$ a %s\" -i %s", pass, user, path_conf);
|
|
|
+ system(cmd);
|
|
|
+ }
|
|
|
+ system("/etc/init.d/S90PDUApp restart snmpd");
|
|
|
|
|
|
return 0;
|
|
|
}
|