#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)
/* take a group id and return a filled struct group */
static struct group *wb_aix_getgrgid(gid_t gid)
{
- struct winbindd_response response;
- struct winbindd_request request;
+ struct winbindd_request request = {
+ .wb_flags = WBFLAG_FROM_NSS,
+ };
+ struct winbindd_response response = {
+ .length = 0,
+ };
struct group *grp;
NSS_STATUS ret;
logit("getgrgid %d\n", gid);
- ZERO_STRUCT(response);
- ZERO_STRUCT(request);
-
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);
/* take a group name and return a filled struct group */
static struct group *wb_aix_getgrnam(const char *name)
{
- struct winbindd_response response;
- struct winbindd_request request;
+ struct winbindd_request request = {
+ .wb_flags = WBFLAG_FROM_NSS,
+ };
+ struct winbindd_response response = {
+ .length = 0,
+ };
NSS_STATUS ret;
struct group *grp;
logit("getgrnam '%s'\n", name);
- ZERO_STRUCT(response);
- ZERO_STRUCT(request);
-
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);
list of group id numbers to which the user belongs */
static char *wb_aix_getgrset(char *user)
{
- struct winbindd_response response;
- struct winbindd_request request;
+ struct winbindd_request request = {
+ .wb_flags = WBFLAG_FROM_NSS,
+ };
+ struct winbindd_response response = {
+ .length = 0,
+ };
NSS_STATUS ret;
int i, idx;
char *tmpbuf;
logit("getgrset '%s'\n", r_user);
- ZERO_STRUCT(response);
- ZERO_STRUCT(request);
-
STRCPY_RETNULL(request.data.username, r_user);
if (*user == WB_AIX_ENCODED) {
free(r_user);
}
- ret = winbindd_request_response(WINBINDD_GETGROUPS, &request, &response);
+ ret = winbindd_request_response(NULL, WINBINDD_GETGROUPS,
+ &request, &response);
HANDLE_ERRORS(ret);
/* take a uid and return a filled struct passwd */
static struct passwd *wb_aix_getpwuid(uid_t uid)
{
- struct winbindd_response response;
- struct winbindd_request request;
+ struct winbindd_request request = {
+ .wb_flags = WBFLAG_FROM_NSS,
+ };
+ struct winbindd_response response = {
+ .length = 0,
+ };
NSS_STATUS ret;
struct passwd *pwd;
logit("getpwuid '%d'\n", uid);
- ZERO_STRUCT(response);
- ZERO_STRUCT(request);
-
request.data.uid = uid;
- ret = winbindd_request_response(WINBINDD_GETPWUID, &request, &response);
+ ret = winbindd_request_response(NULL, WINBINDD_GETPWUID,
+ &request, &response);
HANDLE_ERRORS(ret);
/* take a username and return a filled struct passwd */
static struct passwd *wb_aix_getpwnam(const char *name)
{
- struct winbindd_response response;
- struct winbindd_request request;
+ struct winbindd_request request = {
+ .wb_flags = WBFLAG_FROM_NSS,
+ };
+ struct winbindd_response response = {
+ .length = 0,
+ };
NSS_STATUS ret;
struct passwd *pwd;
logit("getpwnam '%s'\n", name);
- ZERO_STRUCT(response);
- ZERO_STRUCT(request);
-
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);
static int wb_aix_lsuser(char *attributes[], attrval_t results[], int size)
{
NSS_STATUS ret;
- struct winbindd_request request;
- struct winbindd_response response;
+ struct winbindd_request request = {
+ .wb_flags = WBFLAG_FROM_NSS,
+ };
+ struct winbindd_response response = {
+ .length = 0,
+ };
int len;
char *s;
return -1;
}
- 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;
static int wb_aix_lsgroup(char *attributes[], attrval_t results[], int size)
{
NSS_STATUS ret;
- struct winbindd_request request;
- struct winbindd_response response;
+ struct winbindd_request request = {
+ .wb_flags = WBFLAG_FROM_NSS,
+ };
+ struct winbindd_response response = {
+ .length = 0,
+ };
int len;
char *s;
return -1;
}
- 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;
static attrval_t pwd_to_group(struct passwd *pwd)
{
- attrval_t r;
+ attrval_t r = {
+ .attr_flag = EINVAL,
+ };
struct group *grp = wb_aix_getgrgid(pwd->pw_gid);
- if (!grp) {
- r.attr_flag = EINVAL;
- } else {
+ if (grp != NULL) {
r.attr_flag = 0;
r.attr_un.au_char = strdup(grp->gr_name);
free_grp(grp);
static attrval_t pwd_to_groupsids(struct passwd *pwd)
{
- attrval_t r;
+ attrval_t r = {
+ .attr_flag = EINVAL,
+ };
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);
+ r.attr_flag = 0;
r.attr_un.au_char = p;
return r;
static attrval_t pwd_to_sid(struct passwd *pwd)
{
+ char buf[(1 /* U/G */ + 10 /* 2^32 */ + 1 /* \n */) + 1] = { 0, };
+ int len;
struct winbindd_request request;
struct winbindd_response response;
- attrval_t r;
+ NSS_STATUS result;
+ attrval_t r = {
+ .attr_flag = ENOENT,
+ };
- ZERO_STRUCT(request);
- ZERO_STRUCT(response);
+ len = snprintf(buf, sizeof(buf),
+ "U%"PRIu32"\n",
+ (uint32_t)pwd->pw_uid);
+ if (len >= sizeof(buf)) {
+ r = (attrval_t) {
+ .attr_flag = EINVAL,
+ };
+ return r;
+ }
- request.data.uid = pwd->pw_uid;
+ request = (struct winbindd_request) {
+ .wb_flags = WBFLAG_FROM_NSS,
+ .extra_data.data = buf,
+ .extra_len = strlen(buf)+1,
+ };
+ response = (struct winbindd_response) {
+ .length = 0,
+ };
- if (winbindd_request_response(WINBINDD_UID_TO_SID, &request, &response) !=
- NSS_STATUS_SUCCESS) {
- r.attr_flag = ENOENT;
- } else {
+ result = winbindd_request_response(NULL, WINBINDD_XIDS_TO_SIDS,
+ &request, &response);
+ if (result == NSS_STATUS_SUCCESS) {
r.attr_flag = 0;
r.attr_un.au_char = strdup(response.data.sid.sid);
}
}
for (i=0;i<size;i++) {
- results[i].attr_flag = 0;
+ results[i] = (attrval_t) {
+ .attr_flag = 0,
+ };
if (strcmp(attributes[i], S_ID) == 0) {
results[i].attr_un.au_int = pwd->pw_uid;
results[i] = pwd_to_group(pwd);
} else if (strcmp(attributes[i], S_GROUPS) == 0) {
results[i] = pwd_to_groupsids(pwd);
+ } else if (strcmp(attributes[i], S_GROUPSIDS) == 0) {
+ results[i] = pwd_to_groupsids(pwd);
} else if (strcmp(attributes[i], "SID") == 0) {
results[i] = pwd_to_sid(pwd);
} else {
{S_SHELL, AL_USERATTR, SEC_CHAR},
{S_PGRP, AL_USERATTR, SEC_CHAR},
{S_GROUPS, AL_USERATTR, SEC_LIST},
+ {S_GROUPSIDS, AL_USERATTR, SEC_LIST},
{"SID", AL_USERATTR, SEC_CHAR},
/* group attributes */
/* 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;
}
static int wb_aix_authenticate(char *user, char *pass,
int *reenter, char **message)
{
- struct winbindd_request request;
- struct winbindd_response response;
+ struct winbindd_request request = {
+ .wb_flags = WBFLAG_FROM_NSS,
+ };
+ struct winbindd_response response = {
+ .length = 0,
+ };
NSS_STATUS result;
char *r_user = user;
*message = NULL;
/* Send off request */
- ZERO_STRUCT(request);
- ZERO_STRUCT(response);
-
if (*user == WB_AIX_ENCODED) {
r_user = decode_user(r_user);
if (!r_user) {
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);
*/
static int wb_aix_chpass(char *user, char *oldpass, char *newpass, char **message)
{
- struct winbindd_request request;
- struct winbindd_response response;
+ struct winbindd_request request = {
+ .wb_flags = WBFLAG_FROM_NSS,
+ };
+ struct winbindd_response response = {
+ .length = 0,
+ };
NSS_STATUS result;
char *r_user = user;
*message = NULL;
/* Send off request */
- ZERO_STRUCT(request);
- ZERO_STRUCT(response);
-
STRCPY_RET(request.data.chauthtok.user, r_user);
STRCPY_RET(request.data.chauthtok.oldpass, oldpass);
STRCPY_RET(request.data.chauthtok.newpass, newpass);
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);