static void externalAclHandleReply(void *data, char *reply) { externalAclState *state = data; externalAclState *next; int result = 0; char *status; char *token; char *value; char *t; char *user = NULL; char *error = NULL; external_acl_entry *entry = NULL; debug(82, 2) ("externalAclHandleReply: reply=\"%s\"\n", reply); if (reply) { status = strwordtok(reply, &t); if (status && strcmp(status, "OK") == 0) result = 1; while ((token = strwordtok(NULL, &t))) { value = strchr(token, '='); if (value) { *value++ = '\0'; /* terminate the token, and move up to the value */ if (strcmp(token, "user") == 0) user = value; else if (strcmp(token, "error") == 0) error = value; } } } dlinkDelete(&state->list, &state->def->queue); if (cbdataValid(state->def)) { if (reply) entry = external_acl_cache_add(state->def, state->key, result, user, error); else { external_acl_entry *oldentry = hash_lookup(state->def->cache, state->key); if (oldentry) external_acl_cache_delete(state->def, oldentry); } } do { cbdataUnlock(state->def); state->def = NULL; if (cbdataValid(state->callback_data)) state->callback(state->callback_data, entry); cbdataUnlock(state->callback_data); state->callback_data = NULL; next = state->queue; cbdataFree(state); state = next; } while (state); }
int main (int argc, char *argv[]) { char *p, *t; char buf[BUFSIZE]; char *username; char *group; int err = 0; const char *groups[512]; int n; if (argc > 0) { /* should always be true */ myname=strrchr(argv[0],'/'); if (myname==NULL) myname=argv[0]; } else { myname="(unknown)"; } mypid=getpid(); /* make standard output line buffered */ setvbuf (stdout, NULL, _IOLBF, 0); /* Check Command Line */ process_options(argc, argv); debug("External ACL winbindd group helper build " __DATE__ ", " __TIME__ " starting up...\n"); if (use_case_insensitive_compare) debug("Warning: running in case insensitive mode !!!\n"); check_winbindd(); /* Main Loop */ while (fgets (buf, BUFSIZE, stdin)) { if (NULL == strchr(buf, '\n')) { err = 1; continue; } if (err) { warn("Oversized message\n"); goto error; } if ((p = strchr(buf, '\n')) != NULL) *p = '\0'; /* strip \n */ if ((p = strchr(buf, '\r')) != NULL) *p = '\0'; /* strip \r */ debug("Got '%s' from Squid (length: %d).\n",buf,strlen(buf)); if (buf[0] == '\0') { warn("Invalid Request\n"); goto error; } username = strwordtok(buf, &t); for (n = 0; (group = strwordtok(NULL, &t)) != NULL; n++) groups[n] = group; groups[n] = NULL; if (NULL == username) { warn("Invalid Request\n"); goto error; } if (Valid_Groups(username, groups)) { printf ("OK\n"); } else { error: printf ("ERR\n"); } err = 0; } return 0; }
/* * The helper program receives queries on stdin, one * per line, and must return the result on on stdout */ static void refreshCheckHandleReply(void *data, char *reply) { refreshCheckState *state = data; refreshCheckState *next; int freshness = -1; char *log = NULL; MemBuf hdrs = MemBufNULL; debug(84, 2) ("refreshCheckHandleReply: reply=\"%s\"\n", reply); if (reply) { char *t = NULL; char *token = strwordtok(reply, &t); if (token && strcmp(token, "FRESH") == 0) freshness = 0; else if (token && strcmp(token, "OK") == 0) freshness = 0; while ((token = strwordtok(NULL, &t))) { char *value = strchr(token, '='); if (value) { *value++ = '\0'; /* terminate the token, and move up to the value */ rfc1738_unescape(value); if (strcmp(token, "freshness") == 0) freshness = atoi(value); else if (strcmp(token, "log") == 0) log = value; else if (strncmp(token, "res{", 4) == 0) { char *header, *t; header = token + 4; t = strrchr(header, '}'); if (!t) continue; *t = '\0'; if (!hdrs.buf) memBufDefInit(&hdrs); memBufPrintf(&hdrs, "%s: %s\r\n", header, value); } } } } if (freshness >= 0) { if (hdrs.size) { HttpReply *rep = httpReplyCreate(); httpHeaderParse(&rep->header, hdrs.buf, hdrs.buf + hdrs.size); httpReplyUpdateOnNotModified(state->entry->mem_obj->reply, rep); storeTimestampsSet(state->entry); if (!httpHeaderHas(&rep->header, HDR_DATE)) { state->entry->timestamp = squid_curtime; state->entry->expires = squid_curtime + freshness; } else if (freshness) { state->entry->expires = squid_curtime + freshness; } httpReplyDestroy(rep); storeUpdate(state->entry, NULL); } else { state->entry->timestamp = squid_curtime; state->entry->expires = squid_curtime + freshness; } } if (hdrs.buf) memBufClean(&hdrs); dlinkDelete(&state->list, &state->def->queue); do { cbdataUnlock(state->def); state->def = NULL; if (state->callback && cbdataValid(state->callback_data)) state->callback(state->callback_data, freshness >= 0, log); cbdataUnlock(state->callback_data); state->callback_data = NULL; next = state->queue; cbdataFree(state); state = next; } while (state); }