~iahmad/+junk/libpam-freerdp.Name_with_spaces

« back to all changes in this revision

Viewing changes to src/pam-freerdp.c

  • Committer: Tarmac
  • Author(s): Ted Gould
  • Date: 2012-08-29 08:46:03 UTC
  • mfrom: (22.3.1 alloc-trick)
  • Revision ID: tarmac-20120829084603-xp0lzx25hf2xshfo
Change internal API to do less memory allocation.. Approved by Albert Astals Cid, jenkins.

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
        if (type != PAM_TYPE_DOMAIN) {
51
51
                char * value = NULL;
52
52
                if (pam_get_item(pamh, type, (const void **)&value) == PAM_SUCCESS && value != NULL) {
53
 
                        return strdup(value);
 
53
                        return value;
54
54
                }
55
55
                if (type == PAM_AUTHTOK && global_password != NULL) {
56
 
                        return strdup(global_password);
 
56
                        return global_password;
57
57
                }
58
58
        } else {
59
59
                if (global_domain != NULL) {
60
 
                        return strdup(global_domain);
 
60
                        return global_domain;
61
61
                }
62
62
        }
63
63
        /* Now we need to prompt */
100
100
                return NULL;
101
101
        }
102
102
 
103
 
        char * retval = responses->resp;
 
103
        char * promptval = responses->resp;
104
104
        free(responses);
105
105
 
106
106
        if (type == PAM_RHOST) {
107
 
                char * subloc = strstr(retval, "://");
 
107
                char * subloc = strstr(promptval, "://");
108
108
                if (subloc != NULL) {
109
 
                        char * original = retval;
 
109
                        char * original = promptval;
110
110
                        char * newish = subloc + strlen("://");
111
111
                        char * endslash = strstr(newish, "/");
112
112
 
114
114
                                endslash[0] = '\0';
115
115
                        }
116
116
 
117
 
                        retval = strdup(newish);
 
117
                        promptval = strdup(newish);
118
118
                        free(original);
119
119
                }
120
120
        }
121
121
 
122
 
        if (retval != NULL) { /* Can't believe it really would be at this point, but let's be sure */
 
122
        char * retval = NULL;
 
123
        if (promptval != NULL) { /* Can't believe it really would be at this point, but let's be sure */
123
124
                if (type != PAM_TYPE_DOMAIN) {
124
 
                        pam_set_item(pamh, type, (const void *)retval);
 
125
                        pam_set_item(pamh, type, (const void *)promptval);
 
126
                        /* We're returning the value saved by PAM so we can clear promptval */
 
127
                        pam_get_item(pamh, type, (const void **)&retval);
125
128
                } else {
126
129
                        if (global_domain != NULL) {
127
130
                                free(global_domain);
128
131
                        }
129
 
                        global_domain = strdup(retval);
 
132
                        global_domain = strdup(promptval);
 
133
                        retval = global_domain;
130
134
                }
131
135
                if (type == PAM_AUTHTOK) {
132
136
                        if (global_password != NULL) {
134
138
                                munlock(global_password, strlen(global_password));
135
139
                                free(global_password);
136
140
                        }
137
 
                        global_password = strdup(retval);
 
141
                        global_password = strdup(promptval);
138
142
                        mlock(global_password, strlen(global_password));
 
143
                        retval = global_password;
139
144
                }
 
145
 
 
146
                free(promptval);
140
147
        }
141
148
 
142
149
        return retval;
227
234
        }
228
235
        }
229
236
 
230
 
        /* Free Memory and return our status */
 
237
        /* Return our status */
231
238
done:
232
 
        if (username != NULL) { free(username); }
233
 
        if (password != NULL) { free(password); }
234
 
        if (ruser != NULL)    { free(ruser); }
235
 
        if (rhost != NULL)    { free(rhost); }
236
 
        if (rdomain != NULL)  { free(rdomain); }
237
 
 
238
239
        return retval;
239
240
}
240
241
 
365
366
        free(buffer);
366
367
 
367
368
done:
368
 
        if (username != NULL) { free(username); }
369
 
        if (password != NULL) { free(password); }
370
 
        if (ruser != NULL)    { free(ruser); }
371
 
        if (rhost != NULL)    { free(rhost); }
372
 
        if (rdomain != NULL)  { free(rdomain); }
373
 
 
374
369
    return retval;
375
370
}
376
371