home *** CD-ROM | disk | FTP | other *** search
/ Freelog 42 / Freelog042.iso / Alu / Ancestrologie / Sources / InterBase_WI-V6.0.1-server.ZIP / examples / services / start_user_display.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-05  |  5.1 KB  |  154 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <malloc.h>
  4. #include <windows.h>
  5. #include "ibase.h"
  6.  
  7. #define RESPBUF    1024
  8.  
  9. void main (int argc, char *argv)
  10.     {
  11.     char    *user = "SYSDBA",
  12.         *pass = "masterkey",
  13.         *newusr = "newuser",
  14.         *newpass = "newpass";
  15.     
  16.     long    status [20];
  17.     long    *svc_handle = NULL;
  18.     char    svc_name[25], spb_buff[RESPBUF], thd_buff[RESPBUF];
  19.     char    respbuf[RESPBUF], *p = respbuf, *spb = spb_buff, *thd = thd_buff,*x;
  20.     short    spblen, thdlen;
  21.     int    i = 0, cnt=0;
  22.     boolean finished = FALSE;
  23.     char sendbuf[] = {isc_info_svc_get_users};
  24.     ISC_STATUS  loc_status[20], *stat = loc_status;
  25.     
  26.     *spb++ = isc_spb_version;
  27.     *spb++ = isc_spb_current_version;
  28.     
  29.     *spb++ = isc_spb_user_name;
  30.     *spb++ = strlen (user);
  31.     for (x = user; *x;)
  32.         *spb++ = *x++;
  33.     
  34.     *spb++ = isc_spb_password;
  35.     *spb++ = strlen (pass);
  36.     for (x = pass; *x;)
  37.         *spb++ = *x++;
  38.     
  39.     sprintf (svc_name, "service_mgr");
  40.     
  41.     spblen = spb - spb_buff;
  42.     
  43.     if (isc_service_attach (status, 0, svc_name, &svc_handle, spblen, spb_buff))
  44.         {
  45.         isc_print_status (status);
  46.         exit (1);
  47.         }
  48.     
  49.     *thd++ = isc_action_svc_display_user;
  50.     *thd++ = isc_spb_sec_username;
  51.     ADD_SPB_LENGTH (thd, strlen(newusr));
  52.     for (x = newusr; *x;)
  53.         *thd++ = *x++;
  54.     
  55.     thdlen = thd - thd_buff;
  56.     
  57.     printf ("Attach succeed\n");
  58.     
  59.     if (isc_service_start(status, &svc_handle, NULL, thdlen, thd_buff))
  60.         {
  61.         long *vector = status;
  62.         printf ("Unable to start service:\n");
  63.         while (isc_interprete (respbuf, &vector))
  64.             printf ("ERROR: %s\n", respbuf);
  65.         printf ("End of errors\n");
  66.         isc_service_detach (status, &svc_handle);
  67.         exit(1);
  68.         }
  69.     printf ("Start succeed\n");
  70.     
  71.     
  72.     if (isc_service_query (status, &svc_handle, NULL, 0, NULL, sizeof (sendbuf), sendbuf, RESPBUF, respbuf))
  73.         {
  74.         isc_print_status (status);
  75.         isc_service_detach (status, &svc_handle);
  76.         exit(1);
  77.         }
  78.     
  79.     if (*p++ == isc_info_svc_get_users)
  80.         {
  81.         ISC_USHORT len, loop;
  82.         ISC_ULONG  id;
  83.         
  84.         char buffer[50], *buf = buffer;
  85.         
  86.         loop = (ISC_USHORT) isc_vax_integer (p, sizeof (ISC_USHORT));
  87.         p += sizeof (ISC_USHORT);
  88.         
  89.         while (*p != isc_info_end)
  90.             {
  91.             switch (*p++)
  92.                 {
  93.                 case isc_spb_sec_username:
  94.                     len = (ISC_USHORT) isc_vax_integer(p, sizeof(ISC_USHORT));
  95.                     p += sizeof (ISC_USHORT);
  96.                     strncpy (buf, p, len);
  97.                     p += len;
  98.                     buffer[len] = 0;
  99.                     printf ("Username: %s\n", buffer);
  100.                     loop -= (len + sizeof(ISC_USHORT)+1);
  101.                     break;
  102.                     
  103.                 case isc_spb_sec_firstname:
  104.                     len = (ISC_USHORT) isc_vax_integer(p, sizeof(ISC_USHORT));
  105.                     p += sizeof (ISC_USHORT);
  106.                     strncpy (buf, p, len);
  107.                     p += len;
  108.                     buffer[len] = 0;
  109.                     printf ("Firstname: %s\n", buffer);
  110.                     loop -= (len + sizeof(ISC_USHORT)+1);
  111.                     break;
  112.                     
  113.                 case isc_spb_sec_middlename:
  114.                     len = (ISC_USHORT) isc_vax_integer(p, sizeof(ISC_USHORT));
  115.                     p += sizeof (ISC_USHORT);
  116.                     strncpy (buf, p, len);
  117.                     p += len;
  118.                     buffer[len] = 0;
  119.                     printf ("Middlename: %s\n", buffer);
  120.                     loop -= (len + sizeof(ISC_USHORT)+1);
  121.                     break;
  122.                     
  123.                 case isc_spb_sec_lastname:
  124.                     len = (ISC_USHORT) isc_vax_integer(p, sizeof(ISC_USHORT));
  125.                     p += sizeof (ISC_USHORT);
  126.                     strncpy (buf, p, len);
  127.                     p += len;
  128.                     buffer[len] = 0;
  129.                     printf ("Lastname: %s\n", buffer);
  130.                     loop -= (len + sizeof(ISC_USHORT)+1);
  131.                     break;
  132.                     
  133.                 case isc_spb_sec_groupid:
  134.                     id = isc_vax_integer (p, sizeof (ISC_ULONG));
  135.                     p += sizeof (ISC_ULONG);
  136.                     printf ("Group ID: %d\n", id);
  137.                     loop -= (len + sizeof(ISC_ULONG)+1);
  138.                     break;
  139.                     
  140.                 case isc_spb_sec_userid:
  141.                     id = isc_vax_integer (p, sizeof (ISC_ULONG));
  142.                     p += sizeof (ISC_ULONG);
  143.                     printf ("User ID: %d\n", id);
  144.                     loop -= (len + sizeof(ISC_ULONG)+1);
  145.                     break;
  146.                     
  147.                 default: 
  148.                     *x = *p;
  149.                     break;
  150.                 }//switch
  151.             } //endwhile
  152.         }
  153.     isc_service_detach (status, &svc_handle);
  154.     }