Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring #109

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
30 changes: 17 additions & 13 deletions auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,28 @@ struct auth_s *new_auth(void) {
if (tmp == NULL)
return NULL;

memset(tmp->user, 0, MINIBUF_SIZE);
memset(tmp->domain, 0, MINIBUF_SIZE);
memset(tmp->workstation, 0, MINIBUF_SIZE);
memset(tmp->passntlm2, 0, MINIBUF_SIZE);
memset(tmp->passnt, 0, MINIBUF_SIZE);
memset(tmp->passlm, 0, MINIBUF_SIZE);
return init_auth(tmp);
}

struct auth_s *init_auth(struct auth_s *creds) {
memset(creds->user, 0, MINIBUF_SIZE);
memset(creds->domain, 0, MINIBUF_SIZE);
memset(creds->workstation, 0, MINIBUF_SIZE);
memset(creds->passntlm2, 0, MINIBUF_SIZE);
memset(creds->passnt, 0, MINIBUF_SIZE);
memset(creds->passlm, 0, MINIBUF_SIZE);
#ifdef __CYGWIN__
memset(&tmp->sspi, 0, sizeof(struct sspi_handle));
memset(&creds->sspi, 0, sizeof(struct sspi_handle));
#endif
tmp->hashntlm2 = 1;
tmp->hashnt = 0;
tmp->hashlm = 0;
tmp->flags = 0;
creds->hashntlm2 = 1;
creds->hashnt = 0;
creds->hashlm = 0;
creds->flags = 0;
#if config_gss == 1
tmp->haskrb = 0;
creds->haskrb = 0;
#endif

return tmp;
return creds;
}

struct auth_s *copy_auth(struct auth_s *dst, const struct auth_s *src, int fullcopy) {
Expand Down
1 change: 1 addition & 0 deletions auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ struct auth_s {
* new_auth() is also just a convenience malloc/memset() wrapper
*/
extern struct auth_s *new_auth(void);
extern struct auth_s *init_auth(struct auth_s *creds);
extern struct auth_s *copy_auth(struct auth_s *dst, const struct auth_s *src, int fullcopy);
extern struct auth_s *dup_auth(const struct auth_s *creds, int fullcopy);
extern void dump_auth(const struct auth_s *creds);
Expand Down
8 changes: 5 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
*/
int debug = 0; /* all debug printf's and possibly external modules */

struct auth_s *g_creds = NULL; /* throughout the whole module */
struct auth_s g_creds_s;
struct auth_s *g_creds = &g_creds_s; /* throughout the whole module */

int quit = 0; /* sighandler() */
int ntlmbasic = 0; /* forward_request() */
Expand Down Expand Up @@ -735,7 +736,7 @@ int main(int argc, char **argv) {
char *pac_file;

pac_file = zmalloc(PATH_MAX);
g_creds = new_auth();

cuser = zmalloc(MINIBUF_SIZE);
cdomain = zmalloc(MINIBUF_SIZE);
cpassword = zmalloc(PASSWORD_BUFSIZE);
Expand All @@ -747,6 +748,8 @@ int main(int argc, char **argv) {
cuid = zmalloc(MINIBUF_SIZE);
cauth = zmalloc(MINIBUF_SIZE);

init_auth(g_creds);
jschwartzenberg marked this conversation as resolved.
Show resolved Hide resolved

int syslog_debug = 0;
openlog("cntlm", LOG_CONS | LOG_PERROR, LOG_DAEMON);

Expand Down Expand Up @@ -1844,7 +1847,6 @@ int main(int argc, char **argv) {
free(cuid);
free(cpidfile);
free(magic_detect);
free(g_creds);

parent_free();

Expand Down