-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvspasswd.cpp
183 lines (154 loc) · 4.26 KB
/
vspasswd.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include <sys/types.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <curses.h>
#include <menu.h>
#include <form.h>
#include <pwd.h>
#ifndef DB_ORACLE
#include "adabas.h"
#else
#include "oracle.h"
#endif
/*------------------------------------------------------------------------------*/
/* TOOL Functions */
/*------------------------------------------------------------------------------*/
int Copy(char* Source, char* Destination)
{
char Buffer[200];
sprintf(Buffer,"cp %s %s",Source,Destination);
return (system(Buffer) == 0);
}
/*-------------------------------------------------------------------------------------*/
int SetPassword(char* DBUserName, char* OldDBPassword, char* NewDBPassword,char* ShopName)
{
FILE* File1;
FILE* File2;
char Buffer[201];
char Line[501];
char NewPasswordLine[201];
char* Ptr;
EngineDB = new CEngineDB();
EngineDB->Connect("vshop",DBUserName, OldDBPassword,"");
sprintf(Buffer,"ALTER PASSWORD %s TO %s",OldDBPassword,NewDBPassword);
if (EngineDB->SQLUpdate(Buffer) == 0)
{
printf("Fehler beim Žndern des Passwortes in der Datenbank.\n");
return 6;
}
delete EngineDB;
sprintf(Buffer,"%s_DBPASSWORD",ShopName);
cryptpassword (&Ptr, NewDBPassword, "VSHOPDBPASSWORD");
sprintf(NewPasswordLine,"%s_DBPASSWORD %s",ShopName,Ptr);
Copy("/etc/vshop.conf", "/etc/vshop.conf.bak");
if ((File1 = fopen("/etc/vshop.conf.bak","r")) != NULL)
{
if ((File2 = fopen("/etc/vshop.conf","w+")) != NULL)
{
while (fgets(Line,500,File1) != NULL)
{
if (strncasecmp(Line,Buffer,strlen(Buffer)) == 0)
{
fputs(NewPasswordLine,File2);
fputs("\n",File2);
}
else
fputs(Line,File2);
}
fclose(File2);
}
else
printf("Fehler beim ™ffnen von /etc/vshop.conf.\n");
fclose(File1);
}
else
printf("Fehler beim ™ffnen von /etc/vshop.conf.bak.\n");
}
/*-------------------------------------------------------------------------------------*/
int main(int argc, char *argv[])
{
char* Ptr;
char ShopName[10];
int Counter;
char Buffer[256];
char DBPASSWORD[201];
char DBUSER[201];
char Arg1[51];
char Arg2[51];
if (argc <= 2)
{
printf("\nNicht genuegend Parameter !\n");
exit(1);
}
strcpy(Arg1,argv[1]);
strcpy(Arg2,argv[2]);
for (Counter = 0;Counter < (int) strlen(Arg1);Counter++)
if (((int) Arg1[Counter] > 96) && ((int) Arg1[Counter] < 123))
Arg1[Counter] -= 32;
for (Counter = 0;Counter < (int) strlen(Arg2);Counter++)
if (((int) Arg2[Counter] > 96) && ((int) Arg2[Counter] < 123))
Arg2[Counter] -= 32;
if ((Ptr = strrchr(argv[0],'/')) != NULL)
strcpy(ShopName,Ptr+1);
else
strcpy(ShopName,argv[0]);
ShopName[strlen(ShopName)-6] = '\0';
for (Counter = 0;Counter < (int) strlen(ShopName);Counter++)
if (((int) ShopName[Counter] > 96) && ((int) ShopName[Counter] < 123))
ShopName[Counter] -= 32;
OpenIniFile("/etc/vshop.conf");
if((Ptr = GetFirstParam("DBROOT")) != NULL)
{
setenv("DBROOT",Ptr,1);
}
else
{
printf("Parameter DBROOT in /etc/vshop.conf nicht gefunden.\n");
exit(2);
}
sprintf(Buffer,"%s_DBUSER",ShopName);
if((Ptr = GetFirstParam(Buffer)) != NULL)
{
strcpy(DBUSER,Ptr);
}
else
{
printf("Parameter %s_DBUSER in /etc/vshop.conf nicht gefunden.\n",ShopName);
exit(3);
}
sprintf(Buffer,"%s_DBPASSWORD",ShopName);
if((Ptr = GetFirstParam(Buffer)) != NULL)
{
strcpy(DBPASSWORD,Ptr);
}
else
{
printf("Parameter %s_DBPASSWORD in /etc/vshop.conf nicht gefunden.\n",ShopName);
exit(4);
}
CloseIniFile();
decryptpassword (&Ptr, DBPASSWORD, "VSHOPDBPASSWORD");
if (argc != 4)
{
if (strcmp(Ptr,Arg1) != 0)
{
printf("Das alte Password ist nicht korrekt.\n");
exit(5);
}
}
else
{
if (strcmp(DBPASSWORD,Arg1) != 0)
{
printf("Das alte Password ist nicht korrekt.\n");
exit(5);
}
}
if (argc != 4)
return SetPassword(DBUSER,Ptr,Arg2,ShopName);
else
return SetPassword(DBUSER,DBPASSWORD,Arg2,ShopName);
}