s4:dsdb/common: add samdb_domain_guid() helper function
[samba.git] / nsswitch / winbind_nss_aix.c
index 17578cf3501ad2b79206e0003a52f41748338dc1..dc44db40ef96127a2f8863a60b7a516de5f74a40 100644 (file)
@@ -85,13 +85,15 @@ static void logit(const char *format, ...)
 #define STRCPY_RET(dest, src) \
 do { \
        if (strlen(src)+1 > sizeof(dest)) { errno = EINVAL; return -1; } \
-       strcpy(dest, src); \
+       strncpy(dest, src, sizeof(dest)); \
+       dest[sizeof(dest)-1] = '\0'; \
 } while (0)
 
 #define STRCPY_RETNULL(dest, src) \
 do { \
        if (strlen(src)+1 > sizeof(dest)) { errno = EINVAL; return NULL; } \
-       strcpy(dest, src); \
+       strncpy(dest, src, sizeof(dest)); \
+       dest[sizeof(dest)-1] = '\0'; \
 } while (0)
 
 
@@ -237,6 +239,9 @@ static struct group *fill_grent(struct winbindd_gr *gr, char *gr_mem)
 
        result->gr_mem = (char **)malloc(sizeof(char *) * (gr->num_gr_mem+1));
        if (!result->gr_mem) {
+               free(result->gr_name);
+               free(result->gr_passwd);
+               free(result);
                errno = ENOMEM;
                return NULL;
        }
@@ -276,7 +281,8 @@ static struct group *wb_aix_getgrgid(gid_t gid)
 
        request.data.gid = gid;
 
-       ret = winbindd_request_response(WINBINDD_GETGRGID, &request, &response);
+       ret = winbindd_request_response(NULL, WINBINDD_GETGRGID,
+                                       &request, &response);
 
        logit("getgrgid ret=%d\n", ret);
 
@@ -308,7 +314,8 @@ static struct group *wb_aix_getgrnam(const char *name)
 
        STRCPY_RETNULL(request.data.groupname, name);
 
-       ret = winbindd_request_response(WINBINDD_GETGRNAM, &request, &response);
+       ret = winbindd_request_response(NULL, WINBINDD_GETGRNAM,
+                                       &request, &response);
 
        HANDLE_ERRORS(ret);
 
@@ -367,7 +374,8 @@ static char *wb_aix_getgrset(char *user)
                free(r_user);
        }
 
-       ret = winbindd_request_response(WINBINDD_GETGROUPS, &request, &response);
+       ret = winbindd_request_response(NULL, WINBINDD_GETGROUPS,
+                                       &request, &response);
 
        HANDLE_ERRORS(ret);
 
@@ -406,7 +414,8 @@ static struct passwd *wb_aix_getpwuid(uid_t uid)
 
        request.data.uid = uid;
 
-       ret = winbindd_request_response(WINBINDD_GETPWUID, &request, &response);
+       ret = winbindd_request_response(NULL, WINBINDD_GETPWUID,
+                                       &request, &response);
 
        HANDLE_ERRORS(ret);
 
@@ -439,7 +448,8 @@ static struct passwd *wb_aix_getpwnam(const char *name)
 
        STRCPY_RETNULL(request.data.username, name);
 
-       ret = winbindd_request_response(WINBINDD_GETPWNAM, &request, &response);
+       ret = winbindd_request_response(NULL, WINBINDD_GETPWNAM,
+                                       &request, &response);
 
        HANDLE_ERRORS(ret);
 
@@ -472,7 +482,8 @@ static int wb_aix_lsuser(char *attributes[], attrval_t results[], int size)
        ZERO_STRUCT(request);
        ZERO_STRUCT(response);
 
-       ret = winbindd_request_response(WINBINDD_LIST_USERS, &request, &response);
+       ret = winbindd_request_response(NULL, WINBINDD_LIST_USERS,
+                                       &request, &response);
        if (ret != 0) {
                errno = EINVAL;
                return -1;
@@ -520,7 +531,8 @@ static int wb_aix_lsgroup(char *attributes[], attrval_t results[], int size)
        ZERO_STRUCT(request);
        ZERO_STRUCT(response);
 
-       ret = winbindd_request_response(WINBINDD_LIST_GROUPS, &request, &response);
+       ret = winbindd_request_response(NULL, WINBINDD_LIST_GROUPS,
+                                       &request, &response);
        if (ret != 0) {
                errno = EINVAL;
                return -1;
@@ -568,18 +580,21 @@ static attrval_t pwd_to_groupsids(struct passwd *pwd)
 {
        attrval_t r;
        char *s, *p;
+       size_t mlen;
 
        if ( (s = wb_aix_getgrset(pwd->pw_name)) == NULL ) {
                r.attr_flag = EINVAL;
                return r;
        }
 
-       if ( (p = malloc(strlen(s)+2)) == NULL ) {
+       mlen = strlen(s)+2;
+       if ( (p = malloc(mlen)) == NULL ) {
                r.attr_flag = ENOMEM;
                return r;
        }
 
-       strcpy(p, s);
+       strncpy(p, s, mlen);
+       p[mlen-1] = '\0';
        replace_commas(p);
        free(s);
 
@@ -599,13 +614,25 @@ static attrval_t pwd_to_sid(struct passwd *pwd)
 
        request.data.uid = pwd->pw_uid;
 
-       if (winbindd_request_response(WINBINDD_UID_TO_SID, &request, &response) !=
+#if 0
+       /*
+        * Removed because WINBINDD_UID_TO_SID is replaced by
+        * WINBINDD_XIDS_TO_SIDS. I don't have an AIX build
+        * environment around, so I did not convert this call. If
+        * someone stumbles over this, please contact me:
+        * vl@samba.org, I'll convert this.
+        */
+       if (winbindd_request_response(NULL, WINBINDD_UID_TO_SID,
+                                     &request, &response) !=
            NSS_STATUS_SUCCESS) {
                r.attr_flag = ENOENT;
        } else {
                r.attr_flag = 0;
                r.attr_un.au_char = strdup(response.data.sid.sid);
        }
+#else
+       r.attr_flag = ENOENT;
+#endif
 
        return r;
 }
@@ -833,7 +860,8 @@ static int wb_aix_normalize(char *longname, char *shortname)
        /* automatically cope with AIX 5.3 with longer usernames
           when it comes out */
        if (S_NAMELEN > strlen(longname)) {
-               strcpy(shortname, longname);
+               strncpy(shortname, longname, S_NAMELEN);
+               shortname[S_NAMELEN-1] = '\0';
                return 1;
        }
 
@@ -885,7 +913,8 @@ static int wb_aix_authenticate(char *user, char *pass,
                free(r_user);
        }
 
-       result = winbindd_request_response(WINBINDD_PAM_AUTH, &request, &response);
+       result = winbindd_request_response(NULL, WINBINDD_PAM_AUTH,
+                                          &request, &response);
 
        winbindd_free_response(&response);
 
@@ -934,7 +963,8 @@ static int wb_aix_chpass(char *user, char *oldpass, char *newpass, char **messag
                free(r_user);
        }
 
-       result = winbindd_request_response(WINBINDD_PAM_CHAUTHTOK, &request, &response);
+       result = winbindd_request_response(NULL, WINBINDD_PAM_CHAUTHTOK,
+                                          &request, &response);
 
        winbindd_free_response(&response);