static int userrc_parse(struct vboxuser *vboxuser, unsigned char *home) { unsigned char tempsectname[VBOX_MAX_RCLINE_SIZE + 1]; struct passwd *pwdent; struct group *grpent; unsigned char *varusr; unsigned char *vargrp; unsigned char *varspc; unsigned char *varmsk; int havegroup; static struct vboxrc rc_user_c[] = { { "user" , NULL }, { "group" , NULL }, { "umask" , NULL }, { "hdspace" , NULL }, { NULL , NULL } }; xstrncpy(temppathname, SYSCONFDIR , PATH_MAX); xstrncat(temppathname, "/vboxgetty.conf", PATH_MAX); xstrncpy(tempsectname, "vboxgetty-phone-" , VBOX_MAX_RCLINE_SIZE); xstrncat(tempsectname, vboxuser->localphone, VBOX_MAX_RCLINE_SIZE); if (rc_read(rc_user_c, temppathname, tempsectname) < 0) return(-1); varusr = rc_get_entry(rc_user_c, "user" ); vargrp = rc_get_entry(rc_user_c, "group" ); varspc = rc_get_entry(rc_user_c, "hdspace"); varmsk = rc_get_entry(rc_user_c, "umask" ); vboxuser->uid = 0; vboxuser->gid = 0; vboxuser->space = 0; vboxuser->umask = 0; strcpy(vboxuser->home, ""); strcpy(vboxuser->name, ""); if ((!varusr) || (!*varusr)) { log_line(LOG_E, "You *must* specify a user name or a user id!\n"); rc_free(rc_user_c); return(-1); } if (*varusr == '#') pwdent = getpwuid((uid_t)xstrtol(&varusr[1], 0)); else pwdent = getpwnam(varusr); if (!pwdent) { log_line(LOG_E, "Unable to locate \"%s\" in systems passwd list.\n", varusr); rc_free(rc_user_c); return(-1); } vboxuser->uid = pwdent->pw_uid; vboxuser->gid = pwdent->pw_gid; if ((strlen(home) + strlen(pwdent->pw_name) + 2) < (PATH_MAX - 100)) { xstrncpy(vboxuser->name, pwdent->pw_name, VBOXUSER_USERNAME); printstring(vboxuser->home, "%s/%s", home, pwdent->pw_name); } else { log_line(LOG_E, "Oops! Spool directory name and user name too long!\n"); rc_free(rc_user_c); return(-1); } if ((vargrp) && (*vargrp)) { havegroup = 0; setgrent(); while ((grpent = getgrent())) { if (*vargrp == '#') { if (grpent->gr_gid == (gid_t)xstrtol(&vargrp[1], 0)) { vboxuser->gid = grpent->gr_gid; havegroup = 1; break; } } else { if (strcmp(grpent->gr_name, vargrp) == 0) { vboxuser->gid = grpent->gr_gid; havegroup = 1; break; } } } endgrent(); if (!havegroup) { log_line(LOG_E, "Unable to locate \"%s\" in systems group list.\n", vargrp); rc_free(rc_user_c); return(-1); } } if (varspc) vboxuser->space = xstrtol(varspc, 0); if (varmsk) vboxuser->umask = xstrtoo(varmsk, 0); log_line(LOG_D, "User \"%s\" (%d.%d) [%04o] will be used...\n", vboxuser->name, vboxuser->uid, vboxuser->gid, vboxuser->umask); rc_free(rc_user_c); return(0); }
void rc_multiread(uint16_t *data){ uint8_t i = 0; for(i = 0; i < 8; i++) data[i] = rc_read(i + 1); }
static void ramcloudAppend(struct ramcloudData *d, wstr key, struct array *vals, uint32_t vlen, uint16_t flag, int append) { uint32_t actual_len; uint64_t version; uint64_t len = RAMCLOUD_DEFAULT_VALUE_LEN; again: wheatLog(WHEAT_DEBUG, "%s read key %s", __func__, key); wstr origin_val = wstrNewLen(NULL, len); wstr val; Status s = rc_read(global.client, d->table_id, key, wstrlen(key), NULL, &version, origin_val, len, &actual_len); if (s != STATUS_OK) { if (s != STATUS_OBJECT_DOESNT_EXIST) { wheatLog(WHEAT_WARNING, " failed to read %s: %s", key, statusToString(s)); sliceTo(&d->storage_response, (uint8_t*)SERVER_ERROR, sizeof(SERVER_ERROR)-1); } else { sliceTo(&d->storage_response, (uint8_t*)NOT_STORED, sizeof(NOT_STORED)-1); } wstrFree(origin_val); return ; } while (actual_len > len) { wstrFree(origin_val); len = actual_len; origin_val = wstrNewLen(NULL, actual_len); if (origin_val == NULL) { sliceTo(&d->storage_response, (uint8_t*)SERVER_ERROR, sizeof(SERVER_ERROR)-1); wheatLog(WHEAT_WARNING, " failed to alloc memory"); return ; } s = rc_read(global.client, d->table_id, key, wstrlen(key), NULL, &version, origin_val, len, &actual_len); if (s != STATUS_OK) { if (s != STATUS_OBJECT_DOESNT_EXIST) { wheatLog(WHEAT_WARNING, " failed to read %s: %s", key, statusToString(s)); sliceTo(&d->storage_response, (uint8_t*)SERVER_ERROR, sizeof(SERVER_ERROR)-1); } else { sliceTo(&d->storage_response, (uint8_t*)NOT_STORED, sizeof(NOT_STORED)-1); } wstrFree(origin_val); return ; } } wstrupdatelen(origin_val, actual_len-FLAG_SIZE); if (append) { val = origin_val; // reduce flag size } else { val = wstrNewLen(NULL, vlen); } int i = 0; while (i < narray(vals)) { struct slice *slice; slice = arrayIndex(vals, i); val = wstrCatLen(val, (char*)slice->data, slice->len); len += slice->len; ++i; } if (!append) { val = wstrCatLen(val, origin_val, wstrlen(origin_val)); wstrFree(origin_val); } val = wstrCatLen(val, (char*)&flag, FLAG_SIZE); struct RejectRules rule; memset(&rule, 0, sizeof(rule)); rule.doesntExist = 1; rule.versionNeGiven = 1; rule.givenVersion = version; s = rc_write(global.client, d->table_id, key, wstrlen(key), val, wstrlen(val), &rule, NULL); wstrFree(val); if (s != STATUS_OK) { if (s == STATUS_OBJECT_DOESNT_EXIST) { sliceTo(&d->storage_response, (uint8_t*)NOT_STORED, sizeof(NOT_STORED)-1); return ; } else if (s == STATUS_WRONG_VERSION) { goto again; } wheatLog(WHEAT_WARNING, " failed to write %s: %s", key, statusToString(s)); sliceTo(&d->storage_response, (uint8_t*)SERVER_ERROR, sizeof(SERVER_ERROR)-1); return ; } sliceTo(&d->storage_response, (uint8_t*)STORED, sizeof(STORED)-1); }
static List *bqinput(List *ifs, int fd) { char *end, *bufend, *s; List *r, *top, *prev; size_t remain, bufsize; char isifs[256]; int n, state; /* a simple FSA is used to read in data */ memzero(isifs, sizeof isifs); for (isifs['\0'] = TRUE; ifs != NULL; ifs = ifs->n) for (s = ifs->w; *s != '\0'; s++) isifs[*(unsigned char *)s] = TRUE; remain = bufsize = BUFSIZE; top = r = nnew(List); r->w = end = nalloc(bufsize + 1); r->m = NULL; state = 0; prev = NULL; while (1) { if (remain == 0) { /* is the string bigger than the buffer? */ size_t m = end - r->w; char *buf; while (bufsize < m + BUFSIZE) bufsize *= 2; buf = nalloc(bufsize + 1); memcpy(buf, r->w, m); r->w = buf; end = &buf[m]; remain = bufsize - m; } if ((n = rc_read(fd, end, remain)) <= 0) { if (n == 0) /* break */ break; else if (errno == EINTR) return NULL; /* interrupted, wait for subproc */ else { uerror("backquote read"); rc_error(NULL); } } remain -= n; for (bufend = &end[n]; end < bufend; end++) if (state == 0) { if (!isifs[*(unsigned char *)end]) { state = 1; r->w = end; r->m = NULL; } } else { if (isifs[*(unsigned char *)end]) { state = 0; *end = '\0'; prev = r; r = r->n = nnew(List); r->w = end+1; r->m = NULL; } } } if (state == 1) { /* terminate last string */ *end = '\0'; r->n = NULL; } else { if (prev == NULL) /* no input at all? */ top = NULL; else prev->n = NULL; /* else terminate list */ } return top; }
static void ramcloudIncr(struct ramcloudData *d, wstr key, uint64_t num, int positive) { if (num > INT64_MAX) { wheatLog(WHEAT_WARNING, "%s num %ld can't larger than %ld", __func__, num, INT64_MAX); sliceTo(&d->storage_response, (uint8_t*)CLIENT_ERROR, sizeof(CLIENT_ERROR)-1); return ; } static int max_len = 100; char value[max_len]; uint32_t actual_len; uint64_t version; uint16_t flag; again: wheatLog(WHEAT_DEBUG, "%s incr key %s %ld", __func__, key, num); Status s = rc_read(global.client, d->table_id, key, wstrlen(key), NULL, &version, value, max_len, &actual_len); if (s != STATUS_OK) { if (s != STATUS_OBJECT_DOESNT_EXIST) { wheatLog(WHEAT_WARNING, " failed to read %s: %s", key, statusToString(s)); sliceTo(&d->storage_response, (uint8_t*)SERVER_ERROR, sizeof(SERVER_ERROR)-1); } else { sliceTo(&d->storage_response, (uint8_t*)NOT_FOUND, sizeof(NOT_FOUND)-1); } return ; } if (actual_len > max_len) { sliceTo(&d->storage_response, (uint8_t*)CLIENT_ERROR, sizeof(CLIENT_ERROR)-1); return ; } flag = *(uint16_t*)&value[actual_len-FLAG_SIZE]; value[actual_len-FLAG_SIZE] = '\0'; long long n = atoll(value); if (n == 0) { if (value[0] != '0') { sliceTo(&d->storage_response, (uint8_t*)CLIENT_ERROR, sizeof(CLIENT_ERROR)-1); return ; } } if (positive) { n += num; } else { if (num > n) n = 0; else n -= num; } int l = sprintf(value, "%llu", n); memcpy(&value[l], &flag, FLAG_SIZE); struct RejectRules rule; memset(&rule, 0, sizeof(rule)); rule.doesntExist = 1; rule.versionNeGiven = 1; rule.givenVersion = version; s = rc_write(global.client, d->table_id, key, wstrlen(key), value, l+FLAG_SIZE, &rule, &version); if (s != STATUS_OK) { if (s == STATUS_WRONG_VERSION) { goto again; } if (s == STATUS_OBJECT_DOESNT_EXIST) { sliceTo(&d->storage_response, (uint8_t*)NOT_FOUND, sizeof(NOT_FOUND)-1); return ; } sliceTo(&d->storage_response, (uint8_t*)SERVER_ERROR, sizeof(SERVER_ERROR)-1); wheatLog(WHEAT_WARNING, "%s failed to incr %s: %s", __func__, key, statusToString(s)); return ; } else { l = sprintf(value, "%llu\r\n", n); d->retrieval_response = wstrNewLen(value, l); sliceTo(&d->storage_response, (uint8_t*)d->retrieval_response, wstrlen(d->retrieval_response)); } }