Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports-kde
Path: blob/main/comms/aprsd/files/patch-src_validate.cpp
16461 views
1
--- src/validate.cpp.orig 2003-03-31 04:49:41 UTC
2
+++ src/validate.cpp
3
@@ -34,6 +34,10 @@
4
#include <iostream>
5
#include <strstream>
6
#include <iomanip>
7
+#include <netdb.h>
8
+#if (defined(__unix__) || defined(unix)) && !defined(USG)
9
+#include <sys/param.h>
10
+#endif
11
12
using namespace std;
13
14
@@ -47,11 +51,17 @@ struct user_info {
15
const string group;
16
};
17
#else
18
+#ifdef BSD
19
+#include <pwd.h>
20
+#include <grp.h>
21
+#define MAXGROUPSIZE 1024
22
+#else
23
#include <crypt.h>
24
#include <grp.h>
25
#include <pwd.h>
26
#include <shadow.h>
27
#endif
28
+#endif
29
30
#include "validate.h"
31
32
@@ -140,12 +150,21 @@ int checkSystemPass(const string szUser, const string
33
pam_end(pamh, PAM_SUCCESS);
34
return 0;
35
#else
36
+#ifdef BSD
37
passwd *ppw = NULL;
38
+ struct group *pgrp = NULL;
39
+ struct spwd *pspwd = NULL;
40
+ char *member = NULL;
41
+ struct group grp;
42
+ struct passwd pwd;
43
+#else
44
+ passwd *ppw = NULL;
45
group *pgrp = NULL;
46
spwd *pspwd = NULL;
47
char *member = NULL;
48
struct group grp;
49
struct passwd pwd;
50
+#endif
51
int i;
52
char salt[16];
53
int usrfound = 0 ;
54
@@ -158,7 +177,11 @@ int checkSystemPass(const string szUser, const string
55
#endif
56
57
58
+#ifdef BSD
59
+ size_t bufsize=MAXGROUPSIZE;
60
+#else
61
size_t bufsize = sysconf(_SC_GETGR_R_SIZE_MAX);
62
+#endif
63
char *buffer1 = new char[bufsize];
64
//Thread-Safe getgrnam()
65
getgrnam_r(szGroup.c_str(), /* Does group name szGroup exist? */
66
@@ -168,12 +191,14 @@ int checkSystemPass(const string szUser, const string
67
&pgrp);
68
69
if (pgrp == NULL) {
70
- delete buffer1;
71
+ delete[] buffer1;
72
return rc; /* return BADGROUP if not */
73
}
74
-
75
+#ifdef BSD
76
+ bufsize = MAXGROUPSIZE;
77
+#else
78
bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
79
-
80
+#endif
81
char *buffer2 = new char[bufsize];
82
//Thread-Safe getpwnam()
83
getpwnam_r(szUser.c_str(),
84
@@ -183,8 +208,8 @@ int checkSystemPass(const string szUser, const string
85
&ppw);
86
87
if (ppw == NULL){
88
- delete buffer2;
89
- delete buffer1;
90
+ delete[] buffer2;
91
+ delete[] buffer1;
92
return BADUSER ; /* return BADUSER if no such user */
93
}
94
95
@@ -200,8 +225,8 @@ int checkSystemPass(const string szUser, const string
96
}
97
98
if (usrfound == 0) {
99
- delete buffer1;
100
- delete buffer2;
101
+ delete[] buffer1;
102
+ delete[] buffer2;
103
return BADGROUP; /* return BADGROUP if user not in group */
104
}
105
106
@@ -214,6 +239,7 @@ int checkSystemPass(const string szUser, const string
107
108
pwLength = strlen(ppw->pw_passwd);
109
110
+#if 0
111
if (ppw->pw_passwd[0] != '$') {
112
/* DES salt */
113
strncpy(salt,ppw->pw_passwd,2);
114
@@ -230,15 +256,18 @@ int checkSystemPass(const string szUser, const string
115
salt[i++] = '$';
116
salt[i] = '\0';
117
}
118
+#endif
119
+
120
#ifdef DEBUG
121
cout << "salt=" << salt << endl;
122
#endif
123
124
- if (strcmp(crypt(szPass.c_str(), salt), ppw->pw_passwd) == 0 )
125
+ if (strcmp(crypt(szPass.c_str(), ppw->pw_passwd), ppw->pw_passwd) == 0 )
126
rc = 0;
127
else
128
rc = BADPASSWD;
129
130
+#ifndef BSD /* BSD passwords are always shadowed */
131
if ((rc == BADPASSWD) && (strcmp("x",ppw->pw_passwd) == 0)) {
132
#ifdef DEBUG
133
cout << "Shadow passwords enabled\n";
134
@@ -246,8 +275,8 @@ int checkSystemPass(const string szUser, const string
135
pspwd = getspnam(szUser.c_str()); //Get shadow password file data for user
136
if (pspwd == NULL) {
137
cout << "validate: Can't read shadowed password file. This program must run as root\n";
138
- delete buffer1;
139
- delete buffer2;
140
+ delete[] buffer1;
141
+ delete[] buffer2;
142
return MUSTRUNROOT;
143
}
144
pwLength = strlen(pspwd->sp_pwdp);
145
@@ -288,8 +317,9 @@ int checkSystemPass(const string szUser, const string
146
<< endl;
147
#endif
148
}
149
- delete buffer1;
150
- delete buffer2;
151
+#endif
152
+ delete[] buffer1;
153
+ delete[] buffer2;
154
return rc;
155
#endif
156
}
157
158