/* * Read the "fileList" which should be a file containing a list of filenames, and create an MprList of those filenames */ static int makeFileList(Mpr *mpr, MprList *files, char *fileList) { MprFile *file; char path[MPR_MAX_FNAME]; char *p; if ((file = mprOpen(mpr, fileList, O_RDONLY | O_TEXT, 0)) == NULL) { mprError(mpr, "Can't open file list %s", fileList); return MPR_ERR_CANT_OPEN; } while (mprGets(file, path, sizeof(path)) != NULL) { if ((p = strchr(path, '\n')) || (p = strchr(path, '\r'))) { *p = '\0'; } if (*path == '\0') { continue; } mprAddItem(files, mprStrdup(files, path)); } return 0; }
int maReadUserFile(MaServer *server, MaAuth *auth, char *path) { MprFile *file; char buf[MPR_MAX_STRING]; char *enabled, *user, *password, *realm, *tok, *cp; mprFree(auth->userFile); auth->userFile = mprStrdup(auth, path); if ((file = mprOpen(auth, path, O_RDONLY | O_TEXT, 0444)) == 0) { return MPR_ERR_CANT_OPEN; } while (mprGets(file, buf, sizeof(buf))) { enabled = mprStrTok(buf, " :\t", &tok); if (!enabled) { continue; } for (cp = enabled; isspace((int) *cp); cp++) { ; } if (*cp == '\0' || *cp == '#') { continue; } user = mprStrTok(0, ":", &tok); realm = mprStrTok(0, ":", &tok); password = mprStrTok(0, " \t\r\n", &tok); user = trimWhiteSpace(user); realm = trimWhiteSpace(realm); password = trimWhiteSpace(password); maAddUser(auth, realm, user, password, (*enabled == '0' ? 0 : 1)); } mprFree(file); maUpdateUserAcls(auth); return 0; }
int maReadGroupFile(MaServer *server, MaAuth *auth, char *path) { MprFile *file; MaAcl acl; char buf[MPR_MAX_STRING]; char *users, *group, *enabled, *aclSpec, *tok, *cp; mprFree(auth->groupFile); auth->groupFile = mprStrdup(server, path); if ((file = mprOpen(auth, path, O_RDONLY | O_TEXT, 0444)) == 0) { return MPR_ERR_CANT_OPEN; } while (mprGets(file, buf, sizeof(buf))) { enabled = mprStrTok(buf, " :\t", &tok); if (!enabled) { continue; } for (cp = enabled; isspace((int) *cp); cp++) { ; } if (*cp == '\0' || *cp == '#') { continue; } aclSpec = mprStrTok(0, " :\t", &tok); group = mprStrTok(0, " :\t", &tok); users = mprStrTok(0, "\r\n", &tok); acl = maParseAcl(auth, aclSpec); maAddGroup(auth, group, acl, (*enabled == '0') ? 0 : 1); maAddUsersToGroup(auth, group, users); } mprFree(file); maUpdateUserAcls(auth); return 0; }