Ejemplo n.º 1
0
Archivo: Glob.c Proyecto: aosm/ncftp
void RemoteGlob(LineListPtr fileList, char *pattern, char *lsFlags)
{
	char *cp;
	LinePtr lp;

	/* Note that we do attempt to use glob characters even if the remote
	 * host isn't UNIX.  Most non-UNIX remote FTP servers look for UNIX
	 * style wildcards.
	 */
	if (GLOBCHARSINSTR(pattern)) {
		/* Use NLST, which lists files one per line. */
		ListToMemory(fileList, "NLST", lsFlags, pattern);
		if ((fileList->first != NULL) && (fileList->first == fileList->last)) {
			/* If we have only one item in the list, see if it really was
			 * an error message we would recognize.
			 */
			cp = strchr(fileList->first->line, ':');
			if ((cp != NULL) && STREQ(cp, ": No such file or directory")) {
				RemoveLine(fileList, fileList->first);
			}
		}
		RemoteGlobCollapse(pattern, fileList);
		if (gTrace == kTracingOn) {
			for (lp=fileList->first; lp != NULL; lp = lp->next)
				TraceMsg("Rglob [%s]\n", lp->line);
		}
	} else {
		/* Or, if there were no globbing characters in 'pattern', then the
		 * pattern is really just a filename.  So for this case the
		 * file list is really just a single file.
		 */
		fileList->first = fileList->last = NULL;
		AddLine(fileList, pattern);
	}
}	/* RemoteGlob */
Ejemplo n.º 2
0
void CPlayerInfoBar::SetLine(CString label, CString info)
{
    info.Trim();
    if (info.IsEmpty()) {
        RemoveLine(label);
        return;
    }

    for (size_t idx = 0; idx < m_label.GetCount(); idx++) {
        CString tmp;
        m_label[idx]->GetWindowText(tmp);
        if (label == tmp) {
            m_info[idx]->GetWindowText(tmp);
            if (info != tmp) {
                m_info[idx]->SetWindowText(info);
                m_tooltip.UpdateTipText(info, m_info[idx]);
            }
            return;
        }
    }

    CAutoPtr<CStatusLabel> l(DEBUG_NEW CStatusLabel(true, false));
    l->Create(label, WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | SS_OWNERDRAW, CRect(0, 0, 0, 0), this);
    m_label.Add(l);

    CAutoPtr<CStatusLabel> i(DEBUG_NEW CStatusLabel(false, true));
    i->Create(info, WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | SS_OWNERDRAW | SS_NOTIFY, CRect(0, 0, 0, 0), this);
    m_tooltip.AddTool(i, info);
    m_info.Add(i);

    Relayout();
}
Ejemplo n.º 3
0
void CTetrisDlg::OnTimer(UINT_PTR nIDEvent)
{
    if(m_pBlock->canMoveDown())
    {
        m_pBlock->moveDown();
    }
    else
    {
        for(CHAR i = ROW - 1; i >= 0; --i)
        {
            if(CheckLine(i))
            {
                RemoveLine(i);
                ++i;
            }
        }
        MSG msg;
        while(::PeekMessage(&msg, m_hWnd, 0, 0, PM_REMOVE));
        if(IsGameOver(m_gameParam & 0xE0))
        {
            GameOver();
        }
        else
        {
            delete m_pBlock;
            m_pBlock = BlockFromIndex(m_gameParam & 0xE0);
            NextRandomBlock();
            m_nextColor = NextRandomColor();
        }
    }
    Invalidate(FALSE);
    CDialog::OnTimer(nIDEvent);
}
Ejemplo n.º 4
0
int SNM_SendPatcher::RemoveReceives() {
/* can fail since v4.1: freeze
	return RemoveLines("AUXRECV");
*/
	return RemoveLine("TRACK", "AUXRECV", 1, -1, "MIDIOUT");
	// REAPER will remove related envelopes, if any
}
Ejemplo n.º 5
0
LRESULT CAddTaskLinksEdit::OnDocUrlRemoved(WPARAM wParam, LPARAM lParam)
{
	if (0 == lParam)
		return 0;

	RemoveLine((LPCTSTR) lParam);

	return 0;
}
Ejemplo n.º 6
0
/* ---------------------------------------------------------------------------
 * removes a line point, or a line if the selected point is the end
 */
static void *
RemoveLinePoint (LayerTypePtr Layer, LineTypePtr Line, PointTypePtr Point)
{
  PointType other;
  struct rlp_info info;
  if (&Line->Point1 == Point)
    other = Line->Point2;
  else
    other = Line->Point1;
  info.line = Line;
  info.point = Point;
  if (setjmp (info.env) == 0)
    {
      r_search (Layer->line_tree, (const BoxType *) Point, NULL, remove_point,
		&info);
      return RemoveLine (Layer, Line);
    }
  MoveObject (LINEPOINT_TYPE, Layer, info.line, info.point,
	      other.X - Point->X, other.Y - Point->Y);
  return (RemoveLine (Layer, Line));
}
Ejemplo n.º 7
0
Archivo: Glob.c Proyecto: aosm/ncftp
static
void RemoteGlobCollapse(char *pattern, LineListPtr fileList)
{
	LinePtr lp, nextLine;
	string patPrefix;
	string cur, prev;
	char *endp, *cp, *dp;
	char *pp;
	int wasGlobChar;
	size_t plen;

	/* Copy all characters before the first glob-char. */
	dp = patPrefix;
	endp = dp + sizeof(patPrefix) - 1;
	wasGlobChar = 0;
	for (cp = pattern; dp < endp; ) {
		for (pp=kGlobChars; *pp != '\0'; pp++) {
			if (*pp == *cp) {
				wasGlobChar = 1;
				break;
			}
		}
		if (wasGlobChar)
			break;
		*dp++ = *cp++;
	}
	*dp = '\0';
	plen = (size_t) (dp - patPrefix);

	*prev = '\0';
	for (lp=fileList->first; lp != NULL; lp = nextLine) {
		nextLine = lp->next;
		if (strncmp(lp->line, patPrefix, plen) == 0) {
			STRNCPY(cur, lp->line + plen);
			cp = strchr(cur, '/');
			if (cp != NULL)
				*cp = '\0';
			if (*prev && STREQ(cur, prev)) {
				nextLine = RemoveLine(fileList, lp);
			} else {
				STRNCPY(prev, cur);
				/* We are playing with a dynamically
				 * allocated string, but since the
				 * following expression is guaranteed
				 * to be the same or shorter, we won't
				 * overwrite the bounds.
				 */
				sprintf(lp->line, "%s%s", patPrefix, cur);
			}
		}
	}
}	/* RemoteGlobCollapse */
Ejemplo n.º 8
0
void ConsoleWindow::AddLine(const std::wstring &line) const {
    if (m_isInitialized) {
        std::wstring currentText = m_consoleLabel->GetText();
        m_consoleLabel->SetText(currentText + line + L"\r\n");

        size_t numLines = std::count(
                              currentText.begin(),
                              currentText.end(), L'\n');

        if (numLines >= 20)
            RemoveLine(0);
    }
}
Ejemplo n.º 9
0
void CAddTaskLinksEdit::RemoveText(const CFileHashKey &key)
{
	int	iStartPos, iEndPos;
	if ( !FindLineByKey(key, iStartPos, iEndPos) )
		return;

	CString	strOldText;
	CString	strNewText;

	GetWindowText(strOldText);
	strNewText = RemoveLine(strOldText, iStartPos, iEndPos);
	SetWindowText(strNewText);
}
Ejemplo n.º 10
0
CLineSystemFX::~CLineSystemFX()
{
	if (m_pLines)
	{
		for (int i=0; i < m_nTotalNumLines; i++)
		{
			RemoveLine(i);
		}

		debug_deletea(m_pLines);
        m_pLines = LTNULL;
	}
}
Ejemplo n.º 11
0
/*
 * Given a 'brush' that's pushing things out of the way (possibly already
 * cut down to just the part relevant to our line) and a line that
 * intersects it on some layer, find the 45/90 lines required to go around
 * the brush on the named side.  Create them and remove the original.
 */
static int
MakeBypassingLines(POLYAREA *brush, LayerType *layer, LineType *line, int side, POLYAREA **expandp)
{
	Vector pA, pB, flatA, flatB, qA, qB;
	Vector lA, lB;
	Vector a, b, c, d, junk;
	int hits;

	SET_FLAG(DRCFLAG, line);	/* will cause sublines to inherit */
	lA[0] = line->Point1.X;
	lA[1] = line->Point1.Y;
	lB[0] = line->Point2.X;
	lB[1] = line->Point2.Y;

	/*
	 * Imagine side = north:
	 *
	 *                 /      \
	 *            ----b##FLAT##c----
	 *               Q          P
	 *   lA-ORIG####a            d####ORIG-lB
	 *             /              \
	 *
	 * First find the extended three lines that go around the brush.
	 * Then intersect them with each other and the original to find
	 * points a, b, c, d.  Finally connect the dots and remove the
	 * old straight line.
	 */
	POLYAREA_findXmostLine(brush, side, flatA, flatB, line->Thickness / 2);
	POLYAREA_findXmostLine(brush, rotateSide(side, 1), pA, pB, line->Thickness / 2);
	POLYAREA_findXmostLine(brush, rotateSide(side, -1), qA, qB, line->Thickness / 2);
	hits = vect_inters2(lA, lB, qA, qB, a, junk) + 
	       vect_inters2(qA, qB, flatA, flatB, b, junk) +
	       vect_inters2(pA, pB, flatA, flatB, c, junk) +
	       vect_inters2(lA, lB, pA, pB, d, junk);
	if (hits != 4) {
		return 0;
	}
	/* flip the line endpoints to match up with a/b */
	if (vect_dist2(lA, d) < vect_dist2(lA, a)) {
		Vswp2(lA, lB);
	}
	MakeBypassLine(layer, lA, a, line, NULL);
	MakeBypassLine(layer, a, b, line, expandp);
	MakeBypassLine(layer, b, c, line, expandp);
	MakeBypassLine(layer, c, d, line, expandp);
	MakeBypassLine(layer, d, lB, line, NULL);
	RemoveLine(layer, line);
	return 1;
}
Ejemplo n.º 12
0
LRESULT CAddTaskLinksEdit::OnDocUrlModified(WPARAM wParam, LPARAM lParam)
{
	if (0 == lParam)
		return 0;

	BOOL	bCheck = (BOOL) wParam;
	CString	strUrl = (LPCTSTR) lParam;

	if (bCheck)
		AddText(strUrl);
	else
		RemoveLine(strUrl);

	return 0;
}
Ejemplo n.º 13
0
void Credits::Draw()
{
CredLine *line, *next;

	line = firstline;
	while(line)
	{
		next = line->next;
		
		if (DrawLine(line))
		{
			RemoveLine(line);
			delete line;
		}
		
		line = next;
	}
}
Ejemplo n.º 14
0
void CListSide::RemoveLineAt(int nLine)
{
	int nrLines = m_Lines.size();
	for (int i = nLine; i < nrLines; i++)
	{
		HWND hWnd = m_Lines.at(i).edSecond.m_hWnd;
		int len = GetWindowTextLengthA(hWnd);
		char* str = NULL;
		if (len)
		{
			len++;
			str = new char[len];
			GetWindowTextA(hWnd, str, len);
			SetWindowTextA(hWnd, "");
			hWnd = m_Lines.at(i-1).edSecond.m_hWnd;
			SetWindowTextA(hWnd, str);
			delete[] str;
		}

		
		hWnd = m_Lines.at(i).edText.m_hWnd;
		len = GetWindowTextLengthA(hWnd);
		if (len)
		{
			len++;
			str = new char[len];
			GetWindowTextA(hWnd, str, len);
			SetWindowTextA(hWnd, "");
			hWnd = m_Lines.at(i-1).edText.m_hWnd;
			SetWindowTextA(hWnd, str);
			delete[] str;
		}
	}

	RemoveLine();

/*	RECT rect;
	GetWindowRect(m_Lines.back().edText.m_hWnd, &rect);
	POINT pt = {rect.right, rect.bottom};
	ScreenToClient(m_hWnd, &pt);

//	int nBottom = m_rClient.top + m_Lines.back().nIndex * m_nLineHeight + m_nLineHeight;
	UpdateScrollBar(pt.y);*/
}
Ejemplo n.º 15
0
static DWORD RemoveOption(struct SshConf *conf, const char *name)
{
    DWORD ceError = ERROR_SUCCESS;
    int line;

    for(line = 0; line < conf->lineCount; line++)
    {
        line = FindOption(conf, line, name);
        if(line == -1)
            break;

        BAIL_ON_CENTERIS_ERROR(ceError = RemoveLine(conf, &line));
        if(line > 0)
            line--;
    }

error:
    UpdatePublicLines(conf);
    return ceError;
}
Ejemplo n.º 16
0
void CheckForLine()
{	int RemoveLines[10];
	int Remove;
	int x,y;
	int factor=1;
	for(y=0; y<ROWS; y++)
	{  Remove=1;
	   for(x=0; x<COLS; x++)
	   {	  if(ScreenLayout[x][y] == BLANK)
			 Remove=0;
	   }
	   if(Remove)
	   {	  RemoveLine(y);
		  Score += LineScore*factor;
		  factor++;
		  PrintScore();
	   }
	}
	while (kbhit()) getch();      //Empty the keyboard input
}
Ejemplo n.º 17
0
void CLineSystemFX::UpdateSystem()
{
	if (!m_pLines) return;

	// Make sure delta time is no less than 15 frames/sec...

    LTFLOAT fDeltaTime = g_pGameClientShell->GetFrameTime();
	fDeltaTime = fDeltaTime > 0.0666f ? 0.0666f : fDeltaTime;

	// Update all the lines...

    LTLine line;

	for (int i=0; i < m_nTotalNumLines; i++)
	{
        if (m_pLines[i].hLTLine)
		{
            m_pClientDE->GetLineInfo(m_pLines[i].hLTLine, &line);

			line.m_Points[0].m_Pos += (m_pLines[i].vVel * fDeltaTime);
			line.m_Points[1].m_Pos += (m_pLines[i].vVel * fDeltaTime);

            m_pClientDE->SetLineInfo(m_pLines[i].hLTLine, &line);
			m_pLines[i].fLifetime -= fDeltaTime;

			// Remove dead lines...

			if (m_pLines[i].fLifetime <= 0.0f)
			{
				if (m_RemoveLineFn)
				{
					m_RemoveLineFn(m_pUserData, &(m_pLines[i]));
				}

				RemoveLine(i);
			}
		}
	}
}
Ejemplo n.º 18
0
static void
StripUnneccesaryGlobEntries(const FTPCIPtr cip, FTPLineListPtr fileList)
{
    FTPLinePtr lp, nextLine;
    const char *cp;

    for (lp=fileList->first; lp != NULL; lp = nextLine)
    {
        nextLine = lp->next;
        cp = strrchr(lp->line, '/');
        if (cp == NULL)
            cp = strrchr(lp->line, '\\');
        if (cp == NULL)
            cp = lp->line;
        else
            cp++;
        if ((strcmp(cp, ".") == 0) || (strcmp(cp, "..") == 0))
        {
            PrintF(cip, "  Rglob omitted: [%s] (type 1)\n", lp->line);
            nextLine = RemoveLine(fileList, lp);
        }
    }
}	/* StripUnneccesaryGlobEntries */
Ejemplo n.º 19
0
void CLineSystemFX::AddLine(int nIndex, LTBOOL bSetInitialPos)
{
	if (!m_hServerObject || !m_pLines || nIndex < 0 || nIndex >= m_nTotalNumLines) return;

    LTVector vPos, vCamPos, vObjPos, vDist, vVel;
    LTLine line;

	g_pLTClient->GetObjectPos(m_hServerObject, &vObjPos);

	// Get the camera's position...If the camera is too far away from
	// the line being added, don't add it :)

	HOBJECT hCamera = g_pPlayerMgr->GetCamera();
	if (!hCamera) return;

	g_pLTClient->GetObjectPos(hCamera, &vCamPos);
	vCamPos.y = 0.0f;  // Only take x/z into account...

	vPos.x = GetRandom(-m_cs.vDims.x, m_cs.vDims.x);
	vPos.y = GetRandom(-m_cs.vDims.y, m_cs.vDims.y);
	vPos.z = GetRandom(-m_cs.vDims.z, m_cs.vDims.z);

    LTFLOAT fLifetime = m_cs.fLineLifetime;

	vVel.x = GetRandom(m_cs.vMinVel.x, m_cs.vMaxVel.x);
	vVel.y = GetRandom(m_cs.vMinVel.y, m_cs.vMaxVel.y);
	vVel.z = GetRandom(m_cs.vMinVel.z, m_cs.vMaxVel.z);


	// If we need to set the initial line pos...

	if (bSetInitialPos)
	{
		fLifetime = GetRandom(0.0f, m_cs.fLineLifetime);

		if (fLifetime >= 0.0f)
		{
			vPos += (vVel * (m_cs.fLineLifetime - fLifetime));
		}
		else
		{
			fLifetime = m_cs.fLineLifetime;
		}
	}


	vObjPos += vPos;
	vObjPos.y = 0.0f; // Only take x/z into account

	vDist = vCamPos - vObjPos;

	if (vDist.MagSqr() < m_fMaxViewDistSqr || bSetInitialPos)
	{
		line.m_Points[0].m_Pos = vPos + m_vStartOffset;
		line.m_Points[0].r	   = m_cs.vStartColor.x;
		line.m_Points[0].g	   = m_cs.vStartColor.y;
		line.m_Points[0].b	   = m_cs.vStartColor.z;
		line.m_Points[0].a	   = m_cs.fStartAlpha;

		line.m_Points[1].m_Pos = vPos + m_vEndOffset;
		line.m_Points[1].r	   = m_cs.vEndColor.x;
		line.m_Points[1].g	   = m_cs.vEndColor.y;
		line.m_Points[1].b	   = m_cs.vEndColor.z;
		line.m_Points[1].a	   = m_cs.fEndAlpha;

        if (m_pLines[nIndex].hLTLine)
		{
            m_pClientDE->SetLineInfo(m_pLines[nIndex].hLTLine, &line);
		}
		else
		{
            m_pLines[nIndex].hLTLine = m_pClientDE->AddLine(m_hObject, &line);

			m_snTotalLines++;
		}

		m_pLines[nIndex].fLifetime	= fLifetime;
		m_pLines[nIndex].vVel		= vVel;
	}
	else
	{
		RemoveLine(nIndex);
	}
}
Ejemplo n.º 20
0
	//[14] 게임 시작
	void StartGame(void)
	{
		int n;
		int kb;
		int c = 2;

		srand((unsigned)time(0)); // rand() 함수로 랜덤값을 주기 위해서 초기값 부여

		/*게임 시작~끝*/
		while (1)
		{
			//블록 생성 위치 좌표(13, 2)에서 시작 
			SetCursorPosition(13, 2);

			n = rand() % 7;        // 0~27까지의 인덱스 생성 : 블록 종류 결정
			n = n * 4;            // 각 블록의 첫번째 블록(0, 4, 8, 12, 16, 20, 24)을 기준으로 출력, 방향키로 변환할 수 있도록 

			if (level == 10) // 레벨이 10에 도달하면 게임 승리 
			{
				SetCursorPosition(40, 15);
				printf("게임 클리어");
				getchar();
				exit(1);
			}

			if (CanPositionedAt(n, 0, 0) == false)
				break; //게임 끝                

			/*블록 한개 위~밑 이동*/
			while (1)
			{
				int ww = 0;
				int k = 0;

				/*블록 아래로 이동*/
				while (!_kbhit())
				{
					//블록 쇼
					WriteBlock(n);
					//딜레이 타임
					Sleep(DELAY + speed);
					//아래이동시 1이 있는지 확인
					if (CanPositionedAt(n, 0, 1) == false)
					{
						ww = 1;
						BoardInit(n, 0, 0);//보드 열돌 배열 1추가
						RemoveLine();
						break;
					}
					ClearBlock(n, 0, 1);  //board배열 +1행 
				}
				/*CanPositionedAt함수에서 배열값 1발견시 중지*/
				if (ww == 1)
					break;

				kb = _getch();

				/*방향키*/
				switch (kb)
				{
				case LEFT:
					ClearBlock(n, -2, 0);
					WriteBlock(n);
					break;
				case RIGHT:
					ClearBlock(n, 2, 0);
					WriteBlock(n);
					break;
				case UP:
					// 첫수를구한다.
					k = n / 4;
					k *= 4;

					// 다음수가 끝수이하인가 
					if ((n + 1) <= (k + 3))
					{
						k = n + 1;
					}

					if (CanPositionedAt(k, 0, 0) == true)
					{
						ClearBlock(n, 0, 0);
						n = k;
						WriteBlock(n);
						break;
					}
					break;
				case DOWN:
					ClearBlock(n, 0, 2);
					break;
				case SPACE:    // 아래로 뚝 떨어지는 로직
					while (1)
					{
						ClearBlock(n, 0, 1);
						if (CanPositionedAt(n, 0, 1) == false)
						{
							WriteBlock(n);
							BoardInit(n, 0, 0);
							break;
						}
					}
				default: break;
				} // end switch
			} // end while(블록)        
		} // end while(게임)
	}
Ejemplo n.º 21
0
int SNM_SendPatcher::RemoveReceives() {
/* can fail since v4.1: freeze
	return RemoveLines("AUXRECV");
*/
	return RemoveLine("TRACK", "AUXRECV", 1, -1, "MIDIOUT");
}
Ejemplo n.º 22
0
void
RemoteGlobCollapse(const FTPCIPtr cip, const char *pattern, FTPLineListPtr fileList)
{
    FTPLinePtr lp, nextLine;
    char *patPrefix;
    char *patDir;
    char *cur, *prev;
    char *cp;
    char *newpath;
    size_t plen;

    /* Copy all characters before and including the last path delimiter. */
    patDir = NULL;
    cp = StrRFindLocalPathDelim(pattern);
    if (cp != NULL)
    {
        patDir = StrDup(pattern);
        if (patDir == NULL)
            return;
        patDir[(cp - pattern) + 1] = '\0';
    }

    /* Copy all characters before the first glob-char. */
    cp = strpbrk(pattern, kGlobChars);
    patPrefix = StrDup(pattern);
    if (patPrefix == NULL)
    {
        free(patDir);
        return;
    }
    if (cp != NULL)
    {
        plen = (size_t) (cp - pattern);
        patPrefix[plen] = '\0';
    }
    else
    {
        plen = strlen(patPrefix);
    }

    cur = prev = NULL;
    for (lp=fileList->first; lp != NULL; lp = nextLine)
    {
        nextLine = lp->next;
        if (ISTRNEQ(lp->line, patPrefix, plen))
        {
            if (Dynsrecpy(&cur, lp->line + plen, 0) == NULL)
                goto done;
            cp = strpbrk(cur, "/\\");
            if (cp != NULL)
                *cp = '\0';
            if ((prev != NULL) && (STREQ(cur, prev)))
            {
                PrintF(cip, "  Rglob omitted: [%s] (type 2)\n", lp->line);
                nextLine = RemoveLine(fileList, lp);
            }
            else if (PathContainsIntermediateDotDotSubDir(lp->line + plen))
            {
                PrintF(cip, "  Rglob omitted: [%s] (type 3)\n", lp->line);
                nextLine = RemoveLine(fileList, lp);
            }
            else
            {
                if (Dynsrecpy(&prev, cur, 0) == NULL)
                    goto done;

                /* We are playing with a dynamically
                 * allocated string, but since the
                 * following expression is guaranteed
                 * to be the same or shorter, we won't
                 * overwrite the bounds.
                 */
                (void) sprintf(lp->line, "%s%s", patPrefix, cur);
            }
        }
        else if (strpbrk(lp->line, "/\\") == NULL)
        {
            if (patDir != NULL)
            {
                newpath = NULL;
                if (Dynsrecpy(&newpath, patDir, lp->line, 0) == NULL)
                    goto done;
                PrintF(cip, "  Rglob changed: [%s] to [%s]\n", lp->line, newpath);
                free(lp->line);
                lp->line = newpath;
            }
        }
        else
        {
            PrintF(cip, "  Rglob omitted: [%s] (type 4)\n", lp->line);
            nextLine = RemoveLine(fileList, lp);
        }
    }

done:
    StrFree(&patDir);
    StrFree(&patPrefix);
    StrFree(&cur);
    StrFree(&prev);
}	/* RemoteGlobCollapse */
Ejemplo n.º 23
0
static QueryResult RemoveCompat(NsswitchConf *conf, PSTR *description, LWException **exc)
{
    DistroInfo distro;
    int compatLine;
    int noncompatLine;
    int compatModIndex;
    BOOLEAN passwdNeedUpdate = FALSE;
    BOOLEAN groupNeedUpdate = FALSE;
    QueryResult result = FullyConfigured;

    memset(&distro, 0, sizeof(distro));

    /* The default configuration on FreeBSD is:
     * passwd: compat
     * passwd_compat: nis
     * group: compat
     * group_compat: nis
     *
     * The nsswitch man page says that compat must be the only module on the
     * line if it is used. Unfortunately, if a module is listed on the compat
     * line, it goes through a different interface which LSASS does not
     * understand. So this configuration must first be transformed into:
     *
     * passwd: files nis
     * group: files nis
     *
     * If the user is using compat mode with a non-default configuration, show
     * an error message instead.
     */

    LW_CLEANUP_CTERR(exc, DJGetDistroInfo(NULL, &distro));

    compatLine = FindEntry(conf, 0, "passwd_compat");
    if(compatLine != -1)
    {
        const NsswitchEntry *lineEntry = GetEntry(conf, compatLine);

        passwdNeedUpdate = TRUE;

        if(lineEntry->modules.size != 1)
        {
            result = CannotConfigure;
            goto done_configuring;
        }
        if(FindModuleOnLine(conf, compatLine, "nis") == -1)
        {
            result = CannotConfigure;
            goto done_configuring;
        }
        noncompatLine = FindEntry(conf, 0, "passwd");
        if(noncompatLine == -1)
        {
            result = CannotConfigure;
            goto done_configuring;
        }
        lineEntry = GetEntry(conf, noncompatLine);
        if(lineEntry->modules.size != 1)
        {
            result = CannotConfigure;
            goto done_configuring;
        }
        compatModIndex = FindModuleOnLine(conf, noncompatLine, "compat");
        if(compatModIndex == -1)
        {
            result = CannotConfigure;
            goto done_configuring;
        }

        result = NotConfigured;

        LW_CLEANUP_CTERR(exc, InsertModule(conf, &distro, noncompatLine, -1, "files"));
        LW_CLEANUP_CTERR(exc, InsertModule(conf, &distro, noncompatLine, -1, "nis"));
        LW_CLEANUP_CTERR(exc, RemoveModule(conf, noncompatLine, compatModIndex));
        LW_CLEANUP_CTERR(exc, RemoveLine(conf, compatLine));
    }

    compatLine = FindEntry(conf, 0, "group_compat");
    if(compatLine != -1)
    {
        const NsswitchEntry *lineEntry = GetEntry(conf, compatLine);

        groupNeedUpdate = TRUE;

        if(lineEntry->modules.size != 1)
        {
            result = CannotConfigure;
            goto done_configuring;
        }
        if(FindModuleOnLine(conf, compatLine, "nis") == -1)
        {
            result = CannotConfigure;
            goto done_configuring;
        }
        noncompatLine = FindEntry(conf, 0, "group");
        if(noncompatLine == -1)
        {
            result = CannotConfigure;
            goto done_configuring;
        }
        lineEntry = GetEntry(conf, noncompatLine);
        if(lineEntry->modules.size != 1)
        {
            result = CannotConfigure;
            goto done_configuring;
        }
        compatModIndex = FindModuleOnLine(conf, noncompatLine, "compat");
        if(compatModIndex == -1)
        {
            result = CannotConfigure;
            goto done_configuring;
        }

        result = NotConfigured;

        LW_CLEANUP_CTERR(exc, InsertModule(conf, &distro, noncompatLine, -1, "files"));
        LW_CLEANUP_CTERR(exc, InsertModule(conf, &distro, noncompatLine, -1, "nis"));
        LW_CLEANUP_CTERR(exc, RemoveModule(conf, noncompatLine, compatModIndex));
        LW_CLEANUP_CTERR(exc, RemoveLine(conf, compatLine));
    }

done_configuring:
    if(result == CannotConfigure && description != NULL)
    {
        LW_CLEANUP_CTERR(exc, CTStrdup("Remove the passwd_compat and/or group_compat lines and use passwd and group instead. This cannot be done automatically because your system has a non-default nsswitch configuration.\n", description));
    }
    else if((passwdNeedUpdate || groupNeedUpdate) && description != NULL)
    {
        LW_CLEANUP_CTERR(exc, CTStrdup("Remove the passwd_compat and/or group_compat lines and use passwd and group instead.\n", description));
        result = NotConfigured;
    }
    else if(description != NULL)
    {
        LW_CLEANUP_CTERR(exc, CTStrdup("Fully Configured.", description));
    }

cleanup:
    DJFreeDistroInfo(&distro);

    return result;
}
Ejemplo n.º 24
0
int
FTPRemoteGlob(FTPCIPtr cip, FTPLineListPtr fileList, const char *pattern, int doGlob)
{
    char *cp;
    const char *lsflags;
    FTPLinePtr lp;
    int result;

    if (cip == NULL)
        return (kErrBadParameter);
    if (strcmp(cip->magic, kLibraryMagic))
        return (kErrBadMagic);

    if (fileList == NULL)
        return (kErrBadParameter);
    InitLineList(fileList);

    if ((pattern == NULL) || (pattern[0] == '\0'))
        return (kErrBadParameter);

    /* Note that we do attempt to use glob characters even if the remote
     * host isn't UNIX.  Most non-UNIX remote FTP servers look for UNIX
     * style wildcards.
     */
    if ((doGlob == 1) && (GLOBCHARSINSTR(pattern)))
    {
        /* Use NLST, which lists files one per line. */
        lsflags = "";

        /* Optimize for "NLST *" case which is same as "NLST". */
        if (strcmp(pattern, "*") == 0)
        {
            pattern = "";
            lsflags = (cip->hasNLST_a == kCommandNotAvailable) ? "" : "-a";
        }
        else if (strcmp(pattern, "**") == 0)
        {
            /* Hack; Lets you try "NLST -a" if you're daring. */
            /* Need to use "NLST -a" whenever possible,
             * because wu-ftpd doesn't do NLST right, IMHO.
             * (It doesn't include directories in the NLST
             *  if you do "NLST /the/dir" without -a.)
             */
            pattern = "";
            lsflags = (cip->hasNLST_a == kCommandNotAvailable) ? "" : "-a";
        }

        if ((result = FTPListToMemory2(cip, pattern, fileList, lsflags, 0, (int *) 0)) < 0)
        {
            if (*lsflags == '\0')
                return (result);
            if (strchr(lsflags, 'a') != NULL)
            {
                /* Try again, without "-a" */
                cip->hasNLST_a = kCommandNotAvailable;
                lsflags = "";
                if ((result = FTPListToMemory2(cip, pattern, fileList, lsflags, 0, (int *) 0)) < 0)
                {
                    return (result);
                }
                /* else proceed */
            }
            else
            {
                return (result);
            }
        }
#if 0
        DisposeLineListContents(fileList);
        InitLineList(fileList);
        AddLine(fileList, "../FAKEME1.txt");
        AddLine(fileList, "../../FAKEME2.txt");
        AddLine(fileList, "..\\FAKEME3.txt");
        AddLine(fileList, "..\\..\\FAKEME4.txt");
        AddLine(fileList, "...\\FAKEME5.txt");
        AddLine(fileList, "/tmp/bad/FAKEME6.txt");
        AddLine(fileList, "c:\\temp\\FAKEME7.txt");
        AddLine(fileList, "foo/../FAKEME8.txt");
        AddLine(fileList, "foo\\bar\\...\\FAKEME9.txt");
#endif
        if (fileList->first == NULL)
        {
            cip->errNo = kErrGlobNoMatch;
            return (kErrGlobNoMatch);
        }
        if (fileList->first == fileList->last)
        {
#define glberr(a) (ISTRNEQ(cp, a, strlen(a)))
            /* If we have only one item in the list, see if it really was
             * an error message we would recognize.
             */
            cp = strchr(fileList->first->line, ':');
            if (cp != NULL)
            {
                if (glberr(": No such file or directory"))
                {
                    (void) RemoveLine(fileList, fileList->first);
                    cip->errNo = kErrGlobFailed;
                    return (kErrGlobFailed);
                }
                else if (glberr(": No match"))
                {
                    cip->errNo = kErrGlobNoMatch;
                    return (kErrGlobNoMatch);
                }
            }
        }
        StripUnneccesaryGlobEntries(cip, fileList);
        RemoteGlobCollapse(cip, pattern, fileList);
        for (lp=fileList->first; lp != NULL; lp = lp->next)
            PrintF(cip, "  Rglob [%s]\n", lp->line);
    }
    else
    {
        /* Or, if there were no globbing characters in 'pattern', then the
         * pattern is really just a filename.  So for this case the
         * file list is really just a single file.
         */
        fileList->first = fileList->last = NULL;
        (void) AddLine(fileList, pattern);
    }
    return (kNoErr);
}	/* FTPRemoteGlob */