void add_session_user(const char *user) { fstring suser; struct passwd *passwd; if (!(passwd = Get_Pwnam(user))) return; fstrcpy(suser,passwd->pw_name); if(!*suser) return; if( session_userlist && in_list(suser,session_userlist,False) ) return; if( !session_userlist || (strlen(suser) + strlen(session_userlist) + 2 >= len_session_userlist) ) { char *newlist; if (len_session_userlist > 128 * PSTRING_LEN) { DEBUG(3,("add_session_user: session userlist already " "too large.\n")); return; } newlist = (char *)SMB_REALLOC_KEEP_OLD_ON_ERROR( session_userlist, len_session_userlist + PSTRING_LEN ); if( newlist == NULL ) { DEBUG(1,("Unable to resize session_userlist\n")); return; } if (!session_userlist) { *newlist = '\0'; } session_userlist = newlist; len_session_userlist += PSTRING_LEN; } safe_strcat(session_userlist," ",len_session_userlist-1); safe_strcat(session_userlist,suser,len_session_userlist-1); }
static char *grab_line(FILE *f, int *cl) { char *ret = NULL; int i = 0; int len = 0; while ((*cl)) { int c; if (i == len) { char *ret2; if (len == 0) len = 1024; else len *= 2; ret2 = (char *)SMB_REALLOC_KEEP_OLD_ON_ERROR(ret, len); if (!ret2) return ret; ret = ret2; } c = fgetc(f); (*cl)--; if (c == EOF) { (*cl) = 0; break; } if (c == '\r') continue; if (strchr_m("\n&", c)) break; ret[i++] = c; } if (ret) { ret[i] = 0; } return ret; }
static bool Parameter( DATA_BLOB *buf, myFILE *InFile, bool (*pfunc)(const char *, const char *, void *), int c, void *userdata ) { int i = 0; /* Position within bufr. */ int end = 0; /* bufr[end] is current end-of-string. */ int vstart = 0; /* Starting position of the parameter value. */ const char *func = "params.c:Parameter() -"; /* Read the parameter name. */ while( 0 == vstart ) { /* Loop until we've found the start of the value. */ if( i > (buf->length - 2) ) { /* Ensure there's space for next char. */ uint8_t *tb = (uint8_t *)SMB_REALLOC_KEEP_OLD_ON_ERROR( buf->data, buf->length + BUFR_INC ); if (!tb) { DEBUG(0, ("%s Memory re-allocation failure.", func) ); return False; } buf->data = tb; buf->length += BUFR_INC; } switch(c) { case '=': /* Equal sign marks end of param name. */ if( 0 == end ) { /* Don't allow an empty name. */ DEBUG(0, ("%s Invalid parameter name in config. file.\n", func )); return False; } buf->data[end++] = '\0'; /* Mark end of string & advance. */ i = end; /* New string starts here. */ vstart = end; /* New string is parameter value. */ buf->data[i] = '\0'; /* New string is nul, for now. */ break; case '\n': /* Find continuation char, else error. */ i = Continuation( buf->data, i ); if( i < 0 ) { buf->data[end] = '\0'; DEBUG(1,("%s Ignoring badly formed line in configuration file: %s\n", func, buf->data )); return True; } end = ( (i > 0) && (' ' == buf->data[i - 1]) ) ? (i - 1) : (i); c = mygetc( InFile ); /* Read past eoln. */ break; case '\0': /* Shouldn't have EOF within param name. */ case EOF: buf->data[i] = '\0'; DEBUG(1,("%s Unexpected end-of-file at: %s\n", func, buf->data )); return True; default: if(isspace( c )) { /* One ' ' per whitespace region. */ buf->data[end] = ' '; i = end + 1; c = EatWhitespace( InFile ); } else { buf->data[i++] = c; end = i; c = mygetc( InFile ); } } } /* Now parse the value. */ c = EatWhitespace( InFile ); /* Again, trim leading whitespace. */ while( (EOF !=c) && (c > 0) ) { if( i > (buf->length - 2) ) { /* Make sure there's enough room. */ uint8_t *tb = (uint8_t *)SMB_REALLOC_KEEP_OLD_ON_ERROR( buf->data, buf->length + BUFR_INC ); if (!tb) { DEBUG(0, ("%s Memory re-allocation failure.", func)); return False; } buf->data = tb; buf->length += BUFR_INC; } switch(c) { case '\r': /* Explicitly remove '\r' because the older */ c = mygetc( InFile ); /* version called fgets_slash() which also */ break; /* removes them. */ case '\n': /* Marks end of value unless there's a '\'. */ i = Continuation( buf->data, i ); if( i < 0 ) { c = 0; } else { for( end = i; (end >= 0) && isspace((int)buf->data[end]); end-- ) ; c = mygetc( InFile ); } break; default: /* All others verbatim. Note that spaces do not advance <end>. This allows trimming */ buf->data[i++] = c; if( !isspace( c ) ) /* of whitespace at the end of the line. */ end = i; c = mygetc( InFile ); break; } } buf->data[end] = '\0'; /* End of value. */ return( pfunc( (char *)buf->data, (char *)&buf->data[vstart], userdata ) ); /* Pass name & value to pfunc(). */ }
static bool Section( DATA_BLOB *buf, myFILE *InFile, bool (*sfunc)(const char *, void *), void *userdata ) { int c; int i; int end; const char *func = "params.c:Section() -"; i = 0; /* <i> is the offset of the next free byte in bufr[] and */ end = 0; /* <end> is the current "end of string" offset. In most */ /* cases these will be the same, but if the last */ /* character written to bufr[] is a space, then <end> */ /* will be one less than <i>. */ /* Find the end of the section. We must use mb functions for this. */ if (!FindSectionEnd(InFile)) { DEBUG(0, ("%s No terminating ']' character in section.\n", func) ); return False; } c = EatWhitespace( InFile ); /* We've already got the '['. Scan */ /* past initial white space. */ while( (EOF != c) && (c > 0) ) { /* Check that the buffer is big enough for the next character. */ if( i > (buf->length - 2) ) { uint8_t *tb = (uint8_t *)SMB_REALLOC_KEEP_OLD_ON_ERROR(buf->data, buf->length+BUFR_INC ); if(!tb) { DEBUG(0, ("%s Memory re-allocation failure.", func) ); return False; } buf->data = tb; buf->length += BUFR_INC; } /* Handle a single character other than section end. */ switch( c ) { case '\n': /* Got newline before closing ']'. */ i = Continuation( buf->data, i ); /* Check for line continuation. */ if( i < 0 ) { buf->data[end] = '\0'; DEBUG(0, ("%s Badly formed line in configuration file: %s\n", func, buf->data )); return False; } end = ( (i > 0) && (' ' == buf->data[i - 1]) ) ? (i - 1) : (i); c = mygetc( InFile ); /* Continue with next line. */ break; default: /* All else are a valid name chars. */ if(isspace( c )) { /* One space per whitespace region. */ buf->data[end] = ' '; i = end + 1; c = EatWhitespace( InFile ); } else { buf->data[i++] = c; end = i; c = mygetc( InFile ); } } if (AtSectionEnd(InFile)) { /* Got to the closing bracket. */ buf->data[end] = '\0'; if( 0 == end ) { /* Don't allow an empty name. */ DEBUG(0, ("%s Empty section name in configuration file.\n", func )); return False; } if( !sfunc((char *)buf->data, userdata) ) /* Got a valid name. Deal with it. */ return False; EatComment( InFile ); /* Finish off the line. */ return True; } } /* We arrive here if we've met the EOF before the closing bracket. */ DEBUG(0, ("%s Unexpected EOF in the configuration file: %s\n", func, buf->data )); return False; }