#include <stdio.h>
#include <grp.h>
#include <stdlib.h>
#include <project.h>
#include "getent.h"
static int
putprojent(const struct project *proj, FILE *fp)
{
char **names;
if (proj == NULL)
return (1);
if (fprintf(fp, "%s:%ld:%s:",
proj->pj_name != NULL ? proj->pj_name : "",
proj->pj_projid,
proj->pj_comment != NULL ? proj->pj_comment : "") == EOF)
return (1);
names = proj->pj_users;
if (names != NULL) {
if (*names != NULL)
if (fputs(*names++, fp) == EOF)
return (1);
while (*names != NULL)
if (fprintf(fp, ",%s", *names++) == EOF)
return (1);
}
if (putc(':', fp) == EOF)
return (1);
names = proj->pj_groups;
if (names != NULL) {
if (*names != NULL)
if (fputs(*names++, fp) == EOF)
return (1);
while (*names != NULL)
if (fprintf(fp, ",%s", *names++) == EOF)
return (1);
}
if (putc(':', fp) == EOF)
return (1);
if (fprintf(fp, "%s\n",
proj->pj_attr != NULL ? proj->pj_attr : "") == EOF)
return (1);
return (0);
}
int
dogetproject(const char **list)
{
struct project proj;
struct project *pproj;
projid_t projid;
void *buf[PROJECT_BUFSZ];
int rc = EXC_SUCCESS;
char *ptr;
if (list == NULL || *list == NULL) {
setprojent();
while ((pproj = getprojent(&proj, buf, PROJECT_BUFSZ)) != NULL)
(void) putprojent(pproj, stdout);
endprojent();
} else {
for (; *list != NULL; list++) {
projid = strtol(*list, &ptr, 10);
if (ptr == *list)
pproj = getprojbyname(*list, &proj,
buf, PROJECT_BUFSZ);
else
pproj = getprojbyid(projid, &proj,
buf, PROJECT_BUFSZ);
if (pproj == NULL)
rc = EXC_NAME_NOT_FOUND;
else
(void) putprojent(pproj, stdout);
}
}
return (rc);
}