Example #1
0
void Config_FixGatewayDrives (void)
{
   // Zip through the user's network drives and reconnect
   // them as necessary.
   //
   for (TCHAR chDrive = chDRIVE_A; chDrive <= chDRIVE_Z; ++chDrive)
      {
      TCHAR szSubmount[ MAX_PATH ];
      if (!GetDriveSubmount (chDrive, szSubmount))
         continue;

      // We've got a mapping into AFS!  Remove it, rather forcefully.
      //
      TCHAR szDrive[] = "@:";
      szDrive[0] = chDrive;
      WNetCancelConnection (szDrive, TRUE);
      }

   // Now recreate our drive mappings, based on the user's already-
   // specified preferences.
   //
   DRIVEMAPLIST List;
   QueryDriveMapList (&List);

   for (size_t ii = 0; ii < 26; ++ii)
      {
      if (!List.aDriveMap[ii].szMapping[0])
         continue;
      ActivateDriveMap (List.aDriveMap[ii].chDrive, List.aDriveMap[ii].szMapping, List.aDriveMap[ii].szSubmount, List.aDriveMap[ii].fPersistent);
      }
}
Example #2
0
DWORD DisMountDOSDriveFull(const char *szPath,BOOL bForce)
{
#ifndef AFSIFS
    DWORD res=WNetCancelConnection(szPath,bForce);
#else
    DWORD res;
    res = ERROR_DEVICE_IN_USE;
    // must handle drive letters and afs paths
    // DDD_REMOVE_DEFINITION
#endif
    DEBUG_EVENT3("AFS DriveMap","%sDismount Remote[%s]=%x",
                  bForce ? "Forced " : "",szPath,res);
    return (res==ERROR_NOT_CONNECTED)?NO_ERROR:res;
}
Example #3
0
int main(int argc, char ** argv)
{
    NETRESOURCE nr = {0};
    DWORD dwRetVal = 0;
    int c = 0;
    char host[32] = {0};
    LOGINFO LogInfo = {0};

    while ((c = getopt(argc, argv, "h:u:p:e:")) != -1) {
        switch (c) {
        // 目标ip
        case 'h':
            strncpy(host, optarg, 32);
            break;

        // 用户名
        case 'u':
            strncpy(LogInfo.szUserName, optarg, NAME_LEN);
            break;

        // 密码
        case 'p':
            strncpy(LogInfo.szPassword, optarg, PASSWD_LEN);
            break;

        // cmd
        case 'e':
            strncpy(LogInfo.szExcuteCmd, optarg, CMD_LEN);
            break;

        default:
            break;
        }
    }

    char szRemoteName[MAX_PATH] = {0};

    if (host[0])
        sprintf(szRemoteName, "\\\\%s\\%s", host, ADMIN);
    else
        usage();

    if (!LogInfo.szUserName[0] || !LogInfo.szPassword[0])
        usage();

    nr.dwType = RESOURCETYPE_ANY;
    nr.lpLocalName = NULL;
    nr.lpRemoteName = szRemoteName;
    nr.lpProvider =  NULL;
    dwRetVal = WNetAddConnection3(NULL, &nr, LogInfo.szPassword, LogInfo.szUserName, 0);

    if (dwRetVal != NO_ERROR) {
        int a = GetLastError();
        return -1;
    }

    InstallRemoteService(host);
    Client(host, &LogInfo);
    WNetCancelConnection(nr.lpRemoteName, TRUE);
    return 0;
}